mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 21:39:59 +02:00
Compare commits
114 Commits
Author | SHA1 | Date | |
---|---|---|---|
20ceff7eb3 | |||
258f74e883 | |||
d21fa8d4c2 | |||
34ddf5b232 | |||
17674ecf85 | |||
7dfde712a4 | |||
059d4a59c2 | |||
113968ca47 | |||
fedac6cc69 | |||
170a871202 | |||
8599571935 | |||
8af7436f10 | |||
e56c3c5be3 | |||
13b8e9fe16 | |||
a92254107e | |||
d6c2285d7c | |||
52ce633388 | |||
28c4982064 | |||
7363dff25c | |||
826aafa570 | |||
6325882327 | |||
9eb2638119 | |||
2e7bed7925 | |||
cccf5e337a | |||
c9a3f6a1d0 | |||
319f56f1a1 | |||
e8e8db985a | |||
ae54553461 | |||
fef789f366 | |||
fc14fc038b | |||
7656f0b335 | |||
d2e245ea9e | |||
96099a79a8 | |||
5abb55823b | |||
8484a1204c | |||
d7bf01c954 | |||
36c81ff6a9 | |||
988b02abfd | |||
26faf7706b | |||
ab2d08a842 | |||
52273943c6 | |||
8870ba7f06 | |||
4b3c6953ef | |||
17fd4ba820 | |||
411d3677ca | |||
3700ffd7e1 | |||
83604bf3ac | |||
eb44119c3d | |||
9f6055fcb2 | |||
695788e7f5 | |||
906c1fcd61 | |||
8cb7e536d2 | |||
443db47d91 | |||
36a6eea3bc | |||
ec5f12c11a | |||
64425a0884 | |||
bd94090a11 | |||
cf847cba58 | |||
55a080e50a | |||
84739717d6 | |||
def64e920f | |||
cf2f88b38f | |||
f0110baec0 | |||
749a8b99f7 | |||
4f9f00ccf4 | |||
7658c68613 | |||
133ff0e374 | |||
e3c259a278 | |||
b3ff0bdec1 | |||
f9b30586eb | |||
1d58dcfc17 | |||
4407026621 | |||
2565fa8ffb | |||
47309ef52d | |||
687ab00e6e | |||
1b92fe75a1 | |||
53f3d8cf7e | |||
27d082403c | |||
69776e3832 | |||
a99078c1cf | |||
22e404ccbd | |||
71690b524e | |||
6a0ff35872 | |||
0fa56f307f | |||
6cf504d018 | |||
d7844e9762 | |||
7f0064361a | |||
cf047e8347 | |||
c074c65368 | |||
30f0955160 | |||
a76694a1d6 | |||
6e3ef7b326 | |||
47178dbd45 | |||
22cbae33e5 | |||
290dd0b426 | |||
0df474ac9e | |||
c6b75a1966 | |||
295e5e3801 | |||
e2575e05cb | |||
b0e09e346f | |||
cf0e903c89 | |||
bb7bc40b6d | |||
78881b769c | |||
9f750f7a06 | |||
17850e74ce | |||
2fa2552db1 | |||
a4df4aae73 | |||
853ea3d846 | |||
af650c0bd2 | |||
601ef17cf6 | |||
0e48d889eb | |||
24d2ccb4e0 | |||
fab8f9cfcf | |||
94138e0e0d |
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,5 +1,6 @@
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.mailmap export-ignore
|
||||
*.bat text eol=crlf
|
||||
*.pdf -text -diff
|
||||
*.ppm -text -diff
|
||||
|
15
.gitignore
vendored
15
.gitignore
vendored
@ -1,6 +1,7 @@
|
||||
*.l[ao]
|
||||
*.[ao]
|
||||
*.pc
|
||||
.DS_Store
|
||||
.deps
|
||||
.libs
|
||||
/aclocal.m4
|
||||
@ -20,9 +21,11 @@
|
||||
Makefile
|
||||
Makefile.in
|
||||
examples/anim_diff
|
||||
examples/anim_dump
|
||||
examples/[cdv]webp
|
||||
examples/gif2webp
|
||||
examples/img2webp
|
||||
examples/webpinfo
|
||||
examples/webpmux
|
||||
src/webp/config.h*
|
||||
src/webp/stamp-h1
|
||||
@ -31,11 +34,21 @@ src/webp/stamp-h1
|
||||
*.idb
|
||||
*.pdb
|
||||
/iosbuild
|
||||
/WebP.framework
|
||||
/xcframeworkbuild
|
||||
/WebP*.*framework
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
.gradle
|
||||
/build
|
||||
extras/get_disto
|
||||
extras/vwebp_sdl
|
||||
extras/webp_quality
|
||||
tests/fuzzer/advanced_api_fuzzer
|
||||
tests/fuzzer/animation_api_fuzzer
|
||||
tests/fuzzer/animdecoder_fuzzer
|
||||
tests/fuzzer/animencoder_fuzzer
|
||||
tests/fuzzer/demux_api_fuzzer
|
||||
tests/fuzzer/enc_dec_fuzzer
|
||||
tests/fuzzer/mux_demux_api_fuzzer
|
||||
tests/fuzzer/simple_api_fuzzer
|
||||
|
4
AUTHORS
4
AUTHORS
@ -2,9 +2,11 @@ Contributors:
|
||||
- Aidan O'Loan (aidanol at gmail dot com)
|
||||
- Alan Browning (browning at google dot com)
|
||||
- Charles Munger (clm at google dot com)
|
||||
- Cheng Yi (cyi at google dot com)
|
||||
- Christian Duvivier (cduvivier at google dot com)
|
||||
- Djordje Pesut (djordje dot pesut at imgtec dot com)
|
||||
- Hui Su (huisu at google dot com)
|
||||
- Ingvar Stepanyan (rreverser at google dot com)
|
||||
- James Zern (jzern at google dot com)
|
||||
- Jan Engelhardt (jengelh at medozas dot de)
|
||||
- Jehan (jehan at girinstud dot io)
|
||||
@ -21,6 +23,7 @@ Contributors:
|
||||
- Mislav Bradac (mislavm at google dot com)
|
||||
- Nico Weber (thakis at chromium dot org)
|
||||
- Noel Chromium (noel at chromium dot org)
|
||||
- Oliver Wolff (oliver dot wolff at qt dot io)
|
||||
- Owen Rodley (orodley at google dot com)
|
||||
- Parag Salasakar (img dot mips1 at gmail dot com)
|
||||
- Pascal Massimino (pascal dot massimino at gmail dot com)
|
||||
@ -39,5 +42,6 @@ Contributors:
|
||||
- Vikas Arora (vikasa at google dot com)
|
||||
- Vincent Rabaud (vrabaud at google dot com)
|
||||
- Vlad Tsyrklevich (vtsyrklevich at chromium dot org)
|
||||
- Wan-Teh Chang (wtc at google dot com)
|
||||
- Yang Zhang (yang dot zhang at arm dot com)
|
||||
- Yannis Guyon (yguyon at google dot com)
|
||||
|
100
CMakeLists.txt
100
CMakeLists.txt
@ -1,9 +1,24 @@
|
||||
##
|
||||
## Copyright (c) 2020 Google LLC.
|
||||
##
|
||||
## Use of this source code is governed by a BSD-style license
|
||||
## that can be found in the LICENSE file in the root of the source
|
||||
## tree. An additional intellectual property rights grant can be found
|
||||
## in the file PATENTS. All contributing project authors may
|
||||
## be found in the AUTHORS file in the root of the source tree.
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(WebP C)
|
||||
|
||||
# Options for coder / decoder executables.
|
||||
option(WEBP_ENABLE_SIMD "Enable any SIMD optimization." ON)
|
||||
if(NOT EMSCRIPTEN)
|
||||
# Disable SIMD on Emscripten by default, as it's a new unstable Wasm feature.
|
||||
# Users can still explicitly opt-in to make a SIMD-enabled build.
|
||||
set(WEBP_ENABLE_SIMD_DEFAULT ON)
|
||||
endif()
|
||||
option(WEBP_ENABLE_SIMD "Enable any SIMD optimization."
|
||||
${WEBP_ENABLE_SIMD_DEFAULT})
|
||||
option(WEBP_BUILD_ANIM_UTILS "Build animation utilities." ON)
|
||||
option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." ON)
|
||||
option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." ON)
|
||||
@ -26,7 +41,6 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBP_JS)
|
||||
set(WEBP_ENABLE_SIMD OFF)
|
||||
set(WEBP_BUILD_ANIM_UTILS OFF)
|
||||
set(WEBP_BUILD_CWEBP OFF)
|
||||
set(WEBP_BUILD_DWEBP OFF)
|
||||
@ -36,6 +50,10 @@ if(WEBP_BUILD_WEBP_JS)
|
||||
set(WEBP_BUILD_WEBPINFO OFF)
|
||||
set(WEBP_BUILD_WEBPMUX OFF)
|
||||
set(WEBP_BUILD_EXTRAS OFF)
|
||||
|
||||
if(WEBP_ENABLE_SIMD)
|
||||
message("wasm2js does not support SIMD, disabling webp.js generation.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(WEBP_DEP_LIBRARIES)
|
||||
@ -43,7 +61,7 @@ set(WEBP_DEP_INCLUDE_DIRS)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release"
|
||||
CACHE "Build type: Release, Debug, MinSizeRel or RelWithDebInfo" STRING
|
||||
CACHE STRING "Build type: Release, Debug, MinSizeRel or RelWithDebInfo"
|
||||
FORCE)
|
||||
endif()
|
||||
|
||||
@ -164,6 +182,29 @@ add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
# ##############################################################################
|
||||
# Build the webpdecoder library.
|
||||
|
||||
# Creates a source file with an unused stub function in $CMAKE_BINARY_DIR and
|
||||
# adds it to the specified target. Currently used only with Xcode.
|
||||
#
|
||||
# See also:
|
||||
# https://cmake.org/cmake/help/v3.18/command/add_library.html#object-libraries
|
||||
# "Some native build systems (such as Xcode) may not like targets that have
|
||||
# only object files, so consider adding at least one real source file to any
|
||||
# target that references $<TARGET_OBJECTS:objlib>."
|
||||
function(libwebp_add_stub_file TARGET)
|
||||
set(stub_source_dir "${CMAKE_BINARY_DIR}")
|
||||
set(stub_source_file
|
||||
"${stub_source_dir}/libwebp_${TARGET}_stub.c")
|
||||
set(stub_source_code
|
||||
"// Generated file. DO NOT EDIT!\n"
|
||||
"// C source file created for target ${TARGET}.\n"
|
||||
"void libwebp_${TARGET}_stub_function(void)\;\n"
|
||||
"void libwebp_${TARGET}_stub_function(void) {}\n")
|
||||
file(WRITE "${stub_source_file}" ${stub_source_code})
|
||||
|
||||
target_sources(${TARGET} PRIVATE ${stub_source_file})
|
||||
endfunction()
|
||||
|
||||
if(MSVC)
|
||||
# avoid security warnings for e.g., fopen() used in the examples.
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
@ -190,6 +231,9 @@ add_library(webpdecoder
|
||||
$<TARGET_OBJECTS:webpdecode>
|
||||
$<TARGET_OBJECTS:webpdspdecode>
|
||||
$<TARGET_OBJECTS:webputilsdecode>)
|
||||
if(XCODE)
|
||||
libwebp_add_stub_file(webpdecoder)
|
||||
endif()
|
||||
target_link_libraries(webpdecoder ${WEBP_DEP_LIBRARIES})
|
||||
target_include_directories(
|
||||
webpdecoder
|
||||
@ -229,6 +273,9 @@ add_library(webp
|
||||
$<TARGET_OBJECTS:webpdsp>
|
||||
$<TARGET_OBJECTS:webpencode>
|
||||
$<TARGET_OBJECTS:webputils>)
|
||||
if(XCODE)
|
||||
libwebp_add_stub_file(webp)
|
||||
endif()
|
||||
target_link_libraries(webp ${WEBP_DEP_LIBRARIES})
|
||||
target_include_directories(webp
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
@ -349,20 +396,21 @@ if(WEBP_BUILD_ANIM_UTILS
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "EXAMPLEUTIL_SRCS"
|
||||
"example_util_[^ ]*")
|
||||
list(APPEND EXAMPLEUTIL_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h)
|
||||
add_library(exampleutil ${EXAMPLEUTIL_SRCS})
|
||||
add_library(exampleutil STATIC ${EXAMPLEUTIL_SRCS})
|
||||
target_link_libraries(exampleutil imageioutil)
|
||||
target_include_directories(
|
||||
exampleutil
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>)
|
||||
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEIOUTILS_SRCS"
|
||||
"imageio_util_[^ ]*")
|
||||
add_library(imageioutil ${IMAGEIOUTILS_SRCS})
|
||||
add_library(imageioutil STATIC ${IMAGEIOUTILS_SRCS})
|
||||
target_link_libraries(imageioutil webp)
|
||||
|
||||
# Image-decoding utility library.
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS"
|
||||
"imagedec_[^ ]*")
|
||||
add_library(imagedec ${IMAGEDEC_SRCS})
|
||||
add_library(imagedec STATIC ${IMAGEDEC_SRCS})
|
||||
target_link_libraries(imagedec
|
||||
imageioutil
|
||||
webpdemux
|
||||
@ -372,8 +420,8 @@ if(WEBP_BUILD_ANIM_UTILS
|
||||
# Image-encoding utility library.
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS"
|
||||
"imageenc_[^ ]*")
|
||||
add_library(imageenc ${IMAGEENC_SRCS})
|
||||
target_link_libraries(imageenc webp)
|
||||
add_library(imageenc STATIC ${IMAGEENC_SRCS})
|
||||
target_link_libraries(imageenc imageioutil webp)
|
||||
|
||||
set_property(TARGET exampleutil
|
||||
imageioutil
|
||||
@ -466,12 +514,12 @@ if(WEBP_BUILD_VWEBP)
|
||||
target_link_libraries(vwebp
|
||||
${OPENGL_LIBRARIES}
|
||||
exampleutil
|
||||
GLUT::GLUT
|
||||
${GLUT_glut_LIBRARY}
|
||||
imageioutil
|
||||
webp
|
||||
webpdemux)
|
||||
target_include_directories(vwebp
|
||||
PRIVATE GLUT::GLUT
|
||||
PRIVATE ${GLUT_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${OPENGL_INCLUDE_DIR})
|
||||
install(TARGETS vwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
@ -524,7 +572,9 @@ if(WEBP_BUILD_EXTRAS)
|
||||
# webp_quality
|
||||
add_executable(webp_quality ${WEBP_QUALITY_SRCS} ${WEBP_EXTRAS_SRCS})
|
||||
target_link_libraries(webp_quality exampleutil imagedec)
|
||||
target_include_directories(webp_quality PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
target_include_directories(webp_quality
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR})
|
||||
install(TARGETS webp_quality RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
# vwebp_sdl
|
||||
@ -545,18 +595,21 @@ if(WEBP_BUILD_EXTRAS)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBP_JS)
|
||||
# JavaScript version
|
||||
add_executable(webp_js ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
target_link_libraries(webp_js webpdecoder SDL)
|
||||
target_include_directories(webp_js PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(WEBP_HAVE_SDL 1)
|
||||
set_target_properties(
|
||||
webp_js
|
||||
PROPERTIES LINK_FLAGS
|
||||
"-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0 \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]'")
|
||||
set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp)
|
||||
target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
|
||||
# wasm2js does not support SIMD.
|
||||
if(NOT WEBP_ENABLE_SIMD)
|
||||
# JavaScript version
|
||||
add_executable(webp_js ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
target_link_libraries(webp_js webpdecoder SDL)
|
||||
target_include_directories(webp_js PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(WEBP_HAVE_SDL 1)
|
||||
set_target_properties(
|
||||
webp_js
|
||||
PROPERTIES LINK_FLAGS "-s WASM=0 \
|
||||
-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0 \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]'")
|
||||
set_target_properties(webp_js PROPERTIES OUTPUT_NAME webp)
|
||||
target_compile_definitions(webp_js PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
|
||||
endif()
|
||||
|
||||
# WASM version
|
||||
add_executable(webp_wasm ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
@ -607,7 +660,6 @@ if(WEBP_BUILD_ANIM_UTILS)
|
||||
endif()
|
||||
|
||||
# Install the different headers and libraries.
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS ${INSTALLED_LIBRARIES}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp
|
||||
|
106
ChangeLog
106
ChangeLog
@ -1,3 +1,109 @@
|
||||
170a8712 Fix check_c_source_compiles with pthread.
|
||||
85995719 disable CombinedShannonEntropy_SSE2 on x86
|
||||
8af7436f Merge "{ios,xcframework}build.sh: make min version(s) more visible" into 1.2.0
|
||||
e56c3c5b pngdec: raise memory limit if needed
|
||||
13b8e9fe {ios,xcframework}build.sh: make min version(s) more visible
|
||||
a9225410 animdecoder_fuzzer: fix memory leak
|
||||
d6c2285d update gradle to 6.1.1
|
||||
52ce6333 update NEWS
|
||||
28c49820 bump version to 1.2.0
|
||||
7363dff2 webp/encode.h: restore WEBP_ENCODER_ABI_VERSION to v1.1.0
|
||||
826aafa5 update AUTHORS
|
||||
63258823 animdecoder_fuzzer: validate canvas size
|
||||
9eb26381 CMake: remove duplicate "include(GNUInstallDirs)"
|
||||
2e7bed79 WebPPicture: clarify the ownership of user-owned data.
|
||||
cccf5e33 webpmux: add an '-set loop <value>' option
|
||||
c9a3f6a1 Merge changes Ie29f9867,I289c54c4
|
||||
319f56f1 iosbuild.sh: sync some aspects of xcframeworkbuild.sh
|
||||
e8e8db98 add xcframeworkbuild.sh
|
||||
ae545534 dsp.h: allow config.h to override MSVC SIMD autodetection
|
||||
fef789f3 Merge "cmake: fix per-file assembly flags"
|
||||
fc14fc03 Have C encoding predictors use decoding predictors.
|
||||
7656f0b3 README,cosmetics: fix a couple typos
|
||||
d2e245ea cmake: disable webp.js if WEBP_ENABLE_SIMD=1
|
||||
96099a79 cmake: fix per-file assembly flags
|
||||
5abb5582 Merge "cmake: fix compilation w/Xcode generator"
|
||||
8484a120 cmake: fix compilation w/Xcode generator
|
||||
d7bf01c9 Merge changes Ifcae0f38,Iee2d7401
|
||||
36c81ff6 WASM-SIMD: port 2 patches from rreverser@'s tree
|
||||
988b02ab Merge "Couple of fixes to allow SIMD on Emscripten"
|
||||
26faf770 wicdec: fail with animated images
|
||||
ab2d08a8 [cd]webp: document lack of animated webp support
|
||||
52273943 Couple of fixes to allow SIMD on Emscripten
|
||||
8870ba7f Fix skia bug #10952
|
||||
4b3c6953 Detect if StoreFrame read more than anmf_payload_size bytes
|
||||
17fd4ba8 webp/decode.h,cosmetics: normalize 'flip' comment
|
||||
411d3677 remove some unreachable break statements
|
||||
3700ffd7 WebPPictureHasTransparency: remove unreachable return
|
||||
83604bf3 {animencoder,enc_dec}_fuzzer: convert some abort()s to returns
|
||||
eb44119c Merge changes I8ae09473,I678c8b1e
|
||||
9f6055fc fuzz_utils.h: rename max() to Max()
|
||||
695788e7 fuzz_utils.h: make functions WEBP_INLINE
|
||||
906c1fcd make ImgIoUtilReadFile use WebPMalloc instead of malloc
|
||||
8cb7e536 rename demux_api_fuzzer.c -> mux_demux_api_fuzzer.c
|
||||
443db47d add animdecoder_fuzzer.cc
|
||||
36a6eea3 Merge "import fuzzers from oss-fuzz/chromium"
|
||||
ec5f12c1 Makefile.vc: remove deprecated /Gm option
|
||||
64425a08 picture_tools_enc: fix windows build warning
|
||||
bd94090a import fuzzers from oss-fuzz/chromium
|
||||
cf847cba use WEBP_DSP_INIT_FUNC for Init{GammaTables*,GetCoeffs}
|
||||
55a080e5 Add WebPReplaceTransparentPixels() in dsp
|
||||
84739717 GetBackgroundColorGIF: promote to uint32_t before << 24
|
||||
def64e92 cwebp: Fix -print_psnr for near_lossless
|
||||
cf2f88b3 Add palette and spatial for q >= 75 and -m 5
|
||||
f0110bae Add no-color cache configuration to the cruncher
|
||||
749a8b99 Better estimate of the cache cost.
|
||||
4f9f00cc Use spatial predictors on top of palette no matter what.
|
||||
7658c686 Add spatial prediction on top of palette in cruncher.
|
||||
133ff0e3 webp_js: force WASM=0 option explicitly
|
||||
e3c259a2 Fix integer overflow in EmitFancyRGB.
|
||||
b3ff0bde man/{gif2,img2}webp,webpmux: normalize some wording
|
||||
f9b30586 fix ABI breakage introduced by 6a0ff358
|
||||
1d58dcfc README.webp_js: update note about emscripten version
|
||||
44070266 README.webp_js: s/fastcomp/upstream/
|
||||
2565fa8f README.webp_js: update cmake command
|
||||
47309ef5 webp: WEBP_OFFSET_PTR()
|
||||
687ab00e DC{4,8,16}_NEON: replace vmovl w/vaddl
|
||||
1b92fe75 DC16_NEON,aarch64: use vaddlv
|
||||
53f3d8cf dec_neon,DC8_NEON: use vaddlv instead of movl+vaddv
|
||||
27d08240 Fix integer overflow in WebPAnimDecoderGetNext()
|
||||
69776e38 Merge "remove call to MBAnalyzeBestIntra4Mode for method >= 5"
|
||||
a99078c1 remove call to MBAnalyzeBestIntra4Mode for method >= 5
|
||||
22e404cc CMakeLists.txt: fix set(CACHE) argument order
|
||||
71690b52 fix MSVC warning
|
||||
6a0ff358 Enc: add a qmin / qmax range for quality factor
|
||||
0fa56f30 Merge tag 'v1.1.0'
|
||||
6cf504d0 PNM decoding: handle max_value != 255
|
||||
d7844e97 update ChangeLog (tag: v1.1.0-rc2, tag: v1.1.0, origin/1.1.0)
|
||||
7f006436 Makefile.vc: fix webp_quality.exe link
|
||||
cf047e83 Makefile.vc: fix webp_quality.exe link
|
||||
c074c653 update NEWS
|
||||
30f09551 bump version to 1.1.0
|
||||
a76694a1 update AUTHORS
|
||||
6e3ef7b3 extras: fix WEBP_SWAP_16BIT_CSP check
|
||||
47178dbd extras: add WebPUnmultiplyARGB() convenience function
|
||||
22cbae33 idec_dec: fix 0 offset of NULL pointer
|
||||
290dd0b4 muxread: fix 0 offset of NULL pointer
|
||||
0df474ac Merge "lossless_(enc_|)sse2: avoid offsetting a NULL pointer"
|
||||
c6b75a19 lossless_(enc_|)sse2: avoid offsetting a NULL pointer
|
||||
295e5e38 fix UBSAN warning
|
||||
e2575e05 DC8_NEON,aarch64: use vaddv
|
||||
b0e09e34 dec_neon: Fix build failure under some toolchains
|
||||
cf0e903c dsp/lossless: Fix non gcc ARM builds
|
||||
bb7bc40b Remove ubsan errors.
|
||||
78881b76 CMake: fix GLUT library link
|
||||
9f750f7a cmake: fix BUILD_SHARED_LIBS build on mac
|
||||
17850e74 libwebp: Remove char-subscripts warning in pnmdec.c
|
||||
2fa2552d Merge "Expose WebPMalloc() in addition to WebPFree()"
|
||||
a4df4aae Expose WebPMalloc() in addition to WebPFree()
|
||||
853ea3d8 imageio/tiff: Return error before allocating bad tile size
|
||||
af650c0b Fix a Wxor-used-as-pow false positive
|
||||
601ef17c libwebp.py: update to swig 3.0.12
|
||||
0e48d889 bugfix: last alpha rows were incorrectly decoded
|
||||
24d2ccb4 webp: Fix imageio ReadPNM() TUPLTYPE
|
||||
fab8f9cf cosmetics: normalize '*' association
|
||||
94138e0e update .gitignore
|
||||
0fe1a89d update ChangeLog (tag: v1.0.3-rc1, tag: v1.0.3)
|
||||
2ad0916d update NEWS
|
||||
1287362b bump version to 1.0.3
|
||||
7b968cc2 update AUTHORS
|
||||
|
10
Makefile.vc
10
Makefile.vc
@ -28,7 +28,7 @@ PLATFORM_LDFLAGS = /SAFESEH
|
||||
|
||||
NOLOGO = /nologo
|
||||
CCNODBG = cl.exe $(NOLOGO) /O2 /DNDEBUG
|
||||
CCDEBUG = cl.exe $(NOLOGO) /Od /Gm /Zi /D_DEBUG /RTC1
|
||||
CCDEBUG = cl.exe $(NOLOGO) /Od /Zi /D_DEBUG /RTC1
|
||||
CFLAGS = /I. /Isrc $(NOLOGO) /W3 /EHsc /c
|
||||
CFLAGS = $(CFLAGS) /DWIN32 /D_CRT_SECURE_NO_WARNINGS /DWIN32_LEAN_AND_MEAN
|
||||
LDFLAGS = /LARGEADDRESSAWARE /MANIFEST /NXCOMPAT /DYNAMICBASE
|
||||
@ -391,7 +391,13 @@ $(DIRBIN)\get_disto.exe: $(IMAGEIO_DEC_OBJS) $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\get_disto.exe: $(LIBWEBPDEMUX) $(LIBWEBP)
|
||||
$(DIRBIN)\webp_quality.exe: $(DIROBJ)\extras\webp_quality.obj
|
||||
$(DIRBIN)\webp_quality.exe: $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\webp_quality.exe: $(EXTRAS_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\webp_quality.exe: $(EXTRAS_OBJS)
|
||||
# EXTRA_OBJS requires private symbols from dsp. Explicitly add those when
|
||||
# building libwebp as a dll.
|
||||
!IF "$(DLLBUILD)" == "TRUE"
|
||||
$(DIRBIN)\webp_quality.exe: $(DSP_DEC_OBJS)
|
||||
!ENDIF
|
||||
$(DIRBIN)\webp_quality.exe: $(LIBWEBP)
|
||||
$(DIRBIN)\webpinfo.exe: $(DIROBJ)\examples\webpinfo.obj
|
||||
$(DIRBIN)\webpinfo.exe: $(IMAGEIO_DEC_OBJS)
|
||||
$(DIRBIN)\webpinfo.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS)
|
||||
|
23
NEWS
23
NEWS
@ -1,3 +1,26 @@
|
||||
- 12/23/2020: version 1.2.0
|
||||
* API changes:
|
||||
- libwebp:
|
||||
encode.h: add a qmin / qmax range for quality factor (cwebp adds -qrange)
|
||||
* lossless encoder improvements
|
||||
* SIMD support for Wasm builds
|
||||
* add xcframeworkbuild.sh, supports Mac Catalyst builds
|
||||
* import fuzzers from oss-fuzz & chromium (#409)
|
||||
* webpmux: add an '-set loop <value>' option (#494)
|
||||
* toolchain updates and bug fixes (#449, #463, #470, #475, #477, #478, #479,
|
||||
#488, #491)
|
||||
|
||||
- 12/18/2019: version 1.1.0
|
||||
* API changes:
|
||||
- libwebp:
|
||||
WebPMalloc (issue #442)
|
||||
- extras:
|
||||
WebPUnmultiplyARGB
|
||||
* alpha decode fix (issue #439)
|
||||
* toolchain updates and bug fixes
|
||||
(chromium: #1026858, #1027136, #1027409, #1028620, #1028716, #995200)
|
||||
(oss-fuzz: #19430, #19447)
|
||||
|
||||
- 7/4/2019: version 1.0.3
|
||||
This is a binary compatible release.
|
||||
* resize fixes for Nx1 sizes and the addition of non-opaque alpha values for
|
||||
|
14
README
14
README
@ -4,7 +4,7 @@
|
||||
\__\__/\____/\_____/__/ ____ ___
|
||||
/ _/ / \ \ / _ \/ _/
|
||||
/ \_/ / / \ \ __/ \__
|
||||
\____/____/\_____/_____/____/v1.0.3
|
||||
\____/____/\_____/_____/____/v1.2.0
|
||||
|
||||
Description:
|
||||
============
|
||||
@ -113,7 +113,7 @@ make install
|
||||
|
||||
CMake:
|
||||
------
|
||||
With CMake, you can compile libwebp, cwebp, dwebp, gif2web, img2webp, webpinfo
|
||||
With CMake, you can compile libwebp, cwebp, dwebp, gif2webp, img2webp, webpinfo
|
||||
and the JS bindings.
|
||||
|
||||
Prerequisites:
|
||||
@ -225,6 +225,7 @@ Usage:
|
||||
|
||||
If input size (-s) for an image is not specified, it is
|
||||
assumed to be a PNG, JPEG, TIFF or WebP file.
|
||||
Note: Animated PNG and WebP files are not supported.
|
||||
|
||||
Options:
|
||||
-h / -help ............. short help
|
||||
@ -254,6 +255,8 @@ Options:
|
||||
-partition_limit <int> . limit quality to fit the 512k limit on
|
||||
the first partition (0=no degradation ... 100=full)
|
||||
-pass <int> ............ analysis pass number (1..10)
|
||||
-qrange <min> <max> .... specifies the permissible quality range
|
||||
(default: 0 100)
|
||||
-crop <x> <y> <w> <h> .. crop picture with the given rectangle
|
||||
-resize <w> <h> ........ resize picture (after any cropping)
|
||||
-mt .................... use multi-threading if available
|
||||
@ -294,6 +297,7 @@ Experimental Options:
|
||||
-af .................... auto-adjust filter strength
|
||||
-pre <int> ............. pre-processing filter
|
||||
|
||||
|
||||
The main options you might want to try in order to further tune the
|
||||
visual quality are:
|
||||
-preset
|
||||
@ -341,7 +345,9 @@ The full list of options is available using -h:
|
||||
> dwebp -h
|
||||
Usage: dwebp in_file [options] [-o out_file]
|
||||
|
||||
Decodes the WebP image file to PNG format [Default]
|
||||
Decodes the WebP image file to PNG format [Default].
|
||||
Note: Animated WebP files are not supported.
|
||||
|
||||
Use following options to convert into alternate image formats:
|
||||
-pam ......... save the raw RGBA samples as a color PAM
|
||||
-ppm ......... save the raw RGB samples as a color PPM
|
||||
@ -423,7 +429,7 @@ Prerequisites:
|
||||
1) OpenGL & OpenGL Utility Toolkit (GLUT)
|
||||
Linux:
|
||||
$ sudo apt-get install freeglut3-dev mesa-common-dev
|
||||
Mac + XCode:
|
||||
Mac + Xcode:
|
||||
- These libraries should be available in the OpenGL / GLUT frameworks.
|
||||
Windows:
|
||||
http://freeglut.sourceforge.net/index.php#download
|
||||
|
@ -1,7 +1,7 @@
|
||||
__ __ ____ ____ ____ __ __ _ __ __
|
||||
/ \\/ \/ _ \/ _ \/ _ \/ \ \/ \___/_ / _\
|
||||
\ / __/ _ \ __/ / / (_/ /__
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.0.3
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.2.0
|
||||
|
||||
|
||||
Description:
|
||||
@ -44,6 +44,7 @@ GET_OPTIONS:
|
||||
|
||||
SET_OPTIONS:
|
||||
Set color profile/metadata:
|
||||
loop LOOP_COUNT set the loop count
|
||||
icc file.icc set ICC profile
|
||||
exif file.exif set EXIF metadata
|
||||
xmp file.xmp set XMP metadata
|
||||
|
@ -19,21 +19,20 @@ using Emscripten and CMake.
|
||||
accessible. This is the toolchain file used by CMake to invoke Emscripten.
|
||||
If $EMSCRIPTEN is unset search for Emscripten.cmake under $EMSDK and set
|
||||
$EMSCRIPTEN accordingly, for example:
|
||||
unix-like environments: export EMSCRIPTEN=$EMSDK/fastcomp/emscripten
|
||||
windows: set EMSCRIPTEN=%EMSDK%\fastcomp\emscripten
|
||||
unix-like environments: export EMSCRIPTEN=$EMSDK/upstream/emscripten
|
||||
windows: set EMSCRIPTEN=%EMSDK%\upstream\emscripten
|
||||
|
||||
- configure the project 'WEBP_JS' with CMake using:
|
||||
|
||||
cd webp_js && \
|
||||
cmake -DWEBP_BUILD_WEBP_JS=ON \
|
||||
-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \
|
||||
../
|
||||
|
||||
- compile webp.js using 'make'.
|
||||
|
||||
- that's it! Upon completion, you should have the webp.js and
|
||||
webp.js.mem files generated.
|
||||
webp.wasm files generated.
|
||||
|
||||
The callable JavaScript function is WebPToSDL(), which decodes a raw WebP
|
||||
bitstream into a canvas. See webp_js/index.html for a simple usage sample
|
||||
@ -59,8 +58,9 @@ Web-Assembly (WASM) version:
|
||||
See webp_js/index_wasm.html for a simple demo page using the WASM version
|
||||
of the library.
|
||||
|
||||
You will need a fairly recent version of Emscripten (at least 1.37.8) and of
|
||||
your WASM-enabled browser to run this version. Consider it very experimental!
|
||||
You will need a fairly recent version of Emscripten (at least 1.37.8,
|
||||
latest-upstream is recommended) and of your WASM-enabled browser to run this
|
||||
version.
|
||||
|
||||
Caveat:
|
||||
=======
|
||||
@ -78,3 +78,6 @@ Caveat:
|
||||
https://github.com/kripken/emscripten/issues/3788
|
||||
|
||||
Therefore, SSE2 optimization is currently disabled in CMakeLists.txt.
|
||||
|
||||
- If WEBP_ENABLE_SIMD is set to 1 the JavaScript version (webp.js) will be
|
||||
disabled as wasm2js does not support SIMD.
|
||||
|
@ -432,8 +432,3 @@ model {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Task to generate the wrapper.
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '2.13'
|
||||
}
|
||||
|
@ -93,10 +93,6 @@
|
||||
/* Define to the version of this package. */
|
||||
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#cmakedefine PTHREAD_CREATE_JOINABLE 1
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#cmakedefine STDC_HEADERS 1
|
||||
|
||||
|
@ -31,9 +31,17 @@ endfunction()
|
||||
set(WEBP_SIMD_FLAGS "SSE41;SSE2;MIPS32;MIPS_DSP_R2;NEON;MSA")
|
||||
set(WEBP_SIMD_FILE_EXTENSIONS
|
||||
"_sse41.c;_sse2.c;_mips32.c;_mips_dsp_r2.c;_neon.c;_msa.c")
|
||||
if(MSVC)
|
||||
# MSVC does not have a SSE4 flag but AVX support implies SSE4 support.
|
||||
set(SIMD_ENABLE_FLAGS "/arch:AVX;/arch:SSE2;;;;")
|
||||
if(MSVC AND CMAKE_C_COMPILER_ID STREQUAL "MSVC")
|
||||
# With at least Visual Studio 12 (2013)+ /arch is not necessary to build SSE2
|
||||
# or SSE4 code unless a lesser /arch is forced. MSVC does not have a SSE4
|
||||
# flag, but an AVX one. Using that with SSE4 code risks generating illegal
|
||||
# instructions when used on machines with SSE4 only. The flags are left for
|
||||
# older (untested) versions to avoid any potential compatibility issues.
|
||||
if(MSVC_VERSION GREATER_EQUAL 1800 AND NOT CMAKE_C_FLAGS MATCHES "/arch:")
|
||||
set(SIMD_ENABLE_FLAGS)
|
||||
else()
|
||||
set(SIMD_ENABLE_FLAGS "/arch:AVX;/arch:SSE2;;;;")
|
||||
endif()
|
||||
set(SIMD_DISABLE_FLAGS)
|
||||
else()
|
||||
set(SIMD_ENABLE_FLAGS
|
||||
@ -57,9 +65,14 @@ endif()
|
||||
|
||||
list(LENGTH WEBP_SIMD_FLAGS WEBP_SIMD_FLAGS_LENGTH)
|
||||
math(EXPR WEBP_SIMD_FLAGS_RANGE "${WEBP_SIMD_FLAGS_LENGTH} - 1")
|
||||
unset(HIGHEST_SSE_FLAG)
|
||||
|
||||
foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
# With Emscripten 2.0.9 -msimd128 -mfpu=neon will enable NEON, but the
|
||||
# source will fail to compile.
|
||||
if(EMSCRIPTEN AND ${I_SIMD} GREATER_EQUAL 2)
|
||||
break()
|
||||
endif()
|
||||
|
||||
list(GET WEBP_SIMD_FLAGS ${I_SIMD} WEBP_SIMD_FLAG)
|
||||
|
||||
# First try with no extra flag added as the compiler might have default flags
|
||||
@ -70,10 +83,15 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||
if(NOT WEBP_HAVE_${WEBP_SIMD_FLAG})
|
||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||
if(EMSCRIPTEN)
|
||||
set(SIMD_COMPILE_FLAG "-msimd128 ${SIMD_COMPILE_FLAG}")
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||
else()
|
||||
if(MSVC)
|
||||
if(MSVC AND SIMD_ENABLE_FLAGS)
|
||||
# The detection for SSE2/SSE4 support under MSVC is based on the compiler
|
||||
# version so e.g., clang-cl will require flags to enable the assembly.
|
||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||
else()
|
||||
set(SIMD_COMPILE_FLAG " ")
|
||||
@ -84,17 +102,10 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
|
||||
"src/dsp/*${WEBP_SIMD_FILE_EXTENSION}")
|
||||
if(WEBP_HAVE_${WEBP_SIMD_FLAG})
|
||||
if(${I_SIMD} LESS 2 AND NOT HIGHEST_SSE_FLAG)
|
||||
set(HIGHEST_SSE_FLAG ${SIMD_COMPILE_FLAG})
|
||||
endif()
|
||||
# Memorize the file and flags.
|
||||
foreach(FILE ${SIMD_FILES})
|
||||
list(APPEND WEBP_SIMD_FILES_TO_INCLUDE ${FILE})
|
||||
if(${I_SIMD} LESS 2)
|
||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${HIGHEST_SSE_FLAG})
|
||||
else()
|
||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${SIMD_COMPILE_FLAG})
|
||||
endif()
|
||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${SIMD_COMPILE_FLAG})
|
||||
endforeach()
|
||||
else()
|
||||
# Remove the file from the list.
|
||||
|
@ -22,20 +22,23 @@ check_c_source_compiles("
|
||||
" HAVE_BUILTIN_BSWAP64)
|
||||
|
||||
# Check for libraries.
|
||||
find_package(Threads)
|
||||
if(NOT WEBP_BUILD_WEBP_JS)
|
||||
# Disable pThreads for WASM.
|
||||
find_package(Threads)
|
||||
endif()
|
||||
if(Threads_FOUND)
|
||||
if(CMAKE_USE_PTHREADS_INIT)
|
||||
# work around cmake bug on QNX (https://cmake.org/Bug/view.php?id=11333)
|
||||
if(CMAKE_USE_PTHREADS_INIT AND NOT CMAKE_SYSTEM_NAME STREQUAL "QNX")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")
|
||||
endif()
|
||||
foreach(PTHREAD_TEST HAVE_PTHREAD_PRIO_INHERIT PTHREAD_CREATE_UNDETACHED)
|
||||
check_c_source_compiles("
|
||||
#include <pthread.h>
|
||||
int main (void) {
|
||||
int attr = ${PTHREAD_TEST};
|
||||
return attr;
|
||||
}
|
||||
" ${PTHREAD_TEST})
|
||||
endforeach()
|
||||
check_c_source_compiles("
|
||||
#include <pthread.h>
|
||||
int main (void) {
|
||||
int attr = PTHREAD_PRIO_INHERIT;
|
||||
return attr;
|
||||
}
|
||||
" FLAG_HAVE_PTHREAD_PRIO_INHERIT)
|
||||
set(HAVE_PTHREAD_PRIO_INHERIT ${FLAG_HAVE_PTHREAD_PRIO_INHERIT})
|
||||
list(APPEND WEBP_DEP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
set(WEBP_USE_THREAD ${Threads_FOUND})
|
||||
|
@ -1,4 +1,4 @@
|
||||
AC_INIT([libwebp], [1.0.3],
|
||||
AC_INIT([libwebp], [1.2.0],
|
||||
[https://bugs.chromium.org/p/webp],,
|
||||
[http://developers.google.com/speed/webp])
|
||||
AC_CANONICAL_HOST
|
||||
@ -80,6 +80,7 @@ TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wparentheses-equality])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshadow])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshorten-64-to-32])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wundef])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunreachable-code-aggressive])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunreachable-code])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunused-but-set-variable])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunused])
|
||||
|
@ -60,15 +60,15 @@ static int AllocateFrames(AnimatedImage* const image, uint32_t num_frames) {
|
||||
!CheckSizeForOverflow(total_frame_size)) {
|
||||
return 0;
|
||||
}
|
||||
mem = (uint8_t*)malloc((size_t)total_size);
|
||||
frames = (DecodedFrame*)malloc((size_t)total_frame_size);
|
||||
mem = (uint8_t*)WebPMalloc((size_t)total_size);
|
||||
frames = (DecodedFrame*)WebPMalloc((size_t)total_frame_size);
|
||||
|
||||
if (mem == NULL || frames == NULL) {
|
||||
free(mem);
|
||||
free(frames);
|
||||
WebPFree(mem);
|
||||
WebPFree(frames);
|
||||
return 0;
|
||||
}
|
||||
free(image->raw_mem);
|
||||
WebPFree(image->raw_mem);
|
||||
image->num_frames = num_frames;
|
||||
image->frames = frames;
|
||||
for (i = 0; i < num_frames; ++i) {
|
||||
@ -82,8 +82,8 @@ static int AllocateFrames(AnimatedImage* const image, uint32_t num_frames) {
|
||||
|
||||
void ClearAnimatedImage(AnimatedImage* const image) {
|
||||
if (image != NULL) {
|
||||
free(image->raw_mem);
|
||||
free(image->frames);
|
||||
WebPFree(image->raw_mem);
|
||||
WebPFree(image->frames);
|
||||
image->num_frames = 0;
|
||||
image->frames = NULL;
|
||||
image->raw_mem = NULL;
|
||||
@ -165,7 +165,7 @@ static int DumpFrame(const char filename[], const char dump_folder[],
|
||||
base_name = (base_name == NULL) ? (const W_CHAR*)filename : base_name + 1;
|
||||
max_len = WSTRLEN(dump_folder) + 1 + WSTRLEN(base_name)
|
||||
+ strlen("_frame_") + strlen(".pam") + 8;
|
||||
file_name = (W_CHAR*)malloc(max_len * sizeof(*file_name));
|
||||
file_name = (W_CHAR*)WebPMalloc(max_len * sizeof(*file_name));
|
||||
if (file_name == NULL) goto End;
|
||||
|
||||
if (WSNPRINTF(file_name, max_len, "%s/%s_frame_%d.pam",
|
||||
@ -197,7 +197,7 @@ static int DumpFrame(const char filename[], const char dump_folder[],
|
||||
ok = 1;
|
||||
End:
|
||||
if (f != NULL) fclose(f);
|
||||
free(file_name);
|
||||
WebPFree(file_name);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -405,7 +405,7 @@ static uint32_t GetBackgroundColorGIF(GifFileType* gif) {
|
||||
return 0xffffffff; // Invalid: assume white.
|
||||
} else {
|
||||
const GifColorType color = color_map->Colors[gif->SBackGroundColor];
|
||||
return (0xff << 24) |
|
||||
return (0xffu << 24) |
|
||||
(color.Red << 16) |
|
||||
(color.Green << 8) |
|
||||
(color.Blue << 0);
|
||||
|
189
examples/cwebp.c
189
examples/cwebp.c
@ -12,6 +12,7 @@
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -23,6 +24,7 @@
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "../imageio/webpdec.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "./unicode.h"
|
||||
#include "webp/encode.h"
|
||||
@ -92,7 +94,7 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
WebPFree((void*)data);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -119,7 +121,7 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
WebPFree((void*)data);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -128,7 +130,8 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
static void AllocExtraInfo(WebPPicture* const pic) {
|
||||
const int mb_w = (pic->width + 15) / 16;
|
||||
const int mb_h = (pic->height + 15) / 16;
|
||||
pic->extra_info = (uint8_t*)malloc(mb_w * mb_h * sizeof(*pic->extra_info));
|
||||
pic->extra_info =
|
||||
(uint8_t*)WebPMalloc(mb_w * mb_h * sizeof(*pic->extra_info));
|
||||
}
|
||||
|
||||
static void PrintByteCount(const int bytes[4], int total_size,
|
||||
@ -147,7 +150,7 @@ static void PrintPercents(const int counts[4]) {
|
||||
int s;
|
||||
const int total = counts[0] + counts[1] + counts[2] + counts[3];
|
||||
for (s = 0; s < 4; ++s) {
|
||||
fprintf(stderr, "| %2d%%", (int)(100. * counts[s] / total + .5));
|
||||
fprintf(stderr, "| %3d%%", (int)(100. * counts[s] / total + .5));
|
||||
}
|
||||
fprintf(stderr, "| %7d\n", total);
|
||||
}
|
||||
@ -524,6 +527,7 @@ static void HelpLong(void) {
|
||||
printf(" cwebp [-preset <...>] [options] in_file [-o out_file]\n\n");
|
||||
printf("If input size (-s) for an image is not specified, it is\n"
|
||||
"assumed to be a PNG, JPEG, TIFF or WebP file.\n");
|
||||
printf("Note: Animated PNG and WebP files are not supported.\n");
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
printf("Windows builds can take as input any of the files handled by WIC.\n");
|
||||
#endif
|
||||
@ -564,6 +568,8 @@ static void HelpLong(void) {
|
||||
printf(" "
|
||||
"the first partition (0=no degradation ... 100=full)\n");
|
||||
printf(" -pass <int> ............ analysis pass number (1..10)\n");
|
||||
printf(" -qrange <min> <max> .... specifies the permissible quality range\n"
|
||||
" (default: 0 100)\n");
|
||||
printf(" -crop <x> <y> <w> <h> .. crop picture with the given rectangle\n");
|
||||
printf(" -resize <w> <h> ........ resize picture (after any cropping)\n");
|
||||
printf(" -mt .................... use multi-threading if available\n");
|
||||
@ -640,10 +646,10 @@ static const char* const kErrorMessages[VP8_ENC_ERROR_LAST] = {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
int return_value = -1;
|
||||
const char *in_file = NULL, *out_file = NULL, *dump_file = NULL;
|
||||
FILE *out = NULL;
|
||||
const char* in_file = NULL, *out_file = NULL, *dump_file = NULL;
|
||||
FILE* out = NULL;
|
||||
int c;
|
||||
int short_output = 0;
|
||||
int quiet = 0;
|
||||
@ -663,6 +669,7 @@ int main(int argc, const char *argv[]) {
|
||||
WebPConfig config;
|
||||
WebPAuxStats stats;
|
||||
WebPMemoryWriter memory_writer;
|
||||
int use_memory_writer;
|
||||
Metadata metadata;
|
||||
Stopwatch stop_watch;
|
||||
|
||||
@ -690,9 +697,9 @@ int main(int argc, const char *argv[]) {
|
||||
} else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
|
||||
HelpLong();
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-o") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-o") && c + 1 < argc) {
|
||||
out_file = (const char*)GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-d") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-d") && c + 1 < argc) {
|
||||
dump_file = (const char*)GET_WARGV(argv, ++c);
|
||||
config.show_compressed = 1;
|
||||
} else if (!strcmp(argv[c], "-print_psnr")) {
|
||||
@ -706,7 +713,7 @@ int main(int argc, const char *argv[]) {
|
||||
print_distortion = 2;
|
||||
} else if (!strcmp(argv[c], "-short")) {
|
||||
++short_output;
|
||||
} else if (!strcmp(argv[c], "-s") && c < argc - 2) {
|
||||
} else if (!strcmp(argv[c], "-s") && c + 2 < argc) {
|
||||
picture.width = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
picture.height = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
if (picture.width > WEBP_MAX_DIMENSION || picture.width < 0 ||
|
||||
@ -716,30 +723,30 @@ int main(int argc, const char *argv[]) {
|
||||
picture.width, picture.height);
|
||||
goto Error;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-m") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-m") && c + 1 < argc) {
|
||||
config.method = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
use_lossless_preset = 0; // disable -z option
|
||||
} else if (!strcmp(argv[c], "-q") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-q") && c + 1 < argc) {
|
||||
config.quality = ExUtilGetFloat(argv[++c], &parse_error);
|
||||
use_lossless_preset = 0; // disable -z option
|
||||
} else if (!strcmp(argv[c], "-z") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-z") && c + 1 < argc) {
|
||||
lossless_preset = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
if (use_lossless_preset != 0) use_lossless_preset = 1;
|
||||
} else if (!strcmp(argv[c], "-alpha_q") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-alpha_q") && c + 1 < argc) {
|
||||
config.alpha_quality = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-alpha_method") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-alpha_method") && c + 1 < argc) {
|
||||
config.alpha_compression = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-alpha_cleanup")) {
|
||||
// This flag is obsolete, does opposite of -exact.
|
||||
config.exact = 0;
|
||||
} else if (!strcmp(argv[c], "-exact")) {
|
||||
config.exact = 1;
|
||||
} else if (!strcmp(argv[c], "-blend_alpha") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-blend_alpha") && c + 1 < argc) {
|
||||
blend_alpha = 1;
|
||||
// background color is given in hex with an optional '0x' prefix
|
||||
background_color = ExUtilGetInt(argv[++c], 16, &parse_error);
|
||||
background_color = background_color & 0x00ffffffu;
|
||||
} else if (!strcmp(argv[c], "-alpha_filter") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-alpha_filter") && c + 1 < argc) {
|
||||
++c;
|
||||
if (!strcmp(argv[c], "none")) {
|
||||
config.alpha_filtering = 0;
|
||||
@ -755,10 +762,10 @@ int main(int argc, const char *argv[]) {
|
||||
keep_alpha = 0;
|
||||
} else if (!strcmp(argv[c], "-lossless")) {
|
||||
config.lossless = 1;
|
||||
} else if (!strcmp(argv[c], "-near_lossless") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-near_lossless") && c + 1 < argc) {
|
||||
config.near_lossless = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
config.lossless = 1; // use near-lossless only with lossless
|
||||
} else if (!strcmp(argv[c], "-hint") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-hint") && c + 1 < argc) {
|
||||
++c;
|
||||
if (!strcmp(argv[c], "photo")) {
|
||||
config.image_hint = WEBP_HINT_PHOTO;
|
||||
@ -770,13 +777,13 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "Error! Unrecognized image hint: %s\n", argv[c]);
|
||||
goto Error;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-size") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-size") && c + 1 < argc) {
|
||||
config.target_size = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-psnr") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-psnr") && c + 1 < argc) {
|
||||
config.target_PSNR = ExUtilGetFloat(argv[++c], &parse_error);
|
||||
} else if (!strcmp(argv[c], "-sns") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-sns") && c + 1 < argc) {
|
||||
config.sns_strength = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-f") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-f") && c + 1 < argc) {
|
||||
config.filter_strength = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-af")) {
|
||||
config.autofilter = 1;
|
||||
@ -790,27 +797,32 @@ int main(int argc, const char *argv[]) {
|
||||
config.filter_type = 1;
|
||||
} else if (!strcmp(argv[c], "-nostrong")) {
|
||||
config.filter_type = 0;
|
||||
} else if (!strcmp(argv[c], "-sharpness") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-sharpness") && c + 1 < argc) {
|
||||
config.filter_sharpness = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-sharp_yuv")) {
|
||||
config.use_sharp_yuv = 1;
|
||||
} else if (!strcmp(argv[c], "-pass") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-pass") && c + 1 < argc) {
|
||||
config.pass = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-pre") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-qrange") && c + 2 < argc) {
|
||||
config.qmin = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
config.qmax = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
if (config.qmin < 0) config.qmin = 0;
|
||||
if (config.qmax > 100) config.qmax = 100;
|
||||
} else if (!strcmp(argv[c], "-pre") && c + 1 < argc) {
|
||||
config.preprocessing = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-segments") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-segments") && c + 1 < argc) {
|
||||
config.segments = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-partition_limit") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-partition_limit") && c + 1 < argc) {
|
||||
config.partition_limit = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-map") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-map") && c + 1 < argc) {
|
||||
picture.extra_info_type = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-crop") && c < argc - 4) {
|
||||
} else if (!strcmp(argv[c], "-crop") && c + 4 < argc) {
|
||||
crop = 1;
|
||||
crop_x = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
crop_y = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
crop_w = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
crop_h = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-resize") && c < argc - 2) {
|
||||
} else if (!strcmp(argv[c], "-resize") && c + 2 < argc) {
|
||||
resize_w = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
resize_h = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
#ifndef WEBP_DLL
|
||||
@ -826,7 +838,7 @@ int main(int argc, const char *argv[]) {
|
||||
show_progress = 1;
|
||||
} else if (!strcmp(argv[c], "-quiet")) {
|
||||
quiet = 1;
|
||||
} else if (!strcmp(argv[c], "-preset") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-preset") && c + 1 < argc) {
|
||||
WebPPreset preset;
|
||||
++c;
|
||||
if (!strcmp(argv[c], "default")) {
|
||||
@ -849,7 +861,7 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "Error! Could initialize configuration with preset.\n");
|
||||
goto Error;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-metadata") && c < argc - 1) {
|
||||
} else if (!strcmp(argv[c], "-metadata") && c + 1 < argc) {
|
||||
static const struct {
|
||||
const char* option;
|
||||
int flag;
|
||||
@ -897,7 +909,7 @@ int main(int argc, const char *argv[]) {
|
||||
} else if (!strcmp(argv[c], "-v")) {
|
||||
verbose = 1;
|
||||
} else if (!strcmp(argv[c], "--")) {
|
||||
if (c < argc - 1) in_file = (const char*)GET_WARGV(argv, ++c);
|
||||
if (c + 1 < argc) in_file = (const char*)GET_WARGV(argv, ++c);
|
||||
break;
|
||||
} else if (argv[c][0] == '-') {
|
||||
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
|
||||
@ -973,6 +985,14 @@ int main(int argc, const char *argv[]) {
|
||||
const double read_time = StopwatchReadAndReset(&stop_watch);
|
||||
fprintf(stderr, "Time to read input: %.3fs\n", read_time);
|
||||
}
|
||||
// The bitstream should be kept in memory when metadata must be appended
|
||||
// before writing it to a file/stream, and/or when the near-losslessly encoded
|
||||
// bitstream must be decoded for distortion computation (lossy will modify the
|
||||
// 'picture' but not the lossless pipeline).
|
||||
// Otherwise directly write the bitstream to a file.
|
||||
use_memory_writer = (out_file != NULL && keep_metadata) ||
|
||||
(!quiet && print_distortion >= 0 && config.lossless &&
|
||||
config.near_lossless < 100);
|
||||
|
||||
// Open the output
|
||||
if (out_file != NULL) {
|
||||
@ -987,15 +1007,19 @@ int main(int argc, const char *argv[]) {
|
||||
WFPRINTF(stderr, "Saving file '%s'\n", (const W_CHAR*)out_file);
|
||||
}
|
||||
}
|
||||
if (keep_metadata == 0) {
|
||||
picture.writer = MyWriter;
|
||||
picture.custom_ptr = (void*)out;
|
||||
} else {
|
||||
if (use_memory_writer) {
|
||||
picture.writer = WebPMemoryWrite;
|
||||
picture.custom_ptr = (void*)&memory_writer;
|
||||
} else {
|
||||
picture.writer = MyWriter;
|
||||
picture.custom_ptr = (void*)out;
|
||||
}
|
||||
} else {
|
||||
out = NULL;
|
||||
if (use_memory_writer) {
|
||||
picture.writer = WebPMemoryWrite;
|
||||
picture.custom_ptr = (void*)&memory_writer;
|
||||
}
|
||||
if (!quiet && !short_output) {
|
||||
fprintf(stderr, "No output file specified (no -o flag). Encoding will\n");
|
||||
fprintf(stderr, "be performed, but its results discarded.\n\n");
|
||||
@ -1074,8 +1098,12 @@ int main(int argc, const char *argv[]) {
|
||||
if (picture.extra_info_type > 0) {
|
||||
AllocExtraInfo(&picture);
|
||||
}
|
||||
if (print_distortion >= 0) { // Save original picture for later comparison
|
||||
WebPPictureCopy(&picture, &original_picture);
|
||||
// Save original picture for later comparison. Only for lossy as lossless does
|
||||
// not modify 'picture' (even near-lossless).
|
||||
if (print_distortion >= 0 && !config.lossless &&
|
||||
!WebPPictureCopy(&picture, &original_picture)) {
|
||||
fprintf(stderr, "Error! Cannot copy temporary picture\n");
|
||||
goto Error;
|
||||
}
|
||||
|
||||
// Compress.
|
||||
@ -1093,7 +1121,38 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "Time to encode picture: %.3fs\n", encode_time);
|
||||
}
|
||||
|
||||
// Write info
|
||||
// Get the decompressed image for the lossless pipeline.
|
||||
if (!quiet && print_distortion >= 0 && config.lossless) {
|
||||
if (config.near_lossless == 100) {
|
||||
// Pure lossless: image was not modified, make 'original_picture' a view
|
||||
// of 'picture' by copying all members except the freeable pointers.
|
||||
original_picture = picture;
|
||||
original_picture.memory_ = original_picture.memory_argb_ = NULL;
|
||||
} else {
|
||||
// Decode the bitstream stored in 'memory_writer' to get the altered image
|
||||
// to 'picture'; save the 'original_picture' beforehand.
|
||||
assert(use_memory_writer);
|
||||
original_picture = picture;
|
||||
if (!WebPPictureInit(&picture)) { // Do not free 'picture'.
|
||||
fprintf(stderr, "Error! Version mismatch!\n");
|
||||
goto Error;
|
||||
}
|
||||
|
||||
picture.use_argb = 1;
|
||||
if (!ReadWebP(memory_writer.mem, memory_writer.size, &picture,
|
||||
/*keep_alpha=*/WebPPictureHasTransparency(&picture),
|
||||
/*metadata=*/NULL)) {
|
||||
fprintf(stderr, "Error! Cannot decode encoded WebP bitstream\n");
|
||||
fprintf(stderr, "Error code: %d (%s)\n", picture.error_code,
|
||||
kErrorMessages[picture.error_code]);
|
||||
goto Error;
|
||||
}
|
||||
picture.stats = original_picture.stats;
|
||||
}
|
||||
original_picture.stats = NULL;
|
||||
}
|
||||
|
||||
// Write the YUV planes to a PGM file. Only available for lossy.
|
||||
if (dump_file) {
|
||||
if (picture.use_argb) {
|
||||
fprintf(stderr, "Warning: can't dump file (-d option) "
|
||||
@ -1104,31 +1163,29 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
if (keep_metadata != 0) {
|
||||
if (out != NULL) {
|
||||
if (!WriteWebPWithMetadata(out, &picture, &memory_writer,
|
||||
&metadata, keep_metadata, &metadata_written)) {
|
||||
fprintf(stderr, "Error writing WebP file with metadata!\n");
|
||||
goto Error;
|
||||
}
|
||||
} else { // output is disabled, just display the metadata stats.
|
||||
const struct {
|
||||
const MetadataPayload* const payload;
|
||||
int flag;
|
||||
} *iter, info[] = {
|
||||
{ &metadata.exif, METADATA_EXIF },
|
||||
{ &metadata.iccp, METADATA_ICC },
|
||||
{ &metadata.xmp, METADATA_XMP },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
uint32_t unused1 = 0;
|
||||
uint64_t unused2 = 0;
|
||||
if (use_memory_writer && out != NULL &&
|
||||
!WriteWebPWithMetadata(out, &picture, &memory_writer, &metadata,
|
||||
keep_metadata, &metadata_written)) {
|
||||
fprintf(stderr, "Error writing WebP file!\n");
|
||||
goto Error;
|
||||
}
|
||||
|
||||
for (iter = info; iter->payload != NULL; ++iter) {
|
||||
if (UpdateFlagsAndSize(iter->payload, !!(keep_metadata & iter->flag),
|
||||
0, &unused1, &unused2)) {
|
||||
metadata_written |= iter->flag;
|
||||
}
|
||||
if (out == NULL && keep_metadata) {
|
||||
// output is disabled, just display the metadata stats.
|
||||
const struct {
|
||||
const MetadataPayload* const payload;
|
||||
int flag;
|
||||
} *iter, info[] = {{&metadata.exif, METADATA_EXIF},
|
||||
{&metadata.iccp, METADATA_ICC},
|
||||
{&metadata.xmp, METADATA_XMP},
|
||||
{NULL, 0}};
|
||||
uint32_t unused1 = 0;
|
||||
uint64_t unused2 = 0;
|
||||
|
||||
for (iter = info; iter->payload != NULL; ++iter) {
|
||||
if (UpdateFlagsAndSize(iter->payload, !!(keep_metadata & iter->flag),
|
||||
/*flag=*/0, &unused1, &unused2)) {
|
||||
metadata_written |= iter->flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1168,7 +1225,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
Error:
|
||||
WebPMemoryWriterClear(&memory_writer);
|
||||
free(picture.extra_info);
|
||||
WebPFree(picture.extra_info);
|
||||
MetadataFree(&metadata);
|
||||
WebPPictureFree(&picture);
|
||||
WebPPictureFree(&original_picture);
|
||||
|
@ -76,7 +76,8 @@ static int SaveOutput(const WebPDecBuffer* const buffer,
|
||||
|
||||
static void Help(void) {
|
||||
printf("Usage: dwebp in_file [options] [-o out_file]\n\n"
|
||||
"Decodes the WebP image file to PNG format [Default]\n"
|
||||
"Decodes the WebP image file to PNG format [Default].\n"
|
||||
"Note: Animated WebP files are not supported.\n\n"
|
||||
"Use following options to convert into alternate image formats:\n"
|
||||
" -pam ......... save the raw RGBA samples as a color PAM\n"
|
||||
" -ppm ......... save the raw RGB samples as a color PPM\n"
|
||||
@ -132,7 +133,7 @@ static uint8_t* AllocateExternalBuffer(WebPDecoderConfig* config,
|
||||
format == RGB_565) ? 2
|
||||
: 4;
|
||||
uint32_t stride = bpp * w + 7; // <- just for exercising
|
||||
external_buffer = (uint8_t*)malloc(stride * h);
|
||||
external_buffer = (uint8_t*)WebPMalloc(stride * h);
|
||||
if (external_buffer == NULL) return NULL;
|
||||
output_buffer->u.RGBA.stride = stride;
|
||||
output_buffer->u.RGBA.size = stride * h;
|
||||
@ -145,7 +146,7 @@ static uint8_t* AllocateExternalBuffer(WebPDecoderConfig* config,
|
||||
uint32_t total_size = stride * h * (has_alpha ? 2 : 1)
|
||||
+ 2 * uv_stride * (h + 1) / 2;
|
||||
assert(format >= YUV && format <= YUVA);
|
||||
external_buffer = (uint8_t*)malloc(total_size);
|
||||
external_buffer = (uint8_t*)WebPMalloc(total_size);
|
||||
if (external_buffer == NULL) return NULL;
|
||||
tmp = external_buffer;
|
||||
output_buffer->u.YUVA.y = tmp;
|
||||
@ -176,10 +177,10 @@ static uint8_t* AllocateExternalBuffer(WebPDecoderConfig* config,
|
||||
return external_buffer;
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
int ok = 0;
|
||||
const char *in_file = NULL;
|
||||
const char *out_file = NULL;
|
||||
const char* in_file = NULL;
|
||||
const char* out_file = NULL;
|
||||
|
||||
WebPDecoderConfig config;
|
||||
WebPDecBuffer* const output_buffer = &config.output;
|
||||
@ -412,8 +413,8 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
Exit:
|
||||
WebPFreeDecBuffer(output_buffer);
|
||||
free((void*)external_buffer);
|
||||
free((void*)data);
|
||||
WebPFree((void*)external_buffer);
|
||||
WebPFree((void*)data);
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : -1);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ static void ResetCommandLineArguments(int argc, const char* argv[],
|
||||
void ExUtilDeleteCommandLineArguments(CommandLineArguments* const args) {
|
||||
if (args != NULL) {
|
||||
if (args->own_argv_) {
|
||||
free((void*)args->argv_);
|
||||
WebPFree((void*)args->argv_);
|
||||
WebPDataClear(&args->argv_data_);
|
||||
}
|
||||
ResetCommandLineArguments(0, NULL, args);
|
||||
@ -102,7 +102,7 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
|
||||
return 0;
|
||||
}
|
||||
args->own_argv_ = 1;
|
||||
args->argv_ = (const char**)malloc(MAX_ARGC * sizeof(*args->argv_));
|
||||
args->argv_ = (const char**)WebPMalloc(MAX_ARGC * sizeof(*args->argv_));
|
||||
if (args->argv_ == NULL) return 0;
|
||||
|
||||
argc = 0;
|
||||
|
@ -96,12 +96,12 @@ static void Help(void) {
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
int verbose = 0;
|
||||
int gif_error = GIF_ERROR;
|
||||
WebPMuxError err = WEBP_MUX_OK;
|
||||
int ok = 0;
|
||||
const W_CHAR *in_file = NULL, *out_file = NULL;
|
||||
const W_CHAR* in_file = NULL, *out_file = NULL;
|
||||
GifFileType* gif = NULL;
|
||||
int frame_duration = 0;
|
||||
int frame_timestamp = 0;
|
||||
@ -379,7 +379,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
case EXTENSION_RECORD_TYPE: {
|
||||
int extension;
|
||||
GifByteType *data = NULL;
|
||||
GifByteType* data = NULL;
|
||||
if (DGifGetExtension(gif, &extension, &data) == GIF_ERROR) {
|
||||
goto End;
|
||||
}
|
||||
@ -593,7 +593,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
#else // !WEBP_HAVE_GIF
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
fprintf(stderr, "GIF support not enabled in %s.\n", argv[0]);
|
||||
(void)argc;
|
||||
return 0;
|
||||
|
@ -137,7 +137,7 @@ int GIFReadFrame(GifFileType* const gif, int transparent_index,
|
||||
}
|
||||
dst = sub_image.argb;
|
||||
|
||||
tmp = (uint8_t*)malloc(rect.width * sizeof(*tmp));
|
||||
tmp = (uint8_t*)WebPMalloc(rect.width * sizeof(*tmp));
|
||||
if (tmp == NULL) goto End;
|
||||
|
||||
if (image_desc->Interlace) { // Interlaced image.
|
||||
@ -168,7 +168,7 @@ int GIFReadFrame(GifFileType* const gif, int transparent_index,
|
||||
End:
|
||||
if (!ok) picture->error_code = sub_image.error_code;
|
||||
WebPPictureFree(&sub_image);
|
||||
free(tmp);
|
||||
WebPFree(tmp);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ static int ReadImage(const char filename[], WebPPicture* const pic) {
|
||||
if (!ImgIoUtilReadFile(filename, &data, &data_size)) return 0;
|
||||
reader = WebPGuessImageReader(data, data_size);
|
||||
ok = reader(data, data_size, pic, 1, NULL);
|
||||
free((void*)data);
|
||||
WebPFree((void*)data);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -479,7 +479,7 @@ static void Help(void) {
|
||||
" 'q' / 'Q' / ESC .... quit\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
int c;
|
||||
WebPDecoderConfig* const config = &kParams.config;
|
||||
WebPIterator* const curr = &kParams.curr_frame;
|
||||
@ -630,7 +630,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
#else // !WEBP_HAVE_GL
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
fprintf(stderr, "OpenGL support not enabled in %s.\n", argv[0]);
|
||||
(void)argc;
|
||||
return 0;
|
||||
|
@ -26,6 +26,7 @@
|
||||
webpmux -set icc image_profile.icc in.webp -o out_icc_container.webp
|
||||
webpmux -set exif image_metadata.exif in.webp -o out_exif_container.webp
|
||||
webpmux -set xmp image_metadata.xmp in.webp -o out_xmp_container.webp
|
||||
webpmux -set loop 1 in.webp -o out_looped.webp
|
||||
|
||||
Extract relevant data from WebP container file:
|
||||
webpmux -get frame n in.webp -o out_frame.webp
|
||||
@ -97,6 +98,7 @@ typedef enum {
|
||||
FEATURE_ICCP,
|
||||
FEATURE_ANMF,
|
||||
FEATURE_DURATION,
|
||||
FEATURE_LOOP,
|
||||
LAST_FEATURE
|
||||
} FeatureType;
|
||||
|
||||
@ -314,6 +316,7 @@ static void PrintHelp(void) {
|
||||
printf("\n");
|
||||
printf("SET_OPTIONS:\n");
|
||||
printf(" Set color profile/metadata:\n");
|
||||
printf(" loop LOOP_COUNT set the loop count\n");
|
||||
printf(" icc file.icc set ICC profile\n");
|
||||
printf(" exif file.exif set EXIF metadata\n");
|
||||
printf(" xmp file.xmp set XMP metadata\n");
|
||||
@ -768,6 +771,13 @@ static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) {
|
||||
arg->params_ = argv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else if (!strcmp(argv[i], "loop") &&
|
||||
(config->action_type_ == ACTION_SET)) {
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
config->type_ = FEATURE_LOOP;
|
||||
arg->params_ = argv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else { // Assume input file.
|
||||
if (config->input_ == NULL) {
|
||||
config->input_ = wargv[i];
|
||||
@ -1011,13 +1021,38 @@ static int Process(const Config* config) {
|
||||
ok = ExUtilReadFileToWebPData(config->args_[0].filename_, &chunk);
|
||||
if (!ok) goto Err2;
|
||||
err = WebPMuxSetChunk(mux, kFourccList[config->type_], &chunk, 1);
|
||||
free((void*)chunk.bytes);
|
||||
WebPDataClear(&chunk);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
ERROR_GOTO3("ERROR (%s): Could not set the %s.\n",
|
||||
ErrorString(err), kDescriptions[config->type_], Err2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FEATURE_LOOP: {
|
||||
WebPMuxAnimParams params = { 0xFFFFFFFF, 0 };
|
||||
int parse_error = 0;
|
||||
const int loop_count =
|
||||
ExUtilGetInt(config->args_[0].params_, 10, &parse_error);
|
||||
if (loop_count < 0 || loop_count > 65535 || parse_error) {
|
||||
ERROR_GOTO1("ERROR: Loop count must be in the range 0 to 65535.\n",
|
||||
Err2);
|
||||
}
|
||||
ok = CreateMux(config->input_, &mux);
|
||||
if (!ok) goto Err2;
|
||||
ok = (WebPMuxGetAnimationParams(mux, ¶ms) == WEBP_MUX_OK);
|
||||
if (!ok) {
|
||||
ERROR_GOTO1("ERROR: input file does not seem to be an animation.\n",
|
||||
Err2);
|
||||
}
|
||||
params.loop_count = loop_count;
|
||||
err = WebPMuxSetAnimationParams(mux, ¶ms);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
if (!ok) {
|
||||
ERROR_GOTO2("ERROR (%s): Could not set animation parameters.\n",
|
||||
ErrorString(err), Err2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
ERROR_GOTO1("ERROR: Invalid feature for action 'set'.\n", Err2);
|
||||
break;
|
||||
@ -1045,7 +1080,7 @@ static int Process(const Config* config) {
|
||||
int* durations = NULL;
|
||||
WebPMux* new_mux = DuplicateMuxHeader(mux);
|
||||
if (new_mux == NULL) goto Err2;
|
||||
durations = (int*)malloc((size_t)num_frames * sizeof(*durations));
|
||||
durations = (int*)WebPMalloc((size_t)num_frames * sizeof(*durations));
|
||||
if (durations == NULL) goto Err2;
|
||||
for (i = 0; i < num_frames; ++i) durations[i] = -1;
|
||||
|
||||
@ -1103,7 +1138,7 @@ static int Process(const Config* config) {
|
||||
new_mux = NULL;
|
||||
|
||||
Err3:
|
||||
free(durations);
|
||||
WebPFree(durations);
|
||||
WebPMuxDelete(new_mux);
|
||||
if (!ok) goto Err2;
|
||||
}
|
||||
|
@ -12,13 +12,14 @@
|
||||
|
||||
#include "extras/extras.h"
|
||||
#include "webp/format_constants.h"
|
||||
#include "src/dsp/dsp.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define XTRA_MAJ_VERSION 1
|
||||
#define XTRA_MIN_VERSION 0
|
||||
#define XTRA_REV_VERSION 3
|
||||
#define XTRA_MIN_VERSION 2
|
||||
#define XTRA_REV_VERSION 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -57,7 +58,7 @@ int WebPImportRGB565(const uint8_t* rgb565, WebPPicture* pic) {
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
const int width = pic->width;
|
||||
for (x = 0; x < width; ++x) {
|
||||
#ifdef WEBP_SWAP_16BIT_CSP
|
||||
#if defined(WEBP_SWAP_16BIT_CSP) && (WEBP_SWAP_16BIT_CSP == 1)
|
||||
const uint32_t rg = rgb565[2 * x + 1];
|
||||
const uint32_t gb = rgb565[2 * x + 0];
|
||||
#else
|
||||
@ -90,7 +91,7 @@ int WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic) {
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
const int width = pic->width;
|
||||
for (x = 0; x < width; ++x) {
|
||||
#ifdef WEBP_SWAP_16BIT_CSP
|
||||
#if defined(WEBP_SWAP_16BIT_CSP) && (WEBP_SWAP_16BIT_CSP == 1)
|
||||
const uint32_t rg = rgb4444[2 * x + 1];
|
||||
const uint32_t ba = rgb4444[2 * x + 0];
|
||||
#else
|
||||
@ -144,3 +145,18 @@ int WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride,
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int WebPUnmultiplyARGB(WebPPicture* pic) {
|
||||
int y;
|
||||
uint32_t* dst;
|
||||
if (pic == NULL || pic->use_argb != 1 || pic->argb == NULL) return 0;
|
||||
WebPInitAlphaProcessing();
|
||||
dst = pic->argb;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
WebPMultARGBRow(dst, pic->width, /*inverse=*/1);
|
||||
dst += pic->argb_stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -19,7 +19,7 @@ extern "C" {
|
||||
|
||||
#include "webp/encode.h"
|
||||
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0001 // MAJOR(8b) + MINOR(8b)
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0002 // MAJOR(8b) + MINOR(8b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -51,6 +51,13 @@ WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride,
|
||||
const uint32_t palette[], int palette_size,
|
||||
WebPPicture* pic);
|
||||
|
||||
// Convert the ARGB content of 'pic' from associated to unassociated.
|
||||
// 'pic' can be for instance the result of calling of some WebPPictureImportXXX
|
||||
// functions, with pic->use_argb set to 'true'. It is assumed (and not checked)
|
||||
// that the pre-multiplied r/g/b values as less or equal than the alpha value.
|
||||
// Return false in case of error (invalid parameter, ...).
|
||||
WEBP_EXTERN int WebPUnmultiplyARGB(WebPPicture* pic);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Parse a bitstream, search for VP8 (lossy) header and report a
|
||||
|
@ -226,7 +226,7 @@ static void Help(void) {
|
||||
" Also handles PNG, JPG and TIFF files, in addition to WebP.\n");
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
WebPPicture pic1, pic2;
|
||||
size_t size1 = 0, size2 = 0;
|
||||
int ret = 1;
|
||||
|
@ -92,7 +92,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
#else // !WEBP_HAVE_SDL
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
fprintf(stderr, "SDL support not enabled in %s.\n", argv[0]);
|
||||
(void)argc;
|
||||
return 0;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int main(int argc, const char* argv[]) {
|
||||
int c;
|
||||
int quiet = 0;
|
||||
int ok = 1;
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,5 @@
|
||||
#Thu May 12 17:06:25 CEST 2016
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip
|
||||
|
65
gradlew
vendored
65
gradlew
vendored
@ -1,4 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
@ -28,16 +44,16 @@ APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn ( ) {
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die ( ) {
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
@ -109,8 +125,8 @@ if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
@ -138,27 +154,30 @@ if $cygwin ; then
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
190
gradlew.bat
vendored
190
gradlew.bat
vendored
@ -1,90 +1,100 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
@ -91,7 +91,7 @@ int ImgIoUtilReadFile(const char* const file_name,
|
||||
file_size = ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
// we allocate one extra byte for the \0 terminator
|
||||
file_data = (uint8_t*)malloc(file_size + 1);
|
||||
file_data = (uint8_t*)WebPMalloc(file_size + 1);
|
||||
if (file_data == NULL) {
|
||||
fclose(in);
|
||||
WFPRINTF(stderr, "memory allocation failure when reading file %s\n",
|
||||
@ -104,7 +104,7 @@ int ImgIoUtilReadFile(const char* const file_name,
|
||||
if (!ok) {
|
||||
WFPRINTF(stderr, "Could not read %d bytes of data from file %s\n",
|
||||
(int)file_size, (const W_CHAR*)file_name);
|
||||
free(file_data);
|
||||
WebPFree(file_data);
|
||||
return 0;
|
||||
}
|
||||
file_data[file_size] = '\0'; // convenient 0-terminator
|
||||
|
@ -29,7 +29,7 @@ FILE* ImgIoUtilSetBinaryMode(FILE* file);
|
||||
|
||||
// Allocates storage for entire file 'file_name' and returns contents and size
|
||||
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
|
||||
// be deleted using free().
|
||||
// be deleted using WebPFree().
|
||||
// Note: for convenience, the data will be null-terminated with an extra byte
|
||||
// (not accounted for in *data_size), in case the file is text and intended
|
||||
// to be used as a C-string.
|
||||
|
@ -259,6 +259,15 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
|
||||
goto End;
|
||||
}
|
||||
|
||||
#if LOCAL_PNG_PREREQ(1,5) || \
|
||||
(LOCAL_PNG_PREREQ(1,4) && PNG_LIBPNG_VER_RELEASE >= 1)
|
||||
// If it looks like the bitstream is going to need more memory than libpng's
|
||||
// internal limit (default: 8M), try to (reasonably) raise it.
|
||||
if (data_size > png_get_chunk_malloc_max(png) && data_size < (1u << 24)) {
|
||||
png_set_chunk_malloc_max(png, data_size);
|
||||
}
|
||||
#endif
|
||||
|
||||
info = png_create_info_struct(png);
|
||||
if (info == NULL) goto Error;
|
||||
end_info = png_create_info_struct(png);
|
||||
|
115
imageio/pnmdec.c
115
imageio/pnmdec.c
@ -26,15 +26,15 @@ typedef enum {
|
||||
DEPTH_FLAG = 1 << 2,
|
||||
MAXVAL_FLAG = 1 << 3,
|
||||
TUPLE_FLAG = 1 << 4,
|
||||
ALL_NEEDED_FLAGS = 0x1f
|
||||
ALL_NEEDED_FLAGS = WIDTH_FLAG | HEIGHT_FLAG | DEPTH_FLAG | MAXVAL_FLAG
|
||||
} PNMFlags;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
size_t data_size;
|
||||
int width, height;
|
||||
int bytes_per_px; // 1, 3, 4
|
||||
int depth;
|
||||
int bytes_per_px;
|
||||
int depth; // 1 (grayscale), 2 (grayscale + alpha), 3 (rgb), 4 (rgba)
|
||||
int max_value;
|
||||
int type; // 5, 6 or 7
|
||||
int seen_flags;
|
||||
@ -74,6 +74,7 @@ static size_t ReadPAMFields(PNMInfo* const info, size_t off) {
|
||||
char out[MAX_LINE_SIZE + 1];
|
||||
size_t out_size;
|
||||
int tmp;
|
||||
int expected_depth = -1;
|
||||
assert(info != NULL);
|
||||
while (1) {
|
||||
off = ReadLine(info->data, off, info->data_size, out, &out_size);
|
||||
@ -95,13 +96,16 @@ static size_t ReadPAMFields(PNMInfo* const info, size_t off) {
|
||||
info->seen_flags |= MAXVAL_FLAG;
|
||||
info->max_value = tmp;
|
||||
} else if (!strcmp(out, "TUPLTYPE RGB_ALPHA")) {
|
||||
info->bytes_per_px = 4;
|
||||
expected_depth = 4;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "TUPLTYPE RGB")) {
|
||||
info->bytes_per_px = 3;
|
||||
expected_depth = 3;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "TUPLTYPE GRAYSCALE_ALPHA")) {
|
||||
expected_depth = 2;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "TUPLTYPE GRAYSCALE")) {
|
||||
info->bytes_per_px = 1;
|
||||
expected_depth = 1;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "ENDHDR")) {
|
||||
break;
|
||||
@ -110,23 +114,24 @@ static size_t ReadPAMFields(PNMInfo* const info, size_t off) {
|
||||
int i;
|
||||
if (out_size > 20) sprintf(out + 20 - strlen(kEllipsis), kEllipsis);
|
||||
for (i = 0; i < (int)strlen(out); ++i) {
|
||||
if (!isprint(out[i])) out[i] = ' ';
|
||||
// isprint() might trigger a "char-subscripts" warning if given a char.
|
||||
if (!isprint((int)out[i])) out[i] = ' ';
|
||||
}
|
||||
fprintf(stderr, "PAM header error: unrecognized entry [%s]\n", out);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!(info->seen_flags & TUPLE_FLAG)) {
|
||||
if (info->depth > 0 && info->depth <= 4 && info->depth != 2) {
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1);
|
||||
} else {
|
||||
fprintf(stderr, "PAM: invalid bitdepth (%d).\n", info->depth);
|
||||
return 0;
|
||||
}
|
||||
if (!(info->seen_flags & ALL_NEEDED_FLAGS)) {
|
||||
fprintf(stderr, "PAM header error: missing tags%s%s%s%s\n",
|
||||
(info->seen_flags & WIDTH_FLAG) ? "" : " WIDTH",
|
||||
(info->seen_flags & HEIGHT_FLAG) ? "" : " HEIGHT",
|
||||
(info->seen_flags & DEPTH_FLAG) ? "" : " DEPTH",
|
||||
(info->seen_flags & MAXVAL_FLAG) ? "" : " MAXVAL");
|
||||
return 0;
|
||||
}
|
||||
if (info->seen_flags != ALL_NEEDED_FLAGS) {
|
||||
fprintf(stderr, "PAM: incomplete header.\n");
|
||||
if (expected_depth != -1 && info->depth != expected_depth) {
|
||||
fprintf(stderr, "PAM header error: expected DEPTH %d but got DEPTH %d\n",
|
||||
expected_depth, info->depth);
|
||||
return 0;
|
||||
}
|
||||
return off;
|
||||
@ -160,16 +165,15 @@ static size_t ReadHeader(PNMInfo* const info) {
|
||||
|
||||
// finish initializing missing fields
|
||||
info->depth = (info->type == 5) ? 1 : 3;
|
||||
info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1);
|
||||
}
|
||||
// perform some basic numerical validation
|
||||
if (info->width <= 0 || info->height <= 0 ||
|
||||
info->type <= 0 || info->type >= 9 ||
|
||||
info->depth <= 0 || info->depth == 2 || info->depth > 4 ||
|
||||
info->bytes_per_px < info->depth ||
|
||||
info->depth <= 0 || info->depth > 4 ||
|
||||
info->max_value <= 0 || info->max_value >= 65536) {
|
||||
return 0;
|
||||
}
|
||||
info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1);
|
||||
return off;
|
||||
}
|
||||
|
||||
@ -178,7 +182,7 @@ int ReadPNM(const uint8_t* const data, size_t data_size,
|
||||
struct Metadata* const metadata) {
|
||||
int ok = 0;
|
||||
int i, j;
|
||||
uint64_t stride, pixel_bytes;
|
||||
uint64_t stride, pixel_bytes, sample_size, depth;
|
||||
uint8_t* rgb = NULL, *tmp_rgb;
|
||||
size_t offset;
|
||||
PNMInfo info;
|
||||
@ -209,8 +213,10 @@ int ReadPNM(const uint8_t* const data, size_t data_size,
|
||||
fprintf(stderr, "Truncated PNM file (P%d).\n", info.type);
|
||||
goto End;
|
||||
}
|
||||
stride =
|
||||
(uint64_t)(info.bytes_per_px < 3 ? 3 : info.bytes_per_px) * info.width;
|
||||
sample_size = (info.max_value > 255) ? 2 : 1;
|
||||
// final depth
|
||||
depth = (info.depth == 1 || info.depth == 3 || !keep_alpha) ? 3 : 4;
|
||||
stride = depth * info.width;
|
||||
if (stride != (size_t)stride ||
|
||||
!ImgIoUtilCheckSizeArgumentsOverflow(stride, info.height)) {
|
||||
goto End;
|
||||
@ -219,30 +225,63 @@ int ReadPNM(const uint8_t* const data, size_t data_size,
|
||||
rgb = (uint8_t*)malloc((size_t)stride * info.height);
|
||||
if (rgb == NULL) goto End;
|
||||
|
||||
// Convert input
|
||||
// Convert input.
|
||||
// We only optimize for the sample_size=1, max_value=255, depth=1 case.
|
||||
tmp_rgb = rgb;
|
||||
for (j = 0; j < info.height; ++j) {
|
||||
assert(offset + info.bytes_per_px * info.width <= data_size);
|
||||
if (info.depth == 1) {
|
||||
// convert grayscale -> RGB
|
||||
for (i = 0; i < info.width; ++i) {
|
||||
const uint8_t v = data[offset + i];
|
||||
tmp_rgb[3 * i + 0] = tmp_rgb[3 * i + 1] = tmp_rgb[3 * i + 2] = v;
|
||||
}
|
||||
} else if (info.depth == 3) { // RGB
|
||||
memcpy(tmp_rgb, data + offset, 3 * info.width * sizeof(*data));
|
||||
} else if (info.depth == 4) { // RGBA
|
||||
memcpy(tmp_rgb, data + offset, 4 * info.width * sizeof(*data));
|
||||
}
|
||||
const uint8_t* in = data + offset;
|
||||
offset += info.bytes_per_px * info.width;
|
||||
assert(offset <= data_size);
|
||||
if (info.max_value == 255 && info.depth >= 3) {
|
||||
// RGB or RGBA
|
||||
if (info.depth == 3 || keep_alpha) {
|
||||
memcpy(tmp_rgb, in, info.depth * info.width * sizeof(*in));
|
||||
} else {
|
||||
assert(info.depth == 4 && !keep_alpha);
|
||||
for (i = 0; i < info.width; ++i) {
|
||||
tmp_rgb[3 * i + 0] = in[4 * i + 0];
|
||||
tmp_rgb[3 * i + 1] = in[4 * i + 1];
|
||||
tmp_rgb[3 * i + 2] = in[4 * i + 2];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Unoptimized case, we need to handle non-trivial operations:
|
||||
// * convert 16b to 8b (if max_value > 255)
|
||||
// * rescale to [0..255] range (if max_value != 255)
|
||||
// * drop the alpha channel (if keep_alpha is false)
|
||||
const uint32_t round = info.max_value / 2;
|
||||
int k = 0;
|
||||
for (i = 0; i < info.width * info.depth; ++i) {
|
||||
uint32_t v = (sample_size == 2) ? 256u * in[2 * i + 0] + in[2 * i + 1]
|
||||
: in[i];
|
||||
if (info.max_value != 255) v = (v * 255u + round) / info.max_value;
|
||||
if (v > 255u) v = 255u;
|
||||
if (info.depth > 2) {
|
||||
if (!keep_alpha && info.depth == 4 && (i % 4) == 3) {
|
||||
// skip alpha
|
||||
} else {
|
||||
tmp_rgb[k] = v;
|
||||
k += 1;
|
||||
}
|
||||
} else if (info.depth == 1 || (i % 2) == 0) {
|
||||
tmp_rgb[k + 0] = tmp_rgb[k + 1] = tmp_rgb[k + 2] = v;
|
||||
k += 3;
|
||||
} else if (keep_alpha && info.depth == 2) {
|
||||
tmp_rgb[k] = v;
|
||||
k += 1;
|
||||
} else {
|
||||
// skip alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
tmp_rgb += stride;
|
||||
}
|
||||
|
||||
// WebP conversion.
|
||||
pic->width = info.width;
|
||||
pic->height = info.height;
|
||||
ok = (info.depth == 4) ? WebPPictureImportRGBA(pic, rgb, (int)stride)
|
||||
: WebPPictureImportRGB(pic, rgb, (int)stride);
|
||||
ok = (depth == 4) ? WebPPictureImportRGBA(pic, rgb, (int)stride)
|
||||
: WebPPictureImportRGB(pic, rgb, (int)stride);
|
||||
if (!ok) goto End;
|
||||
|
||||
ok = 1;
|
||||
|
@ -156,7 +156,7 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
Metadata* const metadata) {
|
||||
MyData my_data = { data, (toff_t)data_size, 0 };
|
||||
TIFF* tif;
|
||||
uint32_t width, height;
|
||||
uint32_t image_width, image_height, tile_width, tile_height;
|
||||
uint16_t samples_per_px = 0;
|
||||
uint16_t extra_samples = 0;
|
||||
uint16_t* extra_samples_ptr = NULL;
|
||||
@ -189,15 +189,25 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
}
|
||||
if (samples_per_px < 3 || samples_per_px > 4) goto End; // not supported
|
||||
|
||||
if (!(TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) &&
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height))) {
|
||||
if (!(TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &image_width) &&
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &image_height))) {
|
||||
fprintf(stderr, "Error! Cannot retrieve TIFF image dimensions.\n");
|
||||
goto End;
|
||||
}
|
||||
if (!ImgIoUtilCheckSizeArgumentsOverflow((uint64_t)width * height,
|
||||
if (!ImgIoUtilCheckSizeArgumentsOverflow((uint64_t)image_width * image_height,
|
||||
sizeof(*raster))) {
|
||||
goto End;
|
||||
}
|
||||
// According to spec, a tile can be bigger than the image. However it should
|
||||
// be a multiple of 16 and not way too large, so check that it's not more than
|
||||
// twice the image size, for dimensions above some arbitrary minimum 32.
|
||||
if ((TIFFGetField(tif, TIFFTAG_TILEWIDTH, &tile_width) &&
|
||||
tile_width > 32 && tile_width / 2 > image_width) ||
|
||||
(TIFFGetField(tif, TIFFTAG_TILELENGTH, &tile_height) &&
|
||||
tile_height > 32 && tile_height / 2 > image_height)) {
|
||||
fprintf(stderr, "Error! TIFF tile dimensions are too big.\n");
|
||||
goto End;
|
||||
}
|
||||
if (samples_per_px > 3 && !TIFFGetField(tif, TIFFTAG_EXTRASAMPLES,
|
||||
&extra_samples, &extra_samples_ptr)) {
|
||||
fprintf(stderr, "Error! Cannot retrieve TIFF ExtraSamples info.\n");
|
||||
@ -205,27 +215,28 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
}
|
||||
|
||||
// _Tiffmalloc uses a signed type for size.
|
||||
alloc_size = (int64_t)((uint64_t)width * height * sizeof(*raster));
|
||||
alloc_size =
|
||||
(int64_t)((uint64_t)image_width * image_height * sizeof(*raster));
|
||||
if (alloc_size < 0 || alloc_size != (tsize_t)alloc_size) goto End;
|
||||
|
||||
raster = (uint32*)_TIFFmalloc((tsize_t)alloc_size);
|
||||
if (raster != NULL) {
|
||||
if (TIFFReadRGBAImageOriented(tif, width, height, raster,
|
||||
if (TIFFReadRGBAImageOriented(tif, image_width, image_height, raster,
|
||||
ORIENTATION_TOPLEFT, 1)) {
|
||||
const int stride = width * sizeof(*raster);
|
||||
pic->width = width;
|
||||
pic->height = height;
|
||||
const int stride = image_width * sizeof(*raster);
|
||||
pic->width = image_width;
|
||||
pic->height = image_height;
|
||||
// TIFF data is ABGR
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
TIFFSwabArrayOfLong(raster, width * height);
|
||||
TIFFSwabArrayOfLong(raster, image_width * image_height);
|
||||
#endif
|
||||
// if we have an alpha channel, we must un-multiply from rgbA to RGBA
|
||||
if (extra_samples == 1 && extra_samples_ptr != NULL &&
|
||||
extra_samples_ptr[0] == EXTRASAMPLE_ASSOCALPHA) {
|
||||
uint32_t y;
|
||||
uint8_t* tmp = (uint8_t*)raster;
|
||||
for (y = 0; y < height; ++y) {
|
||||
MultARGBRow(tmp, width);
|
||||
for (y = 0; y < image_height; ++y) {
|
||||
MultARGBRow(tmp, image_width);
|
||||
tmp += stride;
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ int LoadWebP(const char* const in_file,
|
||||
|
||||
status = WebPGetFeatures(*data, *data_size, bitstream);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
free((void*)*data);
|
||||
WebPFree((void*)*data);
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
PrintWebPError(in_file, status);
|
||||
|
@ -298,9 +298,15 @@ int ReadPictureWithWIC(const char* const filename,
|
||||
factory, stream, NULL,
|
||||
WICDecodeMetadataCacheOnDemand, &decoder));
|
||||
IFS(IWICBitmapDecoder_GetFrameCount(decoder, &frame_count));
|
||||
if (SUCCEEDED(hr) && frame_count == 0) {
|
||||
fprintf(stderr, "No frame found in input file.\n");
|
||||
hr = E_FAIL;
|
||||
if (SUCCEEDED(hr)) {
|
||||
if (frame_count == 0) {
|
||||
fprintf(stderr, "No frame found in input file.\n");
|
||||
hr = E_FAIL;
|
||||
} else if (frame_count > 1) {
|
||||
// WIC will be tried before native WebP decoding so avoid duplicating the
|
||||
// error message.
|
||||
hr = E_FAIL;
|
||||
}
|
||||
}
|
||||
IFS(IWICBitmapDecoder_GetFrame(decoder, 0, &frame));
|
||||
IFS(IWICBitmapFrameDecode_GetPixelFormat(frame, &src_pixel_format));
|
||||
|
38
iosbuild.sh
38
iosbuild.sh
@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# This script generates 'WebP.framework' and 'WebPDecoder.framework'. An iOS
|
||||
# app can decode WebP images by including 'WebPDecoder.framework' and both
|
||||
# encode and decode WebP images by including 'WebP.framework'.
|
||||
# This script generates 'WebP.framework' and 'WebPDecoder.framework',
|
||||
# 'WebPDemux.framework' and 'WebPMux.framework'.
|
||||
# An iOS app can decode WebP images by including 'WebPDecoder.framework' and
|
||||
# both encode and decode WebP images by including 'WebP.framework'.
|
||||
#
|
||||
# Run ./iosbuild.sh to generate the frameworks under the current directory
|
||||
# (the previous build will be erased if it exists).
|
||||
@ -12,6 +13,9 @@
|
||||
|
||||
set -e
|
||||
|
||||
# Set this variable based on the desired minimum deployment target.
|
||||
readonly IOS_MIN_VERSION=6.0
|
||||
|
||||
# Extract the latest SDK version from the final field of the form: iphoneosX.Y
|
||||
readonly SDK=$(xcodebuild -showsdks \
|
||||
| grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
|
||||
@ -50,13 +54,27 @@ if [[ -z "${SDK}" ]]; then
|
||||
exit 1
|
||||
elif [[ ${SDK%%.*} -gt 8 ]]; then
|
||||
EXTRA_CFLAGS="-fembed-bitcode"
|
||||
elif [[ ${SDK} < 6.0 ]]; then
|
||||
elif [[ ${SDK%%.*} -le 6 ]]; then
|
||||
echo "You need iOS SDK version 6.0 or above"
|
||||
exit 1
|
||||
else
|
||||
echo "iOS SDK Version ${SDK}"
|
||||
fi
|
||||
|
||||
echo "Xcode Version: ${XCODE}"
|
||||
echo "iOS SDK Version: ${SDK}"
|
||||
|
||||
if [[ -e "${BUILDDIR}" || -e "${TARGETDIR}" || -e "${DECTARGETDIR}" \
|
||||
|| -e "${MUXTARGETDIR}" || -e "${DEMUXTARGETDIR}" ]]; then
|
||||
cat << EOF
|
||||
WARNING: The following directories will be deleted:
|
||||
WARNING: ${BUILDDIR}
|
||||
WARNING: ${TARGETDIR}
|
||||
WARNING: ${DECTARGETDIR}
|
||||
WARNING: ${MUXTARGETDIR}
|
||||
WARNING: ${DEMUXTARGETDIR}
|
||||
WARNING: The build will continue in 5 seconds...
|
||||
EOF
|
||||
sleep 5
|
||||
fi
|
||||
rm -rf ${BUILDDIR} ${TARGETDIR} ${DECTARGETDIR} \
|
||||
${MUXTARGETDIR} ${DEMUXTARGETDIR}
|
||||
mkdir -p ${BUILDDIR} ${TARGETDIR}/Headers/ ${DECTARGETDIR}/Headers/ \
|
||||
@ -64,12 +82,12 @@ mkdir -p ${BUILDDIR} ${TARGETDIR}/Headers/ ${DECTARGETDIR}/Headers/ \
|
||||
|
||||
if [[ ! -e ${SRCDIR}/configure ]]; then
|
||||
if ! (cd ${SRCDIR} && sh autogen.sh); then
|
||||
cat <<EOT
|
||||
cat << EOF
|
||||
Error creating configure script!
|
||||
This script requires the autoconf/automake and libtool to build. MacPorts can
|
||||
be used to obtain these:
|
||||
http://www.macports.org/install.php
|
||||
EOT
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@ -103,7 +121,7 @@ for PLATFORM in ${PLATFORMS}; do
|
||||
SDKROOT="${PLATFORMSROOT}/"
|
||||
SDKROOT+="${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDK}.sdk/"
|
||||
CFLAGS="-arch ${ARCH2:-${ARCH}} -pipe -isysroot ${SDKROOT} -O3 -DNDEBUG"
|
||||
CFLAGS+=" -miphoneos-version-min=6.0 ${EXTRA_CFLAGS}"
|
||||
CFLAGS+=" -miphoneos-version-min=${IOS_MIN_VERSION} ${EXTRA_CFLAGS}"
|
||||
|
||||
set -x
|
||||
export PATH="${DEVROOT}/usr/bin:${OLDPATH}"
|
||||
@ -148,3 +166,5 @@ echo "DEMUXLIBLIST = ${DEMUXLIBLIST}"
|
||||
cp -a ${SRCDIR}/src/webp/{decode,types,mux_types,demux}.h \
|
||||
${DEMUXTARGETDIR}/Headers/
|
||||
${LIPO} -create ${DEMUXLIBLIST} -output ${DEMUXTARGETDIR}/WebPDemux
|
||||
|
||||
echo "SUCCESS"
|
||||
|
10
man/cwebp.1
10
man/cwebp.1
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH CWEBP 1 "January 11, 2019"
|
||||
.TH CWEBP 1 "November 19, 2020"
|
||||
.SH NAME
|
||||
cwebp \- compress an image file to a WebP file
|
||||
.SH SYNOPSIS
|
||||
@ -13,6 +13,7 @@ command.
|
||||
.PP
|
||||
\fBcwebp\fP compresses an image using the WebP format.
|
||||
Input format can be either PNG, JPEG, TIFF, WebP or raw Y'CbCr samples.
|
||||
Note: Animated PNG and WebP files are not supported.
|
||||
.SH OPTIONS
|
||||
The basic options are:
|
||||
.TP
|
||||
@ -134,6 +135,13 @@ options \fB\-size\fP or \fB\-psnr\fP. Maximum value is 10, default is 1.
|
||||
If options \fB\-size\fP or \fB\-psnr\fP were used, but \fB\-pass\fP wasn't
|
||||
specified, a default value of '6' passes will be used.
|
||||
.TP
|
||||
.BI \-qrange " int int
|
||||
Specifies the permissible interval for the quality factor. This is particularly
|
||||
useful when using multi-pass (\fB\-size\fP or \fB\-psnr\fP options).
|
||||
Default is 0 100.
|
||||
If the quality factor is outside this range, it will be clamped.
|
||||
If the minimum value must be less or equal to the maximum one.
|
||||
.TP
|
||||
.B \-af
|
||||
Turns auto\-filter on. This algorithm will spend additional time optimizing
|
||||
the filtering strength to reach a well\-balanced quality.
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH DWEBP 1 "June 23, 2016"
|
||||
.TH DWEBP 1 "November 19, 2020"
|
||||
.SH NAME
|
||||
dwebp \- decompress a WebP file to an image file
|
||||
.SH SYNOPSIS
|
||||
@ -12,6 +12,7 @@ This manual page documents the
|
||||
command.
|
||||
.PP
|
||||
\fBdwebp\fP decompresses WebP files into PNG, PAM, PPM or PGM images.
|
||||
Note: Animated WebP files are not supported.
|
||||
.SH OPTIONS
|
||||
The basic options are:
|
||||
.TP
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH GIF2WEBP 1 "January 25, 2018"
|
||||
.TH GIF2WEBP 1 "May 1, 2020"
|
||||
.SH NAME
|
||||
gif2webp \- Convert a GIF image to WebP
|
||||
.SH SYNOPSIS
|
||||
@ -62,9 +62,9 @@ larger file size and lower compression quality.
|
||||
.TP
|
||||
.BI \-min_size
|
||||
Encode image to achieve smallest size. This disables key frame insertion and
|
||||
picks the dispose method resulting in smallest output for each frame. It uses
|
||||
lossless compression by default, but can be combined with \-q, \-m, \-lossy or
|
||||
\-mixed options.
|
||||
picks the dispose method resulting in the smallest output for each frame. It
|
||||
uses lossless compression by default, but can be combined with \-q, \-m,
|
||||
\-lossy or \-mixed options.
|
||||
.TP
|
||||
.BI \-kmin " int
|
||||
.TP
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH IMG2WEBP 1 "April 3, 2018"
|
||||
.TH IMG2WEBP 1 "May 1, 2020"
|
||||
.SH NAME
|
||||
img2webp \- create animated WebP file from a sequence of input images.
|
||||
.SH SYNOPSIS
|
||||
@ -16,8 +16,8 @@ command.
|
||||
\fBimg2webp\fP compresses a sequence of images using the animated WebP format.
|
||||
Input images can either be PNG, JPEG, TIFF or WebP.
|
||||
If a single file name (not starting with the character '\-') is supplied as
|
||||
the argument, the command line argument are actually tokenized from this file.
|
||||
This allows for easy scripting or using large number of arguments.
|
||||
the argument, the command line arguments are actually tokenized from this file.
|
||||
This allows for easy scripting or using a large number of arguments.
|
||||
.SH FILE-LEVEL OPTIONS
|
||||
The file-level options are applied at the beginning of the compression process,
|
||||
before the input frames are read.
|
||||
@ -27,7 +27,7 @@ Specify the name of the output WebP file.
|
||||
.TP
|
||||
.BI \-min_size
|
||||
Encode images to achieve smallest size. This disables key frame insertion and
|
||||
picks the parameters resulting in smallest output for each frame. It uses
|
||||
picks the parameters resulting in the smallest output for each frame. It uses
|
||||
lossless compression by default, but can be combined with \-q, \-m, \-lossy or
|
||||
\-mixed options.
|
||||
.TP
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH WEBPMUX 1 "April 23, 2018"
|
||||
.TH WEBPMUX 1 "December 12, 2020"
|
||||
.SH NAME
|
||||
webpmux \- create animated WebP files from non\-animated WebP images, extract
|
||||
frames from animated WebP images, and manage XMP/EXIF metadata and ICC profile.
|
||||
@ -59,7 +59,7 @@ command.
|
||||
to add/extract/strip XMP/EXIF metadata and ICC profile.
|
||||
If a single file name (not starting with the character '\-') is supplied as
|
||||
the argument, the command line arguments are actually tokenized from this file.
|
||||
This allows for easy scripting or using large number of arguments.
|
||||
This allows for easy scripting or using a large number of arguments.
|
||||
.SH OPTIONS
|
||||
.SS GET_OPTIONS (\-get):
|
||||
.TP
|
||||
@ -77,6 +77,11 @@ Get nth frame from an animated image. (n = 0 has a special meaning: last frame).
|
||||
|
||||
.SS SET_OPTIONS (\-set)
|
||||
.TP
|
||||
.BI loop " loop_count
|
||||
Set loop count on an animated file.
|
||||
.P
|
||||
Where: 'loop_count' must be in range [0, 65535].
|
||||
.TP
|
||||
.BI icc " file.icc
|
||||
Set ICC profile.
|
||||
.P
|
||||
|
@ -36,7 +36,7 @@ libwebp_la_LIBADD += utils/libwebputils.la
|
||||
# other than the ones listed on the command line, i.e., after linking, it will
|
||||
# not have unresolved symbols. Some platforms (Windows among them) require all
|
||||
# symbols in shared libraries to be resolved at library creation.
|
||||
libwebp_la_LDFLAGS = -no-undefined -version-info 7:5:0
|
||||
libwebp_la_LDFLAGS = -no-undefined -version-info 8:1:1
|
||||
libwebpincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebp.pc
|
||||
|
||||
@ -48,7 +48,7 @@ if BUILD_LIBWEBPDECODER
|
||||
libwebpdecoder_la_LIBADD += dsp/libwebpdspdecode.la
|
||||
libwebpdecoder_la_LIBADD += utils/libwebputilsdecode.la
|
||||
|
||||
libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 3:5:0
|
||||
libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 4:1:1
|
||||
pkgconfig_DATA += libwebpdecoder.pc
|
||||
endif
|
||||
|
||||
|
@ -732,7 +732,7 @@ static int AllocateMemory(VP8Decoder* const dec) {
|
||||
mem += f_info_size;
|
||||
dec->thread_ctx_.id_ = 0;
|
||||
dec->thread_ctx_.f_info_ = dec->f_info_;
|
||||
if (dec->mt_method_ > 0) {
|
||||
if (dec->filter_type_ > 0 && dec->mt_method_ > 0) {
|
||||
// secondary cache line. The deblocking process need to make use of the
|
||||
// filtering strength from previous macroblock row, while the new ones
|
||||
// are being decoded in parallel. We'll just swap the pointers.
|
||||
|
@ -166,9 +166,11 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
|
||||
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
||||
MemBuffer* const mem = &idec->mem_;
|
||||
const int need_compressed_alpha = NeedCompressedAlpha(idec);
|
||||
const uint8_t* const old_start = mem->buf_ + mem->start_;
|
||||
const uint8_t* const old_start =
|
||||
(mem->buf_ == NULL) ? NULL : mem->buf_ + mem->start_;
|
||||
const uint8_t* const old_base =
|
||||
need_compressed_alpha ? dec->alpha_data_ : old_start;
|
||||
assert(mem->buf_ != NULL || mem->start_ == 0);
|
||||
assert(mem->mode_ == MEM_MODE_APPEND);
|
||||
if (data_size > MAX_CHUNK_PAYLOAD) {
|
||||
// security safeguard: trying to allocate more than what the format
|
||||
@ -184,7 +186,7 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
|
||||
uint8_t* const new_buf =
|
||||
(uint8_t*)WebPSafeMalloc(extra_size, sizeof(*new_buf));
|
||||
if (new_buf == NULL) return 0;
|
||||
memcpy(new_buf, old_base, current_size);
|
||||
if (old_base != NULL) memcpy(new_buf, old_base, current_size);
|
||||
WebPSafeFree(mem->buf_);
|
||||
mem->buf_ = new_buf;
|
||||
mem->buf_size_ = (size_t)extra_size;
|
||||
@ -192,6 +194,7 @@ static int AppendToMemBuffer(WebPIDecoder* const idec,
|
||||
mem->end_ = current_size;
|
||||
}
|
||||
|
||||
assert(mem->buf_ != NULL);
|
||||
memcpy(mem->buf_ + mem->end_, data, data_size);
|
||||
mem->end_ += data_size;
|
||||
assert(mem->end_ <= mem->buf_size_);
|
||||
@ -204,7 +207,9 @@ static int RemapMemBuffer(WebPIDecoder* const idec,
|
||||
const uint8_t* const data, size_t data_size) {
|
||||
MemBuffer* const mem = &idec->mem_;
|
||||
const uint8_t* const old_buf = mem->buf_;
|
||||
const uint8_t* const old_start = old_buf + mem->start_;
|
||||
const uint8_t* const old_start =
|
||||
(old_buf == NULL) ? NULL : old_buf + mem->start_;
|
||||
assert(old_buf != NULL || mem->start_ == 0);
|
||||
assert(mem->mode_ == MEM_MODE_MAP);
|
||||
|
||||
if (data_size < mem->buf_size_) return 0; // can't remap to a shorter buffer!
|
||||
|
@ -25,21 +25,16 @@
|
||||
static int EmitYUV(const VP8Io* const io, WebPDecParams* const p) {
|
||||
WebPDecBuffer* output = p->output;
|
||||
const WebPYUVABuffer* const buf = &output->u.YUVA;
|
||||
uint8_t* const y_dst = buf->y + io->mb_y * buf->y_stride;
|
||||
uint8_t* const u_dst = buf->u + (io->mb_y >> 1) * buf->u_stride;
|
||||
uint8_t* const v_dst = buf->v + (io->mb_y >> 1) * buf->v_stride;
|
||||
uint8_t* const y_dst = buf->y + (size_t)io->mb_y * buf->y_stride;
|
||||
uint8_t* const u_dst = buf->u + (size_t)(io->mb_y >> 1) * buf->u_stride;
|
||||
uint8_t* const v_dst = buf->v + (size_t)(io->mb_y >> 1) * buf->v_stride;
|
||||
const int mb_w = io->mb_w;
|
||||
const int mb_h = io->mb_h;
|
||||
const int uv_w = (mb_w + 1) / 2;
|
||||
const int uv_h = (mb_h + 1) / 2;
|
||||
int j;
|
||||
for (j = 0; j < mb_h; ++j) {
|
||||
memcpy(y_dst + j * buf->y_stride, io->y + j * io->y_stride, mb_w);
|
||||
}
|
||||
for (j = 0; j < uv_h; ++j) {
|
||||
memcpy(u_dst + j * buf->u_stride, io->u + j * io->uv_stride, uv_w);
|
||||
memcpy(v_dst + j * buf->v_stride, io->v + j * io->uv_stride, uv_w);
|
||||
}
|
||||
WebPCopyPlane(io->y, io->y_stride, y_dst, buf->y_stride, mb_w, mb_h);
|
||||
WebPCopyPlane(io->u, io->uv_stride, u_dst, buf->u_stride, uv_w, uv_h);
|
||||
WebPCopyPlane(io->v, io->uv_stride, v_dst, buf->v_stride, uv_w, uv_h);
|
||||
return io->mb_h;
|
||||
}
|
||||
|
||||
@ -47,7 +42,7 @@ static int EmitYUV(const VP8Io* const io, WebPDecParams* const p) {
|
||||
static int EmitSampledRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
WebPDecBuffer* const output = p->output;
|
||||
WebPRGBABuffer* const buf = &output->u.RGBA;
|
||||
uint8_t* const dst = buf->rgba + io->mb_y * buf->stride;
|
||||
uint8_t* const dst = buf->rgba + (size_t)io->mb_y * buf->stride;
|
||||
WebPSamplerProcessPlane(io->y, io->y_stride,
|
||||
io->u, io->v, io->uv_stride,
|
||||
dst, buf->stride, io->mb_w, io->mb_h,
|
||||
@ -62,7 +57,7 @@ static int EmitSampledRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
static int EmitFancyRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
int num_lines_out = io->mb_h; // a priori guess
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
uint8_t* dst = buf->rgba + io->mb_y * buf->stride;
|
||||
uint8_t* dst = buf->rgba + (size_t)io->mb_y * buf->stride;
|
||||
WebPUpsampleLinePairFunc upsample = WebPUpsamplers[p->output->colorspace];
|
||||
const uint8_t* cur_y = io->y;
|
||||
const uint8_t* cur_u = io->u;
|
||||
@ -133,7 +128,7 @@ static int EmitAlphaYUV(const VP8Io* const io, WebPDecParams* const p,
|
||||
const WebPYUVABuffer* const buf = &p->output->u.YUVA;
|
||||
const int mb_w = io->mb_w;
|
||||
const int mb_h = io->mb_h;
|
||||
uint8_t* dst = buf->a + io->mb_y * buf->a_stride;
|
||||
uint8_t* dst = buf->a + (size_t)io->mb_y * buf->a_stride;
|
||||
int j;
|
||||
(void)expected_num_lines_out;
|
||||
assert(expected_num_lines_out == mb_h);
|
||||
@ -186,7 +181,7 @@ static int EmitAlphaRGB(const VP8Io* const io, WebPDecParams* const p,
|
||||
(colorspace == MODE_ARGB || colorspace == MODE_Argb);
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
int num_rows;
|
||||
const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
|
||||
const size_t start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
|
||||
uint8_t* const base_rgba = buf->rgba + start_y * buf->stride;
|
||||
uint8_t* const dst = base_rgba + (alpha_first ? 0 : 3);
|
||||
const int has_alpha = WebPDispatchAlpha(alpha, io->width, mb_w,
|
||||
@ -210,7 +205,7 @@ static int EmitAlphaRGBA4444(const VP8Io* const io, WebPDecParams* const p,
|
||||
const WEBP_CSP_MODE colorspace = p->output->colorspace;
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
int num_rows;
|
||||
const int start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
|
||||
const size_t start_y = GetAlphaSourceRow(io, &alpha, &num_rows);
|
||||
uint8_t* const base_rgba = buf->rgba + start_y * buf->stride;
|
||||
#if (WEBP_SWAP_16BIT_CSP == 1)
|
||||
uint8_t* alpha_dst = base_rgba;
|
||||
@ -276,9 +271,9 @@ static int EmitRescaledYUV(const VP8Io* const io, WebPDecParams* const p) {
|
||||
static int EmitRescaledAlphaYUV(const VP8Io* const io, WebPDecParams* const p,
|
||||
int expected_num_lines_out) {
|
||||
const WebPYUVABuffer* const buf = &p->output->u.YUVA;
|
||||
uint8_t* const dst_a = buf->a + p->last_y * buf->a_stride;
|
||||
uint8_t* const dst_a = buf->a + (size_t)p->last_y * buf->a_stride;
|
||||
if (io->a != NULL) {
|
||||
uint8_t* const dst_y = buf->y + p->last_y * buf->y_stride;
|
||||
uint8_t* const dst_y = buf->y + (size_t)p->last_y * buf->y_stride;
|
||||
const int num_lines_out = Rescale(io->a, io->width, io->mb_h, p->scaler_a);
|
||||
assert(expected_num_lines_out == num_lines_out);
|
||||
if (num_lines_out > 0) { // unmultiply the Y
|
||||
@ -356,7 +351,7 @@ static int ExportRGB(WebPDecParams* const p, int y_pos) {
|
||||
const WebPYUV444Converter convert =
|
||||
WebPYUV444Converters[p->output->colorspace];
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
uint8_t* dst = buf->rgba + y_pos * buf->stride;
|
||||
uint8_t* dst = buf->rgba + (size_t)y_pos * buf->stride;
|
||||
int num_lines_out = 0;
|
||||
// For RGB rescaling, because of the YUV420, current scan position
|
||||
// U/V can be +1/-1 line from the Y one. Hence the double test.
|
||||
@ -383,15 +378,15 @@ static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
while (j < mb_h) {
|
||||
const int y_lines_in =
|
||||
WebPRescalerImport(p->scaler_y, mb_h - j,
|
||||
io->y + j * io->y_stride, io->y_stride);
|
||||
io->y + (size_t)j * io->y_stride, io->y_stride);
|
||||
j += y_lines_in;
|
||||
if (WebPRescaleNeededLines(p->scaler_u, uv_mb_h - uv_j)) {
|
||||
const int u_lines_in =
|
||||
WebPRescalerImport(p->scaler_u, uv_mb_h - uv_j,
|
||||
io->u + uv_j * io->uv_stride, io->uv_stride);
|
||||
const int v_lines_in =
|
||||
WebPRescalerImport(p->scaler_v, uv_mb_h - uv_j,
|
||||
io->v + uv_j * io->uv_stride, io->uv_stride);
|
||||
const int u_lines_in = WebPRescalerImport(
|
||||
p->scaler_u, uv_mb_h - uv_j, io->u + (size_t)uv_j * io->uv_stride,
|
||||
io->uv_stride);
|
||||
const int v_lines_in = WebPRescalerImport(
|
||||
p->scaler_v, uv_mb_h - uv_j, io->v + (size_t)uv_j * io->uv_stride,
|
||||
io->uv_stride);
|
||||
(void)v_lines_in; // remove a gcc warning
|
||||
assert(u_lines_in == v_lines_in);
|
||||
uv_j += u_lines_in;
|
||||
@ -403,7 +398,7 @@ static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
|
||||
static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) {
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride;
|
||||
uint8_t* const base_rgba = buf->rgba + (size_t)y_pos * buf->stride;
|
||||
const WEBP_CSP_MODE colorspace = p->output->colorspace;
|
||||
const int alpha_first =
|
||||
(colorspace == MODE_ARGB || colorspace == MODE_Argb);
|
||||
@ -431,7 +426,7 @@ static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) {
|
||||
static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos,
|
||||
int max_lines_out) {
|
||||
const WebPRGBABuffer* const buf = &p->output->u.RGBA;
|
||||
uint8_t* const base_rgba = buf->rgba + y_pos * buf->stride;
|
||||
uint8_t* const base_rgba = buf->rgba + (size_t)y_pos * buf->stride;
|
||||
#if (WEBP_SWAP_16BIT_CSP == 1)
|
||||
uint8_t* alpha_dst = base_rgba;
|
||||
#else
|
||||
@ -470,7 +465,7 @@ static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p,
|
||||
int lines_left = expected_num_out_lines;
|
||||
const int y_end = p->last_y + lines_left;
|
||||
while (lines_left > 0) {
|
||||
const int row_offset = scaler->src_y - io->mb_y;
|
||||
const int64_t row_offset = (int64_t)scaler->src_y - io->mb_y;
|
||||
WebPRescalerImport(scaler, io->mb_h + io->mb_y - scaler->src_y,
|
||||
io->a + row_offset * io->width, io->width);
|
||||
lines_left -= p->emit_alpha_row(p, y_end - lines_left, lines_left);
|
||||
|
@ -494,13 +494,11 @@ static int GetCoeffsAlt(VP8BitReader* const br,
|
||||
return 16;
|
||||
}
|
||||
|
||||
static WEBP_TSAN_IGNORE_FUNCTION void InitGetCoeffs(void) {
|
||||
if (GetCoeffs == NULL) {
|
||||
if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) {
|
||||
GetCoeffs = GetCoeffsAlt;
|
||||
} else {
|
||||
GetCoeffs = GetCoeffsFast;
|
||||
}
|
||||
WEBP_DSP_INIT_FUNC(InitGetCoeffs) {
|
||||
if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) {
|
||||
GetCoeffs = GetCoeffsAlt;
|
||||
} else {
|
||||
GetCoeffs = GetCoeffsFast;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ extern "C" {
|
||||
|
||||
// version numbers
|
||||
#define DEC_MAJ_VERSION 1
|
||||
#define DEC_MIN_VERSION 0
|
||||
#define DEC_REV_VERSION 3
|
||||
#define DEC_MIN_VERSION 2
|
||||
#define DEC_REV_VERSION 0
|
||||
|
||||
// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline).
|
||||
// Constraints are: We need to store one 16x16 block of luma samples (y),
|
||||
|
@ -951,7 +951,6 @@ static WEBP_INLINE void CopyBlock8b(uint8_t* const dst, int dist, int length) {
|
||||
break;
|
||||
default:
|
||||
goto Copy;
|
||||
break;
|
||||
}
|
||||
CopySmallPattern8b(src, dst, length, pattern);
|
||||
return;
|
||||
|
@ -37,7 +37,7 @@ struct VP8LTransform {
|
||||
int bits_; // subsampling bits defining transform window.
|
||||
int xsize_; // transform window X index.
|
||||
int ysize_; // transform window Y index.
|
||||
uint32_t *data_; // transform data.
|
||||
uint32_t* data_; // transform data.
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -48,9 +48,9 @@ typedef struct {
|
||||
int huffman_mask_;
|
||||
int huffman_subsample_bits_;
|
||||
int huffman_xsize_;
|
||||
uint32_t *huffman_image_;
|
||||
uint32_t* huffman_image_;
|
||||
int num_htree_groups_;
|
||||
HTreeGroup *htree_groups_;
|
||||
HTreeGroup* htree_groups_;
|
||||
HuffmanTables huffman_tables_;
|
||||
} VP8LMetadata;
|
||||
|
||||
@ -58,13 +58,13 @@ typedef struct VP8LDecoder VP8LDecoder;
|
||||
struct VP8LDecoder {
|
||||
VP8StatusCode status_;
|
||||
VP8LDecodeState state_;
|
||||
VP8Io *io_;
|
||||
VP8Io* io_;
|
||||
|
||||
const WebPDecBuffer *output_; // shortcut to io->opaque->output
|
||||
const WebPDecBuffer* output_; // shortcut to io->opaque->output
|
||||
|
||||
uint32_t *pixels_; // Internal data: either uint8_t* for alpha
|
||||
uint32_t* pixels_; // Internal data: either uint8_t* for alpha
|
||||
// or uint32_t* for BGRA.
|
||||
uint32_t *argb_cache_; // Scratch buffer for temporary BGRA storage.
|
||||
uint32_t* argb_cache_; // Scratch buffer for temporary BGRA storage.
|
||||
|
||||
VP8LBitReader br_;
|
||||
int incremental_; // if true, incremental decoding is expected
|
||||
@ -86,8 +86,8 @@ struct VP8LDecoder {
|
||||
// or'd bitset storing the transforms types.
|
||||
uint32_t transforms_seen_;
|
||||
|
||||
uint8_t *rescaler_memory; // Working memory for rescaling work.
|
||||
WebPRescaler *rescaler; // Common rescaler for all channels.
|
||||
uint8_t* rescaler_memory; // Working memory for rescaling work.
|
||||
WebPRescaler* rescaler; // Common rescaler for all channels.
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -13,6 +13,6 @@ noinst_HEADERS =
|
||||
noinst_HEADERS += ../webp/format_constants.h
|
||||
|
||||
libwebpdemux_la_LIBADD = ../libwebp.la
|
||||
libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:6:0
|
||||
libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:7:0
|
||||
libwebpdemuxincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebpdemux.pc
|
||||
|
@ -346,12 +346,15 @@ int WebPAnimDecoderGetNext(WebPAnimDecoder* dec,
|
||||
{
|
||||
const uint8_t* in = iter.fragment.bytes;
|
||||
const size_t in_size = iter.fragment.size;
|
||||
const size_t out_offset =
|
||||
(iter.y_offset * width + iter.x_offset) * NUM_CHANNELS;
|
||||
const uint32_t stride = width * NUM_CHANNELS; // at most 25 + 2 bits
|
||||
const uint64_t out_offset = (uint64_t)iter.y_offset * stride +
|
||||
(uint64_t)iter.x_offset * NUM_CHANNELS; // 53b
|
||||
const uint64_t size = (uint64_t)iter.height * stride; // at most 25 + 27b
|
||||
WebPDecoderConfig* const config = &dec->config_;
|
||||
WebPRGBABuffer* const buf = &config->output.u.RGBA;
|
||||
buf->stride = NUM_CHANNELS * width;
|
||||
buf->size = buf->stride * iter.height;
|
||||
if ((size_t)size != size) goto Error;
|
||||
buf->stride = (int)stride;
|
||||
buf->size = (size_t)size;
|
||||
buf->rgba = dec->curr_frame_ + out_offset;
|
||||
|
||||
if (WebPDecode(in, in_size, config) != VP8_STATUS_OK) {
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include "src/webp/format_constants.h"
|
||||
|
||||
#define DMUX_MAJ_VERSION 1
|
||||
#define DMUX_MIN_VERSION 0
|
||||
#define DMUX_REV_VERSION 3
|
||||
#define DMUX_MIN_VERSION 2
|
||||
#define DMUX_REV_VERSION 0
|
||||
|
||||
typedef struct {
|
||||
size_t start_; // start location of the data
|
||||
@ -312,6 +312,7 @@ static ParseStatus ParseAnimationFrame(
|
||||
int bits;
|
||||
MemBuffer* const mem = &dmux->mem_;
|
||||
Frame* frame;
|
||||
size_t start_offset;
|
||||
ParseStatus status =
|
||||
NewFrame(mem, ANMF_CHUNK_SIZE, frame_chunk_size, &frame);
|
||||
if (status != PARSE_OK) return status;
|
||||
@ -332,7 +333,11 @@ static ParseStatus ParseAnimationFrame(
|
||||
|
||||
// Store a frame only if the animation flag is set there is some data for
|
||||
// this frame is available.
|
||||
start_offset = mem->start_;
|
||||
status = StoreFrame(dmux->num_frames_ + 1, anmf_payload_size, mem, frame);
|
||||
if (status != PARSE_ERROR && mem->start_ - start_offset > anmf_payload_size) {
|
||||
status = PARSE_ERROR;
|
||||
}
|
||||
if (status != PARSE_ERROR && is_animation && frame->frame_num_ > 0) {
|
||||
added_frame = AddFrame(dmux, frame);
|
||||
if (added_frame) {
|
||||
|
@ -6,8 +6,8 @@
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,3
|
||||
PRODUCTVERSION 1,0,0,3
|
||||
FILEVERSION 1,0,2,0
|
||||
PRODUCTVERSION 1,0,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -24,12 +24,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebpdemux DLL"
|
||||
VALUE "FileVersion", "1.0.3"
|
||||
VALUE "FileVersion", "1.2.0"
|
||||
VALUE "InternalName", "libwebpdemux.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019"
|
||||
VALUE "OriginalFilename", "libwebpdemux.dll"
|
||||
VALUE "ProductName", "WebP Image Demuxer"
|
||||
VALUE "ProductVersion", "1.0.3"
|
||||
VALUE "ProductVersion", "1.2.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -359,6 +359,11 @@ static int HasAlpha32b_C(const uint8_t* src, int length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void AlphaReplace_C(uint32_t* src, int length, uint32_t color) {
|
||||
int x;
|
||||
for (x = 0; x < length; ++x) if ((src[x] >> 24) == 0) src[x] = color;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Simple channel manipulations.
|
||||
|
||||
@ -400,6 +405,7 @@ void (*WebPPackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
|
||||
|
||||
int (*WebPHasAlpha8b)(const uint8_t* src, int length);
|
||||
int (*WebPHasAlpha32b)(const uint8_t* src, int length);
|
||||
void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Init function
|
||||
@ -428,6 +434,7 @@ WEBP_DSP_INIT_FUNC(WebPInitAlphaProcessing) {
|
||||
|
||||
WebPHasAlpha8b = HasAlpha8b_C;
|
||||
WebPHasAlpha32b = HasAlpha32b_C;
|
||||
WebPAlphaReplace = AlphaReplace_C;
|
||||
|
||||
// If defined, use CPUInfo() to overwrite some pointers with faster versions.
|
||||
if (VP8GetCPUInfo != NULL) {
|
||||
@ -469,4 +476,5 @@ WEBP_DSP_INIT_FUNC(WebPInitAlphaProcessing) {
|
||||
assert(WebPPackRGB != NULL);
|
||||
assert(WebPHasAlpha8b != NULL);
|
||||
assert(WebPHasAlpha32b != NULL);
|
||||
assert(WebPAlphaReplace != NULL);
|
||||
}
|
||||
|
@ -265,6 +265,27 @@ static int HasAlpha32b_SSE2(const uint8_t* src, int length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void AlphaReplace_SSE2(uint32_t* src, int length, uint32_t color) {
|
||||
const __m128i m_color = _mm_set1_epi32(color);
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
int i = 0;
|
||||
for (; i + 8 <= length; i += 8) {
|
||||
const __m128i a0 = _mm_loadu_si128((const __m128i*)(src + i + 0));
|
||||
const __m128i a1 = _mm_loadu_si128((const __m128i*)(src + i + 4));
|
||||
const __m128i b0 = _mm_srai_epi32(a0, 24);
|
||||
const __m128i b1 = _mm_srai_epi32(a1, 24);
|
||||
const __m128i c0 = _mm_cmpeq_epi32(b0, zero);
|
||||
const __m128i c1 = _mm_cmpeq_epi32(b1, zero);
|
||||
const __m128i d0 = _mm_and_si128(c0, m_color);
|
||||
const __m128i d1 = _mm_and_si128(c1, m_color);
|
||||
const __m128i e0 = _mm_andnot_si128(c0, a0);
|
||||
const __m128i e1 = _mm_andnot_si128(c1, a1);
|
||||
_mm_storeu_si128((__m128i*)(src + i + 0), _mm_or_si128(d0, e0));
|
||||
_mm_storeu_si128((__m128i*)(src + i + 4), _mm_or_si128(d1, e1));
|
||||
}
|
||||
for (; i < length; ++i) if ((src[i] >> 24) == 0) src[i] = color;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Apply alpha value to rows
|
||||
|
||||
@ -334,6 +355,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE2(void) {
|
||||
|
||||
WebPHasAlpha8b = HasAlpha8b_SSE2;
|
||||
WebPHasAlpha32b = HasAlpha32b_SSE2;
|
||||
WebPAlphaReplace = AlphaReplace_SSE2;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_SSE2
|
||||
|
@ -55,12 +55,18 @@ static WEBP_INLINE void GetCPUInfo(int cpu_info[4], int info_type) {
|
||||
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
|
||||
: "a"(info_type), "c"(0));
|
||||
}
|
||||
#elif (defined(_M_X64) || defined(_M_IX86)) && \
|
||||
defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // >= VS2008 SP1
|
||||
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
|
||||
|
||||
#if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 150030729 // >= VS2008 SP1
|
||||
#include <intrin.h>
|
||||
#define GetCPUInfo(info, type) __cpuidex(info, type, 0) // set ecx=0
|
||||
#elif defined(WEBP_MSC_SSE2)
|
||||
#define WEBP_HAVE_MSC_CPUID
|
||||
#elif _MSC_VER > 1310
|
||||
#include <intrin.h>
|
||||
#define GetCPUInfo __cpuid
|
||||
#define WEBP_HAVE_MSC_CPUID
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// NaCl has no support for xgetbv or the raw opcode.
|
||||
@ -94,7 +100,7 @@ static WEBP_INLINE uint64_t xgetbv(void) {
|
||||
#define xgetbv() 0U // no AVX for older x64 or unrecognized toolchains.
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_MSC_SSE2)
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(WEBP_HAVE_MSC_CPUID)
|
||||
|
||||
// helper function for run-time detection of slow SSSE3 platforms
|
||||
static int CheckSlowModel(int info) {
|
||||
@ -179,6 +185,30 @@ static int AndroidCPUInfo(CPUFeature feature) {
|
||||
return 0;
|
||||
}
|
||||
VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo;
|
||||
#elif defined(EMSCRIPTEN) // also needs to be before generic NEON test
|
||||
// Use compile flags as an indicator of SIMD support instead of a runtime check.
|
||||
static int wasmCPUInfo(CPUFeature feature) {
|
||||
switch (feature) {
|
||||
#ifdef WEBP_USE_SSE2
|
||||
case kSSE2:
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef WEBP_USE_SSE41
|
||||
case kSSE3:
|
||||
case kSlowSSSE3:
|
||||
case kSSE4_1:
|
||||
return 1;
|
||||
#endif
|
||||
#ifdef WEBP_USE_NEON
|
||||
case kNEON:
|
||||
return 1;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo;
|
||||
#elif defined(WEBP_USE_NEON)
|
||||
// define a dummy function to enable turning off NEON at runtime by setting
|
||||
// VP8DecGetCPUInfo = NULL
|
||||
|
@ -1283,12 +1283,12 @@ static void DC4_NEON(uint8_t* dst) { // DC
|
||||
const uint8x8_t A = vld1_u8(dst - BPS); // top row
|
||||
const uint16x4_t p0 = vpaddl_u8(A); // cascading summation of the top
|
||||
const uint16x4_t p1 = vpadd_u16(p0, p0);
|
||||
const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + 0 * BPS - 1));
|
||||
const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + 1 * BPS - 1));
|
||||
const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + 2 * BPS - 1));
|
||||
const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + 3 * BPS - 1));
|
||||
const uint16x8_t s0 = vaddq_u16(L0, L1);
|
||||
const uint16x8_t s1 = vaddq_u16(L2, L3);
|
||||
const uint8x8_t L0 = vld1_u8(dst + 0 * BPS - 1);
|
||||
const uint8x8_t L1 = vld1_u8(dst + 1 * BPS - 1);
|
||||
const uint8x8_t L2 = vld1_u8(dst + 2 * BPS - 1);
|
||||
const uint8x8_t L3 = vld1_u8(dst + 3 * BPS - 1);
|
||||
const uint16x8_t s0 = vaddl_u8(L0, L1);
|
||||
const uint16x8_t s1 = vaddl_u8(L2, L3);
|
||||
const uint16x8_t s01 = vaddq_u16(s0, s1);
|
||||
const uint16x8_t sum = vaddq_u16(s01, vcombine_u16(p1, p1));
|
||||
const uint8x8_t dc0 = vrshrn_n_u16(sum, 3); // (sum + 4) >> 3
|
||||
@ -1361,7 +1361,8 @@ static void RD4_NEON(uint8_t* dst) { // Down-right
|
||||
const uint32_t J = dst[-1 + 1 * BPS];
|
||||
const uint32_t K = dst[-1 + 2 * BPS];
|
||||
const uint32_t L = dst[-1 + 3 * BPS];
|
||||
const uint64x1_t LKJI____ = vcreate_u64(L | (K << 8) | (J << 16) | (I << 24));
|
||||
const uint64x1_t LKJI____ =
|
||||
vcreate_u64((uint64_t)L | (K << 8) | (J << 16) | (I << 24));
|
||||
const uint64x1_t LKJIXABC = vorr_u64(LKJI____, ____XABC);
|
||||
const uint8x8_t KJIXABC_ = vreinterpret_u8_u64(vshr_n_u64(LKJIXABC, 8));
|
||||
const uint8x8_t JIXABC__ = vreinterpret_u8_u64(vshr_n_u64(LKJIXABC, 16));
|
||||
@ -1427,25 +1428,30 @@ static WEBP_INLINE void DC8_NEON(uint8_t* dst, int do_top, int do_left) {
|
||||
|
||||
if (do_top) {
|
||||
const uint8x8_t A = vld1_u8(dst - BPS); // top row
|
||||
#if defined(__aarch64__)
|
||||
const uint16_t p2 = vaddlv_u8(A);
|
||||
sum_top = vdupq_n_u16(p2);
|
||||
#else
|
||||
const uint16x4_t p0 = vpaddl_u8(A); // cascading summation of the top
|
||||
const uint16x4_t p1 = vpadd_u16(p0, p0);
|
||||
const uint16x4_t p2 = vpadd_u16(p1, p1);
|
||||
sum_top = vcombine_u16(p2, p2);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (do_left) {
|
||||
const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + 0 * BPS - 1));
|
||||
const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + 1 * BPS - 1));
|
||||
const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + 2 * BPS - 1));
|
||||
const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + 3 * BPS - 1));
|
||||
const uint16x8_t L4 = vmovl_u8(vld1_u8(dst + 4 * BPS - 1));
|
||||
const uint16x8_t L5 = vmovl_u8(vld1_u8(dst + 5 * BPS - 1));
|
||||
const uint16x8_t L6 = vmovl_u8(vld1_u8(dst + 6 * BPS - 1));
|
||||
const uint16x8_t L7 = vmovl_u8(vld1_u8(dst + 7 * BPS - 1));
|
||||
const uint16x8_t s0 = vaddq_u16(L0, L1);
|
||||
const uint16x8_t s1 = vaddq_u16(L2, L3);
|
||||
const uint16x8_t s2 = vaddq_u16(L4, L5);
|
||||
const uint16x8_t s3 = vaddq_u16(L6, L7);
|
||||
const uint8x8_t L0 = vld1_u8(dst + 0 * BPS - 1);
|
||||
const uint8x8_t L1 = vld1_u8(dst + 1 * BPS - 1);
|
||||
const uint8x8_t L2 = vld1_u8(dst + 2 * BPS - 1);
|
||||
const uint8x8_t L3 = vld1_u8(dst + 3 * BPS - 1);
|
||||
const uint8x8_t L4 = vld1_u8(dst + 4 * BPS - 1);
|
||||
const uint8x8_t L5 = vld1_u8(dst + 5 * BPS - 1);
|
||||
const uint8x8_t L6 = vld1_u8(dst + 6 * BPS - 1);
|
||||
const uint8x8_t L7 = vld1_u8(dst + 7 * BPS - 1);
|
||||
const uint16x8_t s0 = vaddl_u8(L0, L1);
|
||||
const uint16x8_t s1 = vaddl_u8(L2, L3);
|
||||
const uint16x8_t s2 = vaddl_u8(L4, L5);
|
||||
const uint16x8_t s3 = vaddl_u8(L6, L7);
|
||||
const uint16x8_t s01 = vaddq_u16(s0, s1);
|
||||
const uint16x8_t s23 = vaddq_u16(s2, s3);
|
||||
sum_left = vaddq_u16(s01, s23);
|
||||
@ -1505,29 +1511,34 @@ static WEBP_INLINE void DC16_NEON(uint8_t* dst, int do_top, int do_left) {
|
||||
|
||||
if (do_top) {
|
||||
const uint8x16_t A = vld1q_u8(dst - BPS); // top row
|
||||
#if defined(__aarch64__)
|
||||
const uint16_t p3 = vaddlvq_u8(A);
|
||||
sum_top = vdupq_n_u16(p3);
|
||||
#else
|
||||
const uint16x8_t p0 = vpaddlq_u8(A); // cascading summation of the top
|
||||
const uint16x4_t p1 = vadd_u16(vget_low_u16(p0), vget_high_u16(p0));
|
||||
const uint16x4_t p2 = vpadd_u16(p1, p1);
|
||||
const uint16x4_t p3 = vpadd_u16(p2, p2);
|
||||
sum_top = vcombine_u16(p3, p3);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (do_left) {
|
||||
int i;
|
||||
sum_left = vdupq_n_u16(0);
|
||||
for (i = 0; i < 16; i += 8) {
|
||||
const uint16x8_t L0 = vmovl_u8(vld1_u8(dst + (i + 0) * BPS - 1));
|
||||
const uint16x8_t L1 = vmovl_u8(vld1_u8(dst + (i + 1) * BPS - 1));
|
||||
const uint16x8_t L2 = vmovl_u8(vld1_u8(dst + (i + 2) * BPS - 1));
|
||||
const uint16x8_t L3 = vmovl_u8(vld1_u8(dst + (i + 3) * BPS - 1));
|
||||
const uint16x8_t L4 = vmovl_u8(vld1_u8(dst + (i + 4) * BPS - 1));
|
||||
const uint16x8_t L5 = vmovl_u8(vld1_u8(dst + (i + 5) * BPS - 1));
|
||||
const uint16x8_t L6 = vmovl_u8(vld1_u8(dst + (i + 6) * BPS - 1));
|
||||
const uint16x8_t L7 = vmovl_u8(vld1_u8(dst + (i + 7) * BPS - 1));
|
||||
const uint16x8_t s0 = vaddq_u16(L0, L1);
|
||||
const uint16x8_t s1 = vaddq_u16(L2, L3);
|
||||
const uint16x8_t s2 = vaddq_u16(L4, L5);
|
||||
const uint16x8_t s3 = vaddq_u16(L6, L7);
|
||||
const uint8x8_t L0 = vld1_u8(dst + (i + 0) * BPS - 1);
|
||||
const uint8x8_t L1 = vld1_u8(dst + (i + 1) * BPS - 1);
|
||||
const uint8x8_t L2 = vld1_u8(dst + (i + 2) * BPS - 1);
|
||||
const uint8x8_t L3 = vld1_u8(dst + (i + 3) * BPS - 1);
|
||||
const uint8x8_t L4 = vld1_u8(dst + (i + 4) * BPS - 1);
|
||||
const uint8x8_t L5 = vld1_u8(dst + (i + 5) * BPS - 1);
|
||||
const uint8x8_t L6 = vld1_u8(dst + (i + 6) * BPS - 1);
|
||||
const uint8x8_t L7 = vld1_u8(dst + (i + 7) * BPS - 1);
|
||||
const uint16x8_t s0 = vaddl_u8(L0, L1);
|
||||
const uint16x8_t s1 = vaddl_u8(L2, L3);
|
||||
const uint16x8_t s2 = vaddl_u8(L4, L5);
|
||||
const uint16x8_t s3 = vaddl_u8(L6, L7);
|
||||
const uint16x8_t s01 = vaddq_u16(s0, s1);
|
||||
const uint16x8_t s23 = vaddq_u16(s2, s3);
|
||||
const uint16x8_t sum = vaddq_u16(s01, s23);
|
||||
|
@ -51,9 +51,7 @@ extern "C" {
|
||||
# define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
// for now, none of the optimizations below are available in emscripten
|
||||
#if !defined(EMSCRIPTEN)
|
||||
|
||||
#if !defined(HAVE_CONFIG_H)
|
||||
#if defined(_MSC_VER) && _MSC_VER > 1310 && \
|
||||
(defined(_M_X64) || defined(_M_IX86))
|
||||
#define WEBP_MSC_SSE2 // Visual C++ SSE2 targets
|
||||
@ -63,6 +61,7 @@ extern "C" {
|
||||
(defined(_M_X64) || defined(_M_IX86))
|
||||
#define WEBP_MSC_SSE41 // Visual C++ SSE4.1 targets
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp
|
||||
// files without intrinsics, allowing the corresponding Init() to be called.
|
||||
@ -76,6 +75,9 @@ extern "C" {
|
||||
#define WEBP_USE_SSE41
|
||||
#endif
|
||||
|
||||
#undef WEBP_MSC_SSE41
|
||||
#undef WEBP_MSC_SSE2
|
||||
|
||||
// The intrinsics currently cause compiler errors with arm-nacl-gcc and the
|
||||
// inline assembly would need to be modified for use with Native Client.
|
||||
#if (defined(__ARM_NEON__) || \
|
||||
@ -110,8 +112,6 @@ extern "C" {
|
||||
#define WEBP_USE_MSA
|
||||
#endif
|
||||
|
||||
#endif /* EMSCRIPTEN */
|
||||
|
||||
#ifndef WEBP_DSP_OMIT_C_CODE
|
||||
#define WEBP_DSP_OMIT_C_CODE 1
|
||||
#endif
|
||||
@ -193,6 +193,12 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// If 'ptr' is NULL, returns NULL. Otherwise returns 'ptr + off'.
|
||||
// Prevents undefined behavior sanitizer nullptr-with-nonzero-offset warning.
|
||||
#if !defined(WEBP_OFFSET_PTR)
|
||||
#define WEBP_OFFSET_PTR(ptr, off) (((ptr) == NULL) ? NULL : ((ptr) + (off)))
|
||||
#endif
|
||||
|
||||
// Regularize the definition of WEBP_SWAP_16BIT_CSP (backward compatibility)
|
||||
#if !defined(WEBP_SWAP_16BIT_CSP)
|
||||
#define WEBP_SWAP_16BIT_CSP 0
|
||||
@ -246,9 +252,9 @@ extern VP8Fdct VP8FTransform2; // performs two transforms at a time
|
||||
extern VP8WHT VP8FTransformWHT;
|
||||
// Predictions
|
||||
// *dst is the destination block. *top and *left can be NULL.
|
||||
typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
|
||||
typedef void (*VP8IntraPreds)(uint8_t* dst, const uint8_t* left,
|
||||
const uint8_t* top);
|
||||
typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
|
||||
typedef void (*VP8Intra4Preds)(uint8_t* dst, const uint8_t* top);
|
||||
extern VP8Intra4Preds VP8EncPredLuma4;
|
||||
extern VP8IntraPreds VP8EncPredLuma16;
|
||||
extern VP8IntraPreds VP8EncPredChroma8;
|
||||
@ -632,6 +638,8 @@ extern void (*WebPPackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
|
||||
extern int (*WebPHasAlpha8b)(const uint8_t* src, int length);
|
||||
// This function returns true if src[4*i] contains a value different from 0xff.
|
||||
extern int (*WebPHasAlpha32b)(const uint8_t* src, int length);
|
||||
// replaces transparent values in src[] by 'color'.
|
||||
extern void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color);
|
||||
|
||||
// To be called first before using the above.
|
||||
void WebPInitAlphaProcessing(void);
|
||||
|
@ -81,7 +81,7 @@ static WEBP_INLINE uint32_t ClampedAddSubtractHalf(uint32_t c0, uint32_t c1,
|
||||
|
||||
// gcc <= 4.9 on ARM generates incorrect code in Select() when Sub3() is
|
||||
// inlined.
|
||||
#if defined(__arm__) && LOCAL_GCC_VERSION <= 0x409
|
||||
#if defined(__arm__) && defined(__GNUC__) && LOCAL_GCC_VERSION <= 0x409
|
||||
# define LOCAL_INLINE __attribute__ ((noinline))
|
||||
#else
|
||||
# define LOCAL_INLINE WEBP_INLINE
|
||||
@ -107,88 +107,93 @@ static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) {
|
||||
//------------------------------------------------------------------------------
|
||||
// Predictors
|
||||
|
||||
static uint32_t Predictor0_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor0_C(uint32_t left, const uint32_t* const top) {
|
||||
(void)top;
|
||||
(void)left;
|
||||
return ARGB_BLACK;
|
||||
}
|
||||
static uint32_t Predictor1_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor1_C(uint32_t left, const uint32_t* const top) {
|
||||
(void)top;
|
||||
return left;
|
||||
}
|
||||
static uint32_t Predictor2_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor2_C(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[0];
|
||||
}
|
||||
static uint32_t Predictor3_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor3_C(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[1];
|
||||
}
|
||||
static uint32_t Predictor4_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor4_C(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[-1];
|
||||
}
|
||||
static uint32_t Predictor5_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor5_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average3(left, top[0], top[1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor6_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor6_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(left, top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor7_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor7_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(left, top[0]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor8_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor8_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(top[-1], top[0]);
|
||||
(void)left;
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor9_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor9_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(top[0], top[1]);
|
||||
(void)left;
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor10_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor10_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average4(left, top[-1], top[0], top[1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor11_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor11_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Select(top[0], left, top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor12_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor12_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = ClampedAddSubtractFull(left, top[0], top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor13_C(uint32_t left, const uint32_t* const top) {
|
||||
uint32_t VP8LPredictor13_C(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = ClampedAddSubtractHalf(left, top[0], top[-1]);
|
||||
return pred;
|
||||
}
|
||||
|
||||
GENERATE_PREDICTOR_ADD(Predictor0_C, PredictorAdd0_C)
|
||||
static void PredictorAdd0_C(const uint32_t* in, const uint32_t* upper,
|
||||
int num_pixels, uint32_t* out) {
|
||||
int x;
|
||||
(void)upper;
|
||||
for (x = 0; x < num_pixels; ++x) out[x] = VP8LAddPixels(in[x], ARGB_BLACK);
|
||||
}
|
||||
static void PredictorAdd1_C(const uint32_t* in, const uint32_t* upper,
|
||||
int num_pixels, uint32_t* out) {
|
||||
int i;
|
||||
uint32_t left = out[-1];
|
||||
(void)upper;
|
||||
for (i = 0; i < num_pixels; ++i) {
|
||||
out[i] = left = VP8LAddPixels(in[i], left);
|
||||
}
|
||||
(void)upper;
|
||||
}
|
||||
GENERATE_PREDICTOR_ADD(Predictor2_C, PredictorAdd2_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor3_C, PredictorAdd3_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor4_C, PredictorAdd4_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor5_C, PredictorAdd5_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor6_C, PredictorAdd6_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor7_C, PredictorAdd7_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor8_C, PredictorAdd8_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor9_C, PredictorAdd9_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor10_C, PredictorAdd10_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor11_C, PredictorAdd11_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor12_C, PredictorAdd12_C)
|
||||
GENERATE_PREDICTOR_ADD(Predictor13_C, PredictorAdd13_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor2_C, PredictorAdd2_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor3_C, PredictorAdd3_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor4_C, PredictorAdd4_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor5_C, PredictorAdd5_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor6_C, PredictorAdd6_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor7_C, PredictorAdd7_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor8_C, PredictorAdd8_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor9_C, PredictorAdd9_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor10_C, PredictorAdd10_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor11_C, PredictorAdd11_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor12_C, PredictorAdd12_C)
|
||||
GENERATE_PREDICTOR_ADD(VP8LPredictor13_C, PredictorAdd13_C)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -557,7 +562,6 @@ VP8LPredictorFunc VP8LPredictors[16];
|
||||
|
||||
// exposed plain-C implementations
|
||||
VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];
|
||||
VP8LPredictorFunc VP8LPredictors_C[16];
|
||||
|
||||
VP8LTransformColorInverseFunc VP8LTransformColorInverse;
|
||||
|
||||
@ -595,8 +599,7 @@ extern void VP8LDspInitMSA(void);
|
||||
} while (0);
|
||||
|
||||
WEBP_DSP_INIT_FUNC(VP8LDspInit) {
|
||||
COPY_PREDICTOR_ARRAY(Predictor, VP8LPredictors)
|
||||
COPY_PREDICTOR_ARRAY(Predictor, VP8LPredictors_C)
|
||||
COPY_PREDICTOR_ARRAY(VP8LPredictor, VP8LPredictors)
|
||||
COPY_PREDICTOR_ARRAY(PredictorAdd, VP8LPredictorsAdd)
|
||||
COPY_PREDICTOR_ARRAY(PredictorAdd, VP8LPredictorsAdd_C)
|
||||
|
||||
|
@ -30,7 +30,22 @@ extern "C" {
|
||||
|
||||
typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);
|
||||
extern VP8LPredictorFunc VP8LPredictors[16];
|
||||
extern VP8LPredictorFunc VP8LPredictors_C[16];
|
||||
|
||||
uint32_t VP8LPredictor0_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor1_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor2_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor3_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor4_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor5_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor6_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor7_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor8_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor9_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor10_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor11_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor12_C(uint32_t left, const uint32_t* const top);
|
||||
uint32_t VP8LPredictor13_C(uint32_t left, const uint32_t* const top);
|
||||
|
||||
// These Add/Sub function expects upper[-1] and out[-1] to be readable.
|
||||
typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,
|
||||
const uint32_t* upper, int num_pixels,
|
||||
|
@ -177,24 +177,13 @@ uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
|
||||
static void PREDICTOR_ADD(const uint32_t* in, const uint32_t* upper, \
|
||||
int num_pixels, uint32_t* out) { \
|
||||
int x; \
|
||||
assert(upper != NULL); \
|
||||
for (x = 0; x < num_pixels; ++x) { \
|
||||
const uint32_t pred = (PREDICTOR)(out[x - 1], upper + x); \
|
||||
out[x] = VP8LAddPixels(in[x], pred); \
|
||||
} \
|
||||
}
|
||||
|
||||
// It subtracts the prediction from the input pixel and stores the residual
|
||||
// in the output pixel.
|
||||
#define GENERATE_PREDICTOR_SUB(PREDICTOR, PREDICTOR_SUB) \
|
||||
static void PREDICTOR_SUB(const uint32_t* in, const uint32_t* upper, \
|
||||
int num_pixels, uint32_t* out) { \
|
||||
int x; \
|
||||
for (x = 0; x < num_pixels; ++x) { \
|
||||
const uint32_t pred = (PREDICTOR)(in[x - 1], upper + x); \
|
||||
out[x] = VP8LSubPixels(in[x], pred); \
|
||||
} \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
@ -702,140 +702,6 @@ void VP8LHistogramAdd(const VP8LHistogram* const a,
|
||||
//------------------------------------------------------------------------------
|
||||
// Image transforms.
|
||||
|
||||
static WEBP_INLINE uint32_t Average2(uint32_t a0, uint32_t a1) {
|
||||
return (((a0 ^ a1) & 0xfefefefeu) >> 1) + (a0 & a1);
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t Average3(uint32_t a0, uint32_t a1, uint32_t a2) {
|
||||
return Average2(Average2(a0, a2), a1);
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t Average4(uint32_t a0, uint32_t a1,
|
||||
uint32_t a2, uint32_t a3) {
|
||||
return Average2(Average2(a0, a1), Average2(a2, a3));
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t Clip255(uint32_t a) {
|
||||
if (a < 256) {
|
||||
return a;
|
||||
}
|
||||
// return 0, when a is a negative integer.
|
||||
// return 255, when a is positive.
|
||||
return ~a >> 24;
|
||||
}
|
||||
|
||||
static WEBP_INLINE int AddSubtractComponentFull(int a, int b, int c) {
|
||||
return Clip255(a + b - c);
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t ClampedAddSubtractFull(uint32_t c0, uint32_t c1,
|
||||
uint32_t c2) {
|
||||
const int a = AddSubtractComponentFull(c0 >> 24, c1 >> 24, c2 >> 24);
|
||||
const int r = AddSubtractComponentFull((c0 >> 16) & 0xff,
|
||||
(c1 >> 16) & 0xff,
|
||||
(c2 >> 16) & 0xff);
|
||||
const int g = AddSubtractComponentFull((c0 >> 8) & 0xff,
|
||||
(c1 >> 8) & 0xff,
|
||||
(c2 >> 8) & 0xff);
|
||||
const int b = AddSubtractComponentFull(c0 & 0xff, c1 & 0xff, c2 & 0xff);
|
||||
return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
static WEBP_INLINE int AddSubtractComponentHalf(int a, int b) {
|
||||
return Clip255(a + (a - b) / 2);
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t ClampedAddSubtractHalf(uint32_t c0, uint32_t c1,
|
||||
uint32_t c2) {
|
||||
const uint32_t ave = Average2(c0, c1);
|
||||
const int a = AddSubtractComponentHalf(ave >> 24, c2 >> 24);
|
||||
const int r = AddSubtractComponentHalf((ave >> 16) & 0xff, (c2 >> 16) & 0xff);
|
||||
const int g = AddSubtractComponentHalf((ave >> 8) & 0xff, (c2 >> 8) & 0xff);
|
||||
const int b = AddSubtractComponentHalf((ave >> 0) & 0xff, (c2 >> 0) & 0xff);
|
||||
return ((uint32_t)a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
// gcc-4.9 on ARM generates incorrect code in Select() when Sub3() is inlined.
|
||||
#if defined(__arm__) && \
|
||||
(LOCAL_GCC_VERSION == 0x409 || LOCAL_GCC_VERSION == 0x408)
|
||||
# define LOCAL_INLINE __attribute__ ((noinline))
|
||||
#else
|
||||
# define LOCAL_INLINE WEBP_INLINE
|
||||
#endif
|
||||
|
||||
static LOCAL_INLINE int Sub3(int a, int b, int c) {
|
||||
const int pb = b - c;
|
||||
const int pa = a - c;
|
||||
return abs(pb) - abs(pa);
|
||||
}
|
||||
|
||||
#undef LOCAL_INLINE
|
||||
|
||||
static WEBP_INLINE uint32_t Select(uint32_t a, uint32_t b, uint32_t c) {
|
||||
const int pa_minus_pb =
|
||||
Sub3((a >> 24) , (b >> 24) , (c >> 24) ) +
|
||||
Sub3((a >> 16) & 0xff, (b >> 16) & 0xff, (c >> 16) & 0xff) +
|
||||
Sub3((a >> 8) & 0xff, (b >> 8) & 0xff, (c >> 8) & 0xff) +
|
||||
Sub3((a ) & 0xff, (b ) & 0xff, (c ) & 0xff);
|
||||
return (pa_minus_pb <= 0) ? a : b;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Predictors
|
||||
|
||||
static uint32_t Predictor2(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[0];
|
||||
}
|
||||
static uint32_t Predictor3(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[1];
|
||||
}
|
||||
static uint32_t Predictor4(uint32_t left, const uint32_t* const top) {
|
||||
(void)left;
|
||||
return top[-1];
|
||||
}
|
||||
static uint32_t Predictor5(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average3(left, top[0], top[1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor6(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(left, top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor7(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(left, top[0]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor8(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(top[-1], top[0]);
|
||||
(void)left;
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor9(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average2(top[0], top[1]);
|
||||
(void)left;
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor10(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Average4(left, top[-1], top[0], top[1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor11(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = Select(top[0], left, top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor12(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = ClampedAddSubtractFull(left, top[0], top[-1]);
|
||||
return pred;
|
||||
}
|
||||
static uint32_t Predictor13(uint32_t left, const uint32_t* const top) {
|
||||
const uint32_t pred = ClampedAddSubtractHalf(left, top[0], top[-1]);
|
||||
return pred;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static void PredictorSub0_C(const uint32_t* in, const uint32_t* upper,
|
||||
int num_pixels, uint32_t* out) {
|
||||
int i;
|
||||
@ -850,18 +716,33 @@ static void PredictorSub1_C(const uint32_t* in, const uint32_t* upper,
|
||||
(void)upper;
|
||||
}
|
||||
|
||||
GENERATE_PREDICTOR_SUB(Predictor2, PredictorSub2_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor3, PredictorSub3_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor4, PredictorSub4_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor5, PredictorSub5_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor6, PredictorSub6_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor7, PredictorSub7_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor8, PredictorSub8_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor9, PredictorSub9_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor10, PredictorSub10_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor11, PredictorSub11_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor12, PredictorSub12_C)
|
||||
GENERATE_PREDICTOR_SUB(Predictor13, PredictorSub13_C)
|
||||
// It subtracts the prediction from the input pixel and stores the residual
|
||||
// in the output pixel.
|
||||
#define GENERATE_PREDICTOR_SUB(PREDICTOR_I) \
|
||||
static void PredictorSub##PREDICTOR_I##_C(const uint32_t* in, \
|
||||
const uint32_t* upper, \
|
||||
int num_pixels, uint32_t* out) { \
|
||||
int x; \
|
||||
assert(upper != NULL); \
|
||||
for (x = 0; x < num_pixels; ++x) { \
|
||||
const uint32_t pred = \
|
||||
VP8LPredictor##PREDICTOR_I##_C(in[x - 1], upper + x); \
|
||||
out[x] = VP8LSubPixels(in[x], pred); \
|
||||
} \
|
||||
}
|
||||
|
||||
GENERATE_PREDICTOR_SUB(2)
|
||||
GENERATE_PREDICTOR_SUB(3)
|
||||
GENERATE_PREDICTOR_SUB(4)
|
||||
GENERATE_PREDICTOR_SUB(5)
|
||||
GENERATE_PREDICTOR_SUB(6)
|
||||
GENERATE_PREDICTOR_SUB(7)
|
||||
GENERATE_PREDICTOR_SUB(8)
|
||||
GENERATE_PREDICTOR_SUB(9)
|
||||
GENERATE_PREDICTOR_SUB(10)
|
||||
GENERATE_PREDICTOR_SUB(11)
|
||||
GENERATE_PREDICTOR_SUB(12)
|
||||
GENERATE_PREDICTOR_SUB(13)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -249,6 +249,7 @@ static void AddVectorEq_SSE2(const uint32_t* a, uint32_t* out, int size) {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if !(defined(__i386__) || defined(_M_IX86))
|
||||
static float CombinedShannonEntropy_SSE2(const int X[256], const int Y[256]) {
|
||||
int i;
|
||||
double retval = 0.;
|
||||
@ -300,6 +301,8 @@ static float CombinedShannonEntropy_SSE2(const int X[256], const int Y[256]) {
|
||||
retval += VP8LFastSLog2(sumX) + VP8LFastSLog2(sumXY);
|
||||
return (float)retval;
|
||||
}
|
||||
#endif // !(defined(__i386__) || defined(_M_IX86))
|
||||
|
||||
#undef ANALYZE_X_OR_Y
|
||||
#undef ANALYZE_XY
|
||||
|
||||
@ -455,24 +458,27 @@ static void PredictorSub0_SSE2(const uint32_t* in, const uint32_t* upper,
|
||||
_mm_storeu_si128((__m128i*)&out[i], res);
|
||||
}
|
||||
if (i != num_pixels) {
|
||||
VP8LPredictorsSub_C[0](in + i, upper + i, num_pixels - i, out + i);
|
||||
VP8LPredictorsSub_C[0](in + i, NULL, num_pixels - i, out + i);
|
||||
}
|
||||
(void)upper;
|
||||
}
|
||||
|
||||
#define GENERATE_PREDICTOR_1(X, IN) \
|
||||
static void PredictorSub##X##_SSE2(const uint32_t* in, const uint32_t* upper, \
|
||||
int num_pixels, uint32_t* out) { \
|
||||
int i; \
|
||||
for (i = 0; i + 4 <= num_pixels; i += 4) { \
|
||||
const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]); \
|
||||
const __m128i pred = _mm_loadu_si128((const __m128i*)&(IN)); \
|
||||
const __m128i res = _mm_sub_epi8(src, pred); \
|
||||
_mm_storeu_si128((__m128i*)&out[i], res); \
|
||||
} \
|
||||
if (i != num_pixels) { \
|
||||
VP8LPredictorsSub_C[(X)](in + i, upper + i, num_pixels - i, out + i); \
|
||||
} \
|
||||
}
|
||||
#define GENERATE_PREDICTOR_1(X, IN) \
|
||||
static void PredictorSub##X##_SSE2(const uint32_t* const in, \
|
||||
const uint32_t* const upper, \
|
||||
int num_pixels, uint32_t* const out) { \
|
||||
int i; \
|
||||
for (i = 0; i + 4 <= num_pixels; i += 4) { \
|
||||
const __m128i src = _mm_loadu_si128((const __m128i*)&in[i]); \
|
||||
const __m128i pred = _mm_loadu_si128((const __m128i*)&(IN)); \
|
||||
const __m128i res = _mm_sub_epi8(src, pred); \
|
||||
_mm_storeu_si128((__m128i*)&out[i], res); \
|
||||
} \
|
||||
if (i != num_pixels) { \
|
||||
VP8LPredictorsSub_C[(X)](in + i, WEBP_OFFSET_PTR(upper, i), \
|
||||
num_pixels - i, out + i); \
|
||||
} \
|
||||
}
|
||||
|
||||
GENERATE_PREDICTOR_1(1, in[i - 1]) // Predictor1: L
|
||||
GENERATE_PREDICTOR_1(2, upper[i]) // Predictor2: T
|
||||
@ -656,7 +662,12 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitSSE2(void) {
|
||||
VP8LCollectColorRedTransforms = CollectColorRedTransforms_SSE2;
|
||||
VP8LAddVector = AddVector_SSE2;
|
||||
VP8LAddVectorEq = AddVectorEq_SSE2;
|
||||
// TODO(https://crbug.com/webp/499): this function produces different results
|
||||
// from the C code due to use of double/float resulting in output differences
|
||||
// when compared to -noasm.
|
||||
#if !(defined(__i386__) || defined(_M_IX86))
|
||||
VP8LCombinedShannonEntropy = CombinedShannonEntropy_SSE2;
|
||||
#endif
|
||||
VP8LVectorMismatch = VectorMismatch_SSE2;
|
||||
VP8LBundleColorMap = BundleColorMap_SSE2;
|
||||
|
||||
|
@ -191,8 +191,9 @@ static void PredictorAdd0_SSE2(const uint32_t* in, const uint32_t* upper,
|
||||
_mm_storeu_si128((__m128i*)&out[i], res);
|
||||
}
|
||||
if (i != num_pixels) {
|
||||
VP8LPredictorsAdd_C[0](in + i, upper + i, num_pixels - i, out + i);
|
||||
VP8LPredictorsAdd_C[0](in + i, NULL, num_pixels - i, out + i);
|
||||
}
|
||||
(void)upper;
|
||||
}
|
||||
|
||||
// Predictor1: left.
|
||||
|
@ -576,9 +576,9 @@ static void FUNC_NAME(const uint8_t* top_y, const uint8_t* bot_y, \
|
||||
const uint32_t l_uv = ((cur_u[0]) | ((cur_v[0]) << 16)); \
|
||||
const uint32_t uv0 = (3 * tl_uv + l_uv + 0x00020002u) >> 2; \
|
||||
const uint8_t* ptop_y = &top_y[1]; \
|
||||
uint8_t *ptop_dst = top_dst + XSTEP; \
|
||||
uint8_t* ptop_dst = top_dst + XSTEP; \
|
||||
const uint8_t* pbot_y = &bot_y[1]; \
|
||||
uint8_t *pbot_dst = bot_dst + XSTEP; \
|
||||
uint8_t* pbot_dst = bot_dst + XSTEP; \
|
||||
\
|
||||
FUNC(top_y[0], uv0 & 0xff, (uv0 >> 16), top_dst); \
|
||||
if (bot_y != NULL) { \
|
||||
|
@ -58,8 +58,8 @@
|
||||
} while (0)
|
||||
|
||||
// Turn the macro into a function for reducing code-size when non-critical
|
||||
static void Upsample16Pixels_NEON(const uint8_t *r1, const uint8_t *r2,
|
||||
uint8_t *out) {
|
||||
static void Upsample16Pixels_NEON(const uint8_t* r1, const uint8_t* r2,
|
||||
uint8_t* out) {
|
||||
UPSAMPLE_16PIXELS(r1, r2, out);
|
||||
}
|
||||
|
||||
@ -190,14 +190,14 @@ static const int16_t kCoeffs1[4] = { 19077, 26149, 6419, 13320 };
|
||||
}
|
||||
|
||||
#define NEON_UPSAMPLE_FUNC(FUNC_NAME, FMT, XSTEP) \
|
||||
static void FUNC_NAME(const uint8_t *top_y, const uint8_t *bottom_y, \
|
||||
const uint8_t *top_u, const uint8_t *top_v, \
|
||||
const uint8_t *cur_u, const uint8_t *cur_v, \
|
||||
uint8_t *top_dst, uint8_t *bottom_dst, int len) { \
|
||||
static void FUNC_NAME(const uint8_t* top_y, const uint8_t* bottom_y, \
|
||||
const uint8_t* top_u, const uint8_t* top_v, \
|
||||
const uint8_t* cur_u, const uint8_t* cur_v, \
|
||||
uint8_t* top_dst, uint8_t* bottom_dst, int len) { \
|
||||
int block; \
|
||||
/* 16 byte aligned array to cache reconstructed u and v */ \
|
||||
uint8_t uv_buf[2 * 32 + 15]; \
|
||||
uint8_t *const r_uv = (uint8_t*)((uintptr_t)(uv_buf + 15) & ~15); \
|
||||
uint8_t* const r_uv = (uint8_t*)((uintptr_t)(uv_buf + 15) & ~15); \
|
||||
const int uv_len = (len + 1) >> 1; \
|
||||
/* 9 pixels must be read-able for each block */ \
|
||||
const int num_blocks = (uv_len - 1) >> 3; \
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "src/enc/vp8i_enc.h"
|
||||
#include "src/dsp/dsp.h"
|
||||
@ -149,7 +148,6 @@ static int EncodeAlphaInternal(const uint8_t* const data, int width, int height,
|
||||
}
|
||||
} else {
|
||||
VP8LBitWriterWipeOut(&tmp_bw);
|
||||
memset(&result->bw, 0, sizeof(result->bw));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -164,7 +162,7 @@ static int EncodeAlphaInternal(const uint8_t* const data, int width, int height,
|
||||
header = method | (filter << 2);
|
||||
if (reduce_levels) header |= ALPHA_PREPROCESSED_LEVELS << 4;
|
||||
|
||||
if (!VP8BitWriterInit(&result->bw, ALPHA_HEADER_LEN + output_size)) ok = 0;
|
||||
VP8BitWriterInit(&result->bw, ALPHA_HEADER_LEN + output_size);
|
||||
ok = ok && VP8BitWriterAppend(&result->bw, &header, ALPHA_HEADER_LEN);
|
||||
ok = ok && VP8BitWriterAppend(&result->bw, output, output_size);
|
||||
|
||||
|
@ -126,16 +126,6 @@ static void InitHistogram(VP8Histogram* const histo) {
|
||||
histo->last_non_zero = 1;
|
||||
}
|
||||
|
||||
static void MergeHistograms(const VP8Histogram* const in,
|
||||
VP8Histogram* const out) {
|
||||
if (in->max_value > out->max_value) {
|
||||
out->max_value = in->max_value;
|
||||
}
|
||||
if (in->last_non_zero > out->last_non_zero) {
|
||||
out->last_non_zero = in->last_non_zero;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Simplified k-Means, to assign Nb segments based on alpha-histogram
|
||||
|
||||
@ -285,49 +275,6 @@ static int FastMBAnalyze(VP8EncIterator* const it) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int MBAnalyzeBestIntra4Mode(VP8EncIterator* const it,
|
||||
int best_alpha) {
|
||||
uint8_t modes[16];
|
||||
const int max_mode = MAX_INTRA4_MODE;
|
||||
int i4_alpha;
|
||||
VP8Histogram total_histo;
|
||||
int cur_histo = 0;
|
||||
InitHistogram(&total_histo);
|
||||
|
||||
VP8IteratorStartI4(it);
|
||||
do {
|
||||
int mode;
|
||||
int best_mode_alpha = DEFAULT_ALPHA;
|
||||
VP8Histogram histos[2];
|
||||
const uint8_t* const src = it->yuv_in_ + Y_OFF_ENC + VP8Scan[it->i4_];
|
||||
|
||||
VP8MakeIntra4Preds(it);
|
||||
for (mode = 0; mode < max_mode; ++mode) {
|
||||
int alpha;
|
||||
|
||||
InitHistogram(&histos[cur_histo]);
|
||||
VP8CollectHistogram(src, it->yuv_p_ + VP8I4ModeOffsets[mode],
|
||||
0, 1, &histos[cur_histo]);
|
||||
alpha = GetAlpha(&histos[cur_histo]);
|
||||
if (IS_BETTER_ALPHA(alpha, best_mode_alpha)) {
|
||||
best_mode_alpha = alpha;
|
||||
modes[it->i4_] = mode;
|
||||
cur_histo ^= 1; // keep track of best histo so far.
|
||||
}
|
||||
}
|
||||
// accumulate best histogram
|
||||
MergeHistograms(&histos[cur_histo ^ 1], &total_histo);
|
||||
// Note: we reuse the original samples for predictors
|
||||
} while (VP8IteratorRotateI4(it, it->yuv_in_ + Y_OFF_ENC));
|
||||
|
||||
i4_alpha = GetAlpha(&total_histo);
|
||||
if (IS_BETTER_ALPHA(i4_alpha, best_alpha)) {
|
||||
VP8SetIntra4Mode(it, modes);
|
||||
best_alpha = i4_alpha;
|
||||
}
|
||||
return best_alpha;
|
||||
}
|
||||
|
||||
static int MBAnalyzeBestUVMode(VP8EncIterator* const it) {
|
||||
int best_alpha = DEFAULT_ALPHA;
|
||||
int smallest_alpha = 0;
|
||||
@ -371,13 +318,6 @@ static void MBAnalyze(VP8EncIterator* const it,
|
||||
best_alpha = FastMBAnalyze(it);
|
||||
} else {
|
||||
best_alpha = MBAnalyzeBestIntra16Mode(it);
|
||||
if (enc->method_ >= 5) {
|
||||
// We go and make a fast decision for intra4/intra16.
|
||||
// It's usually not a good and definitive pick, but helps seeding the
|
||||
// stats about level bit-cost.
|
||||
// TODO(skal): improve criterion.
|
||||
best_alpha = MBAnalyzeBestIntra4Mode(it, best_alpha);
|
||||
}
|
||||
}
|
||||
best_uv_alpha = MBAnalyzeBestUVMode(it);
|
||||
|
||||
|
@ -11,13 +11,14 @@
|
||||
//
|
||||
|
||||
#include <assert.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "src/enc/backward_references_enc.h"
|
||||
#include "src/enc/histogram_enc.h"
|
||||
#include "src/dsp/dsp.h"
|
||||
#include "src/dsp/lossless.h"
|
||||
#include "src/dsp/lossless_common.h"
|
||||
#include "src/dsp/dsp.h"
|
||||
#include "src/enc/backward_references_enc.h"
|
||||
#include "src/enc/histogram_enc.h"
|
||||
#include "src/utils/color_cache_utils.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
@ -103,6 +104,20 @@ void VP8LBackwardRefsClear(VP8LBackwardRefs* const refs) {
|
||||
}
|
||||
}
|
||||
|
||||
// Swaps the content of two VP8LBackwardRefs.
|
||||
static void BackwardRefsSwap(VP8LBackwardRefs* const refs1,
|
||||
VP8LBackwardRefs* const refs2) {
|
||||
const int point_to_refs1 =
|
||||
(refs1->tail_ != NULL && refs1->tail_ == &refs1->refs_);
|
||||
const int point_to_refs2 =
|
||||
(refs2->tail_ != NULL && refs2->tail_ == &refs2->refs_);
|
||||
const VP8LBackwardRefs tmp = *refs1;
|
||||
*refs1 = *refs2;
|
||||
*refs2 = tmp;
|
||||
if (point_to_refs2) refs1->tail_ = &refs1->refs_;
|
||||
if (point_to_refs1) refs2->tail_ = &refs2->refs_;
|
||||
}
|
||||
|
||||
void VP8LBackwardRefsInit(VP8LBackwardRefs* const refs, int block_size) {
|
||||
assert(refs != NULL);
|
||||
memset(refs, 0, sizeof(*refs));
|
||||
@ -154,6 +169,22 @@ static PixOrCopyBlock* BackwardRefsNewBlock(VP8LBackwardRefs* const refs) {
|
||||
return b;
|
||||
}
|
||||
|
||||
// Return 1 on success, 0 on error.
|
||||
static int BackwardRefsClone(const VP8LBackwardRefs* const from,
|
||||
VP8LBackwardRefs* const to) {
|
||||
const PixOrCopyBlock* block_from = from->refs_;
|
||||
VP8LClearBackwardRefs(to);
|
||||
while (block_from != NULL) {
|
||||
PixOrCopyBlock* const block_to = BackwardRefsNewBlock(to);
|
||||
if (block_to == NULL) return 0;
|
||||
memcpy(block_to->start_, block_from->start_,
|
||||
block_from->size_ * sizeof(PixOrCopy));
|
||||
block_to->size_ = block_from->size_;
|
||||
block_from = block_from->next_;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern void VP8LBackwardRefsCursorAdd(VP8LBackwardRefs* const refs,
|
||||
const PixOrCopy v);
|
||||
void VP8LBackwardRefsCursorAdd(VP8LBackwardRefs* const refs,
|
||||
@ -753,12 +784,18 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int code, extra_bits, extra_bits_value;
|
||||
// We should compute the contribution of the (distance,length)
|
||||
// histograms but those are the same independently from the cache size.
|
||||
// As those constant contributions are in the end added to the other
|
||||
// histogram contributions, we can safely ignore them.
|
||||
// histogram contributions, we can ignore them, except for the length
|
||||
// prefix that is part of the literal_ histogram.
|
||||
int len = PixOrCopyLength(v);
|
||||
uint32_t argb_prev = *argb ^ 0xffffffffu;
|
||||
VP8LPrefixEncode(len, &code, &extra_bits, &extra_bits_value);
|
||||
for (i = 0; i <= cache_bits_max; ++i) {
|
||||
++histos[i]->literal_[NUM_LITERAL_CODES + code];
|
||||
}
|
||||
// Update the color caches.
|
||||
do {
|
||||
if (*argb != argb_prev) {
|
||||
@ -842,16 +879,21 @@ extern int VP8LBackwardReferencesTraceBackwards(
|
||||
int xsize, int ysize, const uint32_t* const argb, int cache_bits,
|
||||
const VP8LHashChain* const hash_chain,
|
||||
const VP8LBackwardRefs* const refs_src, VP8LBackwardRefs* const refs_dst);
|
||||
static VP8LBackwardRefs* GetBackwardReferences(
|
||||
int width, int height, const uint32_t* const argb, int quality,
|
||||
int lz77_types_to_try, int* const cache_bits,
|
||||
const VP8LHashChain* const hash_chain, VP8LBackwardRefs* best,
|
||||
VP8LBackwardRefs* worst) {
|
||||
const int cache_bits_initial = *cache_bits;
|
||||
double bit_cost_best = -1;
|
||||
static int GetBackwardReferences(int width, int height,
|
||||
const uint32_t* const argb, int quality,
|
||||
int lz77_types_to_try, int cache_bits_max,
|
||||
int do_no_cache,
|
||||
const VP8LHashChain* const hash_chain,
|
||||
VP8LBackwardRefs* const refs,
|
||||
int* const cache_bits_best) {
|
||||
VP8LHistogram* histo = NULL;
|
||||
int lz77_type, lz77_type_best = 0;
|
||||
int i, lz77_type;
|
||||
// Index 0 is for a color cache, index 1 for no cache (if needed).
|
||||
int lz77_types_best[2] = {0, 0};
|
||||
double bit_costs_best[2] = {DBL_MAX, DBL_MAX};
|
||||
VP8LHashChain hash_chain_box;
|
||||
VP8LBackwardRefs* const refs_tmp = &refs[do_no_cache ? 2 : 1];
|
||||
int status = 0;
|
||||
memset(&hash_chain_box, 0, sizeof(hash_chain_box));
|
||||
|
||||
histo = VP8LAllocateHistogram(MAX_COLOR_CACHE_BITS);
|
||||
@ -860,87 +902,130 @@ static VP8LBackwardRefs* GetBackwardReferences(
|
||||
for (lz77_type = 1; lz77_types_to_try;
|
||||
lz77_types_to_try &= ~lz77_type, lz77_type <<= 1) {
|
||||
int res = 0;
|
||||
double bit_cost;
|
||||
int cache_bits_tmp = cache_bits_initial;
|
||||
double bit_cost = 0.;
|
||||
if ((lz77_types_to_try & lz77_type) == 0) continue;
|
||||
switch (lz77_type) {
|
||||
case kLZ77RLE:
|
||||
res = BackwardReferencesRle(width, height, argb, 0, worst);
|
||||
res = BackwardReferencesRle(width, height, argb, 0, refs_tmp);
|
||||
break;
|
||||
case kLZ77Standard:
|
||||
// Compute LZ77 with no cache (0 bits), as the ideal LZ77 with a color
|
||||
// cache is not that different in practice.
|
||||
res = BackwardReferencesLz77(width, height, argb, 0, hash_chain, worst);
|
||||
res = BackwardReferencesLz77(width, height, argb, 0, hash_chain,
|
||||
refs_tmp);
|
||||
break;
|
||||
case kLZ77Box:
|
||||
if (!VP8LHashChainInit(&hash_chain_box, width * height)) goto Error;
|
||||
res = BackwardReferencesLz77Box(width, height, argb, 0, hash_chain,
|
||||
&hash_chain_box, worst);
|
||||
&hash_chain_box, refs_tmp);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
if (!res) goto Error;
|
||||
|
||||
// Next, try with a color cache and update the references.
|
||||
if (!CalculateBestCacheSize(argb, quality, worst, &cache_bits_tmp)) {
|
||||
goto Error;
|
||||
}
|
||||
if (cache_bits_tmp > 0) {
|
||||
if (!BackwardRefsWithLocalCache(argb, cache_bits_tmp, worst)) {
|
||||
goto Error;
|
||||
// Start with the no color cache case.
|
||||
for (i = 1; i >= 0; --i) {
|
||||
int cache_bits = (i == 1) ? 0 : cache_bits_max;
|
||||
|
||||
if (i == 1 && !do_no_cache) continue;
|
||||
|
||||
if (i == 0) {
|
||||
// Try with a color cache.
|
||||
if (!CalculateBestCacheSize(argb, quality, refs_tmp, &cache_bits)) {
|
||||
goto Error;
|
||||
}
|
||||
if (cache_bits > 0) {
|
||||
if (!BackwardRefsWithLocalCache(argb, cache_bits, refs_tmp)) {
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (i == 0 && do_no_cache && cache_bits == 0) {
|
||||
// No need to re-compute bit_cost as it was computed at i == 1.
|
||||
} else {
|
||||
VP8LHistogramCreate(histo, refs_tmp, cache_bits);
|
||||
bit_cost = VP8LHistogramEstimateBits(histo);
|
||||
}
|
||||
|
||||
if (bit_cost < bit_costs_best[i]) {
|
||||
if (i == 1) {
|
||||
// Do not swap as the full cache analysis would have the wrong
|
||||
// VP8LBackwardRefs to start with.
|
||||
if (!BackwardRefsClone(refs_tmp, &refs[1])) goto Error;
|
||||
} else {
|
||||
BackwardRefsSwap(refs_tmp, &refs[0]);
|
||||
}
|
||||
bit_costs_best[i] = bit_cost;
|
||||
lz77_types_best[i] = lz77_type;
|
||||
if (i == 0) *cache_bits_best = cache_bits;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the best backward references.
|
||||
VP8LHistogramCreate(histo, worst, cache_bits_tmp);
|
||||
bit_cost = VP8LHistogramEstimateBits(histo);
|
||||
if (lz77_type_best == 0 || bit_cost < bit_cost_best) {
|
||||
VP8LBackwardRefs* const tmp = worst;
|
||||
worst = best;
|
||||
best = tmp;
|
||||
bit_cost_best = bit_cost;
|
||||
*cache_bits = cache_bits_tmp;
|
||||
lz77_type_best = lz77_type;
|
||||
}
|
||||
}
|
||||
assert(lz77_type_best > 0);
|
||||
assert(lz77_types_best[0] > 0);
|
||||
assert(!do_no_cache || lz77_types_best[1] > 0);
|
||||
|
||||
// Improve on simple LZ77 but only for high quality (TraceBackwards is
|
||||
// costly).
|
||||
if ((lz77_type_best == kLZ77Standard || lz77_type_best == kLZ77Box) &&
|
||||
quality >= 25) {
|
||||
const VP8LHashChain* const hash_chain_tmp =
|
||||
(lz77_type_best == kLZ77Standard) ? hash_chain : &hash_chain_box;
|
||||
double bit_cost_trace;
|
||||
if (!VP8LBackwardReferencesTraceBackwards(width, height, argb, *cache_bits,
|
||||
hash_chain_tmp, best, worst)) {
|
||||
goto Error;
|
||||
for (i = 1; i >= 0; --i) {
|
||||
if (i == 1 && !do_no_cache) continue;
|
||||
if ((lz77_types_best[i] == kLZ77Standard ||
|
||||
lz77_types_best[i] == kLZ77Box) &&
|
||||
quality >= 25) {
|
||||
const VP8LHashChain* const hash_chain_tmp =
|
||||
(lz77_types_best[i] == kLZ77Standard) ? hash_chain : &hash_chain_box;
|
||||
const int cache_bits = (i == 1) ? 0 : *cache_bits_best;
|
||||
double bit_cost_trace;
|
||||
if (!VP8LBackwardReferencesTraceBackwards(width, height, argb, cache_bits,
|
||||
hash_chain_tmp, &refs[i],
|
||||
refs_tmp)) {
|
||||
goto Error;
|
||||
}
|
||||
VP8LHistogramCreate(histo, refs_tmp, cache_bits);
|
||||
bit_cost_trace = VP8LHistogramEstimateBits(histo);
|
||||
if (bit_cost_trace < bit_costs_best[i]) {
|
||||
BackwardRefsSwap(refs_tmp, &refs[i]);
|
||||
}
|
||||
}
|
||||
VP8LHistogramCreate(histo, worst, *cache_bits);
|
||||
bit_cost_trace = VP8LHistogramEstimateBits(histo);
|
||||
if (bit_cost_trace < bit_cost_best) best = worst;
|
||||
}
|
||||
|
||||
BackwardReferences2DLocality(width, best);
|
||||
BackwardReferences2DLocality(width, &refs[i]);
|
||||
|
||||
if (i == 1 && lz77_types_best[0] == lz77_types_best[1] &&
|
||||
*cache_bits_best == 0) {
|
||||
// If the best cache size is 0 and we have the same best LZ77, just copy
|
||||
// the data over and stop here.
|
||||
if (!BackwardRefsClone(&refs[1], &refs[0])) goto Error;
|
||||
break;
|
||||
}
|
||||
}
|
||||
status = 1;
|
||||
|
||||
Error:
|
||||
VP8LHashChainClear(&hash_chain_box);
|
||||
VP8LFreeHistogram(histo);
|
||||
return best;
|
||||
return status;
|
||||
}
|
||||
|
||||
VP8LBackwardRefs* VP8LGetBackwardReferences(
|
||||
WebPEncodingError VP8LGetBackwardReferences(
|
||||
int width, int height, const uint32_t* const argb, int quality,
|
||||
int low_effort, int lz77_types_to_try, int* const cache_bits,
|
||||
const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_tmp1,
|
||||
VP8LBackwardRefs* const refs_tmp2) {
|
||||
int low_effort, int lz77_types_to_try, int cache_bits_max, int do_no_cache,
|
||||
const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs,
|
||||
int* const cache_bits_best) {
|
||||
if (low_effort) {
|
||||
return GetBackwardReferencesLowEffort(width, height, argb, cache_bits,
|
||||
hash_chain, refs_tmp1);
|
||||
VP8LBackwardRefs* refs_best;
|
||||
*cache_bits_best = cache_bits_max;
|
||||
refs_best = GetBackwardReferencesLowEffort(
|
||||
width, height, argb, cache_bits_best, hash_chain, refs);
|
||||
if (refs_best == NULL) return VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
// Set it in first position.
|
||||
BackwardRefsSwap(refs_best, &refs[0]);
|
||||
} else {
|
||||
return GetBackwardReferences(width, height, argb, quality,
|
||||
lz77_types_to_try, cache_bits, hash_chain,
|
||||
refs_tmp1, refs_tmp2);
|
||||
if (!GetBackwardReferences(width, height, argb, quality, lz77_types_to_try,
|
||||
cache_bits_max, do_no_cache, hash_chain, refs,
|
||||
cache_bits_best)) {
|
||||
return VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return VP8_ENC_OK;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "src/webp/types.h"
|
||||
#include "src/webp/encode.h"
|
||||
#include "src/webp/format_constants.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -218,14 +219,19 @@ enum VP8LLZ77Type {
|
||||
// Evaluates best possible backward references for specified quality.
|
||||
// The input cache_bits to 'VP8LGetBackwardReferences' sets the maximum cache
|
||||
// bits to use (passing 0 implies disabling the local color cache).
|
||||
// The optimal cache bits is evaluated and set for the *cache_bits parameter.
|
||||
// The return value is the pointer to the best of the two backward refs viz,
|
||||
// refs[0] or refs[1].
|
||||
VP8LBackwardRefs* VP8LGetBackwardReferences(
|
||||
// The optimal cache bits is evaluated and set for the *cache_bits_best
|
||||
// parameter with the matching refs_best.
|
||||
// If do_no_cache == 0, refs is an array of 2 values and the best
|
||||
// VP8LBackwardRefs is put in the first element.
|
||||
// If do_no_cache != 0, refs is an array of 3 values and the best
|
||||
// VP8LBackwardRefs is put in the first element, the best value with no-cache in
|
||||
// the second element.
|
||||
// In both cases, the last element is used as temporary internally.
|
||||
WebPEncodingError VP8LGetBackwardReferences(
|
||||
int width, int height, const uint32_t* const argb, int quality,
|
||||
int low_effort, int lz77_types_to_try, int* const cache_bits,
|
||||
const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_tmp1,
|
||||
VP8LBackwardRefs* const refs_tmp2);
|
||||
int low_effort, int lz77_types_to_try, int cache_bits_max, int do_no_cache,
|
||||
const VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs,
|
||||
int* const cache_bits_best);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -39,6 +39,8 @@ int WebPConfigInitInternal(WebPConfig* config,
|
||||
config->partitions = 0;
|
||||
config->segments = 4;
|
||||
config->pass = 1;
|
||||
config->qmin = 0;
|
||||
config->qmax = 100;
|
||||
config->show_compressed = 0;
|
||||
config->preprocessing = 0;
|
||||
config->autofilter = 0;
|
||||
@ -106,6 +108,9 @@ int WebPValidateConfig(const WebPConfig* config) {
|
||||
if (config->filter_type < 0 || config->filter_type > 1) return 0;
|
||||
if (config->autofilter < 0 || config->autofilter > 1) return 0;
|
||||
if (config->pass < 1 || config->pass > 10) return 0;
|
||||
if (config->qmin < 0 || config->qmax > 100 || config->qmin > config->qmax) {
|
||||
return 0;
|
||||
}
|
||||
if (config->show_compressed < 0 || config->show_compressed > 1) return 0;
|
||||
if (config->preprocessing < 0 || config->preprocessing > 7) return 0;
|
||||
if (config->partitions < 0 || config->partitions > 3) return 0;
|
||||
|
@ -31,10 +31,15 @@
|
||||
// we allow 2k of extra head-room in PARTITION0 limit.
|
||||
#define PARTITION0_SIZE_LIMIT ((VP8_MAX_PARTITION0_SIZE - 2048ULL) << 11)
|
||||
|
||||
static float Clamp(float v, float min, float max) {
|
||||
return (v < min) ? min : (v > max) ? max : v;
|
||||
}
|
||||
|
||||
typedef struct { // struct for organizing convergence in either size or PSNR
|
||||
int is_first;
|
||||
float dq;
|
||||
float q, last_q;
|
||||
float qmin, qmax;
|
||||
double value, last_value; // PSNR or size
|
||||
double target;
|
||||
int do_size_search;
|
||||
@ -47,7 +52,9 @@ static int InitPassStats(const VP8Encoder* const enc, PassStats* const s) {
|
||||
|
||||
s->is_first = 1;
|
||||
s->dq = 10.f;
|
||||
s->q = s->last_q = enc->config_->quality;
|
||||
s->qmin = 1.f * enc->config_->qmin;
|
||||
s->qmax = 1.f * enc->config_->qmax;
|
||||
s->q = s->last_q = Clamp(enc->config_->quality, s->qmin, s->qmax);
|
||||
s->target = do_size_search ? (double)target_size
|
||||
: (target_PSNR > 0.) ? target_PSNR
|
||||
: 40.; // default, just in case
|
||||
@ -56,10 +63,6 @@ static int InitPassStats(const VP8Encoder* const enc, PassStats* const s) {
|
||||
return do_size_search;
|
||||
}
|
||||
|
||||
static float Clamp(float v, float min, float max) {
|
||||
return (v < min) ? min : (v > max) ? max : v;
|
||||
}
|
||||
|
||||
static float ComputeNextQ(PassStats* const s) {
|
||||
float dq;
|
||||
if (s->is_first) {
|
||||
@ -75,7 +78,7 @@ static float ComputeNextQ(PassStats* const s) {
|
||||
s->dq = Clamp(dq, -30.f, 30.f);
|
||||
s->last_q = s->q;
|
||||
s->last_value = s->value;
|
||||
s->q = Clamp(s->q + s->dq, 0.f, 100.f);
|
||||
s->q = Clamp(s->q + s->dq, s->qmin, s->qmax);
|
||||
return s->q;
|
||||
}
|
||||
|
||||
@ -848,9 +851,10 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
|
||||
}
|
||||
|
||||
#if (DEBUG_SEARCH > 0)
|
||||
printf("#%2d metric:%.1lf -> %.1lf last_q=%.2lf q=%.2lf dq=%.2lf\n",
|
||||
printf("#%2d metric:%.1lf -> %.1lf last_q=%.2lf q=%.2lf dq=%.2lf "
|
||||
" range:[%.1f, %.1f]\n",
|
||||
num_pass_left, stats.last_value, stats.value,
|
||||
stats.last_q, stats.q, stats.dq);
|
||||
stats.last_q, stats.q, stats.dq, stats.qmin, stats.qmax);
|
||||
#endif
|
||||
if (enc->max_i4_header_bits_ > 0 && size_p0 > PARTITION0_SIZE_LIMIT) {
|
||||
++num_pass_left;
|
||||
|
@ -208,6 +208,7 @@ void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
||||
} else if (PixOrCopyIsCacheIdx(v)) {
|
||||
const int literal_ix =
|
||||
NUM_LITERAL_CODES + NUM_LENGTH_CODES + PixOrCopyCacheIdx(v);
|
||||
assert(histo->palette_code_bits_ != 0);
|
||||
++histo->literal_[literal_ix];
|
||||
} else {
|
||||
int code, extra_bits;
|
||||
@ -641,7 +642,7 @@ static void HistogramAnalyzeEntropyBin(VP8LHistogramSet* const image_histo,
|
||||
// Merges some histograms with same bin_id together if it's advantageous.
|
||||
// Sets the remaining histograms to NULL.
|
||||
static void HistogramCombineEntropyBin(VP8LHistogramSet* const image_histo,
|
||||
int *num_used,
|
||||
int* num_used,
|
||||
const uint16_t* const clusters,
|
||||
uint16_t* const cluster_mappings,
|
||||
VP8LHistogram* cur_combo,
|
||||
|
@ -29,11 +29,15 @@
|
||||
#define USE_INVERSE_ALPHA_TABLE
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define ALPHA_OFFSET 0 // uint32_t 0xff000000 is 0xff,00,00,00 in memory
|
||||
// uint32_t 0xff000000 is 0xff,00,00,00 in memory
|
||||
#define CHANNEL_OFFSET(i) (i)
|
||||
#else
|
||||
#define ALPHA_OFFSET 3 // uint32_t 0xff000000 is 0x00,00,00,ff in memory
|
||||
// uint32_t 0xff000000 is 0x00,00,00,ff in memory
|
||||
#define CHANNEL_OFFSET(i) (3-(i))
|
||||
#endif
|
||||
|
||||
#define ALPHA_OFFSET CHANNEL_OFFSET(0)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Detection of non-trivial transparency
|
||||
|
||||
@ -57,16 +61,14 @@ static int CheckNonOpaque(const uint8_t* alpha, int width, int height,
|
||||
// Checking for the presence of non-opaque alpha.
|
||||
int WebPPictureHasTransparency(const WebPPicture* picture) {
|
||||
if (picture == NULL) return 0;
|
||||
if (!picture->use_argb) {
|
||||
return CheckNonOpaque(picture->a, picture->width, picture->height,
|
||||
1, picture->a_stride);
|
||||
} else {
|
||||
if (picture->use_argb) {
|
||||
const int alpha_offset = ALPHA_OFFSET;
|
||||
return CheckNonOpaque((const uint8_t*)picture->argb + alpha_offset,
|
||||
picture->width, picture->height,
|
||||
4, picture->argb_stride * sizeof(*picture->argb));
|
||||
}
|
||||
return 0;
|
||||
return CheckNonOpaque(picture->a, picture->width, picture->height,
|
||||
1, picture->a_stride);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -86,8 +88,9 @@ int WebPPictureHasTransparency(const WebPPicture* picture) {
|
||||
static int kLinearToGammaTab[kGammaTabSize + 1];
|
||||
static uint16_t kGammaToLinearTab[256];
|
||||
static volatile int kGammaTablesOk = 0;
|
||||
static void InitGammaTables(void);
|
||||
|
||||
static WEBP_TSAN_IGNORE_FUNCTION void InitGammaTables(void) {
|
||||
WEBP_DSP_INIT_FUNC(InitGammaTables) {
|
||||
if (!kGammaTablesOk) {
|
||||
int v;
|
||||
const double scale = (double)(1 << kGammaTabFix) / kGammaScale;
|
||||
@ -177,8 +180,9 @@ static uint32_t kLinearToGammaTabS[kGammaTabSize + 2];
|
||||
#define GAMMA_TO_LINEAR_BITS 14
|
||||
static uint32_t kGammaToLinearTabS[MAX_Y_T + 1]; // size scales with Y_FIX
|
||||
static volatile int kGammaTablesSOk = 0;
|
||||
static void InitGammaTablesS(void);
|
||||
|
||||
static WEBP_TSAN_IGNORE_FUNCTION void InitGammaTablesS(void) {
|
||||
WEBP_DSP_INIT_FUNC(InitGammaTablesS) {
|
||||
assert(2 * GAMMA_TO_LINEAR_BITS < 32); // we use uint32_t intermediate values
|
||||
if (!kGammaTablesSOk) {
|
||||
int v;
|
||||
@ -997,10 +1001,10 @@ static int PictureARGBToYUVA(WebPPicture* picture, WebPEncCSP colorspace,
|
||||
return WebPEncodingSetError(picture, VP8_ENC_ERROR_INVALID_CONFIGURATION);
|
||||
} else {
|
||||
const uint8_t* const argb = (const uint8_t*)picture->argb;
|
||||
const uint8_t* const a = argb + (0 ^ ALPHA_OFFSET);
|
||||
const uint8_t* const r = argb + (1 ^ ALPHA_OFFSET);
|
||||
const uint8_t* const g = argb + (2 ^ ALPHA_OFFSET);
|
||||
const uint8_t* const b = argb + (3 ^ ALPHA_OFFSET);
|
||||
const uint8_t* const a = argb + CHANNEL_OFFSET(0);
|
||||
const uint8_t* const r = argb + CHANNEL_OFFSET(1);
|
||||
const uint8_t* const g = argb + CHANNEL_OFFSET(2);
|
||||
const uint8_t* const b = argb + CHANNEL_OFFSET(3);
|
||||
|
||||
picture->colorspace = WEBP_YUV420;
|
||||
return ImportYUVAFromRGBA(r, g, b, a, 4, 4 * picture->argb_stride,
|
||||
@ -1050,7 +1054,7 @@ int WebPPictureYUVAToARGB(WebPPicture* picture) {
|
||||
const int height = picture->height;
|
||||
const int argb_stride = 4 * picture->argb_stride;
|
||||
uint8_t* dst = (uint8_t*)picture->argb;
|
||||
const uint8_t *cur_u = picture->u, *cur_v = picture->v, *cur_y = picture->y;
|
||||
const uint8_t* cur_u = picture->u, *cur_v = picture->v, *cur_y = picture->y;
|
||||
WebPUpsampleLinePairFunc upsample =
|
||||
WebPGetLinePairConverter(ALPHA_OFFSET > 0);
|
||||
|
||||
|
@ -83,6 +83,19 @@ static int SmoothenBlock(const uint8_t* a_ptr, int a_stride, uint8_t* y_ptr,
|
||||
return (count == 0);
|
||||
}
|
||||
|
||||
void WebPReplaceTransparentPixels(WebPPicture* const pic, uint32_t color) {
|
||||
if (pic != NULL && pic->use_argb) {
|
||||
int y = pic->height;
|
||||
uint32_t* argb = pic->argb;
|
||||
color &= 0xffffffu; // force alpha=0
|
||||
WebPInitAlphaProcessing();
|
||||
while (y-- > 0) {
|
||||
WebPAlphaReplace(argb, pic->width, color);
|
||||
argb += pic->argb_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WebPCleanupTransparentArea(WebPPicture* pic) {
|
||||
int x, y, w, h;
|
||||
if (pic == NULL) return;
|
||||
@ -165,24 +178,6 @@ void WebPCleanupTransparentArea(WebPPicture* pic) {
|
||||
#undef SIZE
|
||||
#undef SIZE2
|
||||
|
||||
void WebPCleanupTransparentAreaLossless(WebPPicture* const pic) {
|
||||
int x, y, w, h;
|
||||
uint32_t* argb;
|
||||
assert(pic != NULL && pic->use_argb);
|
||||
w = pic->width;
|
||||
h = pic->height;
|
||||
argb = pic->argb;
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < w; ++x) {
|
||||
if ((argb[x] & 0xff000000) == 0) {
|
||||
argb[x] = 0x00000000;
|
||||
}
|
||||
}
|
||||
argb += pic->argb_stride;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Blend color and remove transparency info
|
||||
|
||||
|
@ -31,8 +31,8 @@ extern "C" {
|
||||
|
||||
// version numbers
|
||||
#define ENC_MAJ_VERSION 1
|
||||
#define ENC_MIN_VERSION 0
|
||||
#define ENC_REV_VERSION 3
|
||||
#define ENC_MIN_VERSION 2
|
||||
#define ENC_REV_VERSION 0
|
||||
|
||||
enum { MAX_LF_LEVELS = 64, // Maximum loop filter level
|
||||
MAX_VARIABLE_LEVEL = 67, // last (inclusive) level with variable cost
|
||||
@ -249,7 +249,7 @@ typedef struct {
|
||||
int percent0_; // saved initial progress percent
|
||||
|
||||
DError left_derr_; // left error diffusion (u/v)
|
||||
DError *top_derr_; // top diffusion error - NULL if disabled
|
||||
DError* top_derr_; // top diffusion error - NULL if disabled
|
||||
|
||||
uint8_t* y_left_; // left luma samples (addressable from index -1 to 15).
|
||||
uint8_t* u_left_; // left u samples (addressable from index -1 to 7)
|
||||
@ -505,9 +505,9 @@ int WebPPictureAllocARGB(WebPPicture* const picture, int width, int height);
|
||||
// Returns false in case of error (invalid param, out-of-memory).
|
||||
int WebPPictureAllocYUVA(WebPPicture* const picture, int width, int height);
|
||||
|
||||
// Clean-up the RGB samples under fully transparent area, to help lossless
|
||||
// compressibility (no guarantee, though). Assumes that pic->use_argb is true.
|
||||
void WebPCleanupTransparentAreaLossless(WebPPicture* const pic);
|
||||
// Replace samples that are fully transparent by 'color' to help compressibility
|
||||
// (no guarantee, though). Assumes pic->use_argb is true.
|
||||
void WebPReplaceTransparentPixels(WebPPicture* const pic, uint32_t color);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -144,7 +144,8 @@ typedef enum {
|
||||
kSubGreen = 2,
|
||||
kSpatialSubGreen = 3,
|
||||
kPalette = 4,
|
||||
kNumEntropyIx = 5
|
||||
kPaletteAndSpatial = 5,
|
||||
kNumEntropyIx = 6
|
||||
} EntropyIx;
|
||||
|
||||
typedef enum {
|
||||
@ -354,11 +355,15 @@ static int GetTransformBits(int method, int histo_bits) {
|
||||
}
|
||||
|
||||
// Set of parameters to be used in each iteration of the cruncher.
|
||||
#define CRUNCH_CONFIGS_LZ77_MAX 2
|
||||
#define CRUNCH_SUBCONFIGS_MAX 2
|
||||
typedef struct {
|
||||
int lz77_;
|
||||
int do_no_cache_;
|
||||
} CrunchSubConfig;
|
||||
typedef struct {
|
||||
int entropy_idx_;
|
||||
int lz77s_types_to_try_[CRUNCH_CONFIGS_LZ77_MAX];
|
||||
int lz77s_types_to_try_size_;
|
||||
CrunchSubConfig sub_configs_[CRUNCH_SUBCONFIGS_MAX];
|
||||
int sub_configs_size_;
|
||||
} CrunchConfig;
|
||||
|
||||
#define CRUNCH_CONFIGS_MAX kNumEntropyIx
|
||||
@ -376,6 +381,9 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
|
||||
int i;
|
||||
int use_palette;
|
||||
int n_lz77s;
|
||||
// If set to 0, analyze the cache with the computed cache value. If 1, also
|
||||
// analyze with no-cache.
|
||||
int do_no_cache = 0;
|
||||
assert(pic != NULL && pic->argb != NULL);
|
||||
|
||||
use_palette =
|
||||
@ -402,10 +410,13 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
|
||||
return 0;
|
||||
}
|
||||
if (method == 6 && config->quality == 100) {
|
||||
do_no_cache = 1;
|
||||
// Go brute force on all transforms.
|
||||
*crunch_configs_size = 0;
|
||||
for (i = 0; i < kNumEntropyIx; ++i) {
|
||||
if (i != kPalette || use_palette) {
|
||||
// We can only apply kPalette or kPaletteAndSpatial if we can indeed use
|
||||
// a palette.
|
||||
if ((i != kPalette && i != kPaletteAndSpatial) || use_palette) {
|
||||
assert(*crunch_configs_size < CRUNCH_CONFIGS_MAX);
|
||||
crunch_configs[(*crunch_configs_size)++].entropy_idx_ = i;
|
||||
}
|
||||
@ -414,17 +425,28 @@ static int EncoderAnalyze(VP8LEncoder* const enc,
|
||||
// Only choose the guessed best transform.
|
||||
*crunch_configs_size = 1;
|
||||
crunch_configs[0].entropy_idx_ = min_entropy_ix;
|
||||
if (config->quality >= 75 && method == 5) {
|
||||
// Test with and without color cache.
|
||||
do_no_cache = 1;
|
||||
// If we have a palette, also check in combination with spatial.
|
||||
if (min_entropy_ix == kPalette) {
|
||||
*crunch_configs_size = 2;
|
||||
crunch_configs[1].entropy_idx_ = kPaletteAndSpatial;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fill in the different LZ77s.
|
||||
assert(n_lz77s <= CRUNCH_CONFIGS_LZ77_MAX);
|
||||
assert(n_lz77s <= CRUNCH_SUBCONFIGS_MAX);
|
||||
for (i = 0; i < *crunch_configs_size; ++i) {
|
||||
int j;
|
||||
for (j = 0; j < n_lz77s; ++j) {
|
||||
crunch_configs[i].lz77s_types_to_try_[j] =
|
||||
assert(j < CRUNCH_SUBCONFIGS_MAX);
|
||||
crunch_configs[i].sub_configs_[j].lz77_ =
|
||||
(j == 0) ? kLZ77Standard | kLZ77RLE : kLZ77Box;
|
||||
crunch_configs[i].sub_configs_[j].do_no_cache_ = do_no_cache;
|
||||
}
|
||||
crunch_configs[i].lz77s_types_to_try_size_ = n_lz77s;
|
||||
crunch_configs[i].sub_configs_size_ = n_lz77s;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -440,7 +462,7 @@ static int EncoderInit(VP8LEncoder* const enc) {
|
||||
int i;
|
||||
if (!VP8LHashChainInit(&enc->hash_chain_, pix_cnt)) return 0;
|
||||
|
||||
for (i = 0; i < 3; ++i) VP8LBackwardRefsInit(&enc->refs_[i], refs_block_size);
|
||||
for (i = 0; i < 4; ++i) VP8LBackwardRefsInit(&enc->refs_[i], refs_block_size);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -769,13 +791,10 @@ static WebPEncodingError StoreImageToBitMask(
|
||||
}
|
||||
|
||||
// Special case of EncodeImageInternal() for cache-bits=0, histo_bits=31
|
||||
static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
|
||||
const uint32_t* const argb,
|
||||
VP8LHashChain* const hash_chain,
|
||||
VP8LBackwardRefs* const refs_tmp1,
|
||||
VP8LBackwardRefs* const refs_tmp2,
|
||||
int width, int height,
|
||||
int quality, int low_effort) {
|
||||
static WebPEncodingError EncodeImageNoHuffman(
|
||||
VP8LBitWriter* const bw, const uint32_t* const argb,
|
||||
VP8LHashChain* const hash_chain, VP8LBackwardRefs* const refs_array,
|
||||
int width, int height, int quality, int low_effort) {
|
||||
int i;
|
||||
int max_tokens = 0;
|
||||
WebPEncodingError err = VP8_ENC_OK;
|
||||
@ -798,13 +817,11 @@ static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
refs = VP8LGetBackwardReferences(width, height, argb, quality, 0,
|
||||
kLZ77Standard | kLZ77RLE, &cache_bits,
|
||||
hash_chain, refs_tmp1, refs_tmp2);
|
||||
if (refs == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
err = VP8LGetBackwardReferences(
|
||||
width, height, argb, quality, /*low_effort=*/0, kLZ77Standard | kLZ77RLE,
|
||||
cache_bits, /*do_no_cache=*/0, hash_chain, refs_array, &cache_bits);
|
||||
if (err != VP8_ENC_OK) goto Error;
|
||||
refs = &refs_array[0];
|
||||
histogram_image = VP8LAllocateHistogramSet(1, cache_bits);
|
||||
if (histogram_image == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
@ -860,11 +877,11 @@ static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
|
||||
|
||||
static WebPEncodingError EncodeImageInternal(
|
||||
VP8LBitWriter* const bw, const uint32_t* const argb,
|
||||
VP8LHashChain* const hash_chain, VP8LBackwardRefs refs_array[3], int width,
|
||||
VP8LHashChain* const hash_chain, VP8LBackwardRefs refs_array[4], int width,
|
||||
int height, int quality, int low_effort, int use_cache,
|
||||
const CrunchConfig* const config, int* cache_bits, int histogram_bits,
|
||||
size_t init_byte_position, int* const hdr_size, int* const data_size) {
|
||||
WebPEncodingError err = VP8_ENC_OK;
|
||||
WebPEncodingError err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
const uint32_t histogram_image_xysize =
|
||||
VP8LSubSampleSize(width, histogram_bits) *
|
||||
VP8LSubSampleSize(height, histogram_bits);
|
||||
@ -876,103 +893,103 @@ static WebPEncodingError EncodeImageInternal(
|
||||
3ULL * CODE_LENGTH_CODES, sizeof(*huff_tree));
|
||||
HuffmanTreeToken* tokens = NULL;
|
||||
HuffmanTreeCode* huffman_codes = NULL;
|
||||
VP8LBackwardRefs* refs_best;
|
||||
VP8LBackwardRefs* refs_tmp;
|
||||
uint16_t* const histogram_symbols =
|
||||
(uint16_t*)WebPSafeMalloc(histogram_image_xysize,
|
||||
sizeof(*histogram_symbols));
|
||||
int lz77s_idx;
|
||||
int sub_configs_idx;
|
||||
int cache_bits_init, write_histogram_image;
|
||||
VP8LBitWriter bw_init = *bw, bw_best;
|
||||
int hdr_size_tmp;
|
||||
VP8LHashChain hash_chain_histogram; // histogram image hash chain
|
||||
size_t bw_size_best = ~(size_t)0;
|
||||
assert(histogram_bits >= MIN_HUFFMAN_BITS);
|
||||
assert(histogram_bits <= MAX_HUFFMAN_BITS);
|
||||
assert(hdr_size != NULL);
|
||||
assert(data_size != NULL);
|
||||
|
||||
if (histogram_symbols == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
// Make sure we can allocate the different objects.
|
||||
memset(&hash_chain_histogram, 0, sizeof(hash_chain_histogram));
|
||||
if (huff_tree == NULL || histogram_symbols == NULL ||
|
||||
!VP8LHashChainInit(&hash_chain_histogram, histogram_image_xysize) ||
|
||||
!VP8LHashChainFill(hash_chain, quality, argb, width, height,
|
||||
low_effort)) {
|
||||
goto Error;
|
||||
}
|
||||
|
||||
if (use_cache) {
|
||||
// If the value is different from zero, it has been set during the
|
||||
// palette analysis.
|
||||
if (*cache_bits == 0) *cache_bits = MAX_COLOR_CACHE_BITS;
|
||||
cache_bits_init = (*cache_bits == 0) ? MAX_COLOR_CACHE_BITS : *cache_bits;
|
||||
} else {
|
||||
*cache_bits = 0;
|
||||
cache_bits_init = 0;
|
||||
}
|
||||
// 'best_refs' is the reference to the best backward refs and points to one
|
||||
// of refs_array[0] or refs_array[1].
|
||||
// Calculate backward references from ARGB image.
|
||||
if (huff_tree == NULL ||
|
||||
!VP8LHashChainFill(hash_chain, quality, argb, width, height,
|
||||
low_effort) ||
|
||||
!VP8LBitWriterInit(&bw_best, 0) ||
|
||||
(config->lz77s_types_to_try_size_ > 1 &&
|
||||
// If several iterations will happen, clone into bw_best.
|
||||
if (!VP8LBitWriterInit(&bw_best, 0) ||
|
||||
((config->sub_configs_size_ > 1 ||
|
||||
config->sub_configs_[0].do_no_cache_) &&
|
||||
!VP8LBitWriterClone(bw, &bw_best))) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
for (lz77s_idx = 0; lz77s_idx < config->lz77s_types_to_try_size_;
|
||||
++lz77s_idx) {
|
||||
refs_best = VP8LGetBackwardReferences(
|
||||
width, height, argb, quality, low_effort,
|
||||
config->lz77s_types_to_try_[lz77s_idx], cache_bits, hash_chain,
|
||||
&refs_array[0], &refs_array[1]);
|
||||
if (refs_best == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
// Keep the best references aside and use the other element from the first
|
||||
// two as a temporary for later usage.
|
||||
refs_tmp = &refs_array[refs_best == &refs_array[0] ? 1 : 0];
|
||||
for (sub_configs_idx = 0; sub_configs_idx < config->sub_configs_size_;
|
||||
++sub_configs_idx) {
|
||||
const CrunchSubConfig* const sub_config =
|
||||
&config->sub_configs_[sub_configs_idx];
|
||||
int cache_bits_best, i_cache;
|
||||
err = VP8LGetBackwardReferences(width, height, argb, quality, low_effort,
|
||||
sub_config->lz77_, cache_bits_init,
|
||||
sub_config->do_no_cache_, hash_chain,
|
||||
&refs_array[0], &cache_bits_best);
|
||||
if (err != VP8_ENC_OK) goto Error;
|
||||
|
||||
histogram_image =
|
||||
VP8LAllocateHistogramSet(histogram_image_xysize, *cache_bits);
|
||||
tmp_histo = VP8LAllocateHistogram(*cache_bits);
|
||||
if (histogram_image == NULL || tmp_histo == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
for (i_cache = 0; i_cache < (sub_config->do_no_cache_ ? 2 : 1); ++i_cache) {
|
||||
const int cache_bits_tmp = (i_cache == 0) ? cache_bits_best : 0;
|
||||
// Speed-up: no need to study the no-cache case if it was already studied
|
||||
// in i_cache == 0.
|
||||
if (i_cache == 1 && cache_bits_best == 0) break;
|
||||
|
||||
// Build histogram image and symbols from backward references.
|
||||
if (!VP8LGetHistoImageSymbols(width, height, refs_best, quality, low_effort,
|
||||
histogram_bits, *cache_bits, histogram_image,
|
||||
tmp_histo, histogram_symbols)) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
// Create Huffman bit lengths and codes for each histogram image.
|
||||
histogram_image_size = histogram_image->size;
|
||||
bit_array_size = 5 * histogram_image_size;
|
||||
huffman_codes = (HuffmanTreeCode*)WebPSafeCalloc(bit_array_size,
|
||||
sizeof(*huffman_codes));
|
||||
// Note: some histogram_image entries may point to tmp_histos[], so the
|
||||
// latter need to outlive the following call to GetHuffBitLengthsAndCodes().
|
||||
if (huffman_codes == NULL ||
|
||||
!GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
// Free combined histograms.
|
||||
VP8LFreeHistogramSet(histogram_image);
|
||||
histogram_image = NULL;
|
||||
// Reset the bit writer for this iteration.
|
||||
VP8LBitWriterReset(&bw_init, bw);
|
||||
|
||||
// Free scratch histograms.
|
||||
VP8LFreeHistogram(tmp_histo);
|
||||
tmp_histo = NULL;
|
||||
// Build histogram image and symbols from backward references.
|
||||
histogram_image =
|
||||
VP8LAllocateHistogramSet(histogram_image_xysize, cache_bits_tmp);
|
||||
tmp_histo = VP8LAllocateHistogram(cache_bits_tmp);
|
||||
if (histogram_image == NULL || tmp_histo == NULL ||
|
||||
!VP8LGetHistoImageSymbols(width, height, &refs_array[i_cache],
|
||||
quality, low_effort, histogram_bits,
|
||||
cache_bits_tmp, histogram_image, tmp_histo,
|
||||
histogram_symbols)) {
|
||||
goto Error;
|
||||
}
|
||||
// Create Huffman bit lengths and codes for each histogram image.
|
||||
histogram_image_size = histogram_image->size;
|
||||
bit_array_size = 5 * histogram_image_size;
|
||||
huffman_codes = (HuffmanTreeCode*)WebPSafeCalloc(bit_array_size,
|
||||
sizeof(*huffman_codes));
|
||||
// Note: some histogram_image entries may point to tmp_histos[], so the
|
||||
// latter need to outlive the following call to
|
||||
// GetHuffBitLengthsAndCodes().
|
||||
if (huffman_codes == NULL ||
|
||||
!GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
|
||||
goto Error;
|
||||
}
|
||||
// Free combined histograms.
|
||||
VP8LFreeHistogramSet(histogram_image);
|
||||
histogram_image = NULL;
|
||||
|
||||
// Color Cache parameters.
|
||||
if (*cache_bits > 0) {
|
||||
VP8LPutBits(bw, 1, 1);
|
||||
VP8LPutBits(bw, *cache_bits, 4);
|
||||
} else {
|
||||
VP8LPutBits(bw, 0, 1);
|
||||
}
|
||||
// Free scratch histograms.
|
||||
VP8LFreeHistogram(tmp_histo);
|
||||
tmp_histo = NULL;
|
||||
|
||||
// Huffman image + meta huffman.
|
||||
{
|
||||
const int write_histogram_image = (histogram_image_size > 1);
|
||||
// Color Cache parameters.
|
||||
if (cache_bits_tmp > 0) {
|
||||
VP8LPutBits(bw, 1, 1);
|
||||
VP8LPutBits(bw, cache_bits_tmp, 4);
|
||||
} else {
|
||||
VP8LPutBits(bw, 0, 1);
|
||||
}
|
||||
|
||||
// Huffman image + meta huffman.
|
||||
write_histogram_image = (histogram_image_size > 1);
|
||||
VP8LPutBits(bw, write_histogram_image, 1);
|
||||
if (write_histogram_image) {
|
||||
uint32_t* const histogram_argb =
|
||||
@ -980,10 +997,7 @@ static WebPEncodingError EncodeImageInternal(
|
||||
sizeof(*histogram_argb));
|
||||
int max_index = 0;
|
||||
uint32_t i;
|
||||
if (histogram_argb == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
if (histogram_argb == NULL) goto Error;
|
||||
for (i = 0; i < histogram_image_xysize; ++i) {
|
||||
const int symbol_index = histogram_symbols[i] & 0xffff;
|
||||
histogram_argb[i] = (symbol_index << 8);
|
||||
@ -995,65 +1009,64 @@ static WebPEncodingError EncodeImageInternal(
|
||||
|
||||
VP8LPutBits(bw, histogram_bits - 2, 3);
|
||||
err = EncodeImageNoHuffman(
|
||||
bw, histogram_argb, hash_chain, refs_tmp, &refs_array[2],
|
||||
bw, histogram_argb, &hash_chain_histogram, &refs_array[2],
|
||||
VP8LSubSampleSize(width, histogram_bits),
|
||||
VP8LSubSampleSize(height, histogram_bits), quality, low_effort);
|
||||
WebPSafeFree(histogram_argb);
|
||||
if (err != VP8_ENC_OK) goto Error;
|
||||
}
|
||||
}
|
||||
|
||||
// Store Huffman codes.
|
||||
{
|
||||
int i;
|
||||
int max_tokens = 0;
|
||||
// Find maximum number of symbols for the huffman tree-set.
|
||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||
if (max_tokens < codes->num_symbols) {
|
||||
max_tokens = codes->num_symbols;
|
||||
// Store Huffman codes.
|
||||
{
|
||||
int i;
|
||||
int max_tokens = 0;
|
||||
// Find maximum number of symbols for the huffman tree-set.
|
||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||
if (max_tokens < codes->num_symbols) {
|
||||
max_tokens = codes->num_symbols;
|
||||
}
|
||||
}
|
||||
tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens, sizeof(*tokens));
|
||||
if (tokens == NULL) goto Error;
|
||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||
StoreHuffmanCode(bw, huff_tree, tokens, codes);
|
||||
ClearHuffmanTreeIfOnlyOneSymbol(codes);
|
||||
}
|
||||
}
|
||||
tokens = (HuffmanTreeToken*)WebPSafeMalloc(max_tokens, sizeof(*tokens));
|
||||
if (tokens == NULL) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
// Store actual literals.
|
||||
hdr_size_tmp = (int)(VP8LBitWriterNumBytes(bw) - init_byte_position);
|
||||
err = StoreImageToBitMask(bw, width, histogram_bits, &refs_array[i_cache],
|
||||
histogram_symbols, huffman_codes);
|
||||
if (err != VP8_ENC_OK) goto Error;
|
||||
// Keep track of the smallest image so far.
|
||||
if (VP8LBitWriterNumBytes(bw) < bw_size_best) {
|
||||
bw_size_best = VP8LBitWriterNumBytes(bw);
|
||||
*cache_bits = cache_bits_tmp;
|
||||
*hdr_size = hdr_size_tmp;
|
||||
*data_size =
|
||||
(int)(VP8LBitWriterNumBytes(bw) - init_byte_position - *hdr_size);
|
||||
VP8LBitWriterSwap(bw, &bw_best);
|
||||
}
|
||||
for (i = 0; i < 5 * histogram_image_size; ++i) {
|
||||
HuffmanTreeCode* const codes = &huffman_codes[i];
|
||||
StoreHuffmanCode(bw, huff_tree, tokens, codes);
|
||||
ClearHuffmanTreeIfOnlyOneSymbol(codes);
|
||||
WebPSafeFree(tokens);
|
||||
tokens = NULL;
|
||||
if (huffman_codes != NULL) {
|
||||
WebPSafeFree(huffman_codes->codes);
|
||||
WebPSafeFree(huffman_codes);
|
||||
huffman_codes = NULL;
|
||||
}
|
||||
}
|
||||
// Store actual literals.
|
||||
hdr_size_tmp = (int)(VP8LBitWriterNumBytes(bw) - init_byte_position);
|
||||
err = StoreImageToBitMask(bw, width, histogram_bits, refs_best,
|
||||
histogram_symbols, huffman_codes);
|
||||
// Keep track of the smallest image so far.
|
||||
if (lz77s_idx == 0 ||
|
||||
VP8LBitWriterNumBytes(bw) < VP8LBitWriterNumBytes(&bw_best)) {
|
||||
*hdr_size = hdr_size_tmp;
|
||||
*data_size =
|
||||
(int)(VP8LBitWriterNumBytes(bw) - init_byte_position - *hdr_size);
|
||||
VP8LBitWriterSwap(bw, &bw_best);
|
||||
}
|
||||
// Reset the bit writer for the following iteration if any.
|
||||
if (config->lz77s_types_to_try_size_ > 1) VP8LBitWriterReset(&bw_init, bw);
|
||||
WebPSafeFree(tokens);
|
||||
tokens = NULL;
|
||||
if (huffman_codes != NULL) {
|
||||
WebPSafeFree(huffman_codes->codes);
|
||||
WebPSafeFree(huffman_codes);
|
||||
huffman_codes = NULL;
|
||||
}
|
||||
}
|
||||
VP8LBitWriterSwap(bw, &bw_best);
|
||||
err = VP8_ENC_OK;
|
||||
|
||||
Error:
|
||||
WebPSafeFree(tokens);
|
||||
WebPSafeFree(huff_tree);
|
||||
VP8LFreeHistogramSet(histogram_image);
|
||||
VP8LFreeHistogram(tmp_histo);
|
||||
VP8LHashChainClear(&hash_chain_histogram);
|
||||
if (huffman_codes != NULL) {
|
||||
WebPSafeFree(huffman_codes->codes);
|
||||
WebPSafeFree(huffman_codes);
|
||||
@ -1095,8 +1108,7 @@ static WebPEncodingError ApplyPredictFilter(const VP8LEncoder* const enc,
|
||||
VP8LPutBits(bw, pred_bits - 2, 3);
|
||||
return EncodeImageNoHuffman(
|
||||
bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_,
|
||||
(VP8LBackwardRefs*)&enc->refs_[0], // cast const away
|
||||
(VP8LBackwardRefs*)&enc->refs_[1], transform_width, transform_height,
|
||||
(VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height,
|
||||
quality, low_effort);
|
||||
}
|
||||
|
||||
@ -1116,8 +1128,7 @@ static WebPEncodingError ApplyCrossColorFilter(const VP8LEncoder* const enc,
|
||||
VP8LPutBits(bw, ccolor_transform_bits - 2, 3);
|
||||
return EncodeImageNoHuffman(
|
||||
bw, enc->transform_data_, (VP8LHashChain*)&enc->hash_chain_,
|
||||
(VP8LBackwardRefs*)&enc->refs_[0], // cast const away
|
||||
(VP8LBackwardRefs*)&enc->refs_[1], transform_width, transform_height,
|
||||
(VP8LBackwardRefs*)&enc->refs_[0], transform_width, transform_height,
|
||||
quality, low_effort);
|
||||
}
|
||||
|
||||
@ -1464,8 +1475,8 @@ static WebPEncodingError EncodePalette(VP8LBitWriter* const bw, int low_effort,
|
||||
}
|
||||
tmp_palette[0] = palette[0];
|
||||
return EncodeImageNoHuffman(bw, tmp_palette, &enc->hash_chain_,
|
||||
&enc->refs_[0], &enc->refs_[1], palette_size, 1,
|
||||
20 /* quality */, low_effort);
|
||||
&enc->refs_[0], palette_size, 1, /*quality=*/20,
|
||||
low_effort);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -1491,7 +1502,7 @@ static void VP8LEncoderDelete(VP8LEncoder* enc) {
|
||||
if (enc != NULL) {
|
||||
int i;
|
||||
VP8LHashChainClear(&enc->hash_chain_);
|
||||
for (i = 0; i < 3; ++i) VP8LBackwardRefsClear(&enc->refs_[i]);
|
||||
for (i = 0; i < 4; ++i) VP8LBackwardRefsClear(&enc->refs_[i]);
|
||||
ClearTransformBuffer(enc);
|
||||
WebPSafeFree(enc);
|
||||
}
|
||||
@ -1541,7 +1552,7 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
int data_size = 0;
|
||||
int use_delta_palette = 0;
|
||||
int idx;
|
||||
size_t best_size = 0;
|
||||
size_t best_size = ~(size_t)0;
|
||||
VP8LBitWriter bw_init = *bw, bw_best;
|
||||
(void)data2;
|
||||
|
||||
@ -1553,11 +1564,13 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
|
||||
for (idx = 0; idx < num_crunch_configs; ++idx) {
|
||||
const int entropy_idx = crunch_configs[idx].entropy_idx_;
|
||||
enc->use_palette_ = (entropy_idx == kPalette);
|
||||
enc->use_palette_ =
|
||||
(entropy_idx == kPalette) || (entropy_idx == kPaletteAndSpatial);
|
||||
enc->use_subtract_green_ =
|
||||
(entropy_idx == kSubGreen) || (entropy_idx == kSpatialSubGreen);
|
||||
enc->use_predict_ =
|
||||
(entropy_idx == kSpatial) || (entropy_idx == kSpatialSubGreen);
|
||||
enc->use_predict_ = (entropy_idx == kSpatial) ||
|
||||
(entropy_idx == kSpatialSubGreen) ||
|
||||
(entropy_idx == kPaletteAndSpatial);
|
||||
if (low_effort) {
|
||||
enc->use_cross_color_ = 0;
|
||||
} else {
|
||||
@ -1640,7 +1653,7 @@ static int EncodeStreamHook(void* input, void* data2) {
|
||||
if (err != VP8_ENC_OK) goto Error;
|
||||
|
||||
// If we are better than what we already have.
|
||||
if (idx == 0 || VP8LBitWriterNumBytes(bw) < best_size) {
|
||||
if (VP8LBitWriterNumBytes(bw) < best_size) {
|
||||
best_size = VP8LBitWriterNumBytes(bw);
|
||||
// Store the BitWriter.
|
||||
VP8LBitWriterSwap(bw, &bw_best);
|
||||
@ -1821,7 +1834,7 @@ Error:
|
||||
}
|
||||
|
||||
#undef CRUNCH_CONFIGS_MAX
|
||||
#undef CRUNCH_CONFIGS_LZ77_MAX
|
||||
#undef CRUNCH_SUBCONFIGS_MAX
|
||||
|
||||
int VP8LEncodeImage(const WebPConfig* const config,
|
||||
const WebPPicture* const picture) {
|
||||
|
@ -71,7 +71,7 @@ typedef struct {
|
||||
uint32_t palette_[MAX_PALETTE_SIZE];
|
||||
|
||||
// Some 'scratch' (potentially large) objects.
|
||||
struct VP8LBackwardRefs refs_[3]; // Backward Refs array for temporaries.
|
||||
struct VP8LBackwardRefs refs_[4]; // Backward Refs array for temporaries.
|
||||
VP8LHashChain hash_chain_; // HashChain data for constructing
|
||||
// backward references.
|
||||
} VP8LEncoder;
|
||||
|
@ -400,7 +400,7 @@ int WebPEncode(const WebPConfig* config, WebPPicture* pic) {
|
||||
}
|
||||
|
||||
if (!config->exact) {
|
||||
WebPCleanupTransparentAreaLossless(pic);
|
||||
WebPReplaceTransparentPixels(pic, 0x000000);
|
||||
}
|
||||
|
||||
ok = VP8LEncodeImage(config, pic); // Sets pic->error in case of problem.
|
||||
|
@ -6,8 +6,8 @@
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,3
|
||||
PRODUCTVERSION 1,0,0,3
|
||||
FILEVERSION 1,0,2,0
|
||||
PRODUCTVERSION 1,0,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -24,12 +24,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebp DLL"
|
||||
VALUE "FileVersion", "1.0.3"
|
||||
VALUE "FileVersion", "1.2.0"
|
||||
VALUE "InternalName", "libwebp.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019"
|
||||
VALUE "OriginalFilename", "libwebp.dll"
|
||||
VALUE "ProductName", "WebP Image Codec"
|
||||
VALUE "ProductVersion", "1.0.3"
|
||||
VALUE "ProductVersion", "1.2.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -6,8 +6,8 @@
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,3
|
||||
PRODUCTVERSION 1,0,0,3
|
||||
FILEVERSION 1,0,2,0
|
||||
PRODUCTVERSION 1,0,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -24,12 +24,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebpdecoder DLL"
|
||||
VALUE "FileVersion", "1.0.3"
|
||||
VALUE "FileVersion", "1.2.0"
|
||||
VALUE "InternalName", "libwebpdecoder.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019"
|
||||
VALUE "OriginalFilename", "libwebpdecoder.dll"
|
||||
VALUE "ProductName", "WebP Image Decoder"
|
||||
VALUE "ProductVersion", "1.0.3"
|
||||
VALUE "ProductVersion", "1.2.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -17,6 +17,6 @@ noinst_HEADERS =
|
||||
noinst_HEADERS += ../webp/format_constants.h
|
||||
|
||||
libwebpmux_la_LIBADD = ../libwebp.la
|
||||
libwebpmux_la_LDFLAGS = -no-undefined -version-info 3:4:0 -lm
|
||||
libwebpmux_la_LDFLAGS = -no-undefined -version-info 3:6:0 -lm
|
||||
libwebpmuxincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebpmux.pc
|
||||
|
@ -6,8 +6,8 @@
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,3
|
||||
PRODUCTVERSION 1,0,0,3
|
||||
FILEVERSION 1,0,2,0
|
||||
PRODUCTVERSION 1,0,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -24,12 +24,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebpmux DLL"
|
||||
VALUE "FileVersion", "1.0.3"
|
||||
VALUE "FileVersion", "1.2.0"
|
||||
VALUE "InternalName", "libwebpmux.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019"
|
||||
VALUE "OriginalFilename", "libwebpmux.dll"
|
||||
VALUE "ProductName", "WebP Image Muxer"
|
||||
VALUE "ProductVersion", "1.0.3"
|
||||
VALUE "ProductVersion", "1.2.0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -28,8 +28,8 @@ extern "C" {
|
||||
// Defines and constants.
|
||||
|
||||
#define MUX_MAJ_VERSION 1
|
||||
#define MUX_MIN_VERSION 0
|
||||
#define MUX_REV_VERSION 3
|
||||
#define MUX_MIN_VERSION 2
|
||||
#define MUX_REV_VERSION 0
|
||||
|
||||
// Chunk object.
|
||||
typedef struct WebPChunk WebPChunk;
|
||||
|
@ -100,7 +100,7 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
|
||||
WebPMuxImage* const wpi) {
|
||||
const uint8_t* bytes = chunk->data_.bytes;
|
||||
size_t size = chunk->data_.size;
|
||||
const uint8_t* const last = bytes + size;
|
||||
const uint8_t* const last = (bytes == NULL) ? NULL : bytes + size;
|
||||
WebPChunk subchunk;
|
||||
size_t subchunk_size;
|
||||
WebPChunk** unknown_chunk_list = &wpi->unknown_;
|
||||
@ -155,7 +155,6 @@ static int MuxImageParse(const WebPChunk* const chunk, int copy_data,
|
||||
break;
|
||||
default:
|
||||
goto Fail;
|
||||
break;
|
||||
}
|
||||
subchunk_size = ChunkDiskSize(&subchunk);
|
||||
bytes += subchunk_size;
|
||||
@ -264,7 +263,6 @@ WebPMux* WebPMuxCreateInternal(const WebPData* bitstream, int copy_data,
|
||||
if (!MuxImageParse(&chunk, copy_data, wpi)) goto Err;
|
||||
ChunkRelease(&chunk);
|
||||
goto PushImage;
|
||||
break;
|
||||
default: // A non-image chunk.
|
||||
if (wpi->is_partial_) goto Err; // Encountered a non-image chunk before
|
||||
// getting all chunks of an image.
|
||||
|
@ -26,7 +26,7 @@ extern "C" {
|
||||
|
||||
// Main color cache struct.
|
||||
typedef struct {
|
||||
uint32_t *colors_; // color entries
|
||||
uint32_t* colors_; // color entries
|
||||
int hash_shift_; // Hash shift: 32 - hash_bits_.
|
||||
int hash_bits_;
|
||||
} VP8LColorCache;
|
||||
|
@ -73,7 +73,7 @@ typedef struct {
|
||||
#endif
|
||||
|
||||
static int pthread_create(pthread_t* const thread, const void* attr,
|
||||
unsigned int (__stdcall *start)(void*), void* arg) {
|
||||
unsigned int (__stdcall* start)(void*), void* arg) {
|
||||
(void)attr;
|
||||
#ifdef USE_CREATE_THREAD
|
||||
*thread = CreateThread(NULL, /* lpThreadAttributes */
|
||||
|
@ -216,9 +216,14 @@ void WebPSafeFree(void* const ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
// Public API function.
|
||||
// Public API functions.
|
||||
|
||||
void* WebPMalloc(size_t size) {
|
||||
return WebPSafeMalloc(1, size);
|
||||
}
|
||||
|
||||
void WebPFree(void* ptr) {
|
||||
free(ptr);
|
||||
WebPSafeFree(ptr);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -226,7 +231,7 @@ void WebPFree(void* ptr) {
|
||||
void WebPCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height) {
|
||||
assert(src != NULL && dst != NULL);
|
||||
assert(src_stride >= width && dst_stride >= width);
|
||||
assert(abs(src_stride) >= width && abs(dst_stride) >= width);
|
||||
while (height-- > 0) {
|
||||
memcpy(dst, src, width);
|
||||
src += src_stride;
|
||||
|
@ -20,7 +20,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WEBP_DECODER_ABI_VERSION 0x0208 // MAJOR(8b) + MINOR(8b)
|
||||
#define WEBP_DECODER_ABI_VERSION 0x0209 // MAJOR(8b) + MINOR(8b)
|
||||
|
||||
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
|
||||
// the types are left here for reference.
|
||||
@ -91,9 +91,6 @@ WEBP_EXTERN uint8_t* WebPDecodeYUV(const uint8_t* data, size_t data_size,
|
||||
uint8_t** u, uint8_t** v,
|
||||
int* stride, int* uv_stride);
|
||||
|
||||
// Releases memory returned by the WebPDecode*() functions above.
|
||||
WEBP_EXTERN void WebPFree(void* ptr);
|
||||
|
||||
// These five functions are variants of the above ones, that decode the image
|
||||
// directly into a pre-allocated buffer 'output_buffer'. The maximum storage
|
||||
// available in this buffer is indicated by 'output_buffer_size'. If this
|
||||
@ -456,7 +453,7 @@ struct WebPDecoderOptions {
|
||||
int scaled_width, scaled_height; // final resolution
|
||||
int use_threads; // if true, use multi-threaded decoding
|
||||
int dithering_strength; // dithering strength (0=Off, 100=full)
|
||||
int flip; // flip output vertically
|
||||
int flip; // if true, flip output vertically
|
||||
int alpha_dithering_strength; // alpha dithering strength in [0..100]
|
||||
|
||||
uint32_t pad[5]; // padding for later use
|
||||
|
@ -20,7 +20,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define WEBP_ENCODER_ABI_VERSION 0x020e // MAJOR(8b) + MINOR(8b)
|
||||
#define WEBP_ENCODER_ABI_VERSION 0x020f // MAJOR(8b) + MINOR(8b)
|
||||
|
||||
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
|
||||
// the types are left here for reference.
|
||||
@ -79,9 +79,6 @@ WEBP_EXTERN size_t WebPEncodeLosslessBGRA(const uint8_t* bgra,
|
||||
int width, int height, int stride,
|
||||
uint8_t** output);
|
||||
|
||||
// Releases memory returned by the WebPEncode*() functions above.
|
||||
WEBP_EXTERN void WebPFree(void* ptr);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Coding parameters
|
||||
|
||||
@ -151,7 +148,8 @@ struct WebPConfig {
|
||||
int use_delta_palette; // reserved for future lossless feature
|
||||
int use_sharp_yuv; // if needed, use sharp (and slow) RGB->YUV conversion
|
||||
|
||||
uint32_t pad[2]; // padding for later use
|
||||
int qmin; // minimum permissible quality factor
|
||||
int qmax; // maximum permissible quality factor
|
||||
};
|
||||
|
||||
// Enumerate some predefined settings for WebPConfig, depending on the type
|
||||
@ -294,6 +292,11 @@ typedef enum WebPEncodingError {
|
||||
#define WEBP_MAX_DIMENSION 16383
|
||||
|
||||
// Main exchange structure (input samples, output bytes, statistics)
|
||||
//
|
||||
// Once WebPPictureInit() has been called, it's ok to make all the INPUT fields
|
||||
// (use_argb, y/u/v, argb, ...) point to user-owned data, even if
|
||||
// WebPPictureAlloc() has been called. Depending on the value use_argb,
|
||||
// it's guaranteed that either *argb or *y/*u/*v content will be kept untouched.
|
||||
struct WebPPicture {
|
||||
// INPUT
|
||||
//////////////
|
||||
@ -306,7 +309,7 @@ struct WebPPicture {
|
||||
// YUV input (mostly used for input to lossy compression)
|
||||
WebPEncCSP colorspace; // colorspace: should be YUV420 for now (=Y'CbCr).
|
||||
int width, height; // dimensions (less or equal to WEBP_MAX_DIMENSION)
|
||||
uint8_t *y, *u, *v; // pointers to luma/chroma planes.
|
||||
uint8_t* y, *u, *v; // pointers to luma/chroma planes.
|
||||
int y_stride, uv_stride; // luma/chroma strides.
|
||||
uint8_t* a; // pointer to the alpha plane
|
||||
int a_stride; // stride of the alpha plane
|
||||
@ -350,7 +353,7 @@ struct WebPPicture {
|
||||
uint32_t pad3[3]; // padding for later use
|
||||
|
||||
// Unused for now
|
||||
uint8_t *pad4, *pad5;
|
||||
uint8_t* pad4, *pad5;
|
||||
uint32_t pad6[8]; // padding for later use
|
||||
|
||||
// PRIVATE FIELDS
|
||||
|
@ -57,7 +57,7 @@ extern "C" {
|
||||
WebPMuxGetChunk(mux, "ICCP", &icc_profile);
|
||||
// ... (Consume icc_data).
|
||||
WebPMuxDelete(mux);
|
||||
free(data);
|
||||
WebPFree(data);
|
||||
*/
|
||||
|
||||
// Note: forward declaring enumerations is not allowed in (strict) C and C++,
|
||||
@ -245,7 +245,7 @@ WEBP_EXTERN WebPMuxError WebPMuxPushFrame(
|
||||
WebPMux* mux, const WebPMuxFrameInfo* frame, int copy_data);
|
||||
|
||||
// Gets the nth frame from the mux object.
|
||||
// The content of 'frame->bitstream' is allocated using malloc(), and NOT
|
||||
// The content of 'frame->bitstream' is allocated using WebPMalloc(), and NOT
|
||||
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
|
||||
// WebPDataClear().
|
||||
// nth=0 has a special meaning - last position.
|
||||
@ -376,10 +376,10 @@ WEBP_EXTERN WebPMuxError WebPMuxNumChunks(const WebPMux* mux,
|
||||
// Assembles all chunks in WebP RIFF format and returns in 'assembled_data'.
|
||||
// This function also validates the mux object.
|
||||
// Note: The content of 'assembled_data' will be ignored and overwritten.
|
||||
// Also, the content of 'assembled_data' is allocated using malloc(), and NOT
|
||||
// owned by the 'mux' object. It MUST be deallocated by the caller by calling
|
||||
// WebPDataClear(). It's always safe to call WebPDataClear() upon return,
|
||||
// even in case of error.
|
||||
// Also, the content of 'assembled_data' is allocated using WebPMalloc(), and
|
||||
// NOT owned by the 'mux' object. It MUST be deallocated by the caller by
|
||||
// calling WebPDataClear(). It's always safe to call WebPDataClear() upon
|
||||
// return, even in case of error.
|
||||
// Parameters:
|
||||
// mux - (in/out) object whose chunks are to be assembled
|
||||
// assembled_data - (out) assembled WebP data
|
||||
|
@ -14,7 +14,6 @@
|
||||
#ifndef WEBP_WEBP_MUX_TYPES_H_
|
||||
#define WEBP_WEBP_MUX_TYPES_H_
|
||||
|
||||
#include <stdlib.h> // free()
|
||||
#include <string.h> // memset()
|
||||
#include "./types.h"
|
||||
|
||||
@ -56,6 +55,7 @@ typedef enum WebPMuxAnimBlend {
|
||||
|
||||
// Data type used to describe 'raw' data, e.g., chunk data
|
||||
// (ICC profile, metadata) and WebP compressed image data.
|
||||
// 'bytes' memory must be allocated using WebPMalloc() and such.
|
||||
struct WebPData {
|
||||
const uint8_t* bytes;
|
||||
size_t size;
|
||||
@ -68,11 +68,11 @@ static WEBP_INLINE void WebPDataInit(WebPData* webp_data) {
|
||||
}
|
||||
}
|
||||
|
||||
// Clears the contents of the 'webp_data' object by calling free(). Does not
|
||||
// deallocate the object itself.
|
||||
// Clears the contents of the 'webp_data' object by calling WebPFree().
|
||||
// Does not deallocate the object itself.
|
||||
static WEBP_INLINE void WebPDataClear(WebPData* webp_data) {
|
||||
if (webp_data != NULL) {
|
||||
free((void*)webp_data->bytes);
|
||||
WebPFree((void*)webp_data->bytes);
|
||||
WebPDataInit(webp_data);
|
||||
}
|
||||
}
|
||||
@ -83,7 +83,7 @@ static WEBP_INLINE int WebPDataCopy(const WebPData* src, WebPData* dst) {
|
||||
if (src == NULL || dst == NULL) return 0;
|
||||
WebPDataInit(dst);
|
||||
if (src->bytes != NULL && src->size != 0) {
|
||||
dst->bytes = (uint8_t*)malloc(src->size);
|
||||
dst->bytes = (uint8_t*)WebPMalloc(src->size);
|
||||
if (dst->bytes == NULL) return 0;
|
||||
memcpy((void*)dst->bytes, src->bytes, src->size);
|
||||
dst->size = src->size;
|
||||
|
@ -7,7 +7,7 @@
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Common types
|
||||
// Common types + memory wrappers
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
@ -49,4 +49,20 @@ typedef long long int int64_t;
|
||||
// Macro to check ABI compatibility (same major revision number)
|
||||
#define WEBP_ABI_IS_INCOMPATIBLE(a, b) (((a) >> 8) != ((b) >> 8))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Allocates 'size' bytes of memory. Returns NULL upon error. Memory
|
||||
// must be deallocated by calling WebPFree(). This function is made available
|
||||
// by the core 'libwebp' library.
|
||||
WEBP_EXTERN void* WebPMalloc(size_t size);
|
||||
|
||||
// Releases memory returned by the WebPDecode*() functions (from decode.h).
|
||||
WEBP_EXTERN void WebPFree(void* ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_WEBP_TYPES_H_
|
||||
|
@ -1,14 +1,9 @@
|
||||
# Lint as: python2, python3
|
||||
# This file was automatically generated by SWIG (http://www.swig.org).
|
||||
# Version 3.0.10
|
||||
# Version 3.0.12
|
||||
#
|
||||
# Do not make changes to this file unless you know what you are doing--modify
|
||||
# the SWIG interface file instead.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
from sys import version_info as _swig_python_version_info
|
||||
if _swig_python_version_info >= (2, 7, 0):
|
||||
def swig_import_helper():
|
||||
@ -31,17 +26,18 @@ elif _swig_python_version_info >= (2, 6, 0):
|
||||
except ImportError:
|
||||
import _libwebp
|
||||
return _libwebp
|
||||
if fp is not None:
|
||||
try:
|
||||
_mod = imp.load_module('_libwebp', fp, pathname, description)
|
||||
finally:
|
||||
try:
|
||||
_mod = imp.load_module('_libwebp', fp, pathname, description)
|
||||
finally:
|
||||
if fp is not None:
|
||||
fp.close()
|
||||
return _mod
|
||||
return _mod
|
||||
_libwebp = swig_import_helper()
|
||||
del swig_import_helper
|
||||
else:
|
||||
import _libwebp
|
||||
del _swig_python_version_info
|
||||
|
||||
try:
|
||||
_swig_property = property
|
||||
except NameError:
|
||||
|
@ -32,6 +32,9 @@
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
%module(package="com.google.webp") libwebp
|
||||
%begin %{
|
||||
#define SWIG_PYTHON_STRICT_BYTE_CHAR
|
||||
%}
|
||||
#else
|
||||
%module libwebp
|
||||
#endif /* SWIGPYTHON */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user