mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 13:29:54 +02:00
Compare commits
123 Commits
Author | SHA1 | Date | |
---|---|---|---|
2b98df90cb | |||
61e372b7e3 | |||
7ae658a026 | |||
51c4907d32 | |||
666bd6c654 | |||
561cdce5bd | |||
aec2cf02d1 | |||
928a75deca | |||
5173d4ee6f | |||
5b081219c9 | |||
381b7b54a0 | |||
6ed15ea1cd | |||
22bbb24ea8 | |||
8b3fb2389b | |||
f435de9575 | |||
41521aed47 | |||
9f4d4a3f49 | |||
0fd7514b55 | |||
f95a996c64 | |||
e85d3313d6 | |||
fa8210e43c | |||
fd198f7370 | |||
825389acba | |||
3be698c3d3 | |||
485ff86fbb | |||
4cd0582d50 | |||
4cbb4caf49 | |||
f5a5918d13 | |||
d61385db35 | |||
6752904b2f | |||
0c57031629 | |||
301a2ddae5 | |||
f0abab9217 | |||
f2dfd92557 | |||
06b7bc7dec | |||
b6284d8247 | |||
decf6f6b87 | |||
dea3e89983 | |||
632798ae6f | |||
dc1a9518bc | |||
9cf9841b5e | |||
981794958b | |||
a376e7b96a | |||
cbf82cc04d | |||
5030e90278 | |||
ac5433118a | |||
123d330699 | |||
ef1094b0fe | |||
b911fbc980 | |||
eee00b6627 | |||
ac3ec8c91d | |||
3e13da7b4f | |||
5c395f1d71 | |||
e7a697297b | |||
e52485d6db | |||
92dc0f0937 | |||
39952de265 | |||
382af7a2dd | |||
14d020f6e6 | |||
0d92ff25f2 | |||
556cb1b45e | |||
da26ee49a6 | |||
b2a867c038 | |||
637141bc7c | |||
bc5092b162 | |||
50d8345ae6 | |||
6aa3e8aaf3 | |||
d71df4e2ee | |||
de08d72741 | |||
009562b403 | |||
423f257930 | |||
907208f97e | |||
4649b3c422 | |||
78ad57a36a | |||
da96d8d9ab | |||
2563db4759 | |||
211f37ee63 | |||
5f0f5c07c4 | |||
de98732b04 | |||
4338cd36fe | |||
e00af13ef4 | |||
a9ceda7ff1 | |||
2281bbf6f7 | |||
39cb9aad85 | |||
89cc9d3787 | |||
95fd650706 | |||
9e729fe19b | |||
29fb8562c6 | |||
eb82ce76dd | |||
1344a2e947 | |||
be738c6d39 | |||
2c70ad76c9 | |||
569001f19f | |||
c56a02d971 | |||
1579559662 | |||
1a44c233b9 | |||
e9569ad708 | |||
35c7de6fc4 | |||
0f25e61c13 | |||
5d8985de47 | |||
895fd28f9b | |||
5cf3e2afb5 | |||
2a9de5b9d3 | |||
71ed73cf86 | |||
af0e4fbb06 | |||
dce5d76431 | |||
f9df0081a7 | |||
dc39b16fe4 | |||
c7aa1264f0 | |||
53aa51e9a3 | |||
094b3b285b | |||
71c39a06c8 | |||
fd3d5756cb | |||
b0c966fb66 | |||
d77bf512bd | |||
e122e511cf | |||
1c8f358df4 | |||
a0215fb7dc | |||
abb4776006 | |||
e155dda0cc | |||
994be82d00 | |||
4033e1d70d | |||
978eec2507 |
5
.mailmap
5
.mailmap
@ -1,7 +1,8 @@
|
||||
<johann.koenig@duck.com> <johannkoenig@google.com>
|
||||
Johann Koenig <johann.koenig@duck.com>
|
||||
Johann Koenig <johann.koenig@duck.com> <johannkoenig@google.com>
|
||||
Mikołaj Zalewski <mikolajz@google.com>
|
||||
Pascal Massimino <pascal.massimino@gmail.com>
|
||||
<pascal.massimino@gmail.com> <skal@google.com>
|
||||
Pascal Massimino <pascal.massimino@gmail.com> <skal@google.com>
|
||||
Vikas Arora <vikasa@google.com>
|
||||
<vikasa@google.com> <vikasa@gmail.com>
|
||||
<vikasa@google.com> <vikaas.arora@gmail.com>
|
||||
|
5
AUTHORS
5
AUTHORS
@ -1,4 +1,5 @@
|
||||
Contributors:
|
||||
- Alan Browning (browning at google dot com)
|
||||
- Charles Munger (clm at google dot com)
|
||||
- Christian Duvivier (cduvivier at google dot com)
|
||||
- Djordje Pesut (djordje dot pesut at imgtec dot com)
|
||||
@ -6,9 +7,10 @@ Contributors:
|
||||
- James Zern (jzern at google dot com)
|
||||
- Jan Engelhardt (jengelh at medozas dot de)
|
||||
- Jehan (jehan at girinstud dot io)
|
||||
- Johann (johann dot koenig at duck dot com)
|
||||
- Johann Koenig (johann dot koenig at duck dot com)
|
||||
- Jovan Zelincevic (jovan dot zelincevic at imgtec dot com)
|
||||
- Jyrki Alakuijala (jyrki at google dot com)
|
||||
- Konstantin Ivlev (tomskside at gmail dot com)
|
||||
- Lode Vandevenne (lode at google dot com)
|
||||
- Lou Quillio (louquillio at google dot com)
|
||||
- Mans Rullgard (mans at mansr dot com)
|
||||
@ -37,3 +39,4 @@ Contributors:
|
||||
- Vincent Rabaud (vrabaud at google dot com)
|
||||
- Vlad Tsyrklevich (vtsyrklevich at chromium dot org)
|
||||
- Yang Zhang (yang dot zhang at arm dot com)
|
||||
- Yannis Guyon (yguyon at google dot com)
|
||||
|
10
Android.mk
10
Android.mk
@ -97,9 +97,9 @@ dsp_enc_srcs := \
|
||||
src/dsp/cost.c \
|
||||
src/dsp/cost_mips32.c \
|
||||
src/dsp/cost_mips_dsp_r2.c \
|
||||
src/dsp/cost_neon.$(NEON) \
|
||||
src/dsp/cost_sse2.c \
|
||||
src/dsp/enc.c \
|
||||
src/dsp/enc_avx2.c \
|
||||
src/dsp/enc_mips32.c \
|
||||
src/dsp/enc_mips_dsp_r2.c \
|
||||
src/dsp/enc_msa.c \
|
||||
@ -174,7 +174,7 @@ LOCAL_SRC_FILES := \
|
||||
$(utils_dec_srcs) \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
|
||||
# prefer arm over thumb mode for performance gains
|
||||
LOCAL_ARM_MODE := arm
|
||||
@ -208,7 +208,7 @@ LOCAL_SRC_FILES := \
|
||||
$(utils_enc_srcs) \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
|
||||
# prefer arm over thumb mode for performance gains
|
||||
LOCAL_ARM_MODE := arm
|
||||
@ -231,7 +231,7 @@ include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := $(demux_srcs)
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
|
||||
# prefer arm over thumb mode for performance gains
|
||||
LOCAL_ARM_MODE := arm
|
||||
@ -254,7 +254,7 @@ include $(CLEAR_VARS)
|
||||
LOCAL_SRC_FILES := $(mux_srcs)
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src
|
||||
|
||||
# prefer arm over thumb mode for performance gains
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
649
CMakeLists.txt
649
CMakeLists.txt
@ -1,79 +1,128 @@
|
||||
cmake_minimum_required(VERSION 2.8.7)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(libwebp C)
|
||||
project(WebP C)
|
||||
|
||||
# Options for coder / decoder executables.
|
||||
option(WEBP_ENABLE_SIMD "Enable any SIMD optimization." ON)
|
||||
option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." OFF)
|
||||
option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." OFF)
|
||||
option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." OFF)
|
||||
option(WEBP_BUILD_IMG2WEBP "Build the img2webp animation tool." OFF)
|
||||
option(WEBP_BUILD_WEBPINFO "Build the webpinfo command line tool." OFF)
|
||||
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)
|
||||
option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." ON)
|
||||
option(WEBP_BUILD_IMG2WEBP "Build the img2webp animation tool." ON)
|
||||
option(WEBP_BUILD_VWEBP "Build the vwebp viewer tool." ON)
|
||||
option(WEBP_BUILD_WEBPINFO "Build the webpinfo command line tool." ON)
|
||||
option(WEBP_BUILD_WEBPMUX "Build the webpmux command line tool." ON)
|
||||
option(WEBP_BUILD_EXTRAS "Build extras." ON)
|
||||
option(WEBP_BUILD_WEBP_JS "Emscripten build of webp.js." OFF)
|
||||
option(WEBP_NEAR_LOSSLESS "Enable near-lossless encoding" ON)
|
||||
option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces." OFF)
|
||||
option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces."
|
||||
OFF)
|
||||
|
||||
# Option needed for handling Unicode file names on Windows.
|
||||
if(WIN32)
|
||||
option(WEBP_UNICODE "Build Unicode executables." ON)
|
||||
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)
|
||||
set(WEBP_BUILD_GIF2WEBP OFF)
|
||||
set(WEBP_BUILD_IMG2WEBP OFF)
|
||||
set(WEBP_BUILD_VWEBP OFF)
|
||||
set(WEBP_BUILD_WEBPINFO OFF)
|
||||
set(WEBP_BUILD_WEBPMUX OFF)
|
||||
set(WEBP_BUILD_EXTRAS OFF)
|
||||
endif()
|
||||
|
||||
set(WEBP_DEP_LIBRARIES)
|
||||
set(WEBP_DEP_INCLUDE_DIRS)
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE
|
||||
"Build type: Release, Debug or RelWithDebInfo" STRING FORCE
|
||||
)
|
||||
set(CMAKE_BUILD_TYPE "Release"
|
||||
CACHE "Build type: Release, Debug, MinSizeRel or RelWithDebInfo" STRING
|
||||
FORCE)
|
||||
endif()
|
||||
|
||||
# Include dependencies.
|
||||
include(cmake/deps.cmake)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
################################################################################
|
||||
# ##############################################################################
|
||||
# Options.
|
||||
if(WEBP_ENABLE_SWAP_16BIT_CSP)
|
||||
add_definitions(-DWEBP_SWAP_16BIT_CSP=1)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
if(WEBP_UNICODE)
|
||||
# Windows recommends setting both UNICODE and _UNICODE.
|
||||
add_definitions(-DUNICODE -D_UNICODE)
|
||||
endif()
|
||||
|
||||
set(prefix ${CMAKE_INSTALL_PREFIX})
|
||||
set(exec_prefix "\$\{prefix\}")
|
||||
set(libdir "\$\{prefix\}/lib")
|
||||
set(includedir "\$\{prefix\}/include")
|
||||
set(PTHREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
# ##############################################################################
|
||||
# Android only.
|
||||
if(ANDROID)
|
||||
include_directories(${ANDROID_NDK}/sources/android/cpufeatures)
|
||||
add_library(cpufeatures STATIC
|
||||
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c
|
||||
)
|
||||
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
|
||||
target_link_libraries(cpufeatures dl)
|
||||
set(WEBP_DEP_LIBRARIES ${WEBP_DEP_LIBRARIES} cpufeatures)
|
||||
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS}
|
||||
${ANDROID_NDK}/sources/android/cpufeatures
|
||||
)
|
||||
${ANDROID_NDK}/sources/android/cpufeatures)
|
||||
add_definitions(-DHAVE_CPU_FEATURES_H=1)
|
||||
set(HAVE_CPU_FEATURES_H 1)
|
||||
else()
|
||||
set(HAVE_CPU_FEATURES_H 0)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# WebP source files.
|
||||
# Read the Makefile.am to get the source files.
|
||||
function(configure_pkg_config FILE)
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${FILE}.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${FILE}")
|
||||
|
||||
# We expect the Makefiles to define the sources as defined in
|
||||
# the first regex. E.g.:
|
||||
# libimagedec_la_SOURCES = image_dec.c image_dec.h
|
||||
if(HAVE_MATH_LIBRARY)
|
||||
# MSVC doesn't have libm
|
||||
file(READ ${CMAKE_CURRENT_BINARY_DIR}/${FILE} data)
|
||||
string(REPLACE "-lm" "" data ${data})
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${FILE} ${data})
|
||||
endif()
|
||||
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/${FILE}"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# ##############################################################################
|
||||
# WebP source files. Read the Makefile.am to get the source files.
|
||||
|
||||
# We expect the Makefiles to define the sources as defined in the first regex.
|
||||
# E.g.: libimagedec_la_SOURCES = image_dec.c image_dec.h
|
||||
function(parse_Makefile_am FOLDER VAR SRC_REGEX)
|
||||
file(READ ${FOLDER}/Makefile.am MAKEFILE_AM)
|
||||
string(REGEX MATCHALL "${SRC_REGEX}_SOURCES[ ]*\\+?=[ ]+[0-9a-z\\._ ]*"
|
||||
FILES_PER_LINE ${MAKEFILE_AM}
|
||||
)
|
||||
string(REGEX MATCHALL
|
||||
"${SRC_REGEX}_SOURCES[ ]*\\+?=[ ]+[0-9a-z\\._ ]*"
|
||||
FILES_PER_LINE
|
||||
${MAKEFILE_AM})
|
||||
set(SRCS ${${VAR}})
|
||||
foreach(FILES ${FILES_PER_LINE})
|
||||
string(FIND ${FILES} "=" OFFSET)
|
||||
math(EXPR OFFSET "${OFFSET} + 2")
|
||||
string(SUBSTRING ${FILES} ${OFFSET} -1 FILES)
|
||||
string(SUBSTRING ${FILES}
|
||||
${OFFSET}
|
||||
-1
|
||||
FILES)
|
||||
if(FILES)
|
||||
string(REGEX MATCHALL "[0-9a-z\\._]+"
|
||||
FILES ${FILES}
|
||||
)
|
||||
string(REGEX MATCHALL
|
||||
"[0-9a-z\\._]+"
|
||||
FILES
|
||||
${FILES})
|
||||
foreach(FILE ${FILES})
|
||||
list(APPEND SRCS ${FOLDER}/${FILE})
|
||||
endforeach()
|
||||
@ -83,16 +132,16 @@ function(parse_Makefile_am FOLDER VAR SRC_REGEX)
|
||||
endfunction()
|
||||
|
||||
set(WEBP_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/dec "WEBP_DEC_SRCS" "")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/demux "WEBP_DEMUX_SRCS" "")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_COMMON_SRCS" "COMMON")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "ENC")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "dsp_[^ ]*")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_DEC_SRCS" "decode_[^ ]*")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/enc "WEBP_ENC_SRCS" "")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_COMMON_SRCS" "COMMON")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_ENC_SRCS" "ENC")
|
||||
parse_Makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_DEC_SRCS" "decode_[^ ]*")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/dec "WEBP_DEC_SRCS" "")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/demux "WEBP_DEMUX_SRCS" "")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_COMMON_SRCS" "COMMON")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "ENC")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_ENC_SRCS" "dsp_[^ ]*")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/dsp "WEBP_DSP_DEC_SRCS" "decode_[^ ]*")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/enc "WEBP_ENC_SRCS" "")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_COMMON_SRCS" "COMMON")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_ENC_SRCS" "ENC")
|
||||
parse_makefile_am(${WEBP_SRC_DIR}/utils "WEBP_UTILS_DEC_SRCS" "decode_[^ ]*")
|
||||
|
||||
# Remove the files specific to SIMD we don't use.
|
||||
foreach(FILE ${WEBP_SIMD_FILES_NOT_TO_INCLUDE})
|
||||
@ -100,7 +149,12 @@ foreach(FILE ${WEBP_SIMD_FILES_NOT_TO_INCLUDE})
|
||||
list(REMOVE_ITEM WEBP_DSP_DEC_SRCS ${FILE})
|
||||
endforeach()
|
||||
|
||||
### Define the mandatory libraries.
|
||||
# Generate the config.h file.
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/webp/config.h)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
|
||||
# ##############################################################################
|
||||
# Build the webpdecoder library.
|
||||
if(MSVC)
|
||||
# avoid security warnings for e.g., fopen() used in the examples.
|
||||
@ -108,254 +162,494 @@ if(MSVC)
|
||||
else()
|
||||
add_definitions(-Wall)
|
||||
endif()
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${WEBP_DEP_INCLUDE_DIRS})
|
||||
include_directories(${WEBP_DEP_INCLUDE_DIRS})
|
||||
add_library(webpdecode OBJECT ${WEBP_DEC_SRCS})
|
||||
target_include_directories(webpdecode
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webpdspdecode OBJECT ${WEBP_DSP_COMMON_SRCS} ${WEBP_DSP_DEC_SRCS})
|
||||
add_library(webputilsdecode OBJECT ${WEBP_UTILS_COMMON_SRCS}
|
||||
${WEBP_UTILS_DEC_SRCS})
|
||||
add_library(webpdecoder $<TARGET_OBJECTS:webpdecode>
|
||||
$<TARGET_OBJECTS:webpdspdecode> $<TARGET_OBJECTS:webputilsdecode>)
|
||||
target_include_directories(webpdspdecode
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webputilsdecode
|
||||
OBJECT
|
||||
${WEBP_UTILS_COMMON_SRCS}
|
||||
${WEBP_UTILS_DEC_SRCS})
|
||||
target_include_directories(webputilsdecode
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webpdecoder
|
||||
$<TARGET_OBJECTS:webpdecode>
|
||||
$<TARGET_OBJECTS:webpdspdecode>
|
||||
$<TARGET_OBJECTS:webputilsdecode>)
|
||||
target_link_libraries(webpdecoder ${WEBP_DEP_LIBRARIES})
|
||||
target_include_directories(
|
||||
webpdecoder
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
set_target_properties(
|
||||
webpdecoder
|
||||
PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h")
|
||||
|
||||
configure_pkg_config("src/libwebpdecoder.pc")
|
||||
|
||||
# Build the webp library.
|
||||
add_library(webpencode OBJECT ${WEBP_ENC_SRCS})
|
||||
add_library(webpdsp OBJECT ${WEBP_DSP_COMMON_SRCS} ${WEBP_DSP_DEC_SRCS}
|
||||
${WEBP_DSP_ENC_SRCS})
|
||||
add_library(webputils OBJECT ${WEBP_UTILS_COMMON_SRCS} ${WEBP_UTILS_DEC_SRCS}
|
||||
${WEBP_UTILS_ENC_SRCS})
|
||||
add_library(webp $<TARGET_OBJECTS:webpdecode> $<TARGET_OBJECTS:webpdsp>
|
||||
$<TARGET_OBJECTS:webpencode> $<TARGET_OBJECTS:webputils>)
|
||||
target_include_directories(webpencode
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webpdsp
|
||||
OBJECT
|
||||
${WEBP_DSP_COMMON_SRCS}
|
||||
${WEBP_DSP_DEC_SRCS}
|
||||
${WEBP_DSP_ENC_SRCS})
|
||||
target_include_directories(webpdsp
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webputils
|
||||
OBJECT
|
||||
${WEBP_UTILS_COMMON_SRCS}
|
||||
${WEBP_UTILS_DEC_SRCS}
|
||||
${WEBP_UTILS_ENC_SRCS})
|
||||
target_include_directories(webputils
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_library(webp
|
||||
$<TARGET_OBJECTS:webpdecode>
|
||||
$<TARGET_OBJECTS:webpdsp>
|
||||
$<TARGET_OBJECTS:webpencode>
|
||||
$<TARGET_OBJECTS:webputils>)
|
||||
target_link_libraries(webp ${WEBP_DEP_LIBRARIES})
|
||||
target_include_directories(webp
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
set_target_properties(
|
||||
webp
|
||||
PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/encode.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h")
|
||||
|
||||
# Make sure the OBJECT libraries are built with position independent code
|
||||
# (it is not ON by default).
|
||||
set_target_properties(webpdecode webpdspdecode webputilsdecode
|
||||
webpencode webpdsp webputils PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
# Make sure the OBJECT libraries are built with position independent code (it is
|
||||
# not ON by default).
|
||||
set_target_properties(webpdecode
|
||||
webpdspdecode
|
||||
webputilsdecode
|
||||
webpencode
|
||||
webpdsp
|
||||
webputils
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
configure_pkg_config("src/libwebp.pc")
|
||||
|
||||
# Build the webp demux library.
|
||||
add_library(webpdemux ${WEBP_DEMUX_SRCS})
|
||||
target_link_libraries(webpdemux webp)
|
||||
target_include_directories(webpdemux
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
PUBLIC $<INSTALL_INTERFACE:include>)
|
||||
set_target_properties(
|
||||
webpdemux
|
||||
PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/demux.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h")
|
||||
|
||||
configure_pkg_config("src/demux/libwebpdemux.pc")
|
||||
|
||||
# Set the version numbers.
|
||||
function(parse_version FILE NAME VAR)
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/src/${FILE} SOURCE_FILE)
|
||||
string(REGEX MATCH "${NAME}_la_LDFLAGS[^\n]* -version-info [0-9:]+" TMP
|
||||
${SOURCE_FILE})
|
||||
string(REGEX MATCH "[0-9:]+" TMP ${TMP})
|
||||
string(REGEX REPLACE ":" "." VERSION ${TMP})
|
||||
string(REGEX MATCH
|
||||
"${NAME}_la_LDFLAGS[^\n]* -version-info [0-9:]+"
|
||||
TMP
|
||||
${SOURCE_FILE})
|
||||
string(REGEX MATCH
|
||||
"[0-9:]+"
|
||||
TMP
|
||||
${TMP})
|
||||
string(REGEX
|
||||
REPLACE ":"
|
||||
"."
|
||||
VERSION
|
||||
${TMP})
|
||||
set(${VAR} "${VERSION}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
parse_version(Makefile.am webp WEBP_WEBP_SOVERSION)
|
||||
set_target_properties(webp PROPERTIES VERSION ${PACKAGE_VERSION}
|
||||
SOVERSION ${WEBP_WEBP_SOVERSION})
|
||||
set_target_properties(webp
|
||||
PROPERTIES VERSION
|
||||
${PACKAGE_VERSION}
|
||||
SOVERSION
|
||||
${WEBP_WEBP_SOVERSION})
|
||||
parse_version(Makefile.am webpdecoder WEBP_DECODER_SOVERSION)
|
||||
set_target_properties(webpdecoder PROPERTIES VERSION ${PACKAGE_VERSION}
|
||||
SOVERSION ${WEBP_DECODER_SOVERSION})
|
||||
set_target_properties(webpdecoder
|
||||
PROPERTIES VERSION
|
||||
${PACKAGE_VERSION}
|
||||
SOVERSION
|
||||
${WEBP_DECODER_SOVERSION})
|
||||
parse_version(demux/Makefile.am webpdemux WEBP_DEMUX_SOVERSION)
|
||||
set_target_properties(webpdemux PROPERTIES VERSION ${PACKAGE_VERSION}
|
||||
SOVERSION ${WEBP_DEMUX_SOVERSION})
|
||||
set_target_properties(webpdemux
|
||||
PROPERTIES VERSION
|
||||
${PACKAGE_VERSION}
|
||||
SOVERSION
|
||||
${WEBP_DEMUX_SOVERSION})
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac CONFIGURE_FILE)
|
||||
string(REGEX MATCH
|
||||
"AC_INIT\\([^\n]*\\[[0-9\\.]+\\]"
|
||||
TMP
|
||||
${CONFIGURE_FILE})
|
||||
string(REGEX MATCH
|
||||
"[0-9\\.]+"
|
||||
PROJECT_VERSION
|
||||
${TMP})
|
||||
|
||||
# Define the libraries to install.
|
||||
set(INSTALLED_LIBRARIES webpdecoder webp webpdemux)
|
||||
|
||||
### Deal with SIMD.
|
||||
# Change the compile flags for SIMD files we use.
|
||||
# Deal with SIMD. Change the compile flags for SIMD files we use.
|
||||
list(LENGTH WEBP_SIMD_FILES_TO_INCLUDE WEBP_SIMD_FILES_TO_INCLUDE_LENGTH)
|
||||
math(EXPR WEBP_SIMD_FILES_TO_INCLUDE_RANGE
|
||||
"${WEBP_SIMD_FILES_TO_INCLUDE_LENGTH}-1"
|
||||
)
|
||||
"${WEBP_SIMD_FILES_TO_INCLUDE_LENGTH}-1")
|
||||
|
||||
foreach(I_FILE RANGE ${WEBP_SIMD_FILES_TO_INCLUDE_RANGE})
|
||||
list(GET WEBP_SIMD_FILES_TO_INCLUDE ${I_FILE} FILE)
|
||||
list(GET WEBP_SIMD_FLAGS_TO_INCLUDE ${I_FILE} SIMD_COMPILE_FLAG)
|
||||
set_source_files_properties(${FILE} PROPERTIES
|
||||
COMPILE_FLAGS ${SIMD_COMPILE_FLAG}
|
||||
)
|
||||
set_source_files_properties(${FILE}
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS
|
||||
${SIMD_COMPILE_FLAG})
|
||||
endforeach()
|
||||
|
||||
# Build the executables if asked for.
|
||||
if(WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP OR
|
||||
WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP OR WEBP_BUILD_WEBP_JS)
|
||||
# Example utility library.
|
||||
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})
|
||||
if(WEBP_BUILD_GIF2WEBP AND NOT GIF_FOUND)
|
||||
set(WEBP_BUILD_GIF2WEBP OFF)
|
||||
endif()
|
||||
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEIOUTILS_SRCS"
|
||||
"imageio_util_[^ ]*")
|
||||
if(WEBP_BUILD_ANIM_UTILS AND NOT GIF_FOUND)
|
||||
set(WEBP_BUILD_ANIM_UTILS OFF)
|
||||
endif()
|
||||
|
||||
# Build the executables if asked for.
|
||||
if(WEBP_BUILD_ANIM_UTILS
|
||||
OR WEBP_BUILD_CWEBP
|
||||
OR WEBP_BUILD_DWEBP
|
||||
OR WEBP_BUILD_GIF2WEBP
|
||||
OR WEBP_BUILD_IMG2WEBP
|
||||
OR WEBP_BUILD_VWEBP)
|
||||
# Example utility library.
|
||||
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})
|
||||
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})
|
||||
target_link_libraries(imageioutil webp)
|
||||
|
||||
# Image-decoding utility library.
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS"
|
||||
"imagedec_[^ ]*")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS"
|
||||
"imagedec_[^ ]*")
|
||||
add_library(imagedec ${IMAGEDEC_SRCS})
|
||||
target_link_libraries(imagedec imageioutil webpdemux webp
|
||||
${WEBP_DEP_IMG_LIBRARIES})
|
||||
target_link_libraries(imagedec
|
||||
imageioutil
|
||||
webpdemux
|
||||
webp
|
||||
${WEBP_DEP_IMG_LIBRARIES})
|
||||
|
||||
# Image-encoding utility library.
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS"
|
||||
"imageenc_[^ ]*")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS"
|
||||
"imageenc_[^ ]*")
|
||||
add_library(imageenc ${IMAGEENC_SRCS})
|
||||
target_link_libraries(imageenc webp)
|
||||
|
||||
set_property(TARGET exampleutil imageioutil imagedec imageenc
|
||||
PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
set_property(TARGET exampleutil
|
||||
imageioutil
|
||||
imagedec
|
||||
imageenc
|
||||
PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_DWEBP)
|
||||
# dwebp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "DWEBP_SRCS"
|
||||
"dwebp")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "DWEBP_SRCS" "dwebp")
|
||||
add_executable(dwebp ${DWEBP_SRCS})
|
||||
target_link_libraries(dwebp exampleutil imagedec imageenc webpdecoder)
|
||||
install(TARGETS dwebp RUNTIME DESTINATION bin)
|
||||
set_property(TARGET dwebp PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
target_link_libraries(dwebp exampleutil imagedec imageenc)
|
||||
target_include_directories(dwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS dwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_CWEBP)
|
||||
# cwebp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "CWEBP_SRCS"
|
||||
"cwebp")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "CWEBP_SRCS" "cwebp")
|
||||
add_executable(cwebp ${CWEBP_SRCS})
|
||||
target_link_libraries(cwebp exampleutil imagedec webp)
|
||||
install(TARGETS cwebp RUNTIME DESTINATION bin)
|
||||
set_property(TARGET cwebp PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_GIF2WEBP AND NOT GIF_FOUND)
|
||||
unset(WEBP_BUILD_GIF2WEBP CACHE)
|
||||
target_include_directories(cwebp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS cwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP)
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/mux "WEBP_MUX_SRCS"
|
||||
"")
|
||||
add_library(webpmux ${WEBP_MUX_SRCS})
|
||||
target_link_libraries(webpmux webp)
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/mux "WEBP_MUX_SRCS" "")
|
||||
add_library(libwebpmux ${WEBP_MUX_SRCS})
|
||||
target_link_libraries(libwebpmux webp)
|
||||
target_include_directories(libwebpmux
|
||||
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR})
|
||||
parse_version(mux/Makefile.am webpmux WEBP_MUX_SOVERSION)
|
||||
set_target_properties(webpmux PROPERTIES VERSION ${PACKAGE_VERSION}
|
||||
SOVERSION ${WEBP_MUX_SOVERSION})
|
||||
list(APPEND INSTALLED_LIBRARIES webpmux)
|
||||
set_target_properties(libwebpmux
|
||||
PROPERTIES VERSION
|
||||
${PACKAGE_VERSION}
|
||||
SOVERSION
|
||||
${WEBP_MUX_SOVERSION})
|
||||
set_target_properties(libwebpmux
|
||||
PROPERTIES PUBLIC_HEADER
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h;\
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h;")
|
||||
set_target_properties(libwebpmux PROPERTIES OUTPUT_NAME webpmux)
|
||||
list(APPEND INSTALLED_LIBRARIES libwebpmux)
|
||||
configure_pkg_config("src/mux/libwebpmux.pc")
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_GIF2WEBP)
|
||||
# gif2webp
|
||||
include_directories(${WEBP_DEP_GIF_INCLUDE_DIRS})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "GIF2WEBP_SRCS"
|
||||
"gif2webp")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "GIF2WEBP_SRCS"
|
||||
"gif2webp")
|
||||
add_executable(gif2webp ${GIF2WEBP_SRCS})
|
||||
target_link_libraries(gif2webp exampleutil imageioutil webp webpmux
|
||||
${WEBP_DEP_GIF_LIBRARIES})
|
||||
install(TARGETS gif2webp RUNTIME DESTINATION bin)
|
||||
set_property(TARGET gif2webp PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
target_link_libraries(gif2webp
|
||||
exampleutil
|
||||
imageioutil
|
||||
webp
|
||||
libwebpmux
|
||||
${WEBP_DEP_GIF_LIBRARIES})
|
||||
target_include_directories(gif2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS gif2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_IMG2WEBP)
|
||||
# img2webp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "IMG2WEBP_SRCS"
|
||||
"img2webp")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "IMG2WEBP_SRCS"
|
||||
"img2webp")
|
||||
add_executable(img2webp ${IMG2WEBP_SRCS})
|
||||
target_link_libraries(img2webp exampleutil imagedec imageioutil webp webpmux)
|
||||
install(TARGETS img2webp RUNTIME DESTINATION bin)
|
||||
set_property(TARGET img2webp PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
target_link_libraries(img2webp
|
||||
exampleutil
|
||||
imagedec
|
||||
imageioutil
|
||||
webp
|
||||
libwebpmux)
|
||||
target_include_directories(img2webp PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS img2webp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if (WEBP_BUILD_WEBPINFO)
|
||||
if(WEBP_BUILD_VWEBP)
|
||||
# vwebp
|
||||
find_package(GLUT)
|
||||
if(GLUT_FOUND)
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "VWEBP_SRCS" "vwebp")
|
||||
add_executable(vwebp ${VWEBP_SRCS})
|
||||
target_link_libraries(vwebp
|
||||
${OPENGL_LIBRARIES}
|
||||
exampleutil
|
||||
GLUT::GLUT
|
||||
imageioutil
|
||||
webp
|
||||
webpdemux)
|
||||
target_include_directories(vwebp
|
||||
PRIVATE GLUT::GLUT
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${OPENGL_INCLUDE_DIR})
|
||||
install(TARGETS vwebp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
|
||||
check_c_compiler_flag("-Wno-deprecated-declarations" HAS_NO_DEPRECATED)
|
||||
if(HAS_NO_DEPRECATED)
|
||||
target_compile_options(vwebp PRIVATE "-Wno-deprecated-declarations")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBPINFO)
|
||||
# webpinfo
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "WEBPINFO_SRCS"
|
||||
"webpinfo")
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "WEBPINFO_SRCS"
|
||||
"webpinfo")
|
||||
add_executable(webpinfo ${WEBPINFO_SRCS})
|
||||
target_link_libraries(webpinfo exampleutil imageioutil)
|
||||
install(TARGETS webpinfo RUNTIME DESTINATION bin)
|
||||
set_property(TARGET webpinfo PROPERTY INCLUDE_DIRECTORIES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
target_include_directories(webpinfo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS webpinfo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBPMUX)
|
||||
# webpmux
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "WEBPMUX_SRCS"
|
||||
"webpmux")
|
||||
add_executable(webpmux ${WEBPMUX_SRCS})
|
||||
target_link_libraries(webpmux exampleutil imageioutil libwebpmux webp)
|
||||
target_include_directories(webpmux PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS webpmux RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_EXTRAS)
|
||||
set(EXTRAS_MAKEFILE "${CMAKE_CURRENT_SOURCE_DIR}/extras")
|
||||
parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_EXTRAS_SRCS" "libwebpextras_la")
|
||||
parse_makefile_am(${EXTRAS_MAKEFILE} "GET_DISTO_SRCS" "get_disto")
|
||||
parse_makefile_am(${EXTRAS_MAKEFILE} "WEBP_QUALITY_SRCS" "webp_quality")
|
||||
parse_makefile_am(${EXTRAS_MAKEFILE} "VWEBP_SDL_SRCS" "vwebp_sdl")
|
||||
|
||||
# get_disto
|
||||
add_executable(get_disto ${GET_DISTO_SRCS})
|
||||
target_link_libraries(get_disto imagedec)
|
||||
target_include_directories(get_disto
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
install(TARGETS get_disto RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
# 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})
|
||||
install(TARGETS webp_quality RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
# vwebp_sdl
|
||||
find_package(SDL)
|
||||
if(SDL_FOUND)
|
||||
add_executable(vwebp_sdl ${VWEBP_SDL_SRCS})
|
||||
target_link_libraries(vwebp_sdl ${SDL_LIBRARY} imageioutil webp)
|
||||
target_include_directories(vwebp_sdl
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||
${SDL_INCLUDE_DIR})
|
||||
set(WEBP_HAVE_SDL 1)
|
||||
target_compile_definitions(vwebp_sdl PUBLIC WEBP_HAVE_SDL)
|
||||
install(TARGETS vwebp_sdl RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBP_JS)
|
||||
# JavaScript version
|
||||
add_executable(webp_js
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
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 \
|
||||
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)
|
||||
|
||||
# WASM version
|
||||
add_executable(webp_wasm
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
add_executable(webp_wasm ${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
target_link_libraries(webp_wasm webpdecoder SDL)
|
||||
set_target_properties(webp_wasm PROPERTIES LINK_FLAGS
|
||||
"-s WASM=1 -s 'BINARYEN_METHOD=\"native-wasm\"' \
|
||||
target_include_directories(webp_wasm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_target_properties(
|
||||
webp_wasm
|
||||
PROPERTIES LINK_FLAGS "-s WASM=1 -s 'BINARYEN_METHOD=\"native-wasm\"' \
|
||||
-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0 \
|
||||
-s EXTRA_EXPORTED_RUNTIME_METHODS='[\"cwrap\"]'")
|
||||
target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
|
||||
|
||||
target_compile_definitions(webpdecoder PUBLIC EMSCRIPTEN)
|
||||
target_compile_definitions(webpdspdecode PUBLIC EMSCRIPTEN)
|
||||
endif()
|
||||
|
||||
# Generate the config.h file.
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/webp/config.h)
|
||||
add_definitions(-DHAVE_CONFIG_H)
|
||||
# The webp folder is included as we reference config.h as
|
||||
# ../webp/config.h or webp/config.h
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(WEBP_BUILD_ANIM_UTILS)
|
||||
# anim_diff
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS} ${WEBP_DEP_GIF_INCLUDE_DIRS})
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "ANIM_DIFF_SRCS"
|
||||
"anim_diff")
|
||||
add_executable(anim_diff ${ANIM_DIFF_SRCS})
|
||||
target_link_libraries(anim_diff
|
||||
exampleutil
|
||||
imagedec
|
||||
imageenc
|
||||
imageioutil
|
||||
webp
|
||||
libwebpmux
|
||||
webpdemux
|
||||
${WEBP_DEP_GIF_LIBRARIES})
|
||||
target_include_directories(anim_diff PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
|
||||
# anim_dump
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS} ${WEBP_DEP_GIF_INCLUDE_DIRS})
|
||||
parse_makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/examples "ANIM_DUMP_SRCS"
|
||||
"anim_dump")
|
||||
add_executable(anim_dump ${ANIM_DUMP_SRCS})
|
||||
target_link_libraries(anim_dump
|
||||
exampleutil
|
||||
imagedec
|
||||
imageenc
|
||||
imageioutil
|
||||
webp
|
||||
libwebpmux
|
||||
webpdemux
|
||||
${WEBP_DEP_GIF_LIBRARIES})
|
||||
target_include_directories(anim_dump PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src)
|
||||
endif()
|
||||
|
||||
# Install the different headers and libraries.
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/webp/decode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/demux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/encode.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/mux_types.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/webp/types.h
|
||||
DESTINATION include/webp)
|
||||
include(GNUInstallDirs)
|
||||
install(TARGETS ${INSTALLED_LIBRARIES}
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/webp
|
||||
INCLUDES
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
set(ConfigPackageLocation ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/cmake/)
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${ConfigPackageLocation})
|
||||
|
||||
# Create the CMake version file.
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake"
|
||||
VERSION ${PACKAGE_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
COMPATIBILITY AnyNewerVersion)
|
||||
|
||||
# Create the Config file.
|
||||
include(CMakePackageConfigHelpers)
|
||||
set(ConfigPackageLocation share/WebP/cmake/)
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/WebPConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake
|
||||
INSTALL_DESTINATION ${ConfigPackageLocation}
|
||||
)
|
||||
INSTALL_DESTINATION
|
||||
${ConfigPackageLocation})
|
||||
|
||||
# Install the generated CMake files.
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake"
|
||||
DESTINATION ${ConfigPackageLocation}
|
||||
)
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/WebPConfig.cmake"
|
||||
DESTINATION ${ConfigPackageLocation})
|
||||
|
||||
# Install the man pages.
|
||||
set(MAN_PAGES cwebp.1 dwebp.1 gif2webp.1 img2webp.1 vwebp.1 webpmux.1
|
||||
webpinfo.1)
|
||||
set(EXEC_BUILDS "CWEBP" "DWEBP" "GIF2WEBP" "IMG2WEBP" "VWEBP" "WEBPMUX"
|
||||
"WEBPINFO")
|
||||
set(MAN_PAGES
|
||||
cwebp.1
|
||||
dwebp.1
|
||||
gif2webp.1
|
||||
img2webp.1
|
||||
vwebp.1
|
||||
webpmux.1
|
||||
webpinfo.1)
|
||||
set(EXEC_BUILDS
|
||||
"CWEBP"
|
||||
"DWEBP"
|
||||
"GIF2WEBP"
|
||||
"IMG2WEBP"
|
||||
"VWEBP"
|
||||
"WEBPMUX"
|
||||
"WEBPINFO")
|
||||
list(LENGTH MAN_PAGES MAN_PAGES_LENGTH)
|
||||
math(EXPR MAN_PAGES_RANGE "${MAN_PAGES_LENGTH} - 1")
|
||||
|
||||
@ -364,8 +658,7 @@ foreach(I_MAN RANGE ${MAN_PAGES_RANGE})
|
||||
if(WEBP_BUILD_${EXEC_BUILD})
|
||||
list(GET MAN_PAGES ${I_MAN} MAN_PAGE)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man/${MAN_PAGE}
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
|
||||
COMPONENT doc
|
||||
)
|
||||
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1
|
||||
COMPONENT doc)
|
||||
endif()
|
||||
endforeach()
|
||||
|
123
ChangeLog
123
ChangeLog
@ -1,23 +1,146 @@
|
||||
61e372b7 update NEWS
|
||||
7ae658a0 bump version to 1.0.2
|
||||
51c4907d update AUTHORS
|
||||
666bd6c6 man/cwebp.1: refine near-lossless text
|
||||
561cdce5 Clarify the doc about GetFeatures.
|
||||
aec2cf02 near_lossless: fix fuzzing-detected integer overflow
|
||||
928a75de webp: Fix VP8LBitWriterClone() bug
|
||||
5173d4ee neon IsFlat
|
||||
5b081219 IsFlat: inline when possible
|
||||
381b7b54 IsFlat: use int for thresh
|
||||
6ed15ea1 fix unprobable leak in webp_sdl.c
|
||||
22bbb24e Merge "IsFlat: return int"
|
||||
8b3fb238 Merge tag 'v1.0.1'
|
||||
f435de95 IsFlat: return int
|
||||
41521aed utils.h: only define WEBP_NEED_LOG_TABLE_8BIT when needed
|
||||
9f4d4a3f neon: GetResidualCost
|
||||
0fd7514b neon: SetResidualCoeffs
|
||||
f95a996c Simpler histogram clustering.
|
||||
e85d3313 update ChangeLog (tag: v1.0.1-rc2, tag: v1.0.1, origin/1.0.1, 1.0.1)
|
||||
fa8210e4 Fix pair update in stochastic entropy merging.
|
||||
fd198f73 add codereview.settings
|
||||
825389ac README.mux: add a reference to the AnimDecoder API
|
||||
3be698c3 CMake: fix webp_js compilation
|
||||
485ff86f Fix pair update in stochastic entropy merging.
|
||||
4cd0582d CMake: fix webp_js compilation
|
||||
4cbb4caf update NEWS
|
||||
f5a5918d bump version to 1.0.1
|
||||
d61385db Speed-up: Make sure we only initialize histograms when needed.
|
||||
6752904b Speed-up: Make sure we only initialize histograms when needed.
|
||||
0c570316 update AUTHORS
|
||||
301a2dda img2webp: add help note about arguments from a file
|
||||
f0abab92 Speedups for empty histograms.
|
||||
f2dfd925 Split HistogramAdd to only have the high level logic in C.
|
||||
06b7bc7d Fix compilation on windows and clang-cl+ninja.
|
||||
b6284d82 img2webp: add help note about arguments from a file
|
||||
decf6f6b Speedups for empty histograms.
|
||||
dea3e899 Split HistogramAdd to only have the high level logic in C.
|
||||
632798ae Merge "Fix compilation on windows and clang-cl+ninja."
|
||||
dc1a9518 Merge "libwebp: Unicode command tools on Windows"
|
||||
9cf9841b libwebp: Unicode command tools on Windows
|
||||
98179495 remove some minor TODOs
|
||||
a376e7b9 Fix compilation on windows and clang-cl+ninja.
|
||||
cbf82cc0 Remove AVX2 files.
|
||||
5030e902 Merge "TIFF decoder: remove unused KINV definition"
|
||||
ac543311 Remove a few more useless #defines
|
||||
123d3306 TIFF decoder: remove unused KINV definition
|
||||
ef1094b0 Merge "- install pkg-config files during the CMake build"
|
||||
b911fbc9 libwebp: Remove duplicate GIFDisplayError in anim_util
|
||||
eee00b66 - install pkg-config files during the CMake build
|
||||
ac3ec8c9 Merge "Clean-up the common sources in dsp."
|
||||
3e13da7b Clean-up the common sources in dsp.
|
||||
5c395f1d libwebp: cmake-format all
|
||||
e7a69729 libwebp: Add extras targets in CMakeLists.txt
|
||||
e52485d6 libwebp: Rename macros in webpmux.c
|
||||
92dc0f09 clean-up MakeInputImageCopy()
|
||||
39952de2 VP8IteratorImport: add missing 'const'
|
||||
382af7a2 clean-up WebPBlendAlpha
|
||||
14d020f6 libwebp: Use ExUtilGet*() in anim_diff
|
||||
0d92ff25 libwebp: remove useless variable in gif2webp
|
||||
556cb1b4 Merge "CMake: Set WEBP_BUILD_GIF2WEBP to off"
|
||||
da26ee49 CMake: Set WEBP_BUILD_GIF2WEBP to off
|
||||
b2a867c0 cwebp: Don't premultiply during -resize if -exact
|
||||
637141bc pngdec: fix build w/libpng < 1.4.x
|
||||
bc5092b1 pngdec: set memory functions
|
||||
50d8345a Fix CMake math library.
|
||||
6aa3e8aa Fix math library on Visual Studio.
|
||||
d71df4e2 Fix math library finding in CMake.
|
||||
de08d727 cosmetics: normalize include guard comment
|
||||
009562b4 vwebp: Fix bug when Dispose then NoBlend frames
|
||||
423f2579 Fix up CMake to create targets.
|
||||
907208f9 Wait for all threads to be done in DecodeRemaining.
|
||||
4649b3c4 vwebp: Add background color display option
|
||||
78ad57a3 Fix bad glClearColor parameters
|
||||
da96d8d9 Allow for a non-initialized alpha decompressor in DoRemap.
|
||||
2563db47 fix rescaling rounding inaccuracy
|
||||
211f37ee fix endian problems in pattern copy
|
||||
5f0f5c07 Make sure partition #0 is read before VP8 data in IDecode.
|
||||
de98732b fix GetColorf() bug
|
||||
4338cd36 misc fixes in libwebpmux
|
||||
e00af13e fix signatures after a9ceda7ff1
|
||||
a9ceda7f Speed-up chunk list operations.
|
||||
2281bbf6 Merge "Better handling of bogus Huffman codes."
|
||||
39cb9aad Better handling of bogus Huffman codes.
|
||||
89cc9d37 Merge "fix read-overflow while parsing VP8X chunk"
|
||||
95fd6507 fix read-overflow while parsing VP8X chunk
|
||||
9e729fe1 Fix VP8IoTeardownHook being called twice on worker sync failure
|
||||
29fb8562 Merge "muxread,anmf: fail on multiple image chunks"
|
||||
eb82ce76 muxread,anmf: fail on multiple image chunks
|
||||
1344a2e9 fix alpha-filtering crash when image width is larger than radius
|
||||
be738c6d muxread,ChunkVerifyAndAssign: validate chunk_size
|
||||
2c70ad76 muxread,CreateInternal: fix riff size checks
|
||||
569001f1 Fix for thread race heap-use-after-free
|
||||
c56a02d9 Android.mk: use LOCAL_EXPORT_C_INCLUDES w/public libs
|
||||
15795596 CMakeLists.txt,cosmetics: normalize if() formatting
|
||||
1a44c233 Merge "cmake: add support for webpmux"
|
||||
e9569ad7 Merge "configure,*am,cosmetics: s/WANT_/BUILD_/"
|
||||
35c7de6f cmake: add support for webpmux
|
||||
0f25e61c WebpToSDL(): fix the return value in case of error
|
||||
5d8985de configure,*am,cosmetics: s/WANT_/BUILD_/
|
||||
895fd28f Merge "man/Makefile.am: add img2webp.1"
|
||||
5cf3e2af man/Makefile.am: add img2webp.1
|
||||
2a9de5b9 Add build rules for anim_diff & anim_dump utils.
|
||||
71ed73cf fix invalid check for buffer size
|
||||
af0e4fbb gif2webp: fix transcode of loop count=65535
|
||||
dce5d764 Limit memory allocation when reading invalid Huffman codes.
|
||||
f9df0081 Merge "cmake: quiet glut deprecation warnings on OS X"
|
||||
dc39b16f webpmux.1: correct grammar
|
||||
c7aa1264 cwebp.c: fix a missing \n
|
||||
53aa51e9 Merge tag 'v1.0.0'
|
||||
698b8844 update ChangeLog (tag: v1.0.0)
|
||||
8d510751 webp-container-spec: correct frame duration=0 note
|
||||
e6b2164e vwebp: Copy Chrome's behavior w/frame duration == 0
|
||||
094b3b28 cmake: quiet glut deprecation warnings on OS X
|
||||
71c39a06 webp-container-spec: correct frame duration=0 note
|
||||
fd3d5756 vwebp: Copy Chrome's behavior w/frame duration == 0
|
||||
b0c966fb Build vwebp from CMake.
|
||||
d20b7707 update ChangeLog (tag: v1.0.0-rc3)
|
||||
0d5fad46 add WEBP_DSP_INIT / WEBP_DSP_INIT_FUNC
|
||||
d77bf512 add WEBP_DSP_INIT / WEBP_DSP_INIT_FUNC
|
||||
c1cb86af fix 16b overflow in SSE2
|
||||
e577feb7 makefile.unix: add DEBUG flag for compiling w/ debug-symbol
|
||||
99be34b3 cwebp,get_disto: fix bpp output
|
||||
e122e511 cwebp,get_disto: fix bpp output
|
||||
f5565ca8 cmake: Make sure we use near-lossless by default.
|
||||
d898dc14 fix bug in WebPImport565: alpha value was not set
|
||||
1c8f358d Fix CMake with WASM.
|
||||
a0215fb7 webp_js: fix webp_js demo html
|
||||
882784b0 update ChangeLog (tag: v1.0.0-rc2)
|
||||
2f930e08 Revert "Use proper targets for CMake."
|
||||
8165e8fb Use proper targets for CMake.
|
||||
3f157dd5 Remove some very hard TODOs.
|
||||
abb47760 Merge "Use proper targets for CMake."
|
||||
cd758a17 {de,}mux/Makefile.am: add missing headers
|
||||
e155dda0 Use proper targets for CMake.
|
||||
b892b8ba makefile.unix,dist: use ascii for text output
|
||||
64a57d05 add -version option to anim_dump,anim_diff and img2webp
|
||||
994be82d Merge "Remove some very hard TODOs."
|
||||
4033e1d7 Remove some very hard TODOs.
|
||||
fc1b8e3a webp_js: fix webp_js demo html
|
||||
15aa48d9 update ChangeLog (tag: v1.0.0-rc1)
|
||||
e607dabc update AUTHORS
|
||||
38410c08 [CFI] Remove function pointer casts
|
||||
978eec25 [CFI] Remove function pointer casts
|
||||
c57b2736 bump version to 1.0.0
|
||||
cba28853 update NEWS
|
||||
c909d531 Merge "remove some deprecation warning on MacOSX"
|
||||
|
@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
|
||||
SUBDIRS = src imageio man
|
||||
EXTRA_DIST = COPYING autogen.sh
|
||||
|
||||
if WANT_EXTRAS
|
||||
if BUILD_EXTRAS
|
||||
SUBDIRS += extras
|
||||
endif
|
||||
|
||||
|
27
Makefile.vc
27
Makefile.vc
@ -53,11 +53,6 @@ OUTDIR = ..\obj\
|
||||
OUTDIR = $(OBJDIR)
|
||||
!ENDIF
|
||||
|
||||
!IF "$(HAVE_AVX2)" == "1"
|
||||
CFLAGS = $(CFLAGS) /DWEBP_HAVE_AVX2
|
||||
AVX2_FLAGS = /arch:AVX2
|
||||
!ENDIF
|
||||
|
||||
##############################################################
|
||||
# Runtime library configuration
|
||||
!IF "$(RTLIBCFG)" == "static"
|
||||
@ -134,12 +129,16 @@ LIBWEBP_PDBNAME = $(DIROBJ)\$(LIBWEBP_BASENAME)_dll.pdb
|
||||
CFGSET = TRUE
|
||||
!ENDIF
|
||||
|
||||
!IF "$(UNICODE)" == "1"
|
||||
CFLAGS = $(CFLAGS) /D_UNICODE /DUNICODE
|
||||
!ENDIF
|
||||
|
||||
#######################
|
||||
# Usage
|
||||
#
|
||||
!IF "$(CFGSET)" == "FALSE"
|
||||
!MESSAGE Usage: nmake /f Makefile.vc [CFG=<config>]
|
||||
!MESSAGE . [OBJDIR=<path>] [RTLIBCFG=<rtlib>] [<target>]
|
||||
!MESSAGE . [OBJDIR=<path>] [RTLIBCFG=<rtlib>] [UNICODE=1] [<target>]
|
||||
!MESSAGE
|
||||
!MESSAGE where <config> is one of:
|
||||
!MESSAGE - release-static - release static library
|
||||
@ -239,9 +238,9 @@ DSP_ENC_OBJS = \
|
||||
$(DIROBJ)\dsp\cost.obj \
|
||||
$(DIROBJ)\dsp\cost_mips32.obj \
|
||||
$(DIROBJ)\dsp\cost_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\cost_neon.obj \
|
||||
$(DIROBJ)\dsp\cost_sse2.obj \
|
||||
$(DIROBJ)\dsp\enc.obj \
|
||||
$(DIROBJ)\dsp\enc_avx2.obj \
|
||||
$(DIROBJ)\dsp\enc_mips32.obj \
|
||||
$(DIROBJ)\dsp\enc_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\enc_msa.obj \
|
||||
@ -454,9 +453,6 @@ $(DIROBJ)\$(DLLINC):
|
||||
.SUFFIXES: .c .obj .res .exe
|
||||
# File-specific flag builds. Note batch rules take precedence over wildcards,
|
||||
# so for now name each file individually.
|
||||
$(DIROBJ)\dsp\enc_avx2.obj: src\dsp\enc_avx2.c
|
||||
$(CC) $(CFLAGS) $(AVX2_FLAGS) /Fd$(LIBWEBP_PDBNAME) /Fo$(DIROBJ)\dsp\ \
|
||||
src\dsp\$(@B).c
|
||||
$(DIROBJ)\examples\anim_diff.obj: examples\anim_diff.c
|
||||
$(CC) $(CFLAGS) /DWEBP_HAVE_GIF /Fd$(LIBWEBP_PDBNAME) \
|
||||
/Fo$(DIROBJ)\examples\ examples\$(@B).c
|
||||
@ -492,15 +488,18 @@ $(DIROBJ)\examples\gifdec.obj: examples\gifdec.c
|
||||
{src\utils}.c{$(DIROBJ)\utils}.obj::
|
||||
$(CC) $(CFLAGS) /Fd$(LIBWEBP_PDBNAME) /Fo$(DIROBJ)\utils\ $<
|
||||
|
||||
LNKLIBS = ole32.lib windowscodecs.lib shlwapi.lib
|
||||
!IF "$(UNICODE)" == "1"
|
||||
LNKLIBS = $(LNKLIBS) Shell32.lib
|
||||
!ENDIF
|
||||
|
||||
{$(DIROBJ)\examples}.obj{$(DIRBIN)}.exe:
|
||||
$(LNKEXE) $(LDFLAGS) /OUT:$@ $** \
|
||||
ole32.lib windowscodecs.lib shlwapi.lib
|
||||
$(LNKEXE) $(LDFLAGS) /OUT:$@ $** $(LNKLIBS)
|
||||
$(MT) -manifest $@.manifest -outputresource:$@;1
|
||||
del $@.manifest
|
||||
|
||||
{$(DIROBJ)\extras}.obj{$(DIRBIN)}.exe:
|
||||
$(LNKEXE) $(LDFLAGS) /OUT:$@ $** \
|
||||
ole32.lib windowscodecs.lib shlwapi.lib
|
||||
$(LNKEXE) $(LDFLAGS) /OUT:$@ $** $(LNKLIBS)
|
||||
$(MT) -manifest $@.manifest -outputresource:$@;1
|
||||
del $@.manifest
|
||||
|
||||
|
20
NEWS
20
NEWS
@ -1,3 +1,23 @@
|
||||
- 1/14/2019: version 1.0.2
|
||||
This is a binary compatible release.
|
||||
* (Windows) unicode file support in the tools (linux and mac already had
|
||||
support, issue #398)
|
||||
* lossless encoder speedups
|
||||
* lossy encoder speedup on ARM
|
||||
* lossless multi-threaded security fix (chromium:917029)
|
||||
|
||||
- 11/2/2018: version 1.0.1
|
||||
This is a binary compatible release.
|
||||
* lossless encoder speedups
|
||||
* big-endian fix for alpha decoding (issue #393)
|
||||
* gif2webp fix for loop count=65535 transcode (issue #382)
|
||||
* further security related hardening in libwebp & libwebpmux
|
||||
(issues #383, #385, #386, #387, #388, #391)
|
||||
(oss-fuzz #9099, #9100, #9105, #9106, #9111, #9112, #9119, #9123, #9170,
|
||||
#9178, #9179, #9183, #9186, #9191, #9364, #9417, #9496, #10349,
|
||||
#10423, #10634, #10700, #10838, #10922, #11021, #11088, #11152)
|
||||
* miscellaneous bug & build fixes (issues #381, #394, #396, #397, #400)
|
||||
|
||||
- 4/2/2018: version 1.0.0
|
||||
This is a binary compatible release.
|
||||
* lossy encoder improvements to avoid chroma shifts in various circumstances
|
||||
|
9
README
9
README
@ -4,7 +4,7 @@
|
||||
\__\__/\____/\_____/__/ ____ ___
|
||||
/ _/ / \ \ / _ \/ _/
|
||||
/ \_/ / / \ \ __/ \__
|
||||
\____/____/\_____/_____/____/v1.0.0
|
||||
\____/____/\_____/_____/____/v1.0.2
|
||||
|
||||
Description:
|
||||
============
|
||||
@ -136,6 +136,8 @@ cmake -DWEBP_BUILD_CWEBP=ON -DWEBP_BUILD_DWEBP=ON ../
|
||||
|
||||
or through your favorite interface (like ccmake or cmake-qt-gui).
|
||||
|
||||
Use option -DWEBP_UNICODE=ON for Unicode support on Windows (with chcp 65001).
|
||||
|
||||
Finally, once installed, you can also use WebP in your CMake project by doing:
|
||||
|
||||
find_package(WebP)
|
||||
@ -402,12 +404,14 @@ Options are:
|
||||
-nofilter .... disable in-loop filtering
|
||||
-dither <int> dithering strength (0..100), default=50
|
||||
-noalphadither disable alpha plane dithering
|
||||
-usebgcolor .. display background color
|
||||
-mt .......... use multi-threading
|
||||
-info ........ print info
|
||||
-h ........... this help message
|
||||
|
||||
Keyboard shortcuts:
|
||||
'c' ................ toggle use of color profile
|
||||
'b' ................ toggle background color display
|
||||
'i' ................ overlay file information
|
||||
'd' ................ disable blending & disposal (debug)
|
||||
'q' / 'Q' / ESC .... quit
|
||||
@ -470,6 +474,9 @@ Per-frame options (only used for subsequent images input):
|
||||
example: img2webp -loop 2 in0.png -lossy in1.jpg
|
||||
-d 80 in2.tiff -o out.webp
|
||||
|
||||
Note: if a single file name is passed as the argument, the arguments will be
|
||||
tokenized from this file. The file name must not start with the character '-'.
|
||||
|
||||
Animated GIF conversion:
|
||||
========================
|
||||
Animated GIF files can be converted to WebP files with animation using the
|
||||
|
31
README.mux
31
README.mux
@ -1,7 +1,7 @@
|
||||
__ __ ____ ____ ____ __ __ _ __ __
|
||||
/ \\/ \/ _ \/ _ \/ _ \/ \ \/ \___/_ / _\
|
||||
\ / __/ _ \ __/ / / (_/ /__
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.0.0
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v1.0.2
|
||||
|
||||
|
||||
Description:
|
||||
@ -211,6 +211,35 @@ Code example:
|
||||
For a detailed AnimEncoder API reference, please refer to the header file
|
||||
(src/webp/mux.h).
|
||||
|
||||
AnimDecoder API:
|
||||
================
|
||||
This AnimDecoder API allows decoding (possibly) animated WebP images.
|
||||
|
||||
Code Example:
|
||||
|
||||
WebPAnimDecoderOptions dec_options;
|
||||
WebPAnimDecoderOptionsInit(&dec_options);
|
||||
// Tune 'dec_options' as needed.
|
||||
WebPAnimDecoder* dec = WebPAnimDecoderNew(webp_data, &dec_options);
|
||||
WebPAnimInfo anim_info;
|
||||
WebPAnimDecoderGetInfo(dec, &anim_info);
|
||||
for (uint32_t i = 0; i < anim_info.loop_count; ++i) {
|
||||
while (WebPAnimDecoderHasMoreFrames(dec)) {
|
||||
uint8_t* buf;
|
||||
int timestamp;
|
||||
WebPAnimDecoderGetNext(dec, &buf, ×tamp);
|
||||
// ... (Render 'buf' based on 'timestamp').
|
||||
// ... (Do NOT free 'buf', as it is owned by 'dec').
|
||||
}
|
||||
WebPAnimDecoderReset(dec);
|
||||
}
|
||||
const WebPDemuxer* demuxer = WebPAnimDecoderGetDemuxer(dec);
|
||||
// ... (Do something using 'demuxer'; e.g. get EXIF/XMP/ICC data).
|
||||
WebPAnimDecoderDelete(dec);
|
||||
|
||||
For a detailed AnimDecoder API reference, please refer to the header file
|
||||
(src/webp/demux.h).
|
||||
|
||||
|
||||
Bugs:
|
||||
=====
|
||||
|
@ -173,9 +173,9 @@ model {
|
||||
include "cost.c"
|
||||
include "cost_mips32.c"
|
||||
include "cost_mips_dsp_r2.c"
|
||||
include "cost_neon.$NEON"
|
||||
include "cost_sse2.c"
|
||||
include "enc.c"
|
||||
include "enc_avx2.c"
|
||||
include "enc_mips32.c"
|
||||
include "enc_mips_dsp_r2.c"
|
||||
include "enc_msa.c"
|
||||
|
@ -1,5 +1,10 @@
|
||||
set(WebP_VERSION @PROJECT_VERSION@)
|
||||
set(WEBP_VERSION ${WebP_VERSION})
|
||||
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include ("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
|
||||
set(WebP_INCLUDE_DIRS "webp")
|
||||
set(WEBP_INCLUDE_DIRS ${WebP_INCLUDE_DIRS})
|
||||
set(WebP_LIBRARIES "@INSTALLED_LIBRARIES@")
|
||||
|
@ -103,9 +103,6 @@
|
||||
/* Version number of package */
|
||||
#cmakedefine VERSION "@VERSION@"
|
||||
|
||||
/* Set to 1 if AVX2 is supported */
|
||||
#cmakedefine WEBP_HAVE_AVX2 1
|
||||
|
||||
/* Set to 1 if GIF library is installed */
|
||||
#cmakedefine WEBP_HAVE_GIF 1
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
## Check for SIMD extensions.
|
||||
# Check for SIMD extensions.
|
||||
include(CMakePushCheckState)
|
||||
|
||||
function(webp_check_compiler_flag WEBP_SIMD_FLAG ENABLE_SIMD)
|
||||
@ -18,8 +18,7 @@ function(webp_check_compiler_flag WEBP_SIMD_FLAG ENABLE_SIMD)
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
" WEBP_HAVE_FLAG_${WEBP_SIMD_FLAG}
|
||||
)
|
||||
" WEBP_HAVE_FLAG_${WEBP_SIMD_FLAG})
|
||||
cmake_pop_check_state()
|
||||
if(WEBP_HAVE_FLAG_${WEBP_SIMD_FLAG})
|
||||
set(WEBP_HAVE_${WEBP_SIMD_FLAG} 1 PARENT_SCOPE)
|
||||
@ -29,16 +28,18 @@ function(webp_check_compiler_flag WEBP_SIMD_FLAG ENABLE_SIMD)
|
||||
endfunction()
|
||||
|
||||
# those are included in the names of WEBP_USE_* in c++ code.
|
||||
set(WEBP_SIMD_FLAGS "SSE2;SSE41;AVX2;MIPS32;MIPS_DSP_R2;NEON;MSA")
|
||||
set(WEBP_SIMD_FILE_EXTENSIONS "_sse2.c;_sse41.c;_avx2.c;_mips32.c;_mips_dsp_r2.c;_neon.c;_msa.c")
|
||||
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 AVX2 support implies
|
||||
# SSE4 support.
|
||||
set(SIMD_ENABLE_FLAGS "/arch:SSE2;/arch:AVX2;/arch:AVX2;;;;")
|
||||
# MSVC does not have a SSE4 flag but AVX support implies SSE4 support.
|
||||
set(SIMD_ENABLE_FLAGS "/arch:AVX;/arch:SSE2;;;;")
|
||||
set(SIMD_DISABLE_FLAGS)
|
||||
else()
|
||||
set(SIMD_ENABLE_FLAGS "-msse2;-msse4.1;-mavx2;-mips32;-mdspr2;-mfpu=neon;-mmsa")
|
||||
set(SIMD_DISABLE_FLAGS "-mno-sse2;-mno-sse4.1;-mno-avx2;;-mno-dspr2;;-mno-msa")
|
||||
set(SIMD_ENABLE_FLAGS
|
||||
"-msse4.1;-msse2;-mips32;-mdspr2;-mfpu=neon;-mmsa")
|
||||
set(SIMD_DISABLE_FLAGS
|
||||
"-mno-sse4.1;-mno-sse2;;-mno-dspr2;;-mno-msa")
|
||||
endif()
|
||||
|
||||
set(WEBP_SIMD_FILES_TO_NOT_INCLUDE)
|
||||
@ -47,16 +48,16 @@ set(WEBP_SIMD_FLAGS_TO_INCLUDE)
|
||||
|
||||
if(${ANDROID})
|
||||
if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
|
||||
# This is because Android studio uses the configuration
|
||||
# "-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16"
|
||||
# that does not trigger neon optimizations but should
|
||||
# (as this configuration does not exist anymore).
|
||||
# This is because Android studio uses the configuration "-march=armv7-a
|
||||
# -mfloat-abi=softfp -mfpu=vfpv3-d16" that does not trigger neon
|
||||
# optimizations but should (as this configuration does not exist anymore).
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=neon ")
|
||||
endif()
|
||||
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})
|
||||
list(GET WEBP_SIMD_FLAGS ${I_SIMD} WEBP_SIMD_FLAG)
|
||||
@ -72,18 +73,28 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||
else()
|
||||
set(SIMD_COMPILE_FLAG " ")
|
||||
if(MSVC)
|
||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||
else()
|
||||
set(SIMD_COMPILE_FLAG " ")
|
||||
endif()
|
||||
endif()
|
||||
# Check which files we should include or not.
|
||||
list(GET WEBP_SIMD_FILE_EXTENSIONS ${I_SIMD} WEBP_SIMD_FILE_EXTENSION)
|
||||
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
|
||||
"src/dsp/*${WEBP_SIMD_FILE_EXTENSION}"
|
||||
)
|
||||
"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})
|
||||
list(APPEND WEBP_SIMD_FLAGS_TO_INCLUDE ${SIMD_COMPILE_FLAG})
|
||||
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()
|
||||
endforeach()
|
||||
else()
|
||||
# Remove the file from the list.
|
||||
@ -107,10 +118,10 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_DEFINITIONS ${SIMD_COMPILE_FLAG})
|
||||
check_c_source_compiles("int main(void) {return 0;}"
|
||||
FLAG_${SIMD_COMPILE_FLAG}
|
||||
FAIL_REGEX "warning: argument unused during compilation:"
|
||||
${COMMON_PATTERNS}
|
||||
)
|
||||
FLAG_${SIMD_COMPILE_FLAG}
|
||||
FAIL_REGEX
|
||||
"warning: argument unused during compilation:"
|
||||
${COMMON_PATTERNS})
|
||||
if(NOT FLAG_${SIMD_COMPILE_FLAG})
|
||||
unset(HAS_COMPILE_FLAG CACHE)
|
||||
endif()
|
||||
|
@ -1,33 +1,27 @@
|
||||
# Generate the config.h to compile with specific intrinsics / libs.
|
||||
|
||||
## Check for compiler options.
|
||||
# Check for compiler options.
|
||||
include(CheckCSourceCompiles)
|
||||
check_c_source_compiles("
|
||||
int main(void) {
|
||||
(void)__builtin_bswap16(0);
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
HAVE_BUILTIN_BSWAP16
|
||||
)
|
||||
" HAVE_BUILTIN_BSWAP16)
|
||||
check_c_source_compiles("
|
||||
int main(void) {
|
||||
(void)__builtin_bswap32(0);
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
HAVE_BUILTIN_BSWAP32
|
||||
)
|
||||
" HAVE_BUILTIN_BSWAP32)
|
||||
check_c_source_compiles("
|
||||
int main(void) {
|
||||
(void)__builtin_bswap64(0);
|
||||
return 0;
|
||||
}
|
||||
"
|
||||
HAVE_BUILTIN_BSWAP64
|
||||
)
|
||||
" HAVE_BUILTIN_BSWAP64)
|
||||
|
||||
## Check for libraries.
|
||||
# Check for libraries.
|
||||
find_package(Threads)
|
||||
if(Threads_FOUND)
|
||||
if(CMAKE_USE_PTHREADS_INIT)
|
||||
@ -40,8 +34,7 @@ if(Threads_FOUND)
|
||||
int attr = ${PTHREAD_TEST};
|
||||
return attr;
|
||||
}
|
||||
" ${PTHREAD_TEST}
|
||||
)
|
||||
" ${PTHREAD_TEST})
|
||||
endforeach()
|
||||
list(APPEND WEBP_DEP_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif()
|
||||
@ -51,15 +44,20 @@ set(WEBP_USE_THREAD ${Threads_FOUND})
|
||||
set(LT_OBJDIR ".libs/")
|
||||
|
||||
# Only useful for vwebp, so useless for now.
|
||||
# find_package(OpenGL)
|
||||
# set(WEBP_HAVE_GL ${OPENGL_FOUND})
|
||||
# set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS})
|
||||
# set(WEBP_DEP_LIBRARIES ${WEBP_DEP_LIBRARIES} ${OPENGL_LIBRARIES})
|
||||
find_package(OpenGL)
|
||||
set(WEBP_HAVE_GL ${OPENGL_FOUND})
|
||||
|
||||
# Find the standard C math library.
|
||||
find_library(MATH_LIBRARY NAMES m)
|
||||
if(MATH_LIBRARY)
|
||||
list(APPEND WEBP_DEP_LIBRARIES ${MATH_LIBRARY})
|
||||
# Check if we need to link to the C math library. We do not look for it as it is
|
||||
# not found when cross-compiling, while it is here.
|
||||
check_c_source_compiles("
|
||||
#include <math.h>
|
||||
int main(int argc, char** argv) {
|
||||
return (int)pow(argc, 2.5);
|
||||
}
|
||||
" HAVE_MATH_LIBRARY)
|
||||
if(NOT HAVE_MATH_LIBRARY)
|
||||
message(STATUS "Adding -lm flag.")
|
||||
list(APPEND WEBP_DEP_LIBRARIES m)
|
||||
endif()
|
||||
|
||||
# Find the standard image libraries.
|
||||
@ -70,8 +68,8 @@ foreach(I_LIB PNG JPEG TIFF)
|
||||
set(WEBP_HAVE_${I_LIB} ${${I_LIB}_FOUND})
|
||||
if(${I_LIB}_FOUND)
|
||||
list(APPEND WEBP_DEP_IMG_LIBRARIES ${${I_LIB}_LIBRARIES})
|
||||
list(APPEND WEBP_DEP_IMG_INCLUDE_DIRS
|
||||
${${I_LIB}_INCLUDE_DIR} ${${I_LIB}_INCLUDE_DIRS})
|
||||
list(APPEND WEBP_DEP_IMG_INCLUDE_DIRS ${${I_LIB}_INCLUDE_DIR}
|
||||
${${I_LIB}_INCLUDE_DIRS})
|
||||
endif()
|
||||
endforeach()
|
||||
if(WEBP_DEP_IMG_INCLUDE_DIRS)
|
||||
@ -87,8 +85,8 @@ set(WEBP_HAVE_GIF ${GIF_FOUND})
|
||||
if(GIF_FOUND)
|
||||
# GIF find_package only locates the header and library, it doesn't fail
|
||||
# compile tests when detecting the version, but falls back to 3 (as of at
|
||||
# least cmake 3.7.2). Make sure the library links to avoid incorrect
|
||||
# detection when cross compiling.
|
||||
# least cmake 3.7.2). Make sure the library links to avoid incorrect detection
|
||||
# when cross compiling.
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${GIF_LIBRARIES})
|
||||
set(CMAKE_REQUIRED_INCLUDES ${GIF_INCLUDE_DIR})
|
||||
@ -98,8 +96,7 @@ if(GIF_FOUND)
|
||||
(void)DGifOpenFileHandle;
|
||||
return 0;
|
||||
}
|
||||
" GIF_COMPILES
|
||||
)
|
||||
" GIF_COMPILES)
|
||||
cmake_pop_check_state()
|
||||
if(GIF_COMPILES)
|
||||
list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES})
|
||||
@ -109,7 +106,7 @@ if(GIF_FOUND)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
## Check for specific headers.
|
||||
# Check for specific headers.
|
||||
include(CheckIncludeFiles)
|
||||
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
|
||||
check_include_files(dlfcn.h HAVE_DLFCN_H)
|
||||
@ -131,25 +128,32 @@ check_include_files(windows.h HAVE_WINDOWS_H)
|
||||
|
||||
# Windows specifics
|
||||
if(HAVE_WINCODEC_H)
|
||||
list(APPEND WEBP_DEP_LIBRARIES shlwapi ole32 windowscodecs)
|
||||
list(APPEND WEBP_DEP_LIBRARIES
|
||||
shlwapi
|
||||
ole32
|
||||
windowscodecs)
|
||||
endif()
|
||||
|
||||
## Check for SIMD extensions.
|
||||
# Check for SIMD extensions.
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cpu.cmake)
|
||||
|
||||
## Define extra info.
|
||||
# Define extra info.
|
||||
set(PACKAGE ${PROJECT_NAME})
|
||||
set(PACKAGE_NAME ${PROJECT_NAME})
|
||||
|
||||
# Read from configure.ac.
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac CONFIGURE_AC)
|
||||
string(REGEX MATCHALL "\\[([0-9a-z\\.:/]*)\\]"
|
||||
CONFIGURE_AC_PACKAGE_INFO ${CONFIGURE_AC}
|
||||
)
|
||||
string(REGEX MATCHALL
|
||||
"\\[([0-9a-z\\.:/]*)\\]"
|
||||
CONFIGURE_AC_PACKAGE_INFO
|
||||
${CONFIGURE_AC})
|
||||
function(strip_bracket VAR)
|
||||
string(LENGTH ${${VAR}} TMP_LEN)
|
||||
math(EXPR TMP_LEN ${TMP_LEN}-2)
|
||||
string(SUBSTRING ${${VAR}} 1 ${TMP_LEN} TMP_SUB)
|
||||
string(SUBSTRING ${${VAR}}
|
||||
1
|
||||
${TMP_LEN}
|
||||
TMP_SUB)
|
||||
set(${VAR} ${TMP_SUB} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
|
4
codereview.settings
Normal file
4
codereview.settings
Normal file
@ -0,0 +1,4 @@
|
||||
# This file is used by git cl to get repository specific information.
|
||||
GERRIT_HOST: True
|
||||
CODE_REVIEW_SERVER: chromium-review.googlesource.com
|
||||
GERRIT_SQUASH_UPLOADS: False
|
33
configure.ac
33
configure.ac
@ -1,4 +1,4 @@
|
||||
AC_INIT([libwebp], [1.0.0],
|
||||
AC_INIT([libwebp], [1.0.2],
|
||||
[https://bugs.chromium.org/p/webp],,
|
||||
[http://developers.google.com/speed/webp])
|
||||
AC_CANONICAL_HOST
|
||||
@ -122,31 +122,6 @@ AS_IF([test "$GCC" = "yes" ], [
|
||||
AC_SUBST([AM_CFLAGS])
|
||||
|
||||
dnl === Check for machine specific flags
|
||||
AC_ARG_ENABLE([avx2],
|
||||
AS_HELP_STRING([--disable-avx2],
|
||||
[Disable detection of AVX2 support
|
||||
@<:@default=auto@:>@]))
|
||||
|
||||
AS_IF([test "x$enable_avx2" != "xno" -a "x$enable_sse4_1" != "xno" \
|
||||
-a "x$enable_sse2" != "xno"], [
|
||||
AVX2_CFLAGS="$INTRINSICS_CFLAGS $AVX2_FLAGS"
|
||||
TEST_AND_ADD_CFLAGS([AVX2_FLAGS], [-mavx2])
|
||||
AS_IF([test -n "$AVX2_FLAGS"], [
|
||||
SAVED_CFLAGS=$CFLAGS
|
||||
CFLAGS="$CFLAGS $AVX2_FLAGS"
|
||||
AC_CHECK_HEADER([immintrin.h],
|
||||
[AC_DEFINE(WEBP_HAVE_AVX2, [1],
|
||||
[Set to 1 if AVX2 is supported])],
|
||||
[AVX2_FLAGS=""],
|
||||
dnl it's illegal to directly include avx2intrin.h, but it's
|
||||
dnl included conditionally in immintrin.h, tricky!
|
||||
[#ifndef __AVX2__
|
||||
#error avx2 is not enabled
|
||||
#endif
|
||||
])
|
||||
CFLAGS=$SAVED_CFLAGS])
|
||||
AC_SUBST([AVX2_FLAGS])])
|
||||
|
||||
AC_ARG_ENABLE([sse4.1],
|
||||
AS_HELP_STRING([--disable-sse4.1],
|
||||
[Disable detection of SSE4.1 support
|
||||
@ -722,7 +697,7 @@ AC_ARG_ENABLE([libwebpmux],
|
||||
AS_HELP_STRING([--enable-libwebpmux],
|
||||
[Build libwebpmux @<:@default=no@:>@]))
|
||||
AC_MSG_RESULT(${enable_libwebpmux-no})
|
||||
AM_CONDITIONAL([WANT_MUX], [test "$enable_libwebpmux" = "yes"])
|
||||
AM_CONDITIONAL([BUILD_MUX], [test "$enable_libwebpmux" = "yes"])
|
||||
|
||||
dnl === Check whether libwebpdemux should be built
|
||||
AC_MSG_CHECKING(whether libwebpdemux is to be built)
|
||||
@ -731,7 +706,7 @@ AC_ARG_ENABLE([libwebpdemux],
|
||||
[Disable libwebpdemux @<:@default=no@:>@]),
|
||||
[], [enable_libwebpdemux=yes])
|
||||
AC_MSG_RESULT(${enable_libwebpdemux-no})
|
||||
AM_CONDITIONAL([WANT_DEMUX], [test "$enable_libwebpdemux" = "yes"])
|
||||
AM_CONDITIONAL([BUILD_DEMUX], [test "$enable_libwebpdemux" = "yes"])
|
||||
|
||||
dnl === Check whether decoder library should be built.
|
||||
AC_MSG_CHECKING(whether decoder library is to be built)
|
||||
@ -747,7 +722,7 @@ AC_ARG_ENABLE([libwebpextras],
|
||||
AS_HELP_STRING([--enable-libwebpextras],
|
||||
[Build libwebpextras @<:@default=no@:>@]))
|
||||
AC_MSG_RESULT(${enable_libwebpextras-no})
|
||||
AM_CONDITIONAL([WANT_EXTRAS], [test "$enable_libwebpextras" = "yes"])
|
||||
AM_CONDITIONAL([BUILD_EXTRAS], [test "$enable_libwebpextras" = "yes"])
|
||||
|
||||
dnl =========================
|
||||
|
||||
|
@ -26,7 +26,6 @@ LOCAL_SRC_FILES := \
|
||||
cwebp.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util imagedec webpdemux webp
|
||||
|
||||
LOCAL_MODULE := cwebp
|
||||
@ -42,7 +41,6 @@ LOCAL_SRC_FILES := \
|
||||
dwebp.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imagedec imageenc webpdemux webp
|
||||
LOCAL_MODULE := dwebp
|
||||
|
||||
@ -57,7 +55,6 @@ LOCAL_SRC_FILES := \
|
||||
webpmux.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util webpmux webp
|
||||
|
||||
LOCAL_MODULE := webpmux_example
|
||||
@ -73,7 +70,6 @@ LOCAL_SRC_FILES := \
|
||||
img2webp.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util imagedec webpmux webpdemux \
|
||||
webp
|
||||
|
||||
@ -90,7 +86,6 @@ LOCAL_SRC_FILES := \
|
||||
webpinfo.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util webp
|
||||
|
||||
LOCAL_MODULE := webpinfo_example
|
||||
|
@ -1,7 +1,7 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
|
||||
bin_PROGRAMS =
|
||||
if WANT_DEMUX
|
||||
if BUILD_DEMUX
|
||||
bin_PROGRAMS += dwebp cwebp
|
||||
endif
|
||||
if BUILD_ANIMDIFF
|
||||
@ -13,7 +13,7 @@ endif
|
||||
if BUILD_IMG2WEBP
|
||||
bin_PROGRAMS += img2webp
|
||||
endif
|
||||
if WANT_MUX
|
||||
if BUILD_MUX
|
||||
bin_PROGRAMS += webpmux
|
||||
endif
|
||||
if BUILD_VWEBP
|
||||
@ -28,7 +28,7 @@ noinst_LTLIBRARIES = libexample_util.la
|
||||
libexample_util_la_SOURCES = example_util.c example_util.h
|
||||
libexample_util_la_LIBADD = ../src/libwebp.la
|
||||
|
||||
anim_diff_SOURCES = anim_diff.c anim_util.c anim_util.h
|
||||
anim_diff_SOURCES = anim_diff.c anim_util.c anim_util.h gifdec.c gifdec.h
|
||||
anim_diff_CPPFLAGS = $(AM_CPPFLAGS) $(GIF_INCLUDES)
|
||||
anim_diff_LDADD =
|
||||
anim_diff_LDADD += ../src/demux/libwebpdemux.la
|
||||
@ -36,7 +36,7 @@ anim_diff_LDADD += libexample_util.la
|
||||
anim_diff_LDADD += ../imageio/libimageio_util.la
|
||||
anim_diff_LDADD += $(GIF_LIBS) -lm
|
||||
|
||||
anim_dump_SOURCES = anim_dump.c anim_util.c anim_util.h
|
||||
anim_dump_SOURCES = anim_dump.c anim_util.c anim_util.h gifdec.c gifdec.h
|
||||
anim_dump_CPPFLAGS = $(AM_CPPFLAGS) $(PNG_INCLUDES)
|
||||
anim_dump_CPPFLAGS += $(GIF_INCLUDES)
|
||||
anim_dump_LDADD =
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include <string.h> // for 'strcmp'.
|
||||
|
||||
#include "./anim_util.h"
|
||||
#include "./example_util.h"
|
||||
#include "./unicode.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -143,8 +145,18 @@ static int CompareAnimatedImagePair(const AnimatedImage* const img1,
|
||||
if (!ok) return 0; // These are fatal failures, can't proceed.
|
||||
|
||||
if (is_multi_frame_image) { // Checks relevant for multi-frame images only.
|
||||
ok = CompareValues(img1->loop_count, img2->loop_count,
|
||||
"Loop count mismatch") && ok;
|
||||
int max_loop_count_workaround = 0;
|
||||
// Transcodes to webp increase the gif loop count by 1 for compatibility.
|
||||
// When the gif has the maximum value the webp value will be off by one.
|
||||
if ((img1->format == ANIM_GIF && img1->loop_count == 65536 &&
|
||||
img2->format == ANIM_WEBP && img2->loop_count == 65535) ||
|
||||
(img1->format == ANIM_WEBP && img1->loop_count == 65535 &&
|
||||
img2->format == ANIM_GIF && img2->loop_count == 65536)) {
|
||||
max_loop_count_workaround = 1;
|
||||
}
|
||||
ok = (max_loop_count_workaround ||
|
||||
CompareValues(img1->loop_count, img2->loop_count,
|
||||
"Loop count mismatch")) && ok;
|
||||
ok = CompareBackgroundColor(img1->bgcolor, img2->bgcolor,
|
||||
premultiply) && ok;
|
||||
}
|
||||
@ -207,25 +219,20 @@ int main(int argc, const char* argv[]) {
|
||||
const char* files[2] = { NULL, NULL };
|
||||
AnimatedImage images[2];
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-dump_frames")) {
|
||||
if (c < argc - 1) {
|
||||
dump_frames = 1;
|
||||
dump_folder = argv[++c];
|
||||
dump_folder = (const char*)GET_WARGV(argv, ++c);
|
||||
} else {
|
||||
parse_error = 1;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-min_psnr")) {
|
||||
if (c < argc - 1) {
|
||||
const char* const v = argv[++c];
|
||||
char* end = NULL;
|
||||
const double d = strtod(v, &end);
|
||||
if (end == v) {
|
||||
parse_error = 1;
|
||||
fprintf(stderr, "Error! '%s' is not a floating point number.\n", v);
|
||||
}
|
||||
min_psnr = d;
|
||||
min_psnr = ExUtilGetFloat(argv[++c], &parse_error);
|
||||
} else {
|
||||
parse_error = 1;
|
||||
}
|
||||
@ -233,20 +240,13 @@ int main(int argc, const char* argv[]) {
|
||||
premultiply = 0;
|
||||
} else if (!strcmp(argv[c], "-max_diff")) {
|
||||
if (c < argc - 1) {
|
||||
const char* const v = argv[++c];
|
||||
char* end = NULL;
|
||||
const int n = (int)strtol(v, &end, 10);
|
||||
if (end == v) {
|
||||
parse_error = 1;
|
||||
fprintf(stderr, "Error! '%s' is not an integer.\n", v);
|
||||
}
|
||||
max_diff = n;
|
||||
max_diff = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else {
|
||||
parse_error = 1;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-version")) {
|
||||
int dec_version, demux_version;
|
||||
GetAnimatedImageVersions(&dec_version, &demux_version);
|
||||
@ -255,13 +255,13 @@ int main(int argc, const char* argv[]) {
|
||||
(dec_version >> 0) & 0xff,
|
||||
(demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff,
|
||||
(demux_version >> 0) & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
if (!got_input1) {
|
||||
files[0] = argv[c];
|
||||
files[0] = (const char*)GET_WARGV(argv, c);
|
||||
got_input1 = 1;
|
||||
} else if (!got_input2) {
|
||||
files[1] = argv[c];
|
||||
files[1] = (const char*)GET_WARGV(argv, c);
|
||||
got_input2 = 1;
|
||||
} else {
|
||||
parse_error = 1;
|
||||
@ -269,29 +269,30 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
if (parse_error) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
}
|
||||
if (argc < 3) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
|
||||
if (!got_input2) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
if (dump_frames) {
|
||||
printf("Dumping decoded frames in: %s\n", dump_folder);
|
||||
WPRINTF("Dumping decoded frames in: %s\n", (const W_CHAR*)dump_folder);
|
||||
}
|
||||
|
||||
memset(images, 0, sizeof(images));
|
||||
for (i = 0; i < 2; ++i) {
|
||||
printf("Decoding file: %s\n", files[i]);
|
||||
WPRINTF("Decoding file: %s\n", (const W_CHAR*)files[i]);
|
||||
if (!ReadAnimatedImage(files[i], &images[i], dump_frames, dump_folder)) {
|
||||
fprintf(stderr, "Error decoding file: %s\n Aborting.\n", files[i]);
|
||||
WFPRINTF(stderr, "Error decoding file: %s\n Aborting.\n",
|
||||
(const W_CHAR*)files[i]);
|
||||
return_code = -2;
|
||||
goto End;
|
||||
} else {
|
||||
@ -301,14 +302,16 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
if (!CompareAnimatedImagePair(&images[0], &images[1],
|
||||
premultiply, min_psnr)) {
|
||||
fprintf(stderr, "\nFiles %s and %s differ.\n", files[0], files[1]);
|
||||
WFPRINTF(stderr, "\nFiles %s and %s differ.\n", (const W_CHAR*)files[0],
|
||||
(const W_CHAR*)files[1]);
|
||||
return_code = -3;
|
||||
} else {
|
||||
printf("\nFiles %s and %s are identical.\n", files[0], files[1]);
|
||||
WPRINTF("\nFiles %s and %s are identical.\n", (const W_CHAR*)files[0],
|
||||
(const W_CHAR*)files[1]);
|
||||
return_code = 0;
|
||||
}
|
||||
End:
|
||||
ClearAnimatedImage(&images[0]);
|
||||
ClearAnimatedImage(&images[1]);
|
||||
return return_code;
|
||||
FREE_WARGV_AND_RETURN(return_code);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "./anim_util.h"
|
||||
#include "webp/decode.h"
|
||||
#include "../imageio/image_enc.h"
|
||||
#include "./unicode.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -36,15 +37,17 @@ static void Help(void) {
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
int error = 0;
|
||||
const char* dump_folder = ".";
|
||||
const char* prefix = "dump_";
|
||||
const char* suffix = "png";
|
||||
const W_CHAR* dump_folder = TO_W_CHAR(".");
|
||||
const W_CHAR* prefix = TO_W_CHAR("dump_");
|
||||
const W_CHAR* suffix = TO_W_CHAR("png");
|
||||
WebPOutputFileFormat format = PNG;
|
||||
int c;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (argc < 2) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
for (c = 1; !error && c < argc; ++c) {
|
||||
@ -54,23 +57,23 @@ int main(int argc, const char* argv[]) {
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
dump_folder = argv[++c];
|
||||
dump_folder = GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-prefix")) {
|
||||
if (c + 1 == argc) {
|
||||
fprintf(stderr, "missing argument after option '%s'\n", argv[c]);
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
prefix = argv[++c];
|
||||
prefix = GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-tiff")) {
|
||||
format = TIFF;
|
||||
suffix = "tiff";
|
||||
suffix = TO_W_CHAR("tiff");
|
||||
} else if (!strcmp(argv[c], "-pam")) {
|
||||
format = PAM;
|
||||
suffix = "pam";
|
||||
suffix = TO_W_CHAR("pam");
|
||||
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-version")) {
|
||||
int dec_version, demux_version;
|
||||
GetAnimatedImageVersions(&dec_version, &demux_version);
|
||||
@ -79,21 +82,21 @@ int main(int argc, const char* argv[]) {
|
||||
(dec_version >> 0) & 0xff,
|
||||
(demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff,
|
||||
(demux_version >> 0) & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
uint32_t i;
|
||||
AnimatedImage image;
|
||||
const char* const file = argv[c];
|
||||
const W_CHAR* const file = GET_WARGV(argv, c);
|
||||
memset(&image, 0, sizeof(image));
|
||||
printf("Decoding file: %s as %s/%sxxxx.%s\n",
|
||||
file, dump_folder, prefix, suffix);
|
||||
if (!ReadAnimatedImage(file, &image, 0, NULL)) {
|
||||
fprintf(stderr, "Error decoding file: %s\n Aborting.\n", file);
|
||||
WPRINTF("Decoding file: %s as %s/%sxxxx.%s\n",
|
||||
file, dump_folder, prefix, suffix);
|
||||
if (!ReadAnimatedImage((const char*)file, &image, 0, NULL)) {
|
||||
WFPRINTF(stderr, "Error decoding file: %s\n Aborting.\n", file);
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
for (i = 0; !error && i < image.num_frames; ++i) {
|
||||
char out_file[1024];
|
||||
W_CHAR out_file[1024];
|
||||
WebPDecBuffer buffer;
|
||||
WebPInitDecBuffer(&buffer);
|
||||
buffer.colorspace = MODE_RGBA;
|
||||
@ -103,10 +106,10 @@ int main(int argc, const char* argv[]) {
|
||||
buffer.u.RGBA.rgba = image.frames[i].rgba;
|
||||
buffer.u.RGBA.stride = buffer.width * sizeof(uint32_t);
|
||||
buffer.u.RGBA.size = buffer.u.RGBA.stride * buffer.height;
|
||||
snprintf(out_file, sizeof(out_file), "%s/%s%.4d.%s",
|
||||
dump_folder, prefix, i, suffix);
|
||||
if (!WebPSaveImage(&buffer, format, out_file)) {
|
||||
fprintf(stderr, "Error while saving image '%s'\n", out_file);
|
||||
WSNPRINTF(out_file, sizeof(out_file), "%s/%s%.4d.%s",
|
||||
dump_folder, prefix, i, suffix);
|
||||
if (!WebPSaveImage(&buffer, format, (const char*)out_file)) {
|
||||
WFPRINTF(stderr, "Error while saving image '%s'\n", out_file);
|
||||
error = 1;
|
||||
}
|
||||
WebPFreeDecBuffer(&buffer);
|
||||
@ -114,5 +117,5 @@ int main(int argc, const char* argv[]) {
|
||||
ClearAnimatedImage(&image);
|
||||
}
|
||||
}
|
||||
return error ? 1 : 0;
|
||||
FREE_WARGV_AND_RETURN(error ? 1 : 0);
|
||||
}
|
||||
|
@ -23,6 +23,9 @@
|
||||
#include "webp/decode.h"
|
||||
#include "webp/demux.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./gifdec.h"
|
||||
#include "./unicode.h"
|
||||
#include "./unicode_gif.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -151,42 +154,42 @@ static int DumpFrame(const char filename[], const char dump_folder[],
|
||||
int ok = 0;
|
||||
size_t max_len;
|
||||
int y;
|
||||
const char* base_name = NULL;
|
||||
char* file_name = NULL;
|
||||
const W_CHAR* base_name = NULL;
|
||||
W_CHAR* file_name = NULL;
|
||||
FILE* f = NULL;
|
||||
const char* row;
|
||||
|
||||
if (dump_folder == NULL) dump_folder = ".";
|
||||
if (dump_folder == NULL) dump_folder = (const char*)TO_W_CHAR(".");
|
||||
|
||||
base_name = strrchr(filename, '/');
|
||||
base_name = (base_name == NULL) ? filename : base_name + 1;
|
||||
max_len = strlen(dump_folder) + 1 + strlen(base_name)
|
||||
base_name = WSTRRCHR(filename, '/');
|
||||
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 = (char*)malloc(max_len * sizeof(*file_name));
|
||||
file_name = (W_CHAR*)malloc(max_len * sizeof(*file_name));
|
||||
if (file_name == NULL) goto End;
|
||||
|
||||
if (snprintf(file_name, max_len, "%s/%s_frame_%d.pam",
|
||||
dump_folder, base_name, frame_num) < 0) {
|
||||
if (WSNPRINTF(file_name, max_len, "%s/%s_frame_%d.pam",
|
||||
(const W_CHAR*)dump_folder, base_name, frame_num) < 0) {
|
||||
fprintf(stderr, "Error while generating file name\n");
|
||||
goto End;
|
||||
}
|
||||
|
||||
f = fopen(file_name, "wb");
|
||||
f = WFOPEN(file_name, "wb");
|
||||
if (f == NULL) {
|
||||
fprintf(stderr, "Error opening file for writing: %s\n", file_name);
|
||||
WFPRINTF(stderr, "Error opening file for writing: %s\n", file_name);
|
||||
ok = 0;
|
||||
goto End;
|
||||
}
|
||||
if (fprintf(f, "P7\nWIDTH %d\nHEIGHT %d\n"
|
||||
"DEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n",
|
||||
canvas_width, canvas_height) < 0) {
|
||||
fprintf(stderr, "Write error for file %s\n", file_name);
|
||||
WFPRINTF(stderr, "Write error for file %s\n", file_name);
|
||||
goto End;
|
||||
}
|
||||
row = (const char*)rgba;
|
||||
for (y = 0; y < canvas_height; ++y) {
|
||||
if (fwrite(row, canvas_width * kNumChannels, 1, f) != 1) {
|
||||
fprintf(stderr, "Error writing to file: %s\n", file_name);
|
||||
WFPRINTF(stderr, "Error writing to file: %s\n", file_name);
|
||||
goto End;
|
||||
}
|
||||
row += canvas_width * kNumChannels;
|
||||
@ -222,7 +225,7 @@ static int ReadAnimatedWebP(const char filename[],
|
||||
|
||||
dec = WebPAnimDecoderNew(webp_data, NULL);
|
||||
if (dec == NULL) {
|
||||
fprintf(stderr, "Error parsing image: %s\n", filename);
|
||||
WFPRINTF(stderr, "Error parsing image: %s\n", (const W_CHAR*)filename);
|
||||
goto End;
|
||||
}
|
||||
|
||||
@ -275,6 +278,7 @@ static int ReadAnimatedWebP(const char filename[],
|
||||
prev_frame_timestamp = timestamp;
|
||||
}
|
||||
ok = dump_ok;
|
||||
if (ok) image->format = ANIM_WEBP;
|
||||
|
||||
End:
|
||||
WebPAnimDecoderDelete(dec);
|
||||
@ -369,26 +373,6 @@ static int DGifSavedExtensionToGCB(GifFileType* GifFile, int ImageIndex,
|
||||
#define DGifCloseFile(a, b) DGifCloseFile(a)
|
||||
#endif
|
||||
|
||||
static void GIFDisplayError(const GifFileType* const gif, int gif_error) {
|
||||
// libgif 4.2.0 has retired PrintGifError() and added GifErrorString().
|
||||
#if LOCAL_GIF_PREREQ(4, 2)
|
||||
#if LOCAL_GIF_PREREQ(5, 0)
|
||||
const char* error_str =
|
||||
GifErrorString((gif == NULL) ? gif_error : gif->Error);
|
||||
#else
|
||||
const char* error_str = GifErrorString();
|
||||
(void)gif;
|
||||
#endif
|
||||
if (error_str == NULL) error_str = "Unknown error";
|
||||
fprintf(stderr, "GIFLib Error %d: %s\n", gif_error, error_str);
|
||||
#else
|
||||
(void)gif;
|
||||
fprintf(stderr, "GIFLib Error %d: ", gif_error);
|
||||
PrintGifError();
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
static int IsKeyFrameGIF(const GifImageDesc* prev_desc, int prev_dispose,
|
||||
const DecodedFrame* const prev_frame,
|
||||
int canvas_width, int canvas_height) {
|
||||
@ -529,15 +513,15 @@ static int ReadAnimatedGIF(const char filename[], AnimatedImage* const image,
|
||||
int gif_error;
|
||||
GifFileType* gif;
|
||||
|
||||
gif = DGifOpenFileName(filename, NULL);
|
||||
gif = DGifOpenFileUnicode((const W_CHAR*)filename, NULL);
|
||||
if (gif == NULL) {
|
||||
fprintf(stderr, "Could not read file: %s.\n", filename);
|
||||
WFPRINTF(stderr, "Could not read file: %s.\n", (const W_CHAR*)filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gif_error = DGifSlurp(gif);
|
||||
if (gif_error != GIF_OK) {
|
||||
fprintf(stderr, "Could not parse image: %s.\n", filename);
|
||||
WFPRINTF(stderr, "Could not parse image: %s.\n", (const W_CHAR*)filename);
|
||||
GIFDisplayError(gif, gif_error);
|
||||
DGifCloseFile(gif, NULL);
|
||||
return 0;
|
||||
@ -687,6 +671,7 @@ static int ReadAnimatedGIF(const char filename[], AnimatedImage* const image,
|
||||
}
|
||||
}
|
||||
}
|
||||
image->format = ANIM_GIF;
|
||||
DGifCloseFile(gif, NULL);
|
||||
return 1;
|
||||
}
|
||||
@ -722,7 +707,7 @@ int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
|
||||
memset(image, 0, sizeof(*image));
|
||||
|
||||
if (!ImgIoUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", filename);
|
||||
WFPRINTF(stderr, "Error reading file: %s\n", (const W_CHAR*)filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -732,9 +717,9 @@ int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
|
||||
} else if (IsGIF(&webp_data)) {
|
||||
ok = ReadAnimatedGIF(filename, image, dump_frames, dump_folder);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"Unknown file type: %s. Supported file types are WebP and GIF\n",
|
||||
filename);
|
||||
WFPRINTF(stderr,
|
||||
"Unknown file type: %s. Supported file types are WebP and GIF\n",
|
||||
(const W_CHAR*)filename);
|
||||
ok = 0;
|
||||
}
|
||||
if (!ok) ClearAnimatedImage(image);
|
||||
|
@ -22,6 +22,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ANIM_GIF,
|
||||
ANIM_WEBP
|
||||
} AnimatedFileFormat;
|
||||
|
||||
typedef struct {
|
||||
uint8_t* rgba; // Decoded and reconstructed full frame.
|
||||
int duration; // Frame duration in milliseconds.
|
||||
@ -29,6 +34,7 @@ typedef struct {
|
||||
} DecodedFrame;
|
||||
|
||||
typedef struct {
|
||||
AnimatedFileFormat format;
|
||||
uint32_t canvas_width;
|
||||
uint32_t canvas_height;
|
||||
uint32_t bgcolor;
|
||||
|
103
examples/cwebp.c
103
examples/cwebp.c
@ -24,6 +24,7 @@
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "./unicode.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#ifndef WEBP_DLL
|
||||
@ -88,7 +89,8 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
}
|
||||
}
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error! Could not process file %s\n", filename);
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
return ok;
|
||||
@ -114,7 +116,8 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
}
|
||||
End:
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error! Could not process file %s\n", filename);
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
return ok;
|
||||
@ -185,7 +188,7 @@ static void PrintExtraInfoLossless(const WebPPicture* const pic,
|
||||
if (short_output) {
|
||||
fprintf(stderr, "%7d %2.2f\n", stats->coded_size, stats->PSNR[3]);
|
||||
} else {
|
||||
fprintf(stderr, "File: %s\n", file_name);
|
||||
WFPRINTF(stderr, "File: %s\n", (const W_CHAR*)file_name);
|
||||
fprintf(stderr, "Dimension: %d x %d\n", pic->width, pic->height);
|
||||
fprintf(stderr, "Output: %d bytes (%.2f bpp)\n", stats->coded_size,
|
||||
8.f * stats->coded_size / pic->width / pic->height);
|
||||
@ -204,7 +207,7 @@ static void PrintExtraInfoLossy(const WebPPicture* const pic, int short_output,
|
||||
const int num_i16 = stats->block_count[1];
|
||||
const int num_skip = stats->block_count[2];
|
||||
const int total = num_i4 + num_i16;
|
||||
fprintf(stderr, "File: %s\n", file_name);
|
||||
WFPRINTF(stderr, "File: %s\n", (const W_CHAR*)file_name);
|
||||
fprintf(stderr, "Dimension: %d x %d%s\n",
|
||||
pic->width, pic->height,
|
||||
stats->alpha_data_size ? " (with alpha)" : "");
|
||||
@ -309,7 +312,7 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) {
|
||||
const int alpha_height =
|
||||
WebPPictureHasTransparency(picture) ? picture->height : 0;
|
||||
const int height = picture->height + uv_height + alpha_height;
|
||||
FILE* const f = fopen(PGM_name, "wb");
|
||||
FILE* const f = WFOPEN(PGM_name, "wb");
|
||||
if (f == NULL) return 0;
|
||||
fprintf(f, "P5\n%d %d\n255\n", stride, height);
|
||||
for (y = 0; y < picture->height; ++y) {
|
||||
@ -663,32 +666,34 @@ int main(int argc, const char *argv[]) {
|
||||
Metadata metadata;
|
||||
Stopwatch stop_watch;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
MetadataInit(&metadata);
|
||||
WebPMemoryWriterInit(&memory_writer);
|
||||
if (!WebPPictureInit(&picture) ||
|
||||
!WebPPictureInit(&original_picture) ||
|
||||
!WebPConfigInit(&config)) {
|
||||
fprintf(stderr, "Error! Version mismatch!\n");
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
HelpShort();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
HelpShort();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
|
||||
HelpLong();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-o") && c < argc - 1) {
|
||||
out_file = argv[++c];
|
||||
out_file = (const char*)GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-d") && c < argc - 1) {
|
||||
dump_file = argv[++c];
|
||||
dump_file = (const char*)GET_WARGV(argv, ++c);
|
||||
config.show_compressed = 1;
|
||||
} else if (!strcmp(argv[c], "-print_psnr")) {
|
||||
config.show_compressed = 1;
|
||||
@ -816,7 +821,7 @@ int main(int argc, const char *argv[]) {
|
||||
const int version = WebPGetEncoderVersion();
|
||||
printf("%d.%d.%d\n",
|
||||
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-progress")) {
|
||||
show_progress = 1;
|
||||
} else if (!strcmp(argv[c], "-quiet")) {
|
||||
@ -878,8 +883,7 @@ int main(int argc, const char *argv[]) {
|
||||
if (i == kNumTokens) {
|
||||
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
|
||||
(int)(token - start), start);
|
||||
HelpLong();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
start = token + 1;
|
||||
}
|
||||
@ -893,19 +897,19 @@ 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 = argv[++c];
|
||||
if (c < argc - 1) in_file = (const char*)GET_WARGV(argv, ++c);
|
||||
break;
|
||||
} else if (argv[c][0] == '-') {
|
||||
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
|
||||
HelpLong();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
} else {
|
||||
in_file = argv[c];
|
||||
in_file = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
|
||||
if (parse_error) {
|
||||
HelpLong();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
}
|
||||
if (in_file == NULL) {
|
||||
@ -955,7 +959,8 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
if (!ReadPicture(in_file, &picture, keep_alpha,
|
||||
(keep_metadata == 0) ? NULL : &metadata)) {
|
||||
fprintf(stderr, "Error! Cannot read input picture file '%s'\n", in_file);
|
||||
WFPRINTF(stderr, "Error! Cannot read input picture file '%s'\n",
|
||||
(const W_CHAR*)in_file);
|
||||
goto Error;
|
||||
}
|
||||
picture.progress_hook = (show_progress && !quiet) ? ProgressReport : NULL;
|
||||
@ -971,14 +976,15 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
// Open the output
|
||||
if (out_file != NULL) {
|
||||
const int use_stdout = !strcmp(out_file, "-");
|
||||
out = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
|
||||
const int use_stdout = !WSTRCMP(out_file, "-");
|
||||
out = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : WFOPEN(out_file, "wb");
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file);
|
||||
WFPRINTF(stderr, "Error! Cannot open output file '%s'\n",
|
||||
(const W_CHAR*)out_file);
|
||||
goto Error;
|
||||
} else {
|
||||
if (!short_output && !quiet) {
|
||||
fprintf(stderr, "Saving file '%s'\n", out_file);
|
||||
WFPRINTF(stderr, "Saving file '%s'\n", (const W_CHAR*)out_file);
|
||||
}
|
||||
}
|
||||
if (keep_metadata == 0) {
|
||||
@ -1012,10 +1018,53 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
}
|
||||
if ((resize_w | resize_h) > 0) {
|
||||
WebPPicture picture_no_alpha;
|
||||
if (config.exact) {
|
||||
// If -exact, we can't premultiply RGB by A otherwise RGB is lost if A=0.
|
||||
// We rescale an opaque copy and assemble scaled A and non-premultiplied
|
||||
// RGB channels. This is slower but it's a very uncommon use case. Color
|
||||
// leak at sharp alpha edges is possible.
|
||||
if (!WebPPictureCopy(&picture, &picture_no_alpha)) {
|
||||
fprintf(stderr, "Error! Cannot copy temporary picture\n");
|
||||
goto Error;
|
||||
}
|
||||
|
||||
// We enforced picture.use_argb = 1 above. Now, remove the alpha values.
|
||||
{
|
||||
int x, y;
|
||||
uint32_t* argb_no_alpha = picture_no_alpha.argb;
|
||||
for (y = 0; y < picture_no_alpha.height; ++y) {
|
||||
for (x = 0; x < picture_no_alpha.width; ++x) {
|
||||
argb_no_alpha[x] |= 0xff000000; // Opaque copy.
|
||||
}
|
||||
argb_no_alpha += picture_no_alpha.argb_stride;
|
||||
}
|
||||
}
|
||||
|
||||
if (!WebPPictureRescale(&picture_no_alpha, resize_w, resize_h)) {
|
||||
fprintf(stderr, "Error! Cannot resize temporary picture\n");
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!WebPPictureRescale(&picture, resize_w, resize_h)) {
|
||||
fprintf(stderr, "Error! Cannot resize picture\n");
|
||||
goto Error;
|
||||
}
|
||||
|
||||
if (config.exact) { // Put back the alpha information.
|
||||
int x, y;
|
||||
uint32_t* argb_no_alpha = picture_no_alpha.argb;
|
||||
uint32_t* argb = picture.argb;
|
||||
for (y = 0; y < picture_no_alpha.height; ++y) {
|
||||
for (x = 0; x < picture_no_alpha.width; ++x) {
|
||||
argb[x] = (argb[x] & 0xff000000) | (argb_no_alpha[x] & 0x00ffffff);
|
||||
}
|
||||
argb_no_alpha += picture_no_alpha.argb_stride;
|
||||
argb += picture.argb_stride;
|
||||
}
|
||||
WebPPictureFree(&picture_no_alpha);
|
||||
}
|
||||
}
|
||||
if (verbose && (crop != 0 || (resize_w | resize_h) > 0)) {
|
||||
const double preproc_time = StopwatchReadAndReset(&stop_watch);
|
||||
@ -1047,9 +1096,11 @@ int main(int argc, const char *argv[]) {
|
||||
// Write info
|
||||
if (dump_file) {
|
||||
if (picture.use_argb) {
|
||||
fprintf(stderr, "Warning: can't dump file (-d option) in lossless mode.");
|
||||
fprintf(stderr, "Warning: can't dump file (-d option) "
|
||||
"in lossless mode.\n");
|
||||
} else if (!DumpPicture(&picture, dump_file)) {
|
||||
fprintf(stderr, "Warning, couldn't dump picture %s\n", dump_file);
|
||||
WFPRINTF(stderr, "Warning, couldn't dump picture %s\n",
|
||||
(const W_CHAR*)dump_file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1125,7 +1176,7 @@ int main(int argc, const char *argv[]) {
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
return return_value;
|
||||
FREE_WARGV_AND_RETURN(return_value);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "../imageio/image_enc.h"
|
||||
#include "../imageio/webpdec.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "./unicode.h"
|
||||
|
||||
static int verbose = 0;
|
||||
static int quiet = 0;
|
||||
@ -42,7 +43,7 @@ extern void* VP8GetCPUInfo; // opaque forward declaration.
|
||||
|
||||
static int SaveOutput(const WebPDecBuffer* const buffer,
|
||||
WebPOutputFileFormat format, const char* const out_file) {
|
||||
const int use_stdout = (out_file != NULL) && !strcmp(out_file, "-");
|
||||
const int use_stdout = (out_file != NULL) && !WSTRCMP(out_file, "-");
|
||||
int ok = 1;
|
||||
Stopwatch stop_watch;
|
||||
|
||||
@ -56,7 +57,7 @@ static int SaveOutput(const WebPDecBuffer* const buffer,
|
||||
if (use_stdout) {
|
||||
fprintf(stderr, "Saved to stdout\n");
|
||||
} else {
|
||||
fprintf(stderr, "Saved file %s\n", out_file);
|
||||
WFPRINTF(stderr, "Saved file %s\n", (const W_CHAR*)out_file);
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
@ -67,7 +68,7 @@ static int SaveOutput(const WebPDecBuffer* const buffer,
|
||||
if (use_stdout) {
|
||||
fprintf(stderr, "Error writing to stdout !!\n");
|
||||
} else {
|
||||
fprintf(stderr, "Error writing file %s !!\n", out_file);
|
||||
WFPRINTF(stderr, "Error writing file %s !!\n", (const W_CHAR*)out_file);
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
@ -191,18 +192,20 @@ int main(int argc, const char *argv[]) {
|
||||
int incremental = 0;
|
||||
int c;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-o") && c < argc - 1) {
|
||||
out_file = argv[++c];
|
||||
out_file = (const char*)GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-alpha")) {
|
||||
format = ALPHA_PLANE_ONLY;
|
||||
} else if (!strcmp(argv[c], "-nofancy")) {
|
||||
@ -223,7 +226,7 @@ int main(int argc, const char *argv[]) {
|
||||
const int version = WebPGetDecoderVersion();
|
||||
printf("%d.%d.%d\n",
|
||||
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-pgm")) {
|
||||
format = PGM;
|
||||
} else if (!strcmp(argv[c], "-yuv")) {
|
||||
@ -284,26 +287,26 @@ int main(int argc, const char *argv[]) {
|
||||
} else if (!strcmp(argv[c], "-incremental")) {
|
||||
incremental = 1;
|
||||
} else if (!strcmp(argv[c], "--")) {
|
||||
if (c < argc - 1) in_file = argv[++c];
|
||||
if (c < argc - 1) in_file = (const char*)GET_WARGV(argv, ++c);
|
||||
break;
|
||||
} else if (argv[c][0] == '-') {
|
||||
fprintf(stderr, "Unknown option '%s'\n", argv[c]);
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
} else {
|
||||
in_file = argv[c];
|
||||
in_file = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
|
||||
if (parse_error) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_file == NULL) {
|
||||
fprintf(stderr, "missing input file!!\n");
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
if (quiet) verbose = 0;
|
||||
@ -312,7 +315,7 @@ int main(int argc, const char *argv[]) {
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
size_t data_size = 0;
|
||||
if (!LoadWebP(in_file, &data, &data_size, bitstream)) {
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
@ -389,18 +392,18 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
if (out_file != NULL) {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "Decoded %s. Dimensions: %d x %d %s. Format: %s. "
|
||||
"Now saving...\n",
|
||||
in_file, output_buffer->width, output_buffer->height,
|
||||
WFPRINTF(stderr, "Decoded %s.", (const W_CHAR*)in_file);
|
||||
fprintf(stderr, " Dimensions: %d x %d %s. Format: %s. Now saving...\n",
|
||||
output_buffer->width, output_buffer->height,
|
||||
bitstream->has_alpha ? " (with alpha)" : "",
|
||||
kFormatType[bitstream->format]);
|
||||
}
|
||||
ok = SaveOutput(output_buffer, format, out_file);
|
||||
} else {
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "File %s can be decoded "
|
||||
"(dimensions: %d x %d %s. Format: %s).\n",
|
||||
in_file, output_buffer->width, output_buffer->height,
|
||||
WFPRINTF(stderr, "File %s can be decoded ", (const W_CHAR*)in_file);
|
||||
fprintf(stderr, "(dimensions: %d x %d %s. Format: %s).\n",
|
||||
output_buffer->width, output_buffer->height,
|
||||
bitstream->has_alpha ? " (with alpha)" : "",
|
||||
kFormatType[bitstream->format]);
|
||||
fprintf(stderr, "Nothing written; "
|
||||
@ -411,7 +414,7 @@ int main(int argc, const char *argv[]) {
|
||||
WebPFreeDecBuffer(output_buffer);
|
||||
free((void*)external_buffer);
|
||||
free((void*)data);
|
||||
return ok ? 0 : -1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : -1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -90,6 +90,14 @@ int ExUtilInitCommandLineArguments(int argc, const char* argv[],
|
||||
if (argc == 1 && argv[0][0] != '-') {
|
||||
char* cur;
|
||||
const char sep[] = " \t\r\n\f\v";
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
fprintf(stderr,
|
||||
"Error: Reading arguments from a file is a feature unavailable "
|
||||
"with Unicode binaries.\n");
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if (!ExUtilReadFileToWebPData(argv[0], &args->argv_data_)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,6 +33,8 @@
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./gifdec.h"
|
||||
#include "./unicode.h"
|
||||
#include "./unicode_gif.h"
|
||||
|
||||
#if !defined(STDIN_FILENO)
|
||||
#define STDIN_FILENO 0
|
||||
@ -99,8 +101,7 @@ int main(int argc, const char *argv[]) {
|
||||
int gif_error = GIF_ERROR;
|
||||
WebPMuxError err = WEBP_MUX_OK;
|
||||
int ok = 0;
|
||||
const char *in_file = NULL, *out_file = NULL;
|
||||
FILE* out = NULL;
|
||||
const W_CHAR *in_file = NULL, *out_file = NULL;
|
||||
GifFileType* gif = NULL;
|
||||
int frame_duration = 0;
|
||||
int frame_timestamp = 0;
|
||||
@ -133,11 +134,13 @@ int main(int argc, const char *argv[]) {
|
||||
int default_kmin = 1; // Whether to use default kmin value.
|
||||
int default_kmax = 1;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (!WebPConfigInit(&config) || !WebPAnimEncoderOptionsInit(&enc_options) ||
|
||||
!WebPPictureInit(&frame) || !WebPPictureInit(&curr_canvas) ||
|
||||
!WebPPictureInit(&prev_canvas)) {
|
||||
fprintf(stderr, "Error! Version mismatch!\n");
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
config.lossless = 1; // Use lossless compression by default.
|
||||
|
||||
@ -147,16 +150,16 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
if (argc == 1) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-o") && c < argc - 1) {
|
||||
out_file = argv[++c];
|
||||
out_file = GET_WARGV(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-lossy")) {
|
||||
config.lossless = 0;
|
||||
} else if (!strcmp(argv[c], "-mixed")) {
|
||||
@ -213,7 +216,7 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "Error! Unknown metadata type '%.*s'\n",
|
||||
(int)(token - start), start);
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
start = token + 1;
|
||||
}
|
||||
@ -226,7 +229,7 @@ int main(int argc, const char *argv[]) {
|
||||
(enc_version >> 16) & 0xff, (enc_version >> 8) & 0xff,
|
||||
enc_version & 0xff, (mux_version >> 16) & 0xff,
|
||||
(mux_version >> 8) & 0xff, mux_version & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-quiet")) {
|
||||
quiet = 1;
|
||||
enc_options.verbose = 0;
|
||||
@ -234,19 +237,19 @@ int main(int argc, const char *argv[]) {
|
||||
verbose = 1;
|
||||
enc_options.verbose = 1;
|
||||
} else if (!strcmp(argv[c], "--")) {
|
||||
if (c < argc - 1) in_file = argv[++c];
|
||||
if (c < argc - 1) in_file = GET_WARGV(argv, ++c);
|
||||
break;
|
||||
} else if (argv[c][0] == '-') {
|
||||
fprintf(stderr, "Error! Unknown option '%s'\n", argv[c]);
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
} else {
|
||||
in_file = argv[c];
|
||||
in_file = GET_WARGV(argv, c);
|
||||
}
|
||||
|
||||
if (parse_error) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,13 +273,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
|
||||
// Start the decoder object
|
||||
#if LOCAL_GIF_PREREQ(5,0)
|
||||
gif = !strcmp(in_file, "-") ? DGifOpenFileHandle(STDIN_FILENO, &gif_error)
|
||||
: DGifOpenFileName(in_file, &gif_error);
|
||||
#else
|
||||
gif = !strcmp(in_file, "-") ? DGifOpenFileHandle(STDIN_FILENO)
|
||||
: DGifOpenFileName(in_file);
|
||||
#endif
|
||||
gif = DGifOpenFileUnicode(in_file, &gif_error);
|
||||
if (gif == NULL) goto End;
|
||||
|
||||
// Loop over GIF images
|
||||
@ -478,7 +475,7 @@ int main(int argc, const char *argv[]) {
|
||||
stored_loop_count = 1;
|
||||
loop_count = 1;
|
||||
}
|
||||
} else if (loop_count > 0) {
|
||||
} else if (loop_count > 0 && loop_count < 65535) {
|
||||
// adapt GIF's semantic to WebP's (except in the infinite-loop case)
|
||||
loop_count += 1;
|
||||
}
|
||||
@ -545,17 +542,18 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
|
||||
if (out_file != NULL) {
|
||||
if (!ImgIoUtilWriteFile(out_file, webp_data.bytes, webp_data.size)) {
|
||||
fprintf(stderr, "Error writing output file: %s\n", out_file);
|
||||
if (!ImgIoUtilWriteFile((const char*)out_file, webp_data.bytes,
|
||||
webp_data.size)) {
|
||||
WFPRINTF(stderr, "Error writing output file: %s\n", out_file);
|
||||
goto End;
|
||||
}
|
||||
if (!quiet) {
|
||||
if (!strcmp(out_file, "-")) {
|
||||
if (!WSTRCMP(out_file, "-")) {
|
||||
fprintf(stderr, "Saved %d bytes to STDIO\n",
|
||||
(int)webp_data.size);
|
||||
} else {
|
||||
fprintf(stderr, "Saved output file (%d bytes): %s\n",
|
||||
(int)webp_data.size, out_file);
|
||||
WFPRINTF(stderr, "Saved output file (%d bytes): %s\n",
|
||||
(int)webp_data.size, out_file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -578,7 +576,6 @@ int main(int argc, const char *argv[]) {
|
||||
WebPPictureFree(&curr_canvas);
|
||||
WebPPictureFree(&prev_canvas);
|
||||
WebPAnimEncoderDelete(enc);
|
||||
if (out != NULL && out_file != NULL) fclose(out);
|
||||
|
||||
if (gif_error != GIF_OK) {
|
||||
GIFDisplayError(gif, gif_error);
|
||||
@ -591,7 +588,7 @@ int main(int argc, const char *argv[]) {
|
||||
#endif
|
||||
}
|
||||
|
||||
return !ok;
|
||||
FREE_WARGV_AND_RETURN(!ok);
|
||||
}
|
||||
|
||||
#else // !WEBP_HAVE_GIF
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "./unicode.h"
|
||||
#include "webp/encode.h"
|
||||
#include "webp/mux.h"
|
||||
|
||||
@ -61,6 +62,10 @@ static void Help(void) {
|
||||
printf("\n");
|
||||
printf("example: img2webp -loop 2 in0.png -lossy in1.jpg\n"
|
||||
" -d 80 in2.tiff -o out.webp\n");
|
||||
printf("\nNote: if a single file name is passed as the argument, the "
|
||||
"arguments will be\n");
|
||||
printf("tokenized from this file. The file name must not start with "
|
||||
"the character '-'.\n");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -134,8 +139,13 @@ int main(int argc, const char* argv[]) {
|
||||
int c;
|
||||
int have_input = 0;
|
||||
CommandLineArguments cmd_args;
|
||||
int ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args);
|
||||
if (!ok) return 1;
|
||||
int ok;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
ok = ExUtilInitCommandLineArguments(argc - 1, argv + 1, &cmd_args);
|
||||
if (!ok) FREE_WARGV_AND_RETURN(1);
|
||||
|
||||
argc = cmd_args.argc_;
|
||||
argv = cmd_args.argv_;
|
||||
|
||||
@ -154,7 +164,7 @@ int main(int argc, const char* argv[]) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-o") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
output = argv[++c];
|
||||
output = (const char*)GET_WARGV_SHIFTED(argv, ++c);
|
||||
} else if (!strcmp(argv[c], "-kmin") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
anim_config.kmin = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
@ -241,7 +251,7 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
// read next input image
|
||||
pic.use_argb = 1;
|
||||
ok = ReadImage(argv[c], &pic);
|
||||
ok = ReadImage((const char*)GET_WARGV_SHIFTED(argv, c), &pic);
|
||||
if (!ok) goto End;
|
||||
|
||||
if (enc == NULL) {
|
||||
@ -273,8 +283,8 @@ int main(int argc, const char* argv[]) {
|
||||
if (!ok) goto End;
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Added frame #%3d at time %4d (file: %s)\n",
|
||||
pic_num, timestamp_ms, argv[c]);
|
||||
WFPRINTF(stderr, "Added frame #%3d at time %4d (file: %s)\n",
|
||||
pic_num, timestamp_ms, GET_WARGV_SHIFTED(argv, c));
|
||||
}
|
||||
timestamp_ms += duration;
|
||||
++pic_num;
|
||||
@ -298,7 +308,7 @@ int main(int argc, const char* argv[]) {
|
||||
if (ok) {
|
||||
if (output != NULL) {
|
||||
ok = ImgIoUtilWriteFile(output, webp_data.bytes, webp_data.size);
|
||||
if (ok) fprintf(stderr, "output file: %s ", output);
|
||||
if (ok) WFPRINTF(stderr, "output file: %s ", (const W_CHAR*)output);
|
||||
} else {
|
||||
fprintf(stderr, "[no output file specified] ");
|
||||
}
|
||||
@ -310,5 +320,5 @@ int main(int argc, const char* argv[]) {
|
||||
}
|
||||
WebPDataClear(&webp_data);
|
||||
ExUtilDeleteCommandLineArguments(&cmd_args);
|
||||
return ok ? 0 : 1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : 1);
|
||||
}
|
||||
|
@ -60,4 +60,4 @@ static WEBP_INLINE double StopwatchReadAndReset(Stopwatch* watch) {
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* WEBP_EXAMPLES_STOPWATCH_H_ */
|
||||
#endif // WEBP_EXAMPLES_STOPWATCH_H_
|
||||
|
101
examples/unicode.h
Normal file
101
examples/unicode.h
Normal file
@ -0,0 +1,101 @@
|
||||
// Copyright 2018 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Unicode support for Windows. The main idea is to maintain an array of Unicode
|
||||
// arguments (wargv) and use it only for file paths. The regular argv is used
|
||||
// for everything else.
|
||||
//
|
||||
// Author: Yannis Guyon (yguyon@google.com)
|
||||
|
||||
#ifndef WEBP_EXAMPLES_UNICODE_H_
|
||||
#define WEBP_EXAMPLES_UNICODE_H_
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
|
||||
// wchar_t is used instead of TCHAR because we only perform additional work when
|
||||
// Unicode is enabled and because the output of CommandLineToArgvW() is wchar_t.
|
||||
|
||||
#include <wchar.h>
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
// Create a wchar_t array containing Unicode parameters.
|
||||
#define INIT_WARGV(ARGC, ARGV) \
|
||||
int wargc; \
|
||||
const W_CHAR** const wargv = CommandLineToArgvW(GetCommandLineW(), &wargc); \
|
||||
do { \
|
||||
if (wargv == NULL || wargc != (ARGC)) { \
|
||||
fprintf(stderr, "Error: Unable to get Unicode arguments.\n"); \
|
||||
FREE_WARGV_AND_RETURN(-1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// Use this to get a Unicode argument (e.g. file path).
|
||||
#define GET_WARGV(UNUSED, C) wargv[C]
|
||||
// For cases where argv is shifted by one compared to wargv.
|
||||
#define GET_WARGV_SHIFTED(UNUSED, C) wargv[(C) + 1]
|
||||
#define GET_WARGV_OR_NULL() wargv
|
||||
|
||||
// Release resources. LocalFree() is needed after CommandLineToArgvW().
|
||||
#define FREE_WARGV() LOCAL_FREE((W_CHAR** const)wargv)
|
||||
#define LOCAL_FREE(WARGV) \
|
||||
do { \
|
||||
if ((WARGV) != NULL) LocalFree(WARGV); \
|
||||
} while (0)
|
||||
|
||||
#define W_CHAR wchar_t // WCHAR without underscore might already be defined.
|
||||
#define TO_W_CHAR(STR) (L##STR)
|
||||
|
||||
#define WFOPEN(ARG, OPT) _wfopen((const W_CHAR*)ARG, TO_W_CHAR(OPT))
|
||||
|
||||
#define WPRINTF(STR, ...) wprintf(TO_W_CHAR(STR), __VA_ARGS__)
|
||||
#define WFPRINTF(STDERR, STR, ...) fwprintf(STDERR, TO_W_CHAR(STR), __VA_ARGS__)
|
||||
|
||||
#define WSTRLEN(FILENAME) wcslen((const W_CHAR*)FILENAME)
|
||||
#define WSTRCMP(FILENAME, STR) wcscmp((const W_CHAR*)FILENAME, TO_W_CHAR(STR))
|
||||
#define WSTRRCHR(FILENAME, STR) wcsrchr((const W_CHAR*)FILENAME, TO_W_CHAR(STR))
|
||||
#define WSNPRINTF(A, B, STR, ...) _snwprintf(A, B, TO_W_CHAR(STR), __VA_ARGS__)
|
||||
|
||||
#else
|
||||
|
||||
// Unicode file paths work as is on Unix platforms, and no extra work is done on
|
||||
// Windows either if Unicode is disabled.
|
||||
|
||||
#define INIT_WARGV(ARGC, ARGV)
|
||||
|
||||
#define GET_WARGV(ARGV, C) (ARGV)[C]
|
||||
#define GET_WARGV_SHIFTED(ARGV, C) (ARGV)[C]
|
||||
#define GET_WARGV_OR_NULL() NULL
|
||||
|
||||
#define FREE_WARGV()
|
||||
#define LOCAL_FREE(WARGV)
|
||||
|
||||
#define W_CHAR char
|
||||
#define TO_W_CHAR(STR) (STR)
|
||||
|
||||
#define WFOPEN(ARG, OPT) fopen(ARG, OPT)
|
||||
|
||||
#define WPRINTF(STR, ...) printf(STR, __VA_ARGS__)
|
||||
#define WFPRINTF(STDERR, STR, ...) fprintf(STDERR, STR, __VA_ARGS__)
|
||||
|
||||
#define WSTRLEN(FILENAME) strlen(FILENAME)
|
||||
#define WSTRCMP(FILENAME, STR) strcmp(FILENAME, STR)
|
||||
#define WSTRRCHR(FILENAME, STR) strrchr(FILENAME, STR)
|
||||
#define WSNPRINTF(A, B, STR, ...) snprintf(A, B, STR, __VA_ARGS__)
|
||||
|
||||
#endif // defined(_WIN32) && defined(_UNICODE)
|
||||
|
||||
// Don't forget to free wargv before returning (e.g. from main).
|
||||
#define FREE_WARGV_AND_RETURN(VALUE) \
|
||||
do { \
|
||||
FREE_WARGV(); \
|
||||
return (VALUE); \
|
||||
} while (0)
|
||||
|
||||
#endif // WEBP_EXAMPLES_UNICODE_H_
|
75
examples/unicode_gif.h
Normal file
75
examples/unicode_gif.h
Normal file
@ -0,0 +1,75 @@
|
||||
// Copyright 2018 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// giflib doesn't have a Unicode DGifOpenFileName(). Let's make one.
|
||||
//
|
||||
// Author: Yannis Guyon (yguyon@google.com)
|
||||
|
||||
#ifndef WEBP_EXAMPLES_UNICODE_GIF_H_
|
||||
#define WEBP_EXAMPLES_UNICODE_GIF_H_
|
||||
|
||||
#include "./unicode.h"
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h" // For WEBP_HAVE_GIF
|
||||
#endif
|
||||
|
||||
#if defined(WEBP_HAVE_GIF)
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <fcntl.h> // Not standard, needed for _topen and flags.
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <gif_lib.h>
|
||||
#include <string.h>
|
||||
#include "./gifdec.h"
|
||||
|
||||
#if !defined(STDIN_FILENO)
|
||||
#define STDIN_FILENO 0
|
||||
#endif
|
||||
|
||||
static GifFileType* DGifOpenFileUnicode(const W_CHAR* file_name, int* error) {
|
||||
if (!WSTRCMP(file_name, "-")) {
|
||||
#if LOCAL_GIF_PREREQ(5, 0)
|
||||
return DGifOpenFileHandle(STDIN_FILENO, error);
|
||||
#else
|
||||
(void)error;
|
||||
return DGifOpenFileHandle(STDIN_FILENO);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(_UNICODE)
|
||||
|
||||
int file_handle = _wopen(file_name, _O_RDONLY | _O_BINARY);
|
||||
if (file_handle == -1) {
|
||||
if (error != NULL) *error = D_GIF_ERR_OPEN_FAILED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if LOCAL_GIF_PREREQ(5, 0)
|
||||
return DGifOpenFileHandle(file_handle, error);
|
||||
#else
|
||||
return DGifOpenFileHandle(file_handle);
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if LOCAL_GIF_PREREQ(5, 0)
|
||||
return DGifOpenFileName(file_name, error);
|
||||
#else
|
||||
return DGifOpenFileName(file_name);
|
||||
#endif
|
||||
|
||||
#endif // defined(_WIN32) && defined(_UNICODE)
|
||||
// DGifCloseFile() is called later.
|
||||
}
|
||||
|
||||
#endif // defined(WEBP_HAVE_GIF)
|
||||
|
||||
#endif // WEBP_EXAMPLES_UNICODE_GIF_H_
|
165
examples/vwebp.c
165
examples/vwebp.c
@ -42,6 +42,7 @@
|
||||
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./unicode.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -56,6 +57,7 @@ static struct {
|
||||
int print_info;
|
||||
int only_deltas;
|
||||
int use_color_profile;
|
||||
int draw_anim_background_color;
|
||||
|
||||
int canvas_width, canvas_height;
|
||||
int loop_count;
|
||||
@ -225,6 +227,9 @@ static void decode_callback(int what) {
|
||||
// Callbacks
|
||||
|
||||
static void HandleKey(unsigned char key, int pos_x, int pos_y) {
|
||||
// Note: rescaling the window or toggling some features during an animation
|
||||
// generates visual artifacts. This is not fixed because refreshing the frame
|
||||
// may require rendering the whole animation from start till current frame.
|
||||
(void)pos_x;
|
||||
(void)pos_y;
|
||||
if (key == 'q' || key == 'Q' || key == 27 /* Esc */) {
|
||||
@ -252,9 +257,11 @@ static void HandleKey(unsigned char key, int pos_x, int pos_y) {
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
} else if (key == 'b') {
|
||||
kParams.draw_anim_background_color = 1 - kParams.draw_anim_background_color;
|
||||
if (!kParams.has_animation) ClearPreviousFrame();
|
||||
glutPostRedisplay();
|
||||
} else if (key == 'i') {
|
||||
// Note: doesn't handle refresh of animation's last-frame (it's quite
|
||||
// more involved to do, since you need to save the previous frame).
|
||||
kParams.print_info = 1 - kParams.print_info;
|
||||
if (!kParams.has_animation) ClearPreviousFrame();
|
||||
glutPostRedisplay();
|
||||
@ -286,7 +293,7 @@ static void PrintString(const char* const text) {
|
||||
}
|
||||
|
||||
static float GetColorf(uint32_t color, int shift) {
|
||||
return (color >> shift) / 255.f;
|
||||
return ((color >> shift) & 0xff) / 255.f;
|
||||
}
|
||||
|
||||
static void DrawCheckerBoard(void) {
|
||||
@ -309,6 +316,43 @@ static void DrawCheckerBoard(void) {
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void DrawBackground(void) {
|
||||
// Whole window cleared with clear color, checkerboard rendered on top of it.
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
DrawCheckerBoard();
|
||||
|
||||
// ANIM background color rendered (blend) on top. Default is white for still
|
||||
// images (without ANIM chunk). glClear() can't be used for that (no blend).
|
||||
if (kParams.draw_anim_background_color) {
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glColor4f(GetColorf(kParams.bg_color, 16), // BGRA from spec
|
||||
GetColorf(kParams.bg_color, 8),
|
||||
GetColorf(kParams.bg_color, 0),
|
||||
GetColorf(kParams.bg_color, 24));
|
||||
glRecti(-1, -1, +1, +1);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
// Draw background in a scissored rectangle.
|
||||
static void DrawBackgroundScissored(int window_x, int window_y, int frame_w,
|
||||
int frame_h) {
|
||||
// Only update the requested area, not the whole canvas.
|
||||
window_x = window_x * kParams.viewport_width / kParams.canvas_width;
|
||||
window_y = window_y * kParams.viewport_height / kParams.canvas_height;
|
||||
frame_w = frame_w * kParams.viewport_width / kParams.canvas_width;
|
||||
frame_h = frame_h * kParams.viewport_height / kParams.canvas_height;
|
||||
|
||||
// glScissor() takes window coordinates (0,0 at bottom left).
|
||||
window_y = kParams.viewport_height - window_y - frame_h;
|
||||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(window_x, window_y, frame_w, frame_h);
|
||||
DrawBackground();
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
static void HandleDisplay(void) {
|
||||
const WebPDecBuffer* const pic = kParams.pic;
|
||||
const WebPIterator* const curr = &kParams.curr_frame;
|
||||
@ -325,38 +369,21 @@ static void HandleDisplay(void) {
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4);
|
||||
|
||||
if (kParams.only_deltas) {
|
||||
DrawCheckerBoard();
|
||||
} else if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ||
|
||||
curr->blend_method == WEBP_MUX_NO_BLEND) {
|
||||
// glScissor() takes window coordinates (0,0 at bottom left).
|
||||
int window_x, window_y;
|
||||
int frame_w, frame_h;
|
||||
DrawBackground();
|
||||
} else {
|
||||
// The rectangle of the previous frame might be different than the current
|
||||
// frame, so we may need to DrawBackgroundScissored for both.
|
||||
if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
|
||||
// Clear the previous frame rectangle.
|
||||
window_x = prev->x_offset;
|
||||
window_y = kParams.canvas_height - prev->y_offset - prev->height;
|
||||
frame_w = prev->width;
|
||||
frame_h = prev->height;
|
||||
} else { // curr->blend_method == WEBP_MUX_NO_BLEND.
|
||||
// We simulate no-blending behavior by first clearing the current frame
|
||||
// rectangle (to a checker-board) and then alpha-blending against it.
|
||||
window_x = curr->x_offset;
|
||||
window_y = kParams.canvas_height - curr->y_offset - curr->height;
|
||||
frame_w = curr->width;
|
||||
frame_h = curr->height;
|
||||
DrawBackgroundScissored(prev->x_offset, prev->y_offset, prev->width,
|
||||
prev->height);
|
||||
}
|
||||
if (curr->blend_method == WEBP_MUX_NO_BLEND) {
|
||||
// We simulate no-blending behavior by first clearing the current frame
|
||||
// rectangle and then alpha-blending against it.
|
||||
DrawBackgroundScissored(curr->x_offset, curr->y_offset, curr->width,
|
||||
curr->height);
|
||||
}
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
// Only update the requested area, not the whole canvas.
|
||||
window_x = window_x * kParams.viewport_width / kParams.canvas_width;
|
||||
window_y = window_y * kParams.viewport_height / kParams.canvas_height;
|
||||
frame_w = frame_w * kParams.viewport_width / kParams.canvas_width;
|
||||
frame_h = frame_h * kParams.viewport_height / kParams.canvas_height;
|
||||
glScissor(window_x, window_y, frame_w, frame_h);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT); // use clear color
|
||||
DrawCheckerBoard();
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
*prev = *curr;
|
||||
@ -408,37 +435,35 @@ static void StartDisplay(void) {
|
||||
glutKeyboardFunc(HandleKey);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glClearColor(GetColorf(kParams.bg_color, 0),
|
||||
GetColorf(kParams.bg_color, 8),
|
||||
GetColorf(kParams.bg_color, 16),
|
||||
GetColorf(kParams.bg_color, 24));
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
DrawCheckerBoard();
|
||||
glClearColor(0, 0, 0, 0); // window will be cleared to black (no blend)
|
||||
DrawBackground();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Main
|
||||
|
||||
static void Help(void) {
|
||||
printf("Usage: vwebp in_file [options]\n\n"
|
||||
"Decodes the WebP image file and visualize it using OpenGL\n"
|
||||
"Options are:\n"
|
||||
" -version ..... print version number and exit\n"
|
||||
" -noicc ....... don't use the icc profile if present\n"
|
||||
" -nofancy ..... don't use the fancy YUV420 upscaler\n"
|
||||
" -nofilter .... disable in-loop filtering\n"
|
||||
" -dither <int> dithering strength (0..100), default=50\n"
|
||||
" -noalphadither disable alpha plane dithering\n"
|
||||
" -mt .......... use multi-threading\n"
|
||||
" -info ........ print info\n"
|
||||
" -h ........... this help message\n"
|
||||
"\n"
|
||||
"Keyboard shortcuts:\n"
|
||||
" 'c' ................ toggle use of color profile\n"
|
||||
" 'i' ................ overlay file information\n"
|
||||
" 'd' ................ disable blending & disposal (debug)\n"
|
||||
" 'q' / 'Q' / ESC .... quit\n"
|
||||
);
|
||||
printf(
|
||||
"Usage: vwebp in_file [options]\n\n"
|
||||
"Decodes the WebP image file and visualize it using OpenGL\n"
|
||||
"Options are:\n"
|
||||
" -version ..... print version number and exit\n"
|
||||
" -noicc ....... don't use the icc profile if present\n"
|
||||
" -nofancy ..... don't use the fancy YUV420 upscaler\n"
|
||||
" -nofilter .... disable in-loop filtering\n"
|
||||
" -dither <int> dithering strength (0..100), default=50\n"
|
||||
" -noalphadither disable alpha plane dithering\n"
|
||||
" -usebgcolor .. display background color\n"
|
||||
" -mt .......... use multi-threading\n"
|
||||
" -info ........ print info\n"
|
||||
" -h ........... this help message\n"
|
||||
"\n"
|
||||
"Keyboard shortcuts:\n"
|
||||
" 'c' ................ toggle use of color profile\n"
|
||||
" 'b' ................ toggle background color display\n"
|
||||
" 'i' ................ overlay file information\n"
|
||||
" 'd' ................ disable blending & disposal (debug)\n"
|
||||
" 'q' / 'Q' / ESC .... quit\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@ -446,19 +471,23 @@ int main(int argc, char *argv[]) {
|
||||
WebPDecoderConfig* const config = &kParams.config;
|
||||
WebPIterator* const curr = &kParams.curr_frame;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (!WebPInitDecoderConfig(config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
config->options.dithering_strength = 50;
|
||||
config->options.alpha_dithering_strength = 100;
|
||||
kParams.use_color_profile = 1;
|
||||
// Background color hidden by default to see transparent areas.
|
||||
kParams.draw_anim_background_color = 0;
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-noicc")) {
|
||||
kParams.use_color_profile = 0;
|
||||
} else if (!strcmp(argv[c], "-nofancy")) {
|
||||
@ -467,6 +496,8 @@ int main(int argc, char *argv[]) {
|
||||
config->options.bypass_filtering = 1;
|
||||
} else if (!strcmp(argv[c], "-noalphadither")) {
|
||||
config->options.alpha_dithering_strength = 0;
|
||||
} else if (!strcmp(argv[c], "-usebgcolor")) {
|
||||
kParams.draw_anim_background_color = 1;
|
||||
} else if (!strcmp(argv[c], "-dither") && c + 1 < argc) {
|
||||
config->options.dithering_strength =
|
||||
ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
@ -479,30 +510,30 @@ int main(int argc, char *argv[]) {
|
||||
(dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
|
||||
dec_version & 0xff, (dmux_version >> 16) & 0xff,
|
||||
(dmux_version >> 8) & 0xff, dmux_version & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else if (!strcmp(argv[c], "-mt")) {
|
||||
config->options.use_threads = 1;
|
||||
} else if (!strcmp(argv[c], "--")) {
|
||||
if (c < argc - 1) kParams.file_name = argv[++c];
|
||||
if (c < argc - 1) kParams.file_name = (const char*)GET_WARGV(argv, ++c);
|
||||
break;
|
||||
} else if (argv[c][0] == '-') {
|
||||
printf("Unknown option '%s'\n", argv[c]);
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
} else {
|
||||
kParams.file_name = argv[c];
|
||||
kParams.file_name = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
|
||||
if (parse_error) {
|
||||
Help();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if (kParams.file_name == NULL) {
|
||||
printf("missing input file!!\n");
|
||||
Help();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
}
|
||||
|
||||
if (!ImgIoUtilReadFile(kParams.file_name,
|
||||
@ -577,11 +608,11 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// Should only be reached when using FREEGLUT:
|
||||
ClearParams();
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
|
||||
Error:
|
||||
ClearParams();
|
||||
return -1;
|
||||
FREE_WARGV_AND_RETURN(-1);
|
||||
}
|
||||
|
||||
#else // !WEBP_HAVE_GL
|
||||
|
@ -20,6 +20,7 @@
|
||||
#endif
|
||||
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./unicode.h"
|
||||
#include "webp/decode.h"
|
||||
#include "webp/format_constants.h"
|
||||
#include "webp/mux_types.h"
|
||||
@ -1119,19 +1120,21 @@ int main(int argc, const char* argv[]) {
|
||||
WebPInfoStatus webp_info_status = WEBP_INFO_OK;
|
||||
WebPInfo webp_info;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (argc == 1) {
|
||||
HelpShort();
|
||||
return WEBP_INFO_OK;
|
||||
FREE_WARGV_AND_RETURN(WEBP_INFO_OK);
|
||||
}
|
||||
|
||||
// Parse command-line input.
|
||||
for (c = 1; c < argc; ++c) {
|
||||
if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
HelpShort();
|
||||
return WEBP_INFO_OK;
|
||||
FREE_WARGV_AND_RETURN(WEBP_INFO_OK);
|
||||
} else if (!strcmp(argv[c], "-H") || !strcmp(argv[c], "-longhelp")) {
|
||||
HelpLong();
|
||||
return WEBP_INFO_OK;
|
||||
FREE_WARGV_AND_RETURN(WEBP_INFO_OK);
|
||||
} else if (!strcmp(argv[c], "-quiet")) {
|
||||
quiet = 1;
|
||||
} else if (!strcmp(argv[c], "-diag")) {
|
||||
@ -1144,7 +1147,7 @@ int main(int argc, const char* argv[]) {
|
||||
const int version = WebPGetDecoderVersion();
|
||||
printf("WebP Decoder version: %d.%d.%d\n",
|
||||
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else { // Assume the remaining are all input files.
|
||||
break;
|
||||
}
|
||||
@ -1152,27 +1155,28 @@ int main(int argc, const char* argv[]) {
|
||||
|
||||
if (c == argc) {
|
||||
HelpShort();
|
||||
return WEBP_INFO_INVALID_COMMAND;
|
||||
FREE_WARGV_AND_RETURN(WEBP_INFO_INVALID_COMMAND);
|
||||
}
|
||||
|
||||
// Process input files one by one.
|
||||
for (; c < argc; ++c) {
|
||||
WebPData webp_data;
|
||||
const char* in_file = NULL;
|
||||
const W_CHAR* in_file = NULL;
|
||||
WebPInfoInit(&webp_info);
|
||||
webp_info.quiet_ = quiet;
|
||||
webp_info.show_diagnosis_ = show_diag;
|
||||
webp_info.show_summary_ = show_summary;
|
||||
webp_info.parse_bitstream_ = parse_bitstream;
|
||||
in_file = argv[c];
|
||||
if (in_file == NULL || !ReadFileToWebPData(in_file, &webp_data)) {
|
||||
in_file = GET_WARGV(argv, c);
|
||||
if (in_file == NULL ||
|
||||
!ReadFileToWebPData((const char*)in_file, &webp_data)) {
|
||||
webp_info_status = WEBP_INFO_INVALID_COMMAND;
|
||||
fprintf(stderr, "Failed to open input file %s.\n", in_file);
|
||||
WFPRINTF(stderr, "Failed to open input file %s.\n", in_file);
|
||||
continue;
|
||||
}
|
||||
if (!webp_info.quiet_) printf("File: %s\n", in_file);
|
||||
if (!webp_info.quiet_) WPRINTF("File: %s\n", in_file);
|
||||
webp_info_status = AnalyzeWebP(&webp_info, &webp_data);
|
||||
WebPDataClear(&webp_data);
|
||||
}
|
||||
return webp_info_status;
|
||||
FREE_WARGV_AND_RETURN(webp_info_status);
|
||||
}
|
||||
|
@ -62,6 +62,7 @@
|
||||
#include "webp/mux.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./unicode.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Config object to parse command-line arguments.
|
||||
@ -390,23 +391,25 @@ static int CreateMux(const char* const filename, WebPMux** mux) {
|
||||
*mux = WebPMuxCreate(&bitstream, 1);
|
||||
WebPDataClear(&bitstream);
|
||||
if (*mux != NULL) return 1;
|
||||
fprintf(stderr, "Failed to create mux object from file %s.\n", filename);
|
||||
WFPRINTF(stderr, "Failed to create mux object from file %s.\n",
|
||||
(const W_CHAR*)filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int WriteData(const char* filename, const WebPData* const webpdata) {
|
||||
int ok = 0;
|
||||
FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb")
|
||||
: ImgIoUtilSetBinaryMode(stdout);
|
||||
FILE* fout = WSTRCMP(filename, "-") ? WFOPEN(filename, "wb")
|
||||
: ImgIoUtilSetBinaryMode(stdout);
|
||||
if (fout == NULL) {
|
||||
fprintf(stderr, "Error opening output WebP file %s!\n", filename);
|
||||
WFPRINTF(stderr, "Error opening output WebP file %s!\n",
|
||||
(const W_CHAR*)filename);
|
||||
return 0;
|
||||
}
|
||||
if (fwrite(webpdata->bytes, webpdata->size, 1, fout) != 1) {
|
||||
fprintf(stderr, "Error writing file %s!\n", filename);
|
||||
WFPRINTF(stderr, "Error writing file %s!\n", (const W_CHAR*)filename);
|
||||
} else {
|
||||
fprintf(stderr, "Saved file %s (%d bytes)\n",
|
||||
filename, (int)webpdata->size);
|
||||
WFPRINTF(stderr, "Saved file %s (%d bytes)\n",
|
||||
(const W_CHAR*)filename, (int)webpdata->size);
|
||||
ok = 1;
|
||||
}
|
||||
if (fout != stdout) fclose(fout);
|
||||
@ -595,26 +598,33 @@ static int ValidateCommandLine(const CommandLineArguments* const cmd_args,
|
||||
|
||||
#define FEATURETYPE_IS_NIL (config->type_ == NIL_FEATURE)
|
||||
|
||||
#define CHECK_NUM_ARGS_LESS(NUM, LABEL) \
|
||||
#define CHECK_NUM_ARGS_AT_LEAST(NUM, LABEL) \
|
||||
if (argc < i + (NUM)) { \
|
||||
fprintf(stderr, "ERROR: Too few arguments for '%s'.\n", argv[i]); \
|
||||
goto LABEL; \
|
||||
}
|
||||
|
||||
#define CHECK_NUM_ARGS_NOT_EQUAL(NUM, LABEL) \
|
||||
if (argc != i + (NUM)) { \
|
||||
#define CHECK_NUM_ARGS_AT_MOST(NUM, LABEL) \
|
||||
if (argc > i + (NUM)) { \
|
||||
fprintf(stderr, "ERROR: Too many arguments for '%s'.\n", argv[i]); \
|
||||
goto LABEL; \
|
||||
}
|
||||
|
||||
#define CHECK_NUM_ARGS_EXACTLY(NUM, LABEL) \
|
||||
CHECK_NUM_ARGS_AT_LEAST(NUM, LABEL); \
|
||||
CHECK_NUM_ARGS_AT_MOST(NUM, LABEL);
|
||||
|
||||
// Parses command-line arguments to fill up config object. Also performs some
|
||||
// semantic checks.
|
||||
static int ParseCommandLine(Config* config) {
|
||||
// semantic checks. unicode_argv contains wchar_t arguments or is null.
|
||||
static int ParseCommandLine(Config* config, const W_CHAR** const unicode_argv) {
|
||||
int i = 0;
|
||||
int feature_arg_index = 0;
|
||||
int ok = 1;
|
||||
int argc = config->cmd_args_.argc_;
|
||||
const char* const* argv = config->cmd_args_.argv_;
|
||||
// Unicode file paths will be used if available.
|
||||
const char* const* wargv =
|
||||
(unicode_argv != NULL) ? (const char**)(unicode_argv + 1) : argv;
|
||||
|
||||
while (i < argc) {
|
||||
FeatureArg* const arg = &config->args_[feature_arg_index];
|
||||
@ -627,7 +637,7 @@ static int ParseCommandLine(Config* config) {
|
||||
}
|
||||
++i;
|
||||
} else if (!strcmp(argv[i], "-duration")) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
if (ACTION_IS_NIL || config->action_type_ == ACTION_DURATION) {
|
||||
config->action_type_ = ACTION_DURATION;
|
||||
} else {
|
||||
@ -657,7 +667,7 @@ static int ParseCommandLine(Config* config) {
|
||||
}
|
||||
++i;
|
||||
} else if (!strcmp(argv[i], "-frame")) {
|
||||
CHECK_NUM_ARGS_LESS(3, ErrParse);
|
||||
CHECK_NUM_ARGS_AT_LEAST(3, ErrParse);
|
||||
if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) {
|
||||
config->action_type_ = ACTION_SET;
|
||||
} else {
|
||||
@ -674,7 +684,7 @@ static int ParseCommandLine(Config* config) {
|
||||
++feature_arg_index;
|
||||
i += 3;
|
||||
} else if (!strcmp(argv[i], "-loop") || !strcmp(argv[i], "-bgcolor")) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) {
|
||||
config->action_type_ = ACTION_SET;
|
||||
} else {
|
||||
@ -691,34 +701,36 @@ static int ParseCommandLine(Config* config) {
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else if (!strcmp(argv[i], "-o")) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
config->output_ = argv[i + 1];
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
config->output_ = wargv[i + 1];
|
||||
i += 2;
|
||||
} else if (!strcmp(argv[i], "-info")) {
|
||||
CHECK_NUM_ARGS_NOT_EQUAL(2, ErrParse);
|
||||
CHECK_NUM_ARGS_EXACTLY(2, ErrParse);
|
||||
if (config->action_type_ != NIL_ACTION) {
|
||||
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
|
||||
} else {
|
||||
config->action_type_ = ACTION_INFO;
|
||||
config->arg_count_ = 0;
|
||||
config->input_ = argv[i + 1];
|
||||
config->input_ = wargv[i + 1];
|
||||
}
|
||||
i += 2;
|
||||
} else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) {
|
||||
PrintHelp();
|
||||
DeleteConfig(config);
|
||||
LOCAL_FREE((W_CHAR** const)unicode_argv);
|
||||
exit(0);
|
||||
} else if (!strcmp(argv[i], "-version")) {
|
||||
const int version = WebPGetMuxVersion();
|
||||
printf("%d.%d.%d\n",
|
||||
(version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff);
|
||||
DeleteConfig(config);
|
||||
LOCAL_FREE((W_CHAR** const)unicode_argv);
|
||||
exit(0);
|
||||
} else if (!strcmp(argv[i], "--")) {
|
||||
if (i < argc - 1) {
|
||||
++i;
|
||||
if (config->input_ == NULL) {
|
||||
config->input_ = argv[i];
|
||||
config->input_ = wargv[i];
|
||||
} else {
|
||||
ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n",
|
||||
argv[i], ErrParse);
|
||||
@ -742,8 +754,8 @@ static int ParseCommandLine(Config* config) {
|
||||
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
|
||||
}
|
||||
if (config->action_type_ == ACTION_SET) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
arg->filename_ = argv[i + 1];
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
arg->filename_ = wargv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else {
|
||||
@ -751,14 +763,14 @@ static int ParseCommandLine(Config* config) {
|
||||
}
|
||||
} else if (!strcmp(argv[i], "frame") &&
|
||||
(config->action_type_ == ACTION_GET)) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
CHECK_NUM_ARGS_AT_LEAST(2, ErrParse);
|
||||
config->type_ = FEATURE_ANMF;
|
||||
arg->params_ = argv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else { // Assume input file.
|
||||
if (config->input_ == NULL) {
|
||||
config->input_ = argv[i];
|
||||
config->input_ = wargv[i];
|
||||
} else {
|
||||
ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n",
|
||||
argv[i], ErrParse);
|
||||
@ -804,8 +816,8 @@ static int ValidateConfig(Config* const config) {
|
||||
}
|
||||
|
||||
// Create config object from command-line arguments.
|
||||
static int InitializeConfig(int argc, const char* argv[],
|
||||
Config* const config) {
|
||||
static int InitializeConfig(int argc, const char* argv[], Config* const config,
|
||||
const W_CHAR** const unicode_argv) {
|
||||
int num_feature_args = 0;
|
||||
int ok;
|
||||
|
||||
@ -826,7 +838,7 @@ static int InitializeConfig(int argc, const char* argv[],
|
||||
}
|
||||
|
||||
// Parse command-line.
|
||||
if (!ParseCommandLine(config) || !ValidateConfig(config)) {
|
||||
if (!ParseCommandLine(config, unicode_argv) || !ValidateConfig(config)) {
|
||||
ERROR_GOTO1("Exiting due to command-line parsing error.\n", Err1);
|
||||
}
|
||||
|
||||
@ -836,8 +848,9 @@ static int InitializeConfig(int argc, const char* argv[],
|
||||
|
||||
#undef ACTION_IS_NIL
|
||||
#undef FEATURETYPE_IS_NIL
|
||||
#undef CHECK_NUM_ARGS_LESS
|
||||
#undef CHECK_NUM_ARGS_MORE
|
||||
#undef CHECK_NUM_ARGS_AT_LEAST
|
||||
#undef CHECK_NUM_ARGS_AT_MOST
|
||||
#undef CHECK_NUM_ARGS_EXACTLY
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Processing.
|
||||
@ -1135,14 +1148,18 @@ static int Process(const Config* config) {
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
Config config;
|
||||
int ok = InitializeConfig(argc - 1, argv + 1, &config);
|
||||
int ok;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
ok = InitializeConfig(argc - 1, argv + 1, &config, GET_WARGV_OR_NULL());
|
||||
if (ok) {
|
||||
ok = Process(&config);
|
||||
} else {
|
||||
PrintHelp();
|
||||
}
|
||||
DeleteConfig(&config);
|
||||
return !ok;
|
||||
FREE_WARGV_AND_RETURN(!ok);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -14,7 +14,7 @@ libwebpextras_la_LIBADD = ../src/libwebp.la
|
||||
|
||||
noinst_PROGRAMS =
|
||||
noinst_PROGRAMS += webp_quality
|
||||
if WANT_DEMUX
|
||||
if BUILD_DEMUX
|
||||
noinst_PROGRAMS += get_disto
|
||||
endif
|
||||
if BUILD_VWEBP_SDL
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#define XTRA_MAJ_VERSION 1
|
||||
#define XTRA_MIN_VERSION 0
|
||||
#define XTRA_REV_VERSION 0
|
||||
#define XTRA_REV_VERSION 2
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -67,4 +67,4 @@ WEBP_EXTERN int VP8EstimateQuality(const uint8_t* const data, size_t size);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_EXTRAS_EXTRAS_H_ */
|
||||
#endif // WEBP_EXTRAS_EXTRAS_H_
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "webp/encode.h"
|
||||
#include "imageio/image_dec.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
int keep_alpha) {
|
||||
@ -48,7 +49,8 @@ static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
|
||||
End:
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error! Could not process file %s\n", filename);
|
||||
WFPRINTF(stderr, "Error! Could not process file %s\n",
|
||||
(const W_CHAR*)filename);
|
||||
}
|
||||
free((void*)data);
|
||||
return ok ? data_size : 0;
|
||||
@ -239,9 +241,11 @@ int main(int argc, const char *argv[]) {
|
||||
const char* name2 = NULL;
|
||||
const char* output = NULL;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
if (!WebPPictureInit(&pic1) || !WebPPictureInit(&pic2)) {
|
||||
fprintf(stderr, "Can't init pictures\n");
|
||||
return 1;
|
||||
FREE_WARGV_AND_RETURN(1);
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
@ -263,11 +267,11 @@ int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "missing file name after %s option.\n", argv[c - 1]);
|
||||
goto End;
|
||||
}
|
||||
output = argv[c];
|
||||
output = (const char*)GET_WARGV(argv, c);
|
||||
} else if (name1 == NULL) {
|
||||
name1 = argv[c];
|
||||
name1 = (const char*)GET_WARGV(argv, c);
|
||||
} else {
|
||||
name2 = argv[c];
|
||||
name2 = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
}
|
||||
if (help || name1 == NULL || name2 == NULL) {
|
||||
@ -347,5 +351,5 @@ int main(int argc, const char *argv[]) {
|
||||
End:
|
||||
WebPPictureFree(&pic1);
|
||||
WebPPictureFree(&pic2);
|
||||
return ret;
|
||||
FREE_WARGV_AND_RETURN(ret);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "webp_to_sdl.h"
|
||||
#include "webp/decode.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
@ -51,29 +52,33 @@ static void ProcessEvents(void) {
|
||||
int main(int argc, char* argv[]) {
|
||||
int c;
|
||||
int ok = 0;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
const char* file = NULL;
|
||||
const uint8_t* webp = NULL;
|
||||
size_t webp_size = 0;
|
||||
if (!strcmp(argv[c], "-h")) {
|
||||
printf("Usage: %s [-h] image.webp [more_files.webp...]\n", argv[0]);
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
file = argv[c];
|
||||
file = (const char*)GET_WARGV(argv, c);
|
||||
}
|
||||
if (file == NULL) continue;
|
||||
if (!ImgIoUtilReadFile(file, &webp, &webp_size)) {
|
||||
fprintf(stderr, "Error opening file: %s\n", file);
|
||||
WFPRINTF(stderr, "Error opening file: %s\n", (const W_CHAR*)file);
|
||||
goto Error;
|
||||
}
|
||||
if (webp_size != (size_t)(int)webp_size) {
|
||||
free((void*)webp);
|
||||
fprintf(stderr, "File too large.\n");
|
||||
goto Error;
|
||||
}
|
||||
ok = WebpToSDL((const char*)webp, (int)webp_size);
|
||||
free((void*)webp);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error decoding file %s\n", file);
|
||||
WFPRINTF(stderr, "Error decoding file %s\n", (const W_CHAR*)file);
|
||||
goto Error;
|
||||
}
|
||||
ProcessEvents();
|
||||
@ -82,7 +87,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
Error:
|
||||
SDL_Quit();
|
||||
return ok ? 0 : 1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : 1);
|
||||
}
|
||||
|
||||
#else // !WEBP_HAVE_SDL
|
||||
|
@ -13,26 +13,30 @@
|
||||
|
||||
#include "extras/extras.h"
|
||||
#include "imageio/imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int c;
|
||||
int quiet = 0;
|
||||
int ok = 1;
|
||||
|
||||
INIT_WARGV(argc, argv);
|
||||
|
||||
for (c = 1; ok && c < argc; ++c) {
|
||||
if (!strcmp(argv[c], "-quiet")) {
|
||||
quiet = 1;
|
||||
} else if (!strcmp(argv[c], "-help") || !strcmp(argv[c], "-h")) {
|
||||
printf("webp_quality [-h][-quiet] webp_files...\n");
|
||||
return 0;
|
||||
FREE_WARGV_AND_RETURN(0);
|
||||
} else {
|
||||
const char* const filename = argv[c];
|
||||
const char* const filename = (const char*)GET_WARGV(argv, c);
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
int q;
|
||||
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
if (!ok) break;
|
||||
q = VP8EstimateQuality(data, data_size);
|
||||
if (!quiet) printf("[%s] ", filename);
|
||||
if (!quiet) WPRINTF("[%s] ", (const W_CHAR*)filename);
|
||||
if (q < 0) {
|
||||
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n");
|
||||
ok = 0;
|
||||
@ -46,5 +50,5 @@ int main(int argc, const char *argv[]) {
|
||||
free((void*)data);
|
||||
}
|
||||
}
|
||||
return ok ? 0 : 1;
|
||||
FREE_WARGV_AND_RETURN(ok ? 0 : 1);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ int WebpToSDL(const char* data, unsigned int data_size) {
|
||||
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!init_ok) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
noinst_LTLIBRARIES =
|
||||
noinst_LTLIBRARIES += libimageio_util.la
|
||||
if WANT_DEMUX
|
||||
if BUILD_DEMUX
|
||||
noinst_LTLIBRARIES += libimagedec.la
|
||||
endif
|
||||
noinst_LTLIBRARIES += libimageenc.la
|
||||
|
@ -29,11 +29,13 @@
|
||||
// code with COBJMACROS.
|
||||
#include <ole2.h> // CreateStreamOnHGlobal()
|
||||
#include <shlwapi.h>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <wincodec.h>
|
||||
#endif
|
||||
|
||||
#include "./imageio_util.h"
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PNG
|
||||
@ -61,11 +63,12 @@ static HRESULT CreateOutputStream(const char* out_file_name,
|
||||
// Output to a memory buffer. This is freed when 'stream' is released.
|
||||
IFS(CreateStreamOnHGlobal(NULL, TRUE, stream));
|
||||
} else {
|
||||
IFS(SHCreateStreamOnFileA(out_file_name, STGM_WRITE | STGM_CREATE, stream));
|
||||
IFS(SHCreateStreamOnFile((const LPTSTR)out_file_name,
|
||||
STGM_WRITE | STGM_CREATE, stream));
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
fprintf(stderr, "Error opening output file %s (%08lx)\n",
|
||||
out_file_name, hr);
|
||||
_ftprintf(stderr, _T("Error opening output file %s (%08lx)\n"),
|
||||
(const LPTSTR)out_file_name, hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
@ -549,7 +552,8 @@ int WebPSaveImage(const WebPDecBuffer* const buffer,
|
||||
const char* const out_file_name) {
|
||||
FILE* fout = NULL;
|
||||
int needs_open_file = 1;
|
||||
const int use_stdout = (out_file_name != NULL) && !strcmp(out_file_name, "-");
|
||||
const int use_stdout =
|
||||
(out_file_name != NULL) && !WSTRCMP(out_file_name, "-");
|
||||
int ok = 1;
|
||||
|
||||
if (buffer == NULL || out_file_name == NULL) return 0;
|
||||
@ -560,9 +564,10 @@ int WebPSaveImage(const WebPDecBuffer* const buffer,
|
||||
|
||||
if (needs_open_file) {
|
||||
fout = use_stdout ? ImgIoUtilSetBinaryMode(stdout)
|
||||
: fopen(out_file_name, "wb");
|
||||
: WFOPEN(out_file_name, "wb");
|
||||
if (fout == NULL) {
|
||||
fprintf(stderr, "Error opening output file %s\n", out_file_name);
|
||||
WFPRINTF(stderr, "Error opening output file %s\n",
|
||||
(const W_CHAR*)out_file_name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "../examples/unicode.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File I/O
|
||||
@ -73,7 +74,7 @@ int ImgIoUtilReadFile(const char* const file_name,
|
||||
uint8_t* file_data;
|
||||
size_t file_size;
|
||||
FILE* in;
|
||||
const int from_stdin = (file_name == NULL) || !strcmp(file_name, "-");
|
||||
const int from_stdin = (file_name == NULL) || !WSTRCMP(file_name, "-");
|
||||
|
||||
if (from_stdin) return ImgIoUtilReadFromStdin(data, data_size);
|
||||
|
||||
@ -81,9 +82,9 @@ int ImgIoUtilReadFile(const char* const file_name,
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
|
||||
in = fopen(file_name, "rb");
|
||||
in = WFOPEN(file_name, "rb");
|
||||
if (in == NULL) {
|
||||
fprintf(stderr, "cannot open input file '%s'\n", file_name);
|
||||
WFPRINTF(stderr, "cannot open input file '%s'\n", (const W_CHAR*)file_name);
|
||||
return 0;
|
||||
}
|
||||
fseek(in, 0, SEEK_END);
|
||||
@ -93,16 +94,16 @@ int ImgIoUtilReadFile(const char* const file_name,
|
||||
file_data = (uint8_t*)malloc(file_size + 1);
|
||||
if (file_data == NULL) {
|
||||
fclose(in);
|
||||
fprintf(stderr, "memory allocation failure when reading file %s\n",
|
||||
file_name);
|
||||
WFPRINTF(stderr, "memory allocation failure when reading file %s\n",
|
||||
(const W_CHAR*)file_name);
|
||||
return 0;
|
||||
}
|
||||
ok = (fread(file_data, file_size, 1, in) == 1);
|
||||
fclose(in);
|
||||
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Could not read %d bytes of data from file %s\n",
|
||||
(int)file_size, file_name);
|
||||
WFPRINTF(stderr, "Could not read %d bytes of data from file %s\n",
|
||||
(int)file_size, (const W_CHAR*)file_name);
|
||||
free(file_data);
|
||||
return 0;
|
||||
}
|
||||
@ -118,14 +119,15 @@ int ImgIoUtilWriteFile(const char* const file_name,
|
||||
const uint8_t* data, size_t data_size) {
|
||||
int ok;
|
||||
FILE* out;
|
||||
const int to_stdout = (file_name == NULL) || !strcmp(file_name, "-");
|
||||
const int to_stdout = (file_name == NULL) || !WSTRCMP(file_name, "-");
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
out = to_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(file_name, "wb");
|
||||
out = to_stdout ? ImgIoUtilSetBinaryMode(stdout) : WFOPEN(file_name, "wb");
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "Error! Cannot open output file '%s'\n", file_name);
|
||||
WFPRINTF(stderr, "Error! Cannot open output file '%s'\n",
|
||||
(const W_CHAR*)file_name);
|
||||
return 0;
|
||||
}
|
||||
ok = (fwrite(data, data_size, 1, out) == 1);
|
||||
|
@ -18,6 +18,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WEBP_HAVE_PNG
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
#define PNG_USER_MEM_SUPPORTED // for png_create_read_struct_2
|
||||
#endif
|
||||
#include <png.h>
|
||||
#include <setjmp.h> // note: this must be included *after* png.h
|
||||
#include <stdlib.h>
|
||||
@ -27,11 +30,33 @@
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
#define LOCAL_PNG_VERSION ((PNG_LIBPNG_VER_MAJOR << 8) | PNG_LIBPNG_VER_MINOR)
|
||||
#define LOCAL_PNG_PREREQ(maj, min) \
|
||||
(LOCAL_PNG_VERSION >= (((maj) << 8) | (min)))
|
||||
|
||||
static void PNGAPI error_function(png_structp png, png_const_charp error) {
|
||||
if (error != NULL) fprintf(stderr, "libpng error: %s\n", error);
|
||||
longjmp(png_jmpbuf(png), 1);
|
||||
}
|
||||
|
||||
#if LOCAL_PNG_PREREQ(1,4)
|
||||
typedef png_alloc_size_t LocalPngAllocSize;
|
||||
#else
|
||||
typedef png_size_t LocalPngAllocSize;
|
||||
#endif
|
||||
|
||||
static png_voidp MallocFunc(png_structp png_ptr, LocalPngAllocSize size) {
|
||||
(void)png_ptr;
|
||||
if (size != (size_t)size) return NULL;
|
||||
if (!ImgIoUtilCheckSizeArgumentsOverflow(size, 1)) return NULL;
|
||||
return (png_voidp)malloc((size_t)size);
|
||||
}
|
||||
|
||||
static void FreeFunc(png_structp png_ptr, png_voidp ptr) {
|
||||
(void)png_ptr;
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
// Converts the NULL terminated 'hexstring' which contains 2-byte character
|
||||
// representations of hex values to raw data.
|
||||
// 'hexstring' may contain values consisting of [A-F][a-f][0-9] in pairs,
|
||||
@ -171,11 +196,10 @@ static int ExtractMetadataFromPNG(png_structp png,
|
||||
{
|
||||
png_charp name;
|
||||
int comp_type;
|
||||
#if ((PNG_LIBPNG_VER_MAJOR << 8) | PNG_LIBPNG_VER_MINOR << 0) < \
|
||||
((1 << 8) | (5 << 0))
|
||||
png_charp profile;
|
||||
#else // >= libpng 1.5.0
|
||||
#if LOCAL_PNG_PREREQ(1,5)
|
||||
png_bytep profile;
|
||||
#else
|
||||
png_charp profile;
|
||||
#endif
|
||||
png_uint_32 len;
|
||||
|
||||
@ -224,7 +248,8 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
|
||||
context.data = data;
|
||||
context.data_size = data_size;
|
||||
|
||||
png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
|
||||
png = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL,
|
||||
NULL, MallocFunc, FreeFunc);
|
||||
if (png == NULL) goto End;
|
||||
|
||||
png_set_error_fn(png, 0, error_function, NULL);
|
||||
|
@ -121,7 +121,6 @@ static tsize_t MyRead(thandle_t opaque, void* dst, tsize_t size) {
|
||||
// (we don't want to force a dependency to a libdspdec library).
|
||||
#define MFIX 24 // 24bit fixed-point arithmetic
|
||||
#define HALF ((1u << MFIX) >> 1)
|
||||
#define KINV_255 ((1u << MFIX) / 255u)
|
||||
|
||||
static uint32_t Unmult(uint8_t x, uint32_t mult) {
|
||||
const uint32_t v = (x * mult + HALF) >> MFIX;
|
||||
@ -132,6 +131,9 @@ static WEBP_INLINE uint32_t GetScale(uint32_t a) {
|
||||
return (255u << MFIX) / a;
|
||||
}
|
||||
|
||||
#undef MFIX
|
||||
#undef HALF
|
||||
|
||||
static void MultARGBRow(uint8_t* ptr, int width) {
|
||||
int x;
|
||||
for (x = 0; x < width; ++x, ptr += 4) {
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "webp/decode.h"
|
||||
#include "webp/demux.h"
|
||||
#include "webp/encode.h"
|
||||
#include "../examples/unicode.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
@ -43,7 +44,7 @@ static void PrintAnimationWarning(const WebPDecoderConfig* const config) {
|
||||
}
|
||||
|
||||
void PrintWebPError(const char* const in_file, int status) {
|
||||
fprintf(stderr, "Decoding of %s failed.\n", in_file);
|
||||
WFPRINTF(stderr, "Decoding of %s failed.\n", (const W_CHAR*)in_file);
|
||||
fprintf(stderr, "Status: %d", status);
|
||||
if (status >= VP8_STATUS_OK && status <= VP8_STATUS_NOT_ENOUGH_DATA) {
|
||||
fprintf(stderr, "(%s)", kStatusMessages[status]);
|
||||
|
@ -29,12 +29,14 @@
|
||||
// code with COBJMACROS.
|
||||
#include <ole2.h> // CreateStreamOnHGlobal()
|
||||
#include <shlwapi.h>
|
||||
#include <tchar.h>
|
||||
#include <windows.h>
|
||||
#include <wincodec.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "../examples/unicode.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#define IFS(fn) \
|
||||
do { \
|
||||
@ -85,7 +87,7 @@ WEBP_DEFINE_GUID(GUID_WICPixelFormat64bppRGBA_,
|
||||
|
||||
static HRESULT OpenInputStream(const char* filename, IStream** stream) {
|
||||
HRESULT hr = S_OK;
|
||||
if (!strcmp(filename, "-")) {
|
||||
if (!WSTRCMP(filename, "-")) {
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
const int ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
@ -108,11 +110,12 @@ static HRESULT OpenInputStream(const char* filename, IStream** stream) {
|
||||
hr = E_FAIL;
|
||||
}
|
||||
} else {
|
||||
IFS(SHCreateStreamOnFileA(filename, STGM_READ, stream));
|
||||
IFS(SHCreateStreamOnFile((const LPTSTR)filename, STGM_READ, stream));
|
||||
}
|
||||
|
||||
if (FAILED(hr)) {
|
||||
fprintf(stderr, "Error opening input file %s (%08lx)\n", filename, hr);
|
||||
_ftprintf(stderr, _T("Error opening input file %s (%08lx)\n"),
|
||||
(const LPTSTR)filename, hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
@ -89,12 +89,6 @@ EXTRA_FLAGS += -DWEBP_HAVE_SSE41
|
||||
src/dsp/%_sse41.o: EXTRA_FLAGS += -msse4.1
|
||||
endif
|
||||
|
||||
# AVX2-specific flags:
|
||||
ifeq ($(HAVE_AVX2), 1)
|
||||
EXTRA_FLAGS += -DWEBP_HAVE_AVX2
|
||||
src/dsp/%_avx2.o: EXTRA_FLAGS += -mavx2
|
||||
endif
|
||||
|
||||
# NEON-specific flags:
|
||||
# EXTRA_FLAGS += -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a8
|
||||
# -> seems to make the overall lib slower: -fno-split-wide-types
|
||||
@ -191,9 +185,9 @@ DSP_ENC_OBJS = \
|
||||
src/dsp/cost.o \
|
||||
src/dsp/cost_mips32.o \
|
||||
src/dsp/cost_mips_dsp_r2.o \
|
||||
src/dsp/cost_neon.o \
|
||||
src/dsp/cost_sse2.o \
|
||||
src/dsp/enc.o \
|
||||
src/dsp/enc_avx2.o \
|
||||
src/dsp/enc_mips32.o \
|
||||
src/dsp/enc_mips_dsp_r2.o \
|
||||
src/dsp/enc_msa.o \
|
||||
@ -392,7 +386,7 @@ src/demux/libwebpdemux.a: $(LIBWEBPDEMUX_OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
examples/anim_diff: examples/anim_diff.o $(ANIM_UTIL_OBJS) $(GIFDEC_OBJS)
|
||||
examples/anim_dump: examples/anim_dump.o $(ANIM_UTIL_OBJS)
|
||||
examples/anim_dump: examples/anim_dump.o $(ANIM_UTIL_OBJS) $(GIFDEC_OBJS)
|
||||
examples/cwebp: examples/cwebp.o
|
||||
examples/dwebp: examples/dwebp.o
|
||||
examples/gif2webp: examples/gif2webp.o $(GIFDEC_OBJS)
|
||||
@ -406,7 +400,7 @@ examples/anim_diff: src/demux/libwebpdemux.a examples/libexample_util.a
|
||||
examples/anim_diff: imageio/libimageio_util.a src/libwebp.a
|
||||
examples/anim_diff: EXTRA_LIBS += $(GIF_LIBS)
|
||||
examples/anim_diff: EXTRA_FLAGS += -DWEBP_HAVE_GIF
|
||||
examples/anim_dump: examples/libanim_util.a
|
||||
examples/anim_dump: examples/libanim_util.a examples/libgifdec.a
|
||||
examples/anim_dump: src/demux/libwebpdemux.a
|
||||
examples/anim_dump: examples/libexample_util.a
|
||||
examples/anim_dump: imageio/libimageio_util.a
|
||||
|
@ -1,10 +1,13 @@
|
||||
man_MANS = cwebp.1 dwebp.1
|
||||
if WANT_MUX
|
||||
if BUILD_MUX
|
||||
man_MANS += webpmux.1
|
||||
endif
|
||||
if BUILD_GIF2WEBP
|
||||
man_MANS += gif2webp.1
|
||||
endif
|
||||
if BUILD_IMG2WEBP
|
||||
man_MANS += img2webp.1
|
||||
endif
|
||||
if BUILD_VWEBP
|
||||
man_MANS += vwebp.1
|
||||
endif
|
||||
|
12
man/cwebp.1
12
man/cwebp.1
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH CWEBP 1 "January 20, 2017"
|
||||
.TH CWEBP 1 "January 11, 2019"
|
||||
.SH NAME
|
||||
cwebp \- compress an image file to a WebP file
|
||||
.SH SYNOPSIS
|
||||
@ -41,10 +41,12 @@ the invisible pixel values (R/G/B or Y/U/V) will be preserved only if the
|
||||
\-exact option is used.
|
||||
.TP
|
||||
.BI \-near_lossless " int
|
||||
Use near\-lossless image preprocessing. This option adjusts pixel values
|
||||
to help compressibility, but has minimal impact on the visual quality.
|
||||
It triggers lossless compression mode automatically.
|
||||
Range is 0 (maximum preprocessing) to 100 (no preprocessing, the default).
|
||||
Specify the level of near\-lossless image preprocessing. This option adjusts
|
||||
pixel values to help compressibility, but has minimal impact on the visual
|
||||
quality. It triggers lossless compression mode automatically. The range is 0
|
||||
(maximum preprocessing) to 100 (no preprocessing, the default). The typical
|
||||
value is around 60. Note that lossy with \fB\-q 100\fP can at times yield
|
||||
better results.
|
||||
.TP
|
||||
.BI \-q " float
|
||||
Specify the compression factor for RGB channels between 0 and 100. The default
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH VWEBP 1 "November 25, 2016"
|
||||
.TH VWEBP 1 "July 20, 2018"
|
||||
.SH NAME
|
||||
vwebp \- decompress a WebP file and display it in a window
|
||||
.SH SYNOPSIS
|
||||
@ -38,6 +38,10 @@ It helps by smoothing gradients and avoiding banding artifacts. Default: 50.
|
||||
By default, quantized transparency planes are dithered during decompression,
|
||||
to smooth the gradients. This flag will prevent this dithering.
|
||||
.TP
|
||||
.B \-usebgcolor
|
||||
Fill transparent areas with the bitstream's own background color instead of
|
||||
checkerboard only. Default is white for non-animated images.
|
||||
.TP
|
||||
.B \-mt
|
||||
Use multi-threading for decoding, if possible.
|
||||
.TP
|
||||
@ -56,6 +60,9 @@ the data will be read from \fIstdin\fP instead of a file.
|
||||
.B 'c'
|
||||
Toggle use of color profile.
|
||||
.TP
|
||||
.B 'b'
|
||||
Toggle display of background color.
|
||||
.TP
|
||||
.B 'i'
|
||||
Overlay file information.
|
||||
.TP
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH WEBPMUX 1 "December 1, 2017"
|
||||
.TH WEBPMUX 1 "April 23, 2018"
|
||||
.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.
|
||||
@ -58,7 +58,7 @@ command.
|
||||
\fBwebpmux\fP can be used to create/extract from animated WebP files, as well as
|
||||
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 argument are actually tokenized from this file.
|
||||
the argument, the command line arguments are actually tokenized from this file.
|
||||
This allows for easy scripting or using large number of arguments.
|
||||
.SH OPTIONS
|
||||
.SS GET_OPTIONS (\-get):
|
||||
|
@ -1,10 +1,10 @@
|
||||
# The mux and demux libraries depend on libwebp, thus the '.' to force
|
||||
# the build order so it's available to them.
|
||||
SUBDIRS = dec enc dsp utils .
|
||||
if WANT_MUX
|
||||
if BUILD_MUX
|
||||
SUBDIRS += mux
|
||||
endif
|
||||
if WANT_DEMUX
|
||||
if BUILD_DEMUX
|
||||
SUBDIRS += demux
|
||||
endif
|
||||
|
||||
@ -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:2:0
|
||||
libwebp_la_LDFLAGS = -no-undefined -version-info 7:4:0
|
||||
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:2:0
|
||||
libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 3:4:0
|
||||
pkgconfig_DATA += libwebpdecoder.pc
|
||||
endif
|
||||
|
||||
|
@ -51,4 +51,4 @@ void WebPDeallocateAlphaMemory(VP8Decoder* const dec);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DEC_ALPHAI_DEC_H_ */
|
||||
#endif // WEBP_DEC_ALPHAI_DEC_H_
|
||||
|
@ -74,7 +74,8 @@ static VP8StatusCode CheckDecBuffer(const WebPDecBuffer* const buffer) {
|
||||
} else { // RGB checks
|
||||
const WebPRGBABuffer* const buf = &buffer->u.RGBA;
|
||||
const int stride = abs(buf->stride);
|
||||
const uint64_t size = MIN_BUFFER_SIZE(width, height, stride);
|
||||
const uint64_t size =
|
||||
MIN_BUFFER_SIZE(width * kModeBpp[mode], height, stride);
|
||||
ok &= (size <= buf->size);
|
||||
ok &= (stride >= width * kModeBpp[mode]);
|
||||
ok &= (buf->rgba != NULL);
|
||||
|
@ -51,4 +51,4 @@ enum { MB_FEATURE_TREE_PROBS = 3,
|
||||
NUM_PROBAS = 11
|
||||
};
|
||||
|
||||
#endif // WEBP_DEC_COMMON_DEC_H_
|
||||
#endif // WEBP_DEC_COMMON_DEC_H_
|
||||
|
@ -338,7 +338,6 @@ void VP8InitDithering(const WebPDecoderOptions* const options,
|
||||
for (s = 0; s < NUM_MB_SEGMENTS; ++s) {
|
||||
VP8QuantMatrix* const dqm = &dec->dqm_[s];
|
||||
if (dqm->uv_quant_ < DITHER_AMP_TAB_SIZE) {
|
||||
// TODO(skal): should we specially dither more for uv_quant_ < 0?
|
||||
const int idx = (dqm->uv_quant_ < 0) ? 0 : dqm->uv_quant_;
|
||||
dqm->dither_ = (f * kQuantToDitherAmp[idx]) >> 3;
|
||||
}
|
||||
@ -669,15 +668,9 @@ int VP8GetThreadMethod(const WebPDecoderOptions* const options,
|
||||
(void)height;
|
||||
assert(headers == NULL || !headers->is_lossless);
|
||||
#if defined(WEBP_USE_THREAD)
|
||||
if (width < MIN_WIDTH_FOR_THREADS) return 0;
|
||||
// TODO(skal): tune the heuristic further
|
||||
#if 0
|
||||
if (height < 2 * width) return 2;
|
||||
if (width >= MIN_WIDTH_FOR_THREADS) return 2;
|
||||
#endif
|
||||
return 2;
|
||||
#else // !WEBP_USE_THREAD
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef MT_CACHE_LINES
|
||||
|
@ -140,10 +140,9 @@ static void DoRemap(WebPIDecoder* const idec, ptrdiff_t offset) {
|
||||
if (NeedCompressedAlpha(idec)) {
|
||||
ALPHDecoder* const alph_dec = dec->alph_dec_;
|
||||
dec->alpha_data_ += offset;
|
||||
if (alph_dec != NULL) {
|
||||
if (alph_dec != NULL && alph_dec->vp8l_dec_ != NULL) {
|
||||
if (alph_dec->method_ == ALPHA_LOSSLESS_COMPRESSION) {
|
||||
VP8LDecoder* const alph_vp8l_dec = alph_dec->vp8l_dec_;
|
||||
assert(alph_vp8l_dec != NULL);
|
||||
assert(dec->alpha_data_size_ >= ALPHA_HEADER_LEN);
|
||||
VP8LBitReaderSetBuffer(&alph_vp8l_dec->br_,
|
||||
dec->alpha_data_ + ALPHA_HEADER_LEN,
|
||||
@ -283,10 +282,8 @@ static void RestoreContext(const MBContext* context, VP8Decoder* const dec,
|
||||
|
||||
static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) {
|
||||
if (idec->state_ == STATE_VP8_DATA) {
|
||||
VP8Io* const io = &idec->io_;
|
||||
if (io->teardown != NULL) {
|
||||
io->teardown(io);
|
||||
}
|
||||
// Synchronize the thread, clean-up and check for errors.
|
||||
VP8ExitCritical((VP8Decoder*)idec->dec_, &idec->io_);
|
||||
}
|
||||
idec->state_ = STATE_ERROR;
|
||||
return error;
|
||||
@ -451,7 +448,10 @@ static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) {
|
||||
VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
||||
VP8Io* const io = &idec->io_;
|
||||
|
||||
assert(dec->ready_);
|
||||
// Make sure partition #0 has been read before, to set dec to ready_.
|
||||
if (!dec->ready_) {
|
||||
return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
|
||||
}
|
||||
for (; dec->mb_y_ < dec->mb_h_; ++dec->mb_y_) {
|
||||
if (idec->last_mb_y_ != dec->mb_y_) {
|
||||
if (!VP8ParseIntraModeRow(&dec->br_, dec)) {
|
||||
@ -473,6 +473,12 @@ static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) {
|
||||
MemDataSize(&idec->mem_) > MAX_MB_SIZE) {
|
||||
return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
|
||||
}
|
||||
// Synchronize the threads.
|
||||
if (dec->mt_method_ > 0) {
|
||||
if (!WebPGetWorkerInterface()->Sync(&dec->worker_)) {
|
||||
return IDecError(idec, VP8_STATUS_BITSTREAM_ERROR);
|
||||
}
|
||||
}
|
||||
RestoreContext(&context, dec, token_br);
|
||||
return VP8_STATUS_SUSPENDED;
|
||||
}
|
||||
@ -491,6 +497,7 @@ static VP8StatusCode DecodeRemaining(WebPIDecoder* const idec) {
|
||||
}
|
||||
// Synchronize the thread and check for errors.
|
||||
if (!VP8ExitCritical(dec, io)) {
|
||||
idec->state_ = STATE_ERROR; // prevent re-entry in IDecError
|
||||
return IDecError(idec, VP8_STATUS_USER_ABORT);
|
||||
}
|
||||
dec->ready_ = 0;
|
||||
@ -571,6 +578,10 @@ static VP8StatusCode IDecode(WebPIDecoder* idec) {
|
||||
status = DecodePartition0(idec);
|
||||
}
|
||||
if (idec->state_ == STATE_VP8_DATA) {
|
||||
const VP8Decoder* const dec = (VP8Decoder*)idec->dec_;
|
||||
if (dec == NULL) {
|
||||
return VP8_STATUS_SUSPENDED; // can't continue if we have no decoder.
|
||||
}
|
||||
status = DecodeRemaining(idec);
|
||||
}
|
||||
if (idec->state_ == STATE_VP8L_HEADER) {
|
||||
|
@ -182,4 +182,4 @@ WEBP_EXTERN int VP8LGetInfo(
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DEC_VP8_DEC_H_ */
|
||||
#endif // WEBP_DEC_VP8_DEC_H_
|
||||
|
@ -32,7 +32,7 @@ extern "C" {
|
||||
// version numbers
|
||||
#define DEC_MAJ_VERSION 1
|
||||
#define DEC_MIN_VERSION 0
|
||||
#define DEC_REV_VERSION 0
|
||||
#define DEC_REV_VERSION 2
|
||||
|
||||
// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline).
|
||||
// Constraints are: We need to store one 16x16 block of luma samples (y),
|
||||
@ -316,4 +316,4 @@ const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DEC_VP8I_DEC_H_ */
|
||||
#endif // WEBP_DEC_VP8I_DEC_H_
|
||||
|
@ -362,12 +362,19 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
VP8LMetadata* const hdr = &dec->hdr_;
|
||||
uint32_t* huffman_image = NULL;
|
||||
HTreeGroup* htree_groups = NULL;
|
||||
// When reading htrees, some might be unused, as the format allows it.
|
||||
// We will still read them but put them in this htree_group_bogus.
|
||||
HTreeGroup htree_group_bogus;
|
||||
HuffmanCode* huffman_tables = NULL;
|
||||
HuffmanCode* huffman_tables_bogus = NULL;
|
||||
HuffmanCode* next = NULL;
|
||||
int num_htree_groups = 1;
|
||||
int num_htree_groups_max = 1;
|
||||
int max_alphabet_size = 0;
|
||||
int* code_lengths = NULL;
|
||||
const int table_size = kTableSize[color_cache_bits];
|
||||
int* mapping = NULL;
|
||||
int ok = 0;
|
||||
|
||||
if (allow_recursion && VP8LReadBits(br, 1)) {
|
||||
// use meta Huffman codes.
|
||||
@ -384,10 +391,42 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
// The huffman data is stored in red and green bytes.
|
||||
const int group = (huffman_image[i] >> 8) & 0xffff;
|
||||
huffman_image[i] = group;
|
||||
if (group >= num_htree_groups) {
|
||||
num_htree_groups = group + 1;
|
||||
if (group >= num_htree_groups_max) {
|
||||
num_htree_groups_max = group + 1;
|
||||
}
|
||||
}
|
||||
// Check the validity of num_htree_groups_max. If it seems too big, use a
|
||||
// smaller value for later. This will prevent big memory allocations to end
|
||||
// up with a bad bitstream anyway.
|
||||
// The value of 1000 is totally arbitrary. We know that num_htree_groups_max
|
||||
// is smaller than (1 << 16) and should be smaller than the number of pixels
|
||||
// (though the format allows it to be bigger).
|
||||
if (num_htree_groups_max > 1000 || num_htree_groups_max > xsize * ysize) {
|
||||
// Create a mapping from the used indices to the minimal set of used
|
||||
// values [0, num_htree_groups)
|
||||
mapping = (int*)WebPSafeMalloc(num_htree_groups_max, sizeof(*mapping));
|
||||
if (mapping == NULL) {
|
||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
// -1 means a value is unmapped, and therefore unused in the Huffman
|
||||
// image.
|
||||
memset(mapping, 0xff, num_htree_groups_max * sizeof(*mapping));
|
||||
for (num_htree_groups = 0, i = 0; i < huffman_pixs; ++i) {
|
||||
// Get the current mapping for the group and remap the Huffman image.
|
||||
int* const mapped_group = &mapping[huffman_image[i]];
|
||||
if (*mapped_group == -1) *mapped_group = num_htree_groups++;
|
||||
huffman_image[i] = *mapped_group;
|
||||
}
|
||||
huffman_tables_bogus = (HuffmanCode*)WebPSafeMalloc(
|
||||
table_size, sizeof(*huffman_tables_bogus));
|
||||
if (huffman_tables_bogus == NULL) {
|
||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
} else {
|
||||
num_htree_groups = num_htree_groups_max;
|
||||
}
|
||||
}
|
||||
|
||||
if (br->eos_) goto Error;
|
||||
@ -403,11 +442,11 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
}
|
||||
}
|
||||
|
||||
code_lengths = (int*)WebPSafeCalloc((uint64_t)max_alphabet_size,
|
||||
sizeof(*code_lengths));
|
||||
huffman_tables = (HuffmanCode*)WebPSafeMalloc(num_htree_groups * table_size,
|
||||
sizeof(*huffman_tables));
|
||||
htree_groups = VP8LHtreeGroupsNew(num_htree_groups);
|
||||
code_lengths = (int*)WebPSafeCalloc((uint64_t)max_alphabet_size,
|
||||
sizeof(*code_lengths));
|
||||
|
||||
if (htree_groups == NULL || code_lengths == NULL || huffman_tables == NULL) {
|
||||
dec->status_ = VP8_STATUS_OUT_OF_MEMORY;
|
||||
@ -415,28 +454,35 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
}
|
||||
|
||||
next = huffman_tables;
|
||||
for (i = 0; i < num_htree_groups; ++i) {
|
||||
HTreeGroup* const htree_group = &htree_groups[i];
|
||||
for (i = 0; i < num_htree_groups_max; ++i) {
|
||||
// If the index "i" is unused in the Huffman image, read the coefficients
|
||||
// but store them to a bogus htree_group.
|
||||
const int is_bogus = (mapping != NULL && mapping[i] == -1);
|
||||
HTreeGroup* const htree_group =
|
||||
is_bogus ? &htree_group_bogus :
|
||||
&htree_groups[(mapping == NULL) ? i : mapping[i]];
|
||||
HuffmanCode** const htrees = htree_group->htrees;
|
||||
HuffmanCode* huffman_tables_i = is_bogus ? huffman_tables_bogus : next;
|
||||
int size;
|
||||
int total_size = 0;
|
||||
int is_trivial_literal = 1;
|
||||
int max_bits = 0;
|
||||
for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) {
|
||||
int alphabet_size = kAlphabetSize[j];
|
||||
htrees[j] = next;
|
||||
htrees[j] = huffman_tables_i;
|
||||
if (j == 0 && color_cache_bits > 0) {
|
||||
alphabet_size += 1 << color_cache_bits;
|
||||
}
|
||||
size = ReadHuffmanCode(alphabet_size, dec, code_lengths, next);
|
||||
size =
|
||||
ReadHuffmanCode(alphabet_size, dec, code_lengths, huffman_tables_i);
|
||||
if (size == 0) {
|
||||
goto Error;
|
||||
}
|
||||
if (is_trivial_literal && kLiteralMap[j] == 1) {
|
||||
is_trivial_literal = (next->bits == 0);
|
||||
is_trivial_literal = (huffman_tables_i->bits == 0);
|
||||
}
|
||||
total_size += next->bits;
|
||||
next += size;
|
||||
total_size += huffman_tables_i->bits;
|
||||
huffman_tables_i += size;
|
||||
if (j <= ALPHA) {
|
||||
int local_max_bits = code_lengths[0];
|
||||
int k;
|
||||
@ -448,38 +494,41 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
max_bits += local_max_bits;
|
||||
}
|
||||
}
|
||||
if (!is_bogus) next = huffman_tables_i;
|
||||
htree_group->is_trivial_literal = is_trivial_literal;
|
||||
htree_group->is_trivial_code = 0;
|
||||
if (is_trivial_literal) {
|
||||
const int red = htrees[RED][0].value;
|
||||
const int blue = htrees[BLUE][0].value;
|
||||
const int alpha = htrees[ALPHA][0].value;
|
||||
htree_group->literal_arb =
|
||||
((uint32_t)alpha << 24) | (red << 16) | blue;
|
||||
htree_group->literal_arb = ((uint32_t)alpha << 24) | (red << 16) | blue;
|
||||
if (total_size == 0 && htrees[GREEN][0].value < NUM_LITERAL_CODES) {
|
||||
htree_group->is_trivial_code = 1;
|
||||
htree_group->literal_arb |= htrees[GREEN][0].value << 8;
|
||||
}
|
||||
}
|
||||
htree_group->use_packed_table = !htree_group->is_trivial_code &&
|
||||
(max_bits < HUFFMAN_PACKED_BITS);
|
||||
htree_group->use_packed_table =
|
||||
!htree_group->is_trivial_code && (max_bits < HUFFMAN_PACKED_BITS);
|
||||
if (htree_group->use_packed_table) BuildPackedTable(htree_group);
|
||||
}
|
||||
WebPSafeFree(code_lengths);
|
||||
ok = 1;
|
||||
|
||||
// All OK. Finalize pointers and return.
|
||||
// All OK. Finalize pointers.
|
||||
hdr->huffman_image_ = huffman_image;
|
||||
hdr->num_htree_groups_ = num_htree_groups;
|
||||
hdr->htree_groups_ = htree_groups;
|
||||
hdr->huffman_tables_ = huffman_tables;
|
||||
return 1;
|
||||
|
||||
Error:
|
||||
WebPSafeFree(code_lengths);
|
||||
WebPSafeFree(huffman_image);
|
||||
WebPSafeFree(huffman_tables);
|
||||
VP8LHtreeGroupsFree(htree_groups);
|
||||
return 0;
|
||||
WebPSafeFree(huffman_tables_bogus);
|
||||
WebPSafeFree(mapping);
|
||||
if (!ok) {
|
||||
WebPSafeFree(huffman_image);
|
||||
WebPSafeFree(huffman_tables);
|
||||
VP8LHtreeGroupsFree(htree_groups);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -884,7 +933,11 @@ static WEBP_INLINE void CopyBlock8b(uint8_t* const dst, int dist, int length) {
|
||||
#endif
|
||||
break;
|
||||
case 2:
|
||||
#if !defined(WORDS_BIGENDIAN)
|
||||
memcpy(&pattern, src, sizeof(uint16_t));
|
||||
#else
|
||||
pattern = ((uint32_t)src[0] << 8) | src[1];
|
||||
#endif
|
||||
#if defined(__arm__) || defined(_M_ARM)
|
||||
pattern |= pattern << 16;
|
||||
#elif defined(WEBP_USE_MIPS_DSP_R2)
|
||||
@ -1523,7 +1576,6 @@ int VP8LDecodeAlphaHeader(ALPHDecoder* const alph_dec,
|
||||
if (dec == NULL) return 0;
|
||||
|
||||
assert(alph_dec != NULL);
|
||||
alph_dec->vp8l_dec_ = dec;
|
||||
|
||||
dec->width_ = alph_dec->width_;
|
||||
dec->height_ = alph_dec->height_;
|
||||
@ -1555,11 +1607,12 @@ int VP8LDecodeAlphaHeader(ALPHDecoder* const alph_dec,
|
||||
|
||||
if (!ok) goto Err;
|
||||
|
||||
// Only set here, once we are sure it is valid (to avoid thread races).
|
||||
alph_dec->vp8l_dec_ = dec;
|
||||
return 1;
|
||||
|
||||
Err:
|
||||
VP8LDelete(alph_dec->vp8l_dec_);
|
||||
alph_dec->vp8l_dec_ = NULL;
|
||||
VP8LDelete(dec);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -132,4 +132,4 @@ void VP8LDelete(VP8LDecoder* const dec);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DEC_VP8LI_DEC_H_ */
|
||||
#endif // WEBP_DEC_VP8LI_DEC_H_
|
||||
|
@ -130,4 +130,4 @@ int WebPAvoidSlowMemory(const WebPDecBuffer* const output,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DEC_WEBPI_DEC_H_ */
|
||||
#endif // WEBP_DEC_WEBPI_DEC_H_
|
||||
|
@ -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:4:0
|
||||
libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:6:0
|
||||
libwebpdemuxincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebpdemux.pc
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#define DMUX_MAJ_VERSION 1
|
||||
#define DMUX_MIN_VERSION 0
|
||||
#define DMUX_REV_VERSION 0
|
||||
#define DMUX_REV_VERSION 2
|
||||
|
||||
typedef struct {
|
||||
size_t start_; // start location of the data
|
||||
|
@ -6,8 +6,8 @@
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,0,0,0
|
||||
PRODUCTVERSION 1,0,0,0
|
||||
FILEVERSION 1,0,0,2
|
||||
PRODUCTVERSION 1,0,0,2
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
@ -24,12 +24,12 @@ BEGIN
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebpdemux DLL"
|
||||
VALUE "FileVersion", "1.0.0"
|
||||
VALUE "FileVersion", "1.0.2"
|
||||
VALUE "InternalName", "libwebpdemux.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2018"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2019"
|
||||
VALUE "OriginalFilename", "libwebpdemux.dll"
|
||||
VALUE "ProductName", "WebP Image Demuxer"
|
||||
VALUE "ProductVersion", "1.0.0"
|
||||
VALUE "ProductVersion", "1.0.2"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
@ -1,7 +1,6 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir) -I$(top_srcdir)
|
||||
noinst_LTLIBRARIES =
|
||||
noinst_LTLIBRARIES += libwebpdsp.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_avx2.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_sse2.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_sse2.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_sse41.la
|
||||
@ -10,6 +9,10 @@ noinst_LTLIBRARIES += libwebpdsp_neon.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_neon.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_msa.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_msa.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_mips32.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_mips32.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_mips_dsp_r2.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_mips_dsp_r2.la
|
||||
|
||||
if BUILD_LIBWEBPDECODER
|
||||
noinst_LTLIBRARIES += libwebpdspdecode.la
|
||||
@ -20,48 +23,26 @@ commondir = $(includedir)/webp
|
||||
|
||||
COMMON_SOURCES =
|
||||
COMMON_SOURCES += alpha_processing.c
|
||||
COMMON_SOURCES += alpha_processing_mips_dsp_r2.c
|
||||
COMMON_SOURCES += common_sse2.h
|
||||
COMMON_SOURCES += cpu.c
|
||||
COMMON_SOURCES += dec.c
|
||||
COMMON_SOURCES += dec_clip_tables.c
|
||||
COMMON_SOURCES += dec_mips32.c
|
||||
COMMON_SOURCES += dec_mips_dsp_r2.c
|
||||
COMMON_SOURCES += dsp.h
|
||||
COMMON_SOURCES += filters.c
|
||||
COMMON_SOURCES += filters_mips_dsp_r2.c
|
||||
COMMON_SOURCES += lossless.c
|
||||
COMMON_SOURCES += lossless.h
|
||||
COMMON_SOURCES += lossless_common.h
|
||||
COMMON_SOURCES += lossless_mips_dsp_r2.c
|
||||
COMMON_SOURCES += mips_macro.h
|
||||
COMMON_SOURCES += rescaler.c
|
||||
COMMON_SOURCES += rescaler_mips32.c
|
||||
COMMON_SOURCES += rescaler_mips_dsp_r2.c
|
||||
COMMON_SOURCES += upsampling.c
|
||||
COMMON_SOURCES += upsampling_mips_dsp_r2.c
|
||||
COMMON_SOURCES += yuv.c
|
||||
COMMON_SOURCES += yuv.h
|
||||
COMMON_SOURCES += yuv_mips32.c
|
||||
COMMON_SOURCES += yuv_mips_dsp_r2.c
|
||||
|
||||
ENC_SOURCES =
|
||||
ENC_SOURCES += cost.c
|
||||
ENC_SOURCES += cost_mips32.c
|
||||
ENC_SOURCES += cost_mips_dsp_r2.c
|
||||
ENC_SOURCES += enc.c
|
||||
ENC_SOURCES += enc_mips32.c
|
||||
ENC_SOURCES += enc_mips_dsp_r2.c
|
||||
ENC_SOURCES += lossless_enc.c
|
||||
ENC_SOURCES += lossless_enc_mips32.c
|
||||
ENC_SOURCES += lossless_enc_mips_dsp_r2.c
|
||||
ENC_SOURCES += quant.h
|
||||
ENC_SOURCES += ssim.c
|
||||
|
||||
libwebpdsp_avx2_la_SOURCES =
|
||||
libwebpdsp_avx2_la_SOURCES += enc_avx2.c
|
||||
libwebpdsp_avx2_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_avx2_la_CFLAGS = $(AM_CFLAGS) $(AVX2_FLAGS)
|
||||
|
||||
libwebpdspdecode_sse41_la_SOURCES =
|
||||
libwebpdspdecode_sse41_la_SOURCES += alpha_processing_sse41.c
|
||||
libwebpdspdecode_sse41_la_SOURCES += dec_sse41.c
|
||||
@ -72,6 +53,7 @@ libwebpdspdecode_sse41_la_CFLAGS = $(AM_CFLAGS) $(SSE41_FLAGS)
|
||||
|
||||
libwebpdspdecode_sse2_la_SOURCES =
|
||||
libwebpdspdecode_sse2_la_SOURCES += alpha_processing_sse2.c
|
||||
libwebpdspdecode_sse2_la_SOURCES += common_sse2.h
|
||||
libwebpdspdecode_sse2_la_SOURCES += dec_sse2.c
|
||||
libwebpdspdecode_sse2_la_SOURCES += filters_sse2.c
|
||||
libwebpdspdecode_sse2_la_SOURCES += lossless_sse2.c
|
||||
@ -103,6 +85,26 @@ libwebpdspdecode_msa_la_SOURCES += upsampling_msa.c
|
||||
libwebpdspdecode_msa_la_CPPFLAGS = $(libwebpdsp_msa_la_CPPFLAGS)
|
||||
libwebpdspdecode_msa_la_CFLAGS = $(libwebpdsp_msa_la_CFLAGS)
|
||||
|
||||
libwebpdspdecode_mips32_la_SOURCES =
|
||||
libwebpdspdecode_mips32_la_SOURCES += dec_mips32.c
|
||||
libwebpdspdecode_mips32_la_SOURCES += mips_macro.h
|
||||
libwebpdspdecode_mips32_la_SOURCES += rescaler_mips32.c
|
||||
libwebpdspdecode_mips32_la_SOURCES += yuv_mips32.c
|
||||
libwebpdspdecode_mips32_la_CPPFLAGS = $(libwebpdsp_mips32_la_CPPFLAGS)
|
||||
libwebpdspdecode_mips32_la_CFLAGS = $(libwebpdsp_mips32_la_CFLAGS)
|
||||
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES =
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += alpha_processing_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += dec_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += filters_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += lossless_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += mips_macro.h
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += rescaler_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += upsampling_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_SOURCES += yuv_mips_dsp_r2.c
|
||||
libwebpdspdecode_mips_dsp_r2_la_CPPFLAGS = $(libwebpdsp_mips_dsp_r2_la_CPPFLAGS)
|
||||
libwebpdspdecode_mips_dsp_r2_la_CFLAGS = $(libwebpdsp_mips_dsp_r2_la_CFLAGS)
|
||||
|
||||
libwebpdsp_sse2_la_SOURCES =
|
||||
libwebpdsp_sse2_la_SOURCES += cost_sse2.c
|
||||
libwebpdsp_sse2_la_SOURCES += enc_sse2.c
|
||||
@ -120,6 +122,7 @@ libwebpdsp_sse41_la_CFLAGS = $(AM_CFLAGS) $(SSE41_FLAGS)
|
||||
libwebpdsp_sse41_la_LIBADD = libwebpdspdecode_sse41.la
|
||||
|
||||
libwebpdsp_neon_la_SOURCES =
|
||||
libwebpdsp_neon_la_SOURCES += cost_neon.c
|
||||
libwebpdsp_neon_la_SOURCES += enc_neon.c
|
||||
libwebpdsp_neon_la_SOURCES += lossless_enc_neon.c
|
||||
libwebpdsp_neon_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
@ -133,6 +136,22 @@ libwebpdsp_msa_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_msa_la_CFLAGS = $(AM_CFLAGS)
|
||||
libwebpdsp_msa_la_LIBADD = libwebpdspdecode_msa.la
|
||||
|
||||
libwebpdsp_mips32_la_SOURCES =
|
||||
libwebpdsp_mips32_la_SOURCES += cost_mips32.c
|
||||
libwebpdsp_mips32_la_SOURCES += enc_mips32.c
|
||||
libwebpdsp_mips32_la_SOURCES += lossless_enc_mips32.c
|
||||
libwebpdsp_mips32_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_mips32_la_CFLAGS = $(AM_CFLAGS)
|
||||
libwebpdsp_mips32_la_LIBADD = libwebpdspdecode_mips32.la
|
||||
|
||||
libwebpdsp_mips_dsp_r2_la_SOURCES =
|
||||
libwebpdsp_mips_dsp_r2_la_SOURCES += cost_mips_dsp_r2.c
|
||||
libwebpdsp_mips_dsp_r2_la_SOURCES += enc_mips_dsp_r2.c
|
||||
libwebpdsp_mips_dsp_r2_la_SOURCES += lossless_enc_mips_dsp_r2.c
|
||||
libwebpdsp_mips_dsp_r2_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_mips_dsp_r2_la_CFLAGS = $(AM_CFLAGS)
|
||||
libwebpdsp_mips_dsp_r2_la_LIBADD = libwebpdspdecode_mips_dsp_r2.la
|
||||
|
||||
libwebpdsp_la_SOURCES = $(COMMON_SOURCES) $(ENC_SOURCES)
|
||||
|
||||
noinst_HEADERS =
|
||||
@ -144,11 +163,12 @@ libwebpdsp_la_CPPFLAGS += $(AM_CPPFLAGS)
|
||||
libwebpdsp_la_CPPFLAGS += $(USE_SWAP_16BIT_CSP)
|
||||
libwebpdsp_la_LDFLAGS = -lm
|
||||
libwebpdsp_la_LIBADD =
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_avx2.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_sse2.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_sse41.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_neon.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_msa.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_mips32.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_mips_dsp_r2.la
|
||||
|
||||
if BUILD_LIBWEBPDECODER
|
||||
libwebpdspdecode_la_SOURCES = $(COMMON_SOURCES)
|
||||
@ -160,4 +180,6 @@ if BUILD_LIBWEBPDECODER
|
||||
libwebpdspdecode_la_LIBADD += libwebpdspdecode_sse41.la
|
||||
libwebpdspdecode_la_LIBADD += libwebpdspdecode_neon.la
|
||||
libwebpdspdecode_la_LIBADD += libwebpdspdecode_msa.la
|
||||
libwebpdspdecode_la_LIBADD += libwebpdspdecode_mips32.la
|
||||
libwebpdspdecode_la_LIBADD += libwebpdspdecode_mips_dsp_r2.la
|
||||
endif
|
||||
|
@ -377,6 +377,7 @@ VP8SetResidualCoeffsFunc VP8SetResidualCoeffs;
|
||||
extern void VP8EncDspCostInitMIPS32(void);
|
||||
extern void VP8EncDspCostInitMIPSdspR2(void);
|
||||
extern void VP8EncDspCostInitSSE2(void);
|
||||
extern void VP8EncDspCostInitNEON(void);
|
||||
|
||||
WEBP_DSP_INIT_FUNC(VP8EncDspCostInit) {
|
||||
VP8GetResidualCost = GetResidualCost_C;
|
||||
@ -398,6 +399,11 @@ WEBP_DSP_INIT_FUNC(VP8EncDspCostInit) {
|
||||
if (VP8GetCPUInfo(kSSE2)) {
|
||||
VP8EncDspCostInitSSE2();
|
||||
}
|
||||
#endif
|
||||
#if defined(WEBP_USE_NEON)
|
||||
if (VP8GetCPUInfo(kNEON)) {
|
||||
VP8EncDspCostInitNEON();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
122
src/dsp/cost_neon.c
Normal file
122
src/dsp/cost_neon.c
Normal file
@ -0,0 +1,122 @@
|
||||
// Copyright 2018 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// ARM NEON version of cost functions
|
||||
|
||||
#include "src/dsp/dsp.h"
|
||||
|
||||
#if defined(WEBP_USE_NEON)
|
||||
|
||||
#include "src/dsp/neon.h"
|
||||
#include "src/enc/cost_enc.h"
|
||||
|
||||
static const uint8_t position[16] = { 1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 13, 14, 15, 16 };
|
||||
|
||||
static void SetResidualCoeffs_NEON(const int16_t* const coeffs,
|
||||
VP8Residual* const res) {
|
||||
const int16x8_t minus_one = vdupq_n_s16(-1);
|
||||
const int16x8_t coeffs_0 = vld1q_s16(coeffs);
|
||||
const int16x8_t coeffs_1 = vld1q_s16(coeffs + 8);
|
||||
const uint16x8_t eob_0 = vtstq_s16(coeffs_0, minus_one);
|
||||
const uint16x8_t eob_1 = vtstq_s16(coeffs_1, minus_one);
|
||||
const uint8x16_t eob = vcombine_u8(vqmovn_u16(eob_0), vqmovn_u16(eob_1));
|
||||
const uint8x16_t masked = vandq_u8(eob, vld1q_u8(position));
|
||||
|
||||
#ifdef __aarch64__
|
||||
res->last = vmaxvq_u8(masked) - 1;
|
||||
#else
|
||||
const uint8x8_t eob_8x8 = vmax_u8(vget_low_u8(masked), vget_high_u8(masked));
|
||||
const uint16x8_t eob_16x8 = vmovl_u8(eob_8x8);
|
||||
const uint16x4_t eob_16x4 =
|
||||
vmax_u16(vget_low_u16(eob_16x8), vget_high_u16(eob_16x8));
|
||||
const uint32x4_t eob_32x4 = vmovl_u16(eob_16x4);
|
||||
uint32x2_t eob_32x2 =
|
||||
vmax_u32(vget_low_u32(eob_32x4), vget_high_u32(eob_32x4));
|
||||
eob_32x2 = vpmax_u32(eob_32x2, eob_32x2);
|
||||
|
||||
vst1_lane_s32(&res->last, vreinterpret_s32_u32(eob_32x2), 0);
|
||||
--res->last;
|
||||
#endif // __aarch64__
|
||||
|
||||
res->coeffs = coeffs;
|
||||
}
|
||||
|
||||
static int GetResidualCost_NEON(int ctx0, const VP8Residual* const res) {
|
||||
uint8_t levels[16], ctxs[16];
|
||||
uint16_t abs_levels[16];
|
||||
int n = res->first;
|
||||
// should be prob[VP8EncBands[n]], but it's equivalent for n=0 or 1
|
||||
const int p0 = res->prob[n][ctx0][0];
|
||||
CostArrayPtr const costs = res->costs;
|
||||
const uint16_t* t = costs[n][ctx0];
|
||||
// bit_cost(1, p0) is already incorporated in t[] tables, but only if ctx != 0
|
||||
// (as required by the syntax). For ctx0 == 0, we need to add it here or it'll
|
||||
// be missing during the loop.
|
||||
int cost = (ctx0 == 0) ? VP8BitCost(1, p0) : 0;
|
||||
|
||||
if (res->last < 0) {
|
||||
return VP8BitCost(0, p0);
|
||||
}
|
||||
|
||||
{ // precompute clamped levels and contexts, packed to 8b.
|
||||
const uint8x16_t kCst2 = vdupq_n_u8(2);
|
||||
const uint8x16_t kCst67 = vdupq_n_u8(MAX_VARIABLE_LEVEL);
|
||||
const int16x8_t c0 = vld1q_s16(res->coeffs);
|
||||
const int16x8_t c1 = vld1q_s16(res->coeffs + 8);
|
||||
const uint16x8_t E0 = vreinterpretq_u16_s16(vabsq_s16(c0));
|
||||
const uint16x8_t E1 = vreinterpretq_u16_s16(vabsq_s16(c1));
|
||||
const uint8x16_t F = vcombine_u8(vqmovn_u16(E0), vqmovn_u16(E1));
|
||||
const uint8x16_t G = vminq_u8(F, kCst2); // context = 0,1,2
|
||||
const uint8x16_t H = vminq_u8(F, kCst67); // clamp_level in [0..67]
|
||||
|
||||
vst1q_u8(ctxs, G);
|
||||
vst1q_u8(levels, H);
|
||||
|
||||
vst1q_u16(abs_levels, E0);
|
||||
vst1q_u16(abs_levels + 8, E1);
|
||||
}
|
||||
for (; n < res->last; ++n) {
|
||||
const int ctx = ctxs[n];
|
||||
const int level = levels[n];
|
||||
const int flevel = abs_levels[n]; // full level
|
||||
cost += VP8LevelFixedCosts[flevel] + t[level]; // simplified VP8LevelCost()
|
||||
t = costs[n + 1][ctx];
|
||||
}
|
||||
// Last coefficient is always non-zero
|
||||
{
|
||||
const int level = levels[n];
|
||||
const int flevel = abs_levels[n];
|
||||
assert(flevel != 0);
|
||||
cost += VP8LevelFixedCosts[flevel] + t[level];
|
||||
if (n < 15) {
|
||||
const int b = VP8EncBands[n + 1];
|
||||
const int ctx = ctxs[n];
|
||||
const int last_p0 = res->prob[b][ctx][0];
|
||||
cost += VP8BitCost(0, last_p0);
|
||||
}
|
||||
}
|
||||
return cost;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Entry point
|
||||
|
||||
extern void VP8EncDspCostInitNEON(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspCostInitNEON(void) {
|
||||
VP8SetResidualCoeffs = SetResidualCoeffs_NEON;
|
||||
VP8GetResidualCost = GetResidualCost_NEON;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_NEON
|
||||
|
||||
WEBP_DSP_INIT_STUB(VP8EncDspCostInitNEON)
|
||||
|
||||
#endif // WEBP_USE_NEON
|
@ -76,10 +76,6 @@ extern "C" {
|
||||
#define WEBP_USE_SSE41
|
||||
#endif
|
||||
|
||||
#if defined(__AVX2__) || defined(WEBP_HAVE_AVX2)
|
||||
#define WEBP_USE_AVX2
|
||||
#endif
|
||||
|
||||
// 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__) || \
|
||||
@ -679,4 +675,4 @@ void VP8FiltersInit(void);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DSP_DSP_H_ */
|
||||
#endif // WEBP_DSP_DSP_H_
|
||||
|
@ -734,7 +734,6 @@ VP8BlockCopy VP8Copy16x8;
|
||||
|
||||
extern void VP8EncDspInitSSE2(void);
|
||||
extern void VP8EncDspInitSSE41(void);
|
||||
extern void VP8EncDspInitAVX2(void);
|
||||
extern void VP8EncDspInitNEON(void);
|
||||
extern void VP8EncDspInitMIPS32(void);
|
||||
extern void VP8EncDspInitMIPSdspR2(void);
|
||||
@ -784,11 +783,6 @@ WEBP_DSP_INIT_FUNC(VP8EncDspInit) {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined(WEBP_USE_AVX2)
|
||||
if (VP8GetCPUInfo(kAVX2)) {
|
||||
VP8EncDspInitAVX2();
|
||||
}
|
||||
#endif
|
||||
#if defined(WEBP_USE_MIPS32)
|
||||
if (VP8GetCPUInfo(kMIPS32)) {
|
||||
VP8EncDspInitMIPS32();
|
||||
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2014 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// AVX2 version of speed-critical encoding functions.
|
||||
|
||||
#include "src/dsp/dsp.h"
|
||||
|
||||
#if defined(WEBP_USE_AVX2)
|
||||
|
||||
#endif // WEBP_USE_AVX2
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Entry point
|
||||
|
||||
WEBP_DSP_INIT_STUB(VP8EncDspInitAVX2)
|
@ -23,8 +23,6 @@
|
||||
#include "src/dsp/lossless.h"
|
||||
#include "src/dsp/lossless_common.h"
|
||||
|
||||
#define MAX_DIFF_COST (1e30f)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Image transforms.
|
||||
|
||||
|
@ -163,7 +163,7 @@ extern VP8LCostCombinedFunc VP8LExtraCostCombined;
|
||||
extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
|
||||
|
||||
typedef struct { // small struct to hold counters
|
||||
int counts[2]; // index: 0=zero steak, 1=non-zero streak
|
||||
int counts[2]; // index: 0=zero streak, 1=non-zero streak
|
||||
int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]
|
||||
} VP8LStreaks;
|
||||
|
||||
@ -194,10 +194,14 @@ extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
|
||||
void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,
|
||||
VP8LBitEntropy* const entropy);
|
||||
|
||||
typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
VP8LHistogram* const out);
|
||||
extern VP8LHistogramAddFunc VP8LHistogramAdd;
|
||||
typedef void (*VP8LAddVectorFunc)(const uint32_t* a, const uint32_t* b,
|
||||
uint32_t* out, int size);
|
||||
extern VP8LAddVectorFunc VP8LAddVector;
|
||||
typedef void (*VP8LAddVectorEqFunc)(const uint32_t* a, uint32_t* out, int size);
|
||||
extern VP8LAddVectorEqFunc VP8LAddVectorEq;
|
||||
void VP8LHistogramAdd(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
VP8LHistogram* const out);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// PrefixEncode()
|
||||
|
@ -632,38 +632,67 @@ static double ExtraCostCombined_C(const uint32_t* X, const uint32_t* Y,
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static void HistogramAdd_C(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
VP8LHistogram* const out) {
|
||||
static void AddVector_C(const uint32_t* a, const uint32_t* b, uint32_t* out,
|
||||
int size) {
|
||||
int i;
|
||||
for (i = 0; i < size; ++i) out[i] = a[i] + b[i];
|
||||
}
|
||||
|
||||
static void AddVectorEq_C(const uint32_t* a, uint32_t* out, int size) {
|
||||
int i;
|
||||
for (i = 0; i < size; ++i) out[i] += a[i];
|
||||
}
|
||||
|
||||
#define ADD(X, ARG, LEN) do { \
|
||||
if (a->is_used_[X]) { \
|
||||
if (b->is_used_[X]) { \
|
||||
VP8LAddVector(a->ARG, b->ARG, out->ARG, (LEN)); \
|
||||
} else { \
|
||||
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||
} \
|
||||
} else if (b->is_used_[X]) { \
|
||||
memcpy(&out->ARG[0], &b->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||
} else { \
|
||||
memset(&out->ARG[0], 0, (LEN) * sizeof(out->ARG[0])); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ADD_EQ(X, ARG, LEN) do { \
|
||||
if (a->is_used_[X]) { \
|
||||
if (out->is_used_[X]) { \
|
||||
VP8LAddVectorEq(a->ARG, out->ARG, (LEN)); \
|
||||
} else { \
|
||||
memcpy(&out->ARG[0], &a->ARG[0], (LEN) * sizeof(out->ARG[0])); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void VP8LHistogramAdd(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b, VP8LHistogram* const out) {
|
||||
int i;
|
||||
const int literal_size = VP8LHistogramNumCodes(a->palette_code_bits_);
|
||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
||||
|
||||
if (b != out) {
|
||||
for (i = 0; i < literal_size; ++i) {
|
||||
out->literal_[i] = a->literal_[i] + b->literal_[i];
|
||||
}
|
||||
for (i = 0; i < NUM_DISTANCE_CODES; ++i) {
|
||||
out->distance_[i] = a->distance_[i] + b->distance_[i];
|
||||
}
|
||||
for (i = 0; i < NUM_LITERAL_CODES; ++i) {
|
||||
out->red_[i] = a->red_[i] + b->red_[i];
|
||||
out->blue_[i] = a->blue_[i] + b->blue_[i];
|
||||
out->alpha_[i] = a->alpha_[i] + b->alpha_[i];
|
||||
ADD(0, literal_, literal_size);
|
||||
ADD(1, red_, NUM_LITERAL_CODES);
|
||||
ADD(2, blue_, NUM_LITERAL_CODES);
|
||||
ADD(3, alpha_, NUM_LITERAL_CODES);
|
||||
ADD(4, distance_, NUM_DISTANCE_CODES);
|
||||
for (i = 0; i < 5; ++i) {
|
||||
out->is_used_[i] = (a->is_used_[i] | b->is_used_[i]);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < literal_size; ++i) {
|
||||
out->literal_[i] += a->literal_[i];
|
||||
}
|
||||
for (i = 0; i < NUM_DISTANCE_CODES; ++i) {
|
||||
out->distance_[i] += a->distance_[i];
|
||||
}
|
||||
for (i = 0; i < NUM_LITERAL_CODES; ++i) {
|
||||
out->red_[i] += a->red_[i];
|
||||
out->blue_[i] += a->blue_[i];
|
||||
out->alpha_[i] += a->alpha_[i];
|
||||
}
|
||||
ADD_EQ(0, literal_, literal_size);
|
||||
ADD_EQ(1, red_, NUM_LITERAL_CODES);
|
||||
ADD_EQ(2, blue_, NUM_LITERAL_CODES);
|
||||
ADD_EQ(3, alpha_, NUM_LITERAL_CODES);
|
||||
ADD_EQ(4, distance_, NUM_DISTANCE_CODES);
|
||||
for (i = 0; i < 5; ++i) out->is_used_[i] |= a->is_used_[i];
|
||||
}
|
||||
}
|
||||
#undef ADD
|
||||
#undef ADD_EQ
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Image transforms.
|
||||
@ -848,7 +877,8 @@ VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
|
||||
VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
|
||||
VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
|
||||
|
||||
VP8LHistogramAddFunc VP8LHistogramAdd;
|
||||
VP8LAddVectorFunc VP8LAddVector;
|
||||
VP8LAddVectorEqFunc VP8LAddVectorEq;
|
||||
|
||||
VP8LVectorMismatchFunc VP8LVectorMismatch;
|
||||
VP8LBundleColorMapFunc VP8LBundleColorMap;
|
||||
@ -885,7 +915,8 @@ WEBP_DSP_INIT_FUNC(VP8LEncDspInit) {
|
||||
VP8LGetEntropyUnrefined = GetEntropyUnrefined_C;
|
||||
VP8LGetCombinedEntropyUnrefined = GetCombinedEntropyUnrefined_C;
|
||||
|
||||
VP8LHistogramAdd = HistogramAdd_C;
|
||||
VP8LAddVector = AddVector_C;
|
||||
VP8LAddVectorEq = AddVectorEq_C;
|
||||
|
||||
VP8LVectorMismatch = VectorMismatch_C;
|
||||
VP8LBundleColorMap = VP8LBundleColorMap_C;
|
||||
@ -971,7 +1002,8 @@ WEBP_DSP_INIT_FUNC(VP8LEncDspInit) {
|
||||
assert(VP8LCombinedShannonEntropy != NULL);
|
||||
assert(VP8LGetEntropyUnrefined != NULL);
|
||||
assert(VP8LGetCombinedEntropyUnrefined != NULL);
|
||||
assert(VP8LHistogramAdd != NULL);
|
||||
assert(VP8LAddVector != NULL);
|
||||
assert(VP8LAddVectorEq != NULL);
|
||||
assert(VP8LVectorMismatch != NULL);
|
||||
assert(VP8LBundleColorMap != NULL);
|
||||
assert(VP8LPredictorsSub[0] != NULL);
|
||||
|
@ -344,65 +344,29 @@ static void GetCombinedEntropyUnrefined_MIPS32(const uint32_t X[],
|
||||
ASM_END_COMMON_0 \
|
||||
ASM_END_COMMON_1
|
||||
|
||||
#define ADD_VECTOR(A, B, OUT, SIZE, EXTRA_SIZE) do { \
|
||||
const uint32_t* pa = (const uint32_t*)(A); \
|
||||
const uint32_t* pb = (const uint32_t*)(B); \
|
||||
uint32_t* pout = (uint32_t*)(OUT); \
|
||||
const uint32_t* const LoopEnd = pa + (SIZE); \
|
||||
assert((SIZE) % 4 == 0); \
|
||||
ASM_START \
|
||||
ADD_TO_OUT(0, 4, 8, 12, 1, pa, pb, pout) \
|
||||
ASM_END_0 \
|
||||
if ((EXTRA_SIZE) > 0) { \
|
||||
const int last = (EXTRA_SIZE); \
|
||||
int i; \
|
||||
for (i = 0; i < last; ++i) pout[i] = pa[i] + pb[i]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ADD_VECTOR_EQ(A, OUT, SIZE, EXTRA_SIZE) do { \
|
||||
const uint32_t* pa = (const uint32_t*)(A); \
|
||||
uint32_t* pout = (uint32_t*)(OUT); \
|
||||
const uint32_t* const LoopEnd = pa + (SIZE); \
|
||||
assert((SIZE) % 4 == 0); \
|
||||
ASM_START \
|
||||
ADD_TO_OUT(0, 4, 8, 12, 0, pa, pout, pout) \
|
||||
ASM_END_1 \
|
||||
if ((EXTRA_SIZE) > 0) { \
|
||||
const int last = (EXTRA_SIZE); \
|
||||
int i; \
|
||||
for (i = 0; i < last; ++i) pout[i] += pa[i]; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void HistogramAdd_MIPS32(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
VP8LHistogram* const out) {
|
||||
static void AddVector_MIPS32(const uint32_t* pa, const uint32_t* pb,
|
||||
uint32_t* pout, int size) {
|
||||
uint32_t temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
|
||||
const int extra_cache_size = VP8LHistogramNumCodes(a->palette_code_bits_)
|
||||
- (NUM_LITERAL_CODES + NUM_LENGTH_CODES);
|
||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
||||
|
||||
if (b != out) {
|
||||
ADD_VECTOR(a->literal_, b->literal_, out->literal_,
|
||||
NUM_LITERAL_CODES + NUM_LENGTH_CODES, extra_cache_size);
|
||||
ADD_VECTOR(a->distance_, b->distance_, out->distance_,
|
||||
NUM_DISTANCE_CODES, 0);
|
||||
ADD_VECTOR(a->red_, b->red_, out->red_, NUM_LITERAL_CODES, 0);
|
||||
ADD_VECTOR(a->blue_, b->blue_, out->blue_, NUM_LITERAL_CODES, 0);
|
||||
ADD_VECTOR(a->alpha_, b->alpha_, out->alpha_, NUM_LITERAL_CODES, 0);
|
||||
} else {
|
||||
ADD_VECTOR_EQ(a->literal_, out->literal_,
|
||||
NUM_LITERAL_CODES + NUM_LENGTH_CODES, extra_cache_size);
|
||||
ADD_VECTOR_EQ(a->distance_, out->distance_, NUM_DISTANCE_CODES, 0);
|
||||
ADD_VECTOR_EQ(a->red_, out->red_, NUM_LITERAL_CODES, 0);
|
||||
ADD_VECTOR_EQ(a->blue_, out->blue_, NUM_LITERAL_CODES, 0);
|
||||
ADD_VECTOR_EQ(a->alpha_, out->alpha_, NUM_LITERAL_CODES, 0);
|
||||
}
|
||||
const uint32_t end = ((size) / 4) * 4;
|
||||
const uint32_t* const LoopEnd = pa + end;
|
||||
int i;
|
||||
ASM_START
|
||||
ADD_TO_OUT(0, 4, 8, 12, 1, pa, pb, pout)
|
||||
ASM_END_0
|
||||
for (i = end; i < size; ++i) pout[i] = pa[i] + pb[i];
|
||||
}
|
||||
|
||||
static void AddVectorEq_MIPS32(const uint32_t* pa, uint32_t* pout, int size) {
|
||||
uint32_t temp0, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
|
||||
const uint32_t end = ((size) / 4) * 4;
|
||||
const uint32_t* const LoopEnd = pa + end;
|
||||
int i;
|
||||
ASM_START
|
||||
ADD_TO_OUT(0, 4, 8, 12, 0, pa, pout, pout)
|
||||
ASM_END_1
|
||||
for (i = end; i < size; ++i) pout[i] += pa[i];
|
||||
}
|
||||
|
||||
#undef ADD_VECTOR_EQ
|
||||
#undef ADD_VECTOR
|
||||
#undef ASM_END_1
|
||||
#undef ASM_END_0
|
||||
#undef ASM_END_COMMON_1
|
||||
@ -422,7 +386,8 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitMIPS32(void) {
|
||||
VP8LExtraCostCombined = ExtraCostCombined_MIPS32;
|
||||
VP8LGetEntropyUnrefined = GetEntropyUnrefined_MIPS32;
|
||||
VP8LGetCombinedEntropyUnrefined = GetCombinedEntropyUnrefined_MIPS32;
|
||||
VP8LHistogramAdd = HistogramAdd_MIPS32;
|
||||
VP8LAddVector = AddVector_MIPS32;
|
||||
VP8LAddVectorEq = AddVectorEq_MIPS32;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_MIPS32
|
||||
|
@ -170,12 +170,13 @@ static void CollectColorRedTransforms_SSE2(const uint32_t* argb, int stride,
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Note we are adding uint32_t's as *signed* int32's (using _mm_add_epi32). But
|
||||
// that's ok since the histogram values are less than 1<<28 (max picture size).
|
||||
#define LINE_SIZE 16 // 8 or 16
|
||||
static void AddVector_SSE2(const uint32_t* a, const uint32_t* b, uint32_t* out,
|
||||
int size) {
|
||||
int i;
|
||||
assert(size % LINE_SIZE == 0);
|
||||
for (i = 0; i < size; i += LINE_SIZE) {
|
||||
for (i = 0; i + LINE_SIZE <= size; i += LINE_SIZE) {
|
||||
const __m128i a0 = _mm_loadu_si128((const __m128i*)&a[i + 0]);
|
||||
const __m128i a1 = _mm_loadu_si128((const __m128i*)&a[i + 4]);
|
||||
#if (LINE_SIZE == 16)
|
||||
@ -195,12 +196,14 @@ static void AddVector_SSE2(const uint32_t* a, const uint32_t* b, uint32_t* out,
|
||||
_mm_storeu_si128((__m128i*)&out[i + 12], _mm_add_epi32(a3, b3));
|
||||
#endif
|
||||
}
|
||||
for (; i < size; ++i) {
|
||||
out[i] = a[i] + b[i];
|
||||
}
|
||||
}
|
||||
|
||||
static void AddVectorEq_SSE2(const uint32_t* a, uint32_t* out, int size) {
|
||||
int i;
|
||||
assert(size % LINE_SIZE == 0);
|
||||
for (i = 0; i < size; i += LINE_SIZE) {
|
||||
for (i = 0; i + LINE_SIZE <= size; i += LINE_SIZE) {
|
||||
const __m128i a0 = _mm_loadu_si128((const __m128i*)&a[i + 0]);
|
||||
const __m128i a1 = _mm_loadu_si128((const __m128i*)&a[i + 4]);
|
||||
#if (LINE_SIZE == 16)
|
||||
@ -220,36 +223,12 @@ static void AddVectorEq_SSE2(const uint32_t* a, uint32_t* out, int size) {
|
||||
_mm_storeu_si128((__m128i*)&out[i + 12], _mm_add_epi32(a3, b3));
|
||||
#endif
|
||||
}
|
||||
for (; i < size; ++i) {
|
||||
out[i] += a[i];
|
||||
}
|
||||
}
|
||||
#undef LINE_SIZE
|
||||
|
||||
// Note we are adding uint32_t's as *signed* int32's (using _mm_add_epi32). But
|
||||
// that's ok since the histogram values are less than 1<<28 (max picture size).
|
||||
static void HistogramAdd_SSE2(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
VP8LHistogram* const out) {
|
||||
int i;
|
||||
const int literal_size = VP8LHistogramNumCodes(a->palette_code_bits_);
|
||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
||||
if (b != out) {
|
||||
AddVector_SSE2(a->literal_, b->literal_, out->literal_, NUM_LITERAL_CODES);
|
||||
AddVector_SSE2(a->red_, b->red_, out->red_, NUM_LITERAL_CODES);
|
||||
AddVector_SSE2(a->blue_, b->blue_, out->blue_, NUM_LITERAL_CODES);
|
||||
AddVector_SSE2(a->alpha_, b->alpha_, out->alpha_, NUM_LITERAL_CODES);
|
||||
} else {
|
||||
AddVectorEq_SSE2(a->literal_, out->literal_, NUM_LITERAL_CODES);
|
||||
AddVectorEq_SSE2(a->red_, out->red_, NUM_LITERAL_CODES);
|
||||
AddVectorEq_SSE2(a->blue_, out->blue_, NUM_LITERAL_CODES);
|
||||
AddVectorEq_SSE2(a->alpha_, out->alpha_, NUM_LITERAL_CODES);
|
||||
}
|
||||
for (i = NUM_LITERAL_CODES; i < literal_size; ++i) {
|
||||
out->literal_[i] = a->literal_[i] + b->literal_[i];
|
||||
}
|
||||
for (i = 0; i < NUM_DISTANCE_CODES; ++i) {
|
||||
out->distance_[i] = a->distance_[i] + b->distance_[i];
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Entropy
|
||||
|
||||
@ -675,7 +654,8 @@ WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitSSE2(void) {
|
||||
VP8LTransformColor = TransformColor_SSE2;
|
||||
VP8LCollectColorBlueTransforms = CollectColorBlueTransforms_SSE2;
|
||||
VP8LCollectColorRedTransforms = CollectColorRedTransforms_SSE2;
|
||||
VP8LHistogramAdd = HistogramAdd_SSE2;
|
||||
VP8LAddVector = AddVector_SSE2;
|
||||
VP8LAddVectorEq = AddVectorEq_SSE2;
|
||||
VP8LCombinedShannonEntropy = CombinedShannonEntropy_SSE2;
|
||||
VP8LVectorMismatch = VectorMismatch_SSE2;
|
||||
VP8LBundleColorMap = BundleColorMap_SSE2;
|
||||
|
@ -1389,4 +1389,4 @@ static WEBP_INLINE uint32_t func_hadd_uh_u32(v8u16 in) {
|
||||
} while (0)
|
||||
#define AVER_UB2_UB(...) AVER_UB2(v16u8, __VA_ARGS__)
|
||||
|
||||
#endif /* WEBP_DSP_MSA_MACRO_H_ */
|
||||
#endif // WEBP_DSP_MSA_MACRO_H_
|
||||
|
70
src/dsp/quant.h
Normal file
70
src/dsp/quant.h
Normal file
@ -0,0 +1,70 @@
|
||||
// Copyright 2018 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifndef WEBP_DSP_QUANT_H_
|
||||
#define WEBP_DSP_QUANT_H_
|
||||
|
||||
#include "src/dsp/dsp.h"
|
||||
#include "src/webp/types.h"
|
||||
|
||||
#if defined(WEBP_USE_NEON) && !defined(WEBP_ANDROID_NEON) && \
|
||||
!defined(WEBP_HAVE_NEON_RTCD)
|
||||
#include <arm_neon.h>
|
||||
|
||||
#define IsFlat IsFlat_NEON
|
||||
|
||||
static uint32x2_t horizontal_add_uint32x4(const uint32x4_t a) {
|
||||
const uint64x2_t b = vpaddlq_u32(a);
|
||||
return vadd_u32(vreinterpret_u32_u64(vget_low_u64(b)),
|
||||
vreinterpret_u32_u64(vget_high_u64(b)));
|
||||
}
|
||||
|
||||
static WEBP_INLINE int IsFlat(const int16_t* levels, int num_blocks,
|
||||
int thresh) {
|
||||
const int16x8_t tst_ones = vdupq_n_s16(-1);
|
||||
uint32x4_t sum = vdupq_n_u32(0);
|
||||
|
||||
for (int i = 0; i < num_blocks; ++i) {
|
||||
// Set DC to zero.
|
||||
const int16x8_t a_0 = vsetq_lane_s16(0, vld1q_s16(levels), 0);
|
||||
const int16x8_t a_1 = vld1q_s16(levels + 8);
|
||||
|
||||
const uint16x8_t b_0 = vshrq_n_u16(vtstq_s16(a_0, tst_ones), 15);
|
||||
const uint16x8_t b_1 = vshrq_n_u16(vtstq_s16(a_1, tst_ones), 15);
|
||||
|
||||
sum = vpadalq_u16(sum, b_0);
|
||||
sum = vpadalq_u16(sum, b_1);
|
||||
|
||||
levels += 16;
|
||||
}
|
||||
return thresh >= (int32_t)vget_lane_u32(horizontal_add_uint32x4(sum), 0);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define IsFlat IsFlat_C
|
||||
|
||||
static WEBP_INLINE int IsFlat(const int16_t* levels, int num_blocks,
|
||||
int thresh) {
|
||||
int score = 0;
|
||||
while (num_blocks-- > 0) { // TODO(skal): refine positional scoring?
|
||||
int i;
|
||||
for (i = 1; i < 16; ++i) { // omit DC, we're only interested in AC
|
||||
score += (levels[i] != 0);
|
||||
if (score > thresh) return 0;
|
||||
}
|
||||
levels += 16;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif // defined(WEBP_USE_NEON) && !defined(WEBP_ANDROID_NEON) &&
|
||||
// !defined(WEBP_HAVE_NEON_RTCD)
|
||||
|
||||
#endif // WEBP_DSP_QUANT_H_
|
@ -21,6 +21,7 @@
|
||||
|
||||
#define ROUNDER (WEBP_RESCALER_ONE >> 1)
|
||||
#define MULT_FIX(x, y) (((uint64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
|
||||
#define MULT_FIX_FLOOR(x, y) (((uint64_t)(x) * (y)) >> WEBP_RESCALER_RFIX)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Row import
|
||||
@ -138,7 +139,7 @@ void WebPRescalerExportRowShrink_C(WebPRescaler* const wrk) {
|
||||
if (yscale) {
|
||||
for (x_out = 0; x_out < x_out_max; ++x_out) {
|
||||
const uint32_t frac = (uint32_t)MULT_FIX(frow[x_out], yscale);
|
||||
const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR(irow[x_out] - frac, wrk->fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
dst[x_out] = v;
|
||||
irow[x_out] = frac; // new fractional start
|
||||
@ -153,6 +154,7 @@ void WebPRescalerExportRowShrink_C(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#undef MULT_FIX_FLOOR
|
||||
#undef MULT_FIX
|
||||
#undef ROUNDER
|
||||
|
||||
|
@ -209,6 +209,7 @@ static void ExportRowExpand_MIPS32(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // disabled for now. TODO(skal): make match the C-code
|
||||
static void ExportRowShrink_MIPS32(WebPRescaler* const wrk) {
|
||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||
uint8_t* dst = wrk->dst;
|
||||
@ -273,6 +274,7 @@ static void ExportRowShrink_MIPS32(WebPRescaler* const wrk) {
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Entry point
|
||||
@ -283,7 +285,7 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInitMIPS32(void) {
|
||||
WebPRescalerImportRowExpand = ImportRowExpand_MIPS32;
|
||||
WebPRescalerImportRowShrink = ImportRowShrink_MIPS32;
|
||||
WebPRescalerExportRowExpand = ExportRowExpand_MIPS32;
|
||||
WebPRescalerExportRowShrink = ExportRowShrink_MIPS32;
|
||||
// WebPRescalerExportRowShrink = ExportRowShrink_MIPS32;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_MIPS32
|
||||
|
@ -20,10 +20,12 @@
|
||||
|
||||
#define ROUNDER (WEBP_RESCALER_ONE >> 1)
|
||||
#define MULT_FIX(x, y) (((uint64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
|
||||
#define MULT_FIX_FLOOR(x, y) (((uint64_t)(x) * (y)) >> WEBP_RESCALER_RFIX)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Row export
|
||||
|
||||
#if 0 // disabled for now. TODO(skal): make match the C-code
|
||||
static void ExportRowShrink_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
int i;
|
||||
const int x_out_max = wrk->dst_width * wrk->num_channels;
|
||||
@ -106,7 +108,7 @@ static void ExportRowShrink_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
}
|
||||
for (i = 0; i < (x_out_max & 0x3); ++i) {
|
||||
const uint32_t frac = (uint32_t)MULT_FIX(*frow++, yscale);
|
||||
const int v = (int)MULT_FIX(*irow - frac, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR(*irow - frac, wrk->fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
*dst++ = v;
|
||||
*irow++ = frac; // new fractional start
|
||||
@ -154,13 +156,14 @@ static void ExportRowShrink_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
);
|
||||
}
|
||||
for (i = 0; i < (x_out_max & 0x3); ++i) {
|
||||
const int v = (int)MULT_FIX(*irow, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR(*irow, wrk->fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
*dst++ = v;
|
||||
*irow++ = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
static void ExportRowExpand_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
int i;
|
||||
@ -294,6 +297,7 @@ static void ExportRowExpand_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#undef MULT_FIX_FLOOR
|
||||
#undef MULT_FIX
|
||||
#undef ROUNDER
|
||||
|
||||
@ -304,7 +308,7 @@ extern void WebPRescalerDspInitMIPSdspR2(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInitMIPSdspR2(void) {
|
||||
WebPRescalerExportRowExpand = ExportRowExpand_MIPSdspR2;
|
||||
WebPRescalerExportRowShrink = ExportRowShrink_MIPSdspR2;
|
||||
// WebPRescalerExportRowShrink = ExportRowShrink_MIPSdspR2;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_MIPS_DSP_R2
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#define ROUNDER (WEBP_RESCALER_ONE >> 1)
|
||||
#define MULT_FIX(x, y) (((uint64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
|
||||
#define MULT_FIX_FLOOR(x, y) (((uint64_t)(x) * (y)) >> WEBP_RESCALER_RFIX)
|
||||
|
||||
#define CALC_MULT_FIX_16(in0, in1, in2, in3, scale, shift, dst) do { \
|
||||
v4u32 tmp0, tmp1, tmp2, tmp3; \
|
||||
@ -262,6 +263,7 @@ static void RescalerExportRowExpand_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0 // disabled for now. TODO(skal): make match the C-code
|
||||
static WEBP_INLINE void ExportRowShrink_0(const uint32_t* frow, uint32_t* irow,
|
||||
uint8_t* dst, int length,
|
||||
const uint32_t yscale,
|
||||
@ -341,7 +343,7 @@ static WEBP_INLINE void ExportRowShrink_0(const uint32_t* frow, uint32_t* irow,
|
||||
}
|
||||
for (x_out = 0; x_out < length; ++x_out) {
|
||||
const uint32_t frac = (uint32_t)MULT_FIX(frow[x_out], yscale);
|
||||
const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR(irow[x_out] - frac, wrk->fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
dst[x_out] = v;
|
||||
irow[x_out] = frac;
|
||||
@ -426,6 +428,7 @@ static void RescalerExportRowShrink_MIPSdspR2(WebPRescaler* const wrk) {
|
||||
ExportRowShrink_1(irow, dst, x_out_max, wrk);
|
||||
}
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Entry point
|
||||
@ -434,7 +437,7 @@ extern void WebPRescalerDspInitMSA(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void WebPRescalerDspInitMSA(void) {
|
||||
WebPRescalerExportRowExpand = RescalerExportRowExpand_MIPSdspR2;
|
||||
WebPRescalerExportRowShrink = RescalerExportRowShrink_MIPSdspR2;
|
||||
// WebPRescalerExportRowShrink = RescalerExportRowShrink_MIPSdspR2;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_MSA
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#define ROUNDER (WEBP_RESCALER_ONE >> 1)
|
||||
#define MULT_FIX_C(x, y) (((uint64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
|
||||
#define MULT_FIX_FLOOR_C(x, y) (((uint64_t)(x) * (y)) >> WEBP_RESCALER_RFIX)
|
||||
|
||||
#define LOAD_32x4(SRC, DST) const uint32x4_t DST = vld1q_u32((SRC))
|
||||
#define LOAD_32x8(SRC, DST0, DST1) \
|
||||
@ -35,8 +36,11 @@
|
||||
|
||||
#if (WEBP_RESCALER_RFIX == 32)
|
||||
#define MAKE_HALF_CST(C) vdupq_n_s32((int32_t)((C) >> 1))
|
||||
#define MULT_FIX(A, B) /* note: B is actualy scale>>1. See MAKE_HALF_CST */ \
|
||||
// note: B is actualy scale>>1. See MAKE_HALF_CST
|
||||
#define MULT_FIX(A, B) \
|
||||
vreinterpretq_u32_s32(vqrdmulhq_s32(vreinterpretq_s32_u32((A)), (B)))
|
||||
#define MULT_FIX_FLOOR(A, B) \
|
||||
vreinterpretq_u32_s32(vqdmulhq_s32(vreinterpretq_s32_u32((A)), (B)))
|
||||
#else
|
||||
#error "MULT_FIX/WEBP_RESCALER_RFIX need some more work"
|
||||
#endif
|
||||
@ -135,8 +139,8 @@ static void RescalerExportRowShrink_NEON(WebPRescaler* const wrk) {
|
||||
const uint32x4_t A1 = MULT_FIX(in1, yscale_half);
|
||||
const uint32x4_t B0 = vqsubq_u32(in2, A0);
|
||||
const uint32x4_t B1 = vqsubq_u32(in3, A1);
|
||||
const uint32x4_t C0 = MULT_FIX(B0, fxy_scale_half);
|
||||
const uint32x4_t C1 = MULT_FIX(B1, fxy_scale_half);
|
||||
const uint32x4_t C0 = MULT_FIX_FLOOR(B0, fxy_scale_half);
|
||||
const uint32x4_t C1 = MULT_FIX_FLOOR(B1, fxy_scale_half);
|
||||
const uint16x4_t D0 = vmovn_u32(C0);
|
||||
const uint16x4_t D1 = vmovn_u32(C1);
|
||||
const uint8x8_t E = vmovn_u16(vcombine_u16(D0, D1));
|
||||
@ -145,7 +149,7 @@ static void RescalerExportRowShrink_NEON(WebPRescaler* const wrk) {
|
||||
}
|
||||
for (; x_out < x_out_max; ++x_out) {
|
||||
const uint32_t frac = (uint32_t)MULT_FIX_C(frow[x_out], yscale);
|
||||
const int v = (int)MULT_FIX_C(irow[x_out] - frac, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR_C(irow[x_out] - frac, fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
dst[x_out] = v;
|
||||
irow[x_out] = frac; // new fractional start
|
||||
@ -170,6 +174,12 @@ static void RescalerExportRowShrink_NEON(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#undef MULT_FIX_FLOOR_C
|
||||
#undef MULT_FIX_C
|
||||
#undef MULT_FIX_FLOOR
|
||||
#undef MULT_FIX
|
||||
#undef ROUNDER
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void WebPRescalerDspInitNEON(void);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#define ROUNDER (WEBP_RESCALER_ONE >> 1)
|
||||
#define MULT_FIX(x, y) (((uint64_t)(x) * (y) + ROUNDER) >> WEBP_RESCALER_RFIX)
|
||||
#define MULT_FIX_FLOOR(x, y) (((uint64_t)(x) * (y)) >> WEBP_RESCALER_RFIX)
|
||||
|
||||
// input: 8 bytes ABCDEFGH -> output: A0E0B0F0C0G0D0H0
|
||||
static void LoadTwoPixels_SSE2(const uint8_t* const src, __m128i* out) {
|
||||
@ -224,6 +225,35 @@ static WEBP_INLINE void ProcessRow_SSE2(const __m128i* const A0,
|
||||
_mm_storel_epi64((__m128i*)dst, G);
|
||||
}
|
||||
|
||||
static WEBP_INLINE void ProcessRow_Floor_SSE2(const __m128i* const A0,
|
||||
const __m128i* const A1,
|
||||
const __m128i* const A2,
|
||||
const __m128i* const A3,
|
||||
const __m128i* const mult,
|
||||
uint8_t* const dst) {
|
||||
const __m128i mask = _mm_set_epi32(0xffffffffu, 0, 0xffffffffu, 0);
|
||||
const __m128i B0 = _mm_mul_epu32(*A0, *mult);
|
||||
const __m128i B1 = _mm_mul_epu32(*A1, *mult);
|
||||
const __m128i B2 = _mm_mul_epu32(*A2, *mult);
|
||||
const __m128i B3 = _mm_mul_epu32(*A3, *mult);
|
||||
const __m128i D0 = _mm_srli_epi64(B0, WEBP_RESCALER_RFIX);
|
||||
const __m128i D1 = _mm_srli_epi64(B1, WEBP_RESCALER_RFIX);
|
||||
#if (WEBP_RESCALER_RFIX < 32)
|
||||
const __m128i D2 =
|
||||
_mm_and_si128(_mm_slli_epi64(B2, 32 - WEBP_RESCALER_RFIX), mask);
|
||||
const __m128i D3 =
|
||||
_mm_and_si128(_mm_slli_epi64(B3, 32 - WEBP_RESCALER_RFIX), mask);
|
||||
#else
|
||||
const __m128i D2 = _mm_and_si128(B2, mask);
|
||||
const __m128i D3 = _mm_and_si128(B3, mask);
|
||||
#endif
|
||||
const __m128i E0 = _mm_or_si128(D0, D2);
|
||||
const __m128i E1 = _mm_or_si128(D1, D3);
|
||||
const __m128i F = _mm_packs_epi32(E0, E1);
|
||||
const __m128i G = _mm_packus_epi16(F, F);
|
||||
_mm_storel_epi64((__m128i*)dst, G);
|
||||
}
|
||||
|
||||
static void RescalerExportRowExpand_SSE2(WebPRescaler* const wrk) {
|
||||
int x_out;
|
||||
uint8_t* const dst = wrk->dst;
|
||||
@ -322,12 +352,12 @@ static void RescalerExportRowShrink_SSE2(WebPRescaler* const wrk) {
|
||||
const __m128i G1 = _mm_or_si128(D1, F3);
|
||||
_mm_storeu_si128((__m128i*)(irow + x_out + 0), G0);
|
||||
_mm_storeu_si128((__m128i*)(irow + x_out + 4), G1);
|
||||
ProcessRow_SSE2(&E0, &E1, &E2, &E3, &mult_xy, dst + x_out);
|
||||
ProcessRow_Floor_SSE2(&E0, &E1, &E2, &E3, &mult_xy, dst + x_out);
|
||||
}
|
||||
}
|
||||
for (; x_out < x_out_max; ++x_out) {
|
||||
const uint32_t frac = (int)MULT_FIX(frow[x_out], yscale);
|
||||
const int v = (int)MULT_FIX(irow[x_out] - frac, wrk->fxy_scale);
|
||||
const int v = (int)MULT_FIX_FLOOR(irow[x_out] - frac, wrk->fxy_scale);
|
||||
assert(v >= 0 && v <= 255);
|
||||
dst[x_out] = v;
|
||||
irow[x_out] = frac; // new fractional start
|
||||
@ -352,6 +382,7 @@ static void RescalerExportRowShrink_SSE2(WebPRescaler* const wrk) {
|
||||
}
|
||||
}
|
||||
|
||||
#undef MULT_FIX_FLOOR
|
||||
#undef MULT_FIX
|
||||
#undef ROUNDER
|
||||
|
||||
|
@ -207,4 +207,4 @@ static WEBP_INLINE int VP8RGBToV(int r, int g, int b, int rounding) {
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_DSP_YUV_H_ */
|
||||
#endif // WEBP_DSP_YUV_H_
|
||||
|
@ -458,7 +458,7 @@ static void MergeJobs(const SegmentJob* const src, SegmentJob* const dst) {
|
||||
dst->uv_alpha += src->uv_alpha;
|
||||
}
|
||||
|
||||
// initialize the job struct with some TODOs
|
||||
// initialize the job struct with some tasks to perform
|
||||
static void InitSegmentJob(VP8Encoder* const enc, SegmentJob* const job,
|
||||
int start_row, int end_row) {
|
||||
WebPGetWorkerInterface()->Init(&job->worker);
|
||||
|
@ -67,7 +67,7 @@ static int CostModelBuild(CostModel* const m, int xsize, int cache_bits,
|
||||
|
||||
// The following code is similar to VP8LHistogramCreate but converts the
|
||||
// distance to plane code.
|
||||
VP8LHistogramInit(histo, cache_bits);
|
||||
VP8LHistogramInit(histo, cache_bits, /*init_arrays=*/ 1);
|
||||
while (VP8LRefsCursorOk(&c)) {
|
||||
VP8LHistogramAddSinglePixOrCopy(histo, c.cur_pos, VP8LDistanceToPlaneCode,
|
||||
xsize);
|
||||
|
@ -715,6 +715,7 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality,
|
||||
for (i = 0; i <= cache_bits_max; ++i) {
|
||||
histos[i] = VP8LAllocateHistogram(i);
|
||||
if (histos[i] == NULL) goto Error;
|
||||
VP8LHistogramInit(histos[i], i, /*init_arrays=*/ 1);
|
||||
if (i == 0) continue;
|
||||
cc_init[i] = VP8LColorCacheInit(&hashers[i], i);
|
||||
if (!cc_init[i]) goto Error;
|
||||
|
@ -79,4 +79,4 @@ extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_ENC_COST_ENC_H_ */
|
||||
#endif // WEBP_ENC_COST_ENC_H_
|
||||
|
@ -51,10 +51,12 @@ static void HistogramCopy(const VP8LHistogram* const src,
|
||||
VP8LHistogram* const dst) {
|
||||
uint32_t* const dst_literal = dst->literal_;
|
||||
const int dst_cache_bits = dst->palette_code_bits_;
|
||||
const int literal_size = VP8LHistogramNumCodes(dst_cache_bits);
|
||||
const int histo_size = VP8LGetHistogramSize(dst_cache_bits);
|
||||
assert(src->palette_code_bits_ == dst_cache_bits);
|
||||
memcpy(dst, src, histo_size);
|
||||
dst->literal_ = dst_literal;
|
||||
memcpy(dst->literal_, src->literal_, literal_size * sizeof(*dst->literal_));
|
||||
}
|
||||
|
||||
int VP8LGetHistogramSize(int cache_bits) {
|
||||
@ -91,9 +93,19 @@ void VP8LHistogramCreate(VP8LHistogram* const p,
|
||||
VP8LHistogramStoreRefs(refs, p);
|
||||
}
|
||||
|
||||
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits) {
|
||||
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits,
|
||||
int init_arrays) {
|
||||
p->palette_code_bits_ = palette_code_bits;
|
||||
HistogramClear(p);
|
||||
if (init_arrays) {
|
||||
HistogramClear(p);
|
||||
} else {
|
||||
p->trivial_symbol_ = 0;
|
||||
p->bit_cost_ = 0.;
|
||||
p->literal_cost_ = 0.;
|
||||
p->red_cost_ = 0.;
|
||||
p->blue_cost_ = 0.;
|
||||
memset(p->is_used_, 0, sizeof(p->is_used_));
|
||||
}
|
||||
}
|
||||
|
||||
VP8LHistogram* VP8LAllocateHistogram(int cache_bits) {
|
||||
@ -104,37 +116,84 @@ VP8LHistogram* VP8LAllocateHistogram(int cache_bits) {
|
||||
histo = (VP8LHistogram*)memory;
|
||||
// literal_ won't necessary be aligned.
|
||||
histo->literal_ = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
||||
VP8LHistogramInit(histo, cache_bits);
|
||||
VP8LHistogramInit(histo, cache_bits, /*init_arrays=*/ 0);
|
||||
return histo;
|
||||
}
|
||||
|
||||
// Resets the pointers of the histograms to point to the bit buffer in the set.
|
||||
static void HistogramSetResetPointers(VP8LHistogramSet* const set,
|
||||
int cache_bits) {
|
||||
int i;
|
||||
const int histo_size = VP8LGetHistogramSize(cache_bits);
|
||||
uint8_t* memory = (uint8_t*) (set->histograms);
|
||||
memory += set->max_size * sizeof(*set->histograms);
|
||||
for (i = 0; i < set->max_size; ++i) {
|
||||
memory = (uint8_t*) WEBP_ALIGN(memory);
|
||||
set->histograms[i] = (VP8LHistogram*) memory;
|
||||
// literal_ won't necessary be aligned.
|
||||
set->histograms[i]->literal_ = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
||||
memory += histo_size;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the total size of the VP8LHistogramSet.
|
||||
static size_t HistogramSetTotalSize(int size, int cache_bits) {
|
||||
const int histo_size = VP8LGetHistogramSize(cache_bits);
|
||||
return (sizeof(VP8LHistogramSet) + size * (sizeof(VP8LHistogram*) +
|
||||
histo_size + WEBP_ALIGN_CST));
|
||||
}
|
||||
|
||||
VP8LHistogramSet* VP8LAllocateHistogramSet(int size, int cache_bits) {
|
||||
int i;
|
||||
VP8LHistogramSet* set;
|
||||
const int histo_size = VP8LGetHistogramSize(cache_bits);
|
||||
const size_t total_size =
|
||||
sizeof(*set) + size * (sizeof(*set->histograms) +
|
||||
histo_size + WEBP_ALIGN_CST);
|
||||
const size_t total_size = HistogramSetTotalSize(size, cache_bits);
|
||||
uint8_t* memory = (uint8_t*)WebPSafeMalloc(total_size, sizeof(*memory));
|
||||
if (memory == NULL) return NULL;
|
||||
|
||||
set = (VP8LHistogramSet*)memory;
|
||||
memory += sizeof(*set);
|
||||
set->histograms = (VP8LHistogram**)memory;
|
||||
memory += size * sizeof(*set->histograms);
|
||||
set->max_size = size;
|
||||
set->size = size;
|
||||
HistogramSetResetPointers(set, cache_bits);
|
||||
for (i = 0; i < size; ++i) {
|
||||
memory = (uint8_t*)WEBP_ALIGN(memory);
|
||||
set->histograms[i] = (VP8LHistogram*)memory;
|
||||
// literal_ won't necessary be aligned.
|
||||
set->histograms[i]->literal_ = (uint32_t*)(memory + sizeof(VP8LHistogram));
|
||||
VP8LHistogramInit(set->histograms[i], cache_bits);
|
||||
memory += histo_size;
|
||||
VP8LHistogramInit(set->histograms[i], cache_bits, /*init_arrays=*/ 0);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
void VP8LHistogramSetClear(VP8LHistogramSet* const set) {
|
||||
int i;
|
||||
const int cache_bits = set->histograms[0]->palette_code_bits_;
|
||||
const int size = set->max_size;
|
||||
const size_t total_size = HistogramSetTotalSize(size, cache_bits);
|
||||
uint8_t* memory = (uint8_t*)set;
|
||||
|
||||
memset(memory, 0, total_size);
|
||||
memory += sizeof(*set);
|
||||
set->histograms = (VP8LHistogram**)memory;
|
||||
set->max_size = size;
|
||||
set->size = size;
|
||||
HistogramSetResetPointers(set, cache_bits);
|
||||
for (i = 0; i < size; ++i) {
|
||||
set->histograms[i]->palette_code_bits_ = cache_bits;
|
||||
}
|
||||
}
|
||||
|
||||
// Removes the histogram 'i' from 'set' by setting it to NULL.
|
||||
static void HistogramSetRemoveHistogram(VP8LHistogramSet* const set, int i,
|
||||
int* const num_used) {
|
||||
assert(set->histograms[i] != NULL);
|
||||
set->histograms[i] = NULL;
|
||||
--*num_used;
|
||||
// If we remove the last valid one, shrink until the next valid one.
|
||||
if (i == set->size - 1) {
|
||||
while (set->size >= 1 && set->histograms[set->size - 1] == NULL) {
|
||||
--set->size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void VP8LHistogramAddSinglePixOrCopy(VP8LHistogram* const histo,
|
||||
@ -237,7 +296,8 @@ static double FinalHuffmanCost(const VP8LStreaks* const stats) {
|
||||
// Get the symbol entropy for the distribution 'population'.
|
||||
// Set 'trivial_sym', if there's only one symbol present in the distribution.
|
||||
static double PopulationCost(const uint32_t* const population, int length,
|
||||
uint32_t* const trivial_sym) {
|
||||
uint32_t* const trivial_sym,
|
||||
uint8_t* const is_used) {
|
||||
VP8LBitEntropy bit_entropy;
|
||||
VP8LStreaks stats;
|
||||
VP8LGetEntropyUnrefined(population, length, &bit_entropy, &stats);
|
||||
@ -245,6 +305,8 @@ static double PopulationCost(const uint32_t* const population, int length,
|
||||
*trivial_sym = (bit_entropy.nonzeros == 1) ? bit_entropy.nonzero_code
|
||||
: VP8L_NON_TRIVIAL_SYM;
|
||||
}
|
||||
// The histogram is used if there is at least one non-zero streak.
|
||||
*is_used = (stats.streaks[1][0] != 0 || stats.streaks[1][1] != 0);
|
||||
|
||||
return BitsEntropyRefine(&bit_entropy) + FinalHuffmanCost(&stats);
|
||||
}
|
||||
@ -253,7 +315,9 @@ static double PopulationCost(const uint32_t* const population, int length,
|
||||
// non-zero: both the zero-th one, or both the last one.
|
||||
static WEBP_INLINE double GetCombinedEntropy(const uint32_t* const X,
|
||||
const uint32_t* const Y,
|
||||
int length, int trivial_at_end) {
|
||||
int length, int is_X_used,
|
||||
int is_Y_used,
|
||||
int trivial_at_end) {
|
||||
VP8LStreaks stats;
|
||||
if (trivial_at_end) {
|
||||
// This configuration is due to palettization that transforms an indexed
|
||||
@ -262,28 +326,43 @@ static WEBP_INLINE double GetCombinedEntropy(const uint32_t* const X,
|
||||
// Only FinalHuffmanCost needs to be evaluated.
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
// Deal with the non-zero value at index 0 or length-1.
|
||||
stats.streaks[1][0] += 1;
|
||||
stats.streaks[1][0] = 1;
|
||||
// Deal with the following/previous zero streak.
|
||||
stats.counts[0] += 1;
|
||||
stats.streaks[0][1] += length - 1;
|
||||
stats.counts[0] = 1;
|
||||
stats.streaks[0][1] = length - 1;
|
||||
return FinalHuffmanCost(&stats);
|
||||
} else {
|
||||
VP8LBitEntropy bit_entropy;
|
||||
VP8LGetCombinedEntropyUnrefined(X, Y, length, &bit_entropy, &stats);
|
||||
if (is_X_used) {
|
||||
if (is_Y_used) {
|
||||
VP8LGetCombinedEntropyUnrefined(X, Y, length, &bit_entropy, &stats);
|
||||
} else {
|
||||
VP8LGetEntropyUnrefined(X, length, &bit_entropy, &stats);
|
||||
}
|
||||
} else {
|
||||
if (is_Y_used) {
|
||||
VP8LGetEntropyUnrefined(Y, length, &bit_entropy, &stats);
|
||||
} else {
|
||||
memset(&stats, 0, sizeof(stats));
|
||||
stats.counts[0] = 1;
|
||||
stats.streaks[0][length > 3] = length;
|
||||
VP8LBitEntropyInit(&bit_entropy);
|
||||
}
|
||||
}
|
||||
|
||||
return BitsEntropyRefine(&bit_entropy) + FinalHuffmanCost(&stats);
|
||||
}
|
||||
}
|
||||
|
||||
// Estimates the Entropy + Huffman + other block overhead size cost.
|
||||
double VP8LHistogramEstimateBits(const VP8LHistogram* const p) {
|
||||
double VP8LHistogramEstimateBits(VP8LHistogram* const p) {
|
||||
return
|
||||
PopulationCost(
|
||||
p->literal_, VP8LHistogramNumCodes(p->palette_code_bits_), NULL)
|
||||
+ PopulationCost(p->red_, NUM_LITERAL_CODES, NULL)
|
||||
+ PopulationCost(p->blue_, NUM_LITERAL_CODES, NULL)
|
||||
+ PopulationCost(p->alpha_, NUM_LITERAL_CODES, NULL)
|
||||
+ PopulationCost(p->distance_, NUM_DISTANCE_CODES, NULL)
|
||||
PopulationCost(p->literal_, VP8LHistogramNumCodes(p->palette_code_bits_),
|
||||
NULL, &p->is_used_[0])
|
||||
+ PopulationCost(p->red_, NUM_LITERAL_CODES, NULL, &p->is_used_[1])
|
||||
+ PopulationCost(p->blue_, NUM_LITERAL_CODES, NULL, &p->is_used_[2])
|
||||
+ PopulationCost(p->alpha_, NUM_LITERAL_CODES, NULL, &p->is_used_[3])
|
||||
+ PopulationCost(p->distance_, NUM_DISTANCE_CODES, NULL, &p->is_used_[4])
|
||||
+ VP8LExtraCost(p->literal_ + NUM_LITERAL_CODES, NUM_LENGTH_CODES)
|
||||
+ VP8LExtraCost(p->distance_, NUM_DISTANCE_CODES);
|
||||
}
|
||||
@ -299,7 +378,8 @@ static int GetCombinedHistogramEntropy(const VP8LHistogram* const a,
|
||||
int trivial_at_end = 0;
|
||||
assert(a->palette_code_bits_ == b->palette_code_bits_);
|
||||
*cost += GetCombinedEntropy(a->literal_, b->literal_,
|
||||
VP8LHistogramNumCodes(palette_code_bits), 0);
|
||||
VP8LHistogramNumCodes(palette_code_bits),
|
||||
a->is_used_[0], b->is_used_[0], 0);
|
||||
*cost += VP8LExtraCostCombined(a->literal_ + NUM_LITERAL_CODES,
|
||||
b->literal_ + NUM_LITERAL_CODES,
|
||||
NUM_LENGTH_CODES);
|
||||
@ -319,19 +399,23 @@ static int GetCombinedHistogramEntropy(const VP8LHistogram* const a,
|
||||
}
|
||||
|
||||
*cost +=
|
||||
GetCombinedEntropy(a->red_, b->red_, NUM_LITERAL_CODES, trivial_at_end);
|
||||
GetCombinedEntropy(a->red_, b->red_, NUM_LITERAL_CODES, a->is_used_[1],
|
||||
b->is_used_[1], trivial_at_end);
|
||||
if (*cost > cost_threshold) return 0;
|
||||
|
||||
*cost +=
|
||||
GetCombinedEntropy(a->blue_, b->blue_, NUM_LITERAL_CODES, trivial_at_end);
|
||||
if (*cost > cost_threshold) return 0;
|
||||
|
||||
*cost += GetCombinedEntropy(a->alpha_, b->alpha_, NUM_LITERAL_CODES,
|
||||
trivial_at_end);
|
||||
GetCombinedEntropy(a->blue_, b->blue_, NUM_LITERAL_CODES, a->is_used_[2],
|
||||
b->is_used_[2], trivial_at_end);
|
||||
if (*cost > cost_threshold) return 0;
|
||||
|
||||
*cost +=
|
||||
GetCombinedEntropy(a->distance_, b->distance_, NUM_DISTANCE_CODES, 0);
|
||||
GetCombinedEntropy(a->alpha_, b->alpha_, NUM_LITERAL_CODES,
|
||||
a->is_used_[3], b->is_used_[3], trivial_at_end);
|
||||
if (*cost > cost_threshold) return 0;
|
||||
|
||||
*cost +=
|
||||
GetCombinedEntropy(a->distance_, b->distance_, NUM_DISTANCE_CODES,
|
||||
a->is_used_[4], b->is_used_[4], 0);
|
||||
*cost +=
|
||||
VP8LExtraCostCombined(a->distance_, b->distance_, NUM_DISTANCE_CODES);
|
||||
if (*cost > cost_threshold) return 0;
|
||||
@ -377,7 +461,9 @@ static double HistogramAddEval(const VP8LHistogram* const a,
|
||||
static double HistogramAddThresh(const VP8LHistogram* const a,
|
||||
const VP8LHistogram* const b,
|
||||
double cost_threshold) {
|
||||
double cost = -a->bit_cost_;
|
||||
double cost;
|
||||
assert(a != NULL && b != NULL);
|
||||
cost = -a->bit_cost_;
|
||||
GetCombinedHistogramEntropy(a, b, cost_threshold, &cost);
|
||||
return cost;
|
||||
}
|
||||
@ -419,16 +505,19 @@ static void UpdateDominantCostRange(
|
||||
static void UpdateHistogramCost(VP8LHistogram* const h) {
|
||||
uint32_t alpha_sym, red_sym, blue_sym;
|
||||
const double alpha_cost =
|
||||
PopulationCost(h->alpha_, NUM_LITERAL_CODES, &alpha_sym);
|
||||
PopulationCost(h->alpha_, NUM_LITERAL_CODES, &alpha_sym,
|
||||
&h->is_used_[3]);
|
||||
const double distance_cost =
|
||||
PopulationCost(h->distance_, NUM_DISTANCE_CODES, NULL) +
|
||||
PopulationCost(h->distance_, NUM_DISTANCE_CODES, NULL, &h->is_used_[4]) +
|
||||
VP8LExtraCost(h->distance_, NUM_DISTANCE_CODES);
|
||||
const int num_codes = VP8LHistogramNumCodes(h->palette_code_bits_);
|
||||
h->literal_cost_ = PopulationCost(h->literal_, num_codes, NULL) +
|
||||
VP8LExtraCost(h->literal_ + NUM_LITERAL_CODES,
|
||||
NUM_LENGTH_CODES);
|
||||
h->red_cost_ = PopulationCost(h->red_, NUM_LITERAL_CODES, &red_sym);
|
||||
h->blue_cost_ = PopulationCost(h->blue_, NUM_LITERAL_CODES, &blue_sym);
|
||||
h->literal_cost_ =
|
||||
PopulationCost(h->literal_, num_codes, NULL, &h->is_used_[0]) +
|
||||
VP8LExtraCost(h->literal_ + NUM_LITERAL_CODES, NUM_LENGTH_CODES);
|
||||
h->red_cost_ =
|
||||
PopulationCost(h->red_, NUM_LITERAL_CODES, &red_sym, &h->is_used_[1]);
|
||||
h->blue_cost_ =
|
||||
PopulationCost(h->blue_, NUM_LITERAL_CODES, &blue_sym, &h->is_used_[2]);
|
||||
h->bit_cost_ = h->literal_cost_ + h->red_cost_ + h->blue_cost_ +
|
||||
alpha_cost + distance_cost;
|
||||
if ((alpha_sym | red_sym | blue_sym) == VP8L_NON_TRIVIAL_SYM) {
|
||||
@ -473,6 +562,7 @@ static void HistogramBuild(
|
||||
VP8LHistogram** const histograms = image_histo->histograms;
|
||||
VP8LRefsCursor c = VP8LRefsCursorInit(backward_refs);
|
||||
assert(histo_bits > 0);
|
||||
VP8LHistogramSetClear(image_histo);
|
||||
while (VP8LRefsCursorOk(&c)) {
|
||||
const PixOrCopy* const v = c.cur_pos;
|
||||
const int ix = (y >> histo_bits) * histo_xsize + (x >> histo_bits);
|
||||
@ -487,17 +577,37 @@ static void HistogramBuild(
|
||||
}
|
||||
|
||||
// Copies the histograms and computes its bit_cost.
|
||||
static void HistogramCopyAndAnalyze(
|
||||
VP8LHistogramSet* const orig_histo, VP8LHistogramSet* const image_histo) {
|
||||
int i;
|
||||
const int histo_size = orig_histo->size;
|
||||
static const uint16_t kInvalidHistogramSymbol = (uint16_t)(-1);
|
||||
static void HistogramCopyAndAnalyze(VP8LHistogramSet* const orig_histo,
|
||||
VP8LHistogramSet* const image_histo,
|
||||
int* const num_used,
|
||||
uint16_t* const histogram_symbols) {
|
||||
int i, cluster_id;
|
||||
int num_used_orig = *num_used;
|
||||
VP8LHistogram** const orig_histograms = orig_histo->histograms;
|
||||
VP8LHistogram** const histograms = image_histo->histograms;
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
assert(image_histo->max_size == orig_histo->max_size);
|
||||
for (cluster_id = 0, i = 0; i < orig_histo->max_size; ++i) {
|
||||
VP8LHistogram* const histo = orig_histograms[i];
|
||||
UpdateHistogramCost(histo);
|
||||
// Copy histograms from orig_histo[] to image_histo[].
|
||||
HistogramCopy(histo, histograms[i]);
|
||||
|
||||
// Skip the histogram if it is completely empty, which can happen for tiles
|
||||
// with no information (when they are skipped because of LZ77).
|
||||
if (!histo->is_used_[0] && !histo->is_used_[1] && !histo->is_used_[2]
|
||||
&& !histo->is_used_[3] && !histo->is_used_[4]) {
|
||||
// The first histogram is always used. If an histogram is empty, we set
|
||||
// its id to be the same as the previous one: this will improve
|
||||
// compressibility for later LZ77.
|
||||
assert(i > 0);
|
||||
HistogramSetRemoveHistogram(image_histo, i, num_used);
|
||||
HistogramSetRemoveHistogram(orig_histo, i, &num_used_orig);
|
||||
histogram_symbols[i] = kInvalidHistogramSymbol;
|
||||
} else {
|
||||
// Copy histograms from orig_histo[] to image_histo[].
|
||||
HistogramCopy(histo, histograms[i]);
|
||||
histogram_symbols[i] = cluster_id++;
|
||||
assert(cluster_id <= image_histo->max_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,29 +624,33 @@ static void HistogramAnalyzeEntropyBin(VP8LHistogramSet* const image_histo,
|
||||
|
||||
// Analyze the dominant (literal, red and blue) entropy costs.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
if (histograms[i] == NULL) continue;
|
||||
UpdateDominantCostRange(histograms[i], &cost_range);
|
||||
}
|
||||
|
||||
// bin-hash histograms on three of the dominant (literal, red and blue)
|
||||
// symbol costs and store the resulting bin_id for each histogram.
|
||||
for (i = 0; i < histo_size; ++i) {
|
||||
// bin_map[i] is not set to a special value as its use will later be guarded
|
||||
// by another (histograms[i] == NULL).
|
||||
if (histograms[i] == NULL) continue;
|
||||
bin_map[i] = GetHistoBinIndex(histograms[i], &cost_range, low_effort);
|
||||
}
|
||||
}
|
||||
|
||||
// Compact image_histo[] by merging some histograms with same bin_id together if
|
||||
// it's advantageous.
|
||||
// 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,
|
||||
const uint16_t* const clusters,
|
||||
uint16_t* const cluster_mappings,
|
||||
VP8LHistogram* cur_combo,
|
||||
const uint16_t* const bin_map,
|
||||
int bin_map_size, int num_bins,
|
||||
int num_bins,
|
||||
double combine_cost_factor,
|
||||
int low_effort) {
|
||||
VP8LHistogram** const histograms = image_histo->histograms;
|
||||
int idx;
|
||||
// Work in-place: processed histograms are put at the beginning of
|
||||
// image_histo[]. At the end, we just have to truncate the array.
|
||||
int size = 0;
|
||||
struct {
|
||||
int16_t first; // position of the histogram that accumulates all
|
||||
// histograms with the same bin_id
|
||||
@ -549,16 +663,19 @@ static void HistogramCombineEntropyBin(VP8LHistogramSet* const image_histo,
|
||||
bin_info[idx].num_combine_failures = 0;
|
||||
}
|
||||
|
||||
for (idx = 0; idx < bin_map_size; ++idx) {
|
||||
const int bin_id = bin_map[idx];
|
||||
const int first = bin_info[bin_id].first;
|
||||
assert(size <= idx);
|
||||
// By default, a cluster matches itself.
|
||||
for (idx = 0; idx < *num_used; ++idx) cluster_mappings[idx] = idx;
|
||||
for (idx = 0; idx < image_histo->size; ++idx) {
|
||||
int bin_id, first;
|
||||
if (histograms[idx] == NULL) continue;
|
||||
bin_id = bin_map[idx];
|
||||
first = bin_info[bin_id].first;
|
||||
if (first == -1) {
|
||||
// just move histogram #idx to its final position
|
||||
histograms[size] = histograms[idx];
|
||||
bin_info[bin_id].first = size++;
|
||||
bin_info[bin_id].first = idx;
|
||||
} else if (low_effort) {
|
||||
HistogramAdd(histograms[idx], histograms[first], histograms[first]);
|
||||
HistogramSetRemoveHistogram(image_histo, idx, num_used);
|
||||
cluster_mappings[clusters[idx]] = clusters[first];
|
||||
} else {
|
||||
// try to merge #idx into #first (both share the same bin_id)
|
||||
const double bit_cost = histograms[idx]->bit_cost_;
|
||||
@ -581,19 +698,18 @@ static void HistogramCombineEntropyBin(VP8LHistogramSet* const image_histo,
|
||||
bin_info[bin_id].num_combine_failures >= max_combine_failures) {
|
||||
// move the (better) merged histogram to its final slot
|
||||
HistogramSwap(&cur_combo, &histograms[first]);
|
||||
HistogramSetRemoveHistogram(image_histo, idx, num_used);
|
||||
cluster_mappings[clusters[idx]] = clusters[first];
|
||||
} else {
|
||||
histograms[size++] = histograms[idx];
|
||||
++bin_info[bin_id].num_combine_failures;
|
||||
}
|
||||
} else {
|
||||
histograms[size++] = histograms[idx];
|
||||
}
|
||||
}
|
||||
}
|
||||
image_histo->size = size;
|
||||
if (low_effort) {
|
||||
// for low_effort case, update the final cost when everything is merged
|
||||
for (idx = 0; idx < size; ++idx) {
|
||||
for (idx = 0; idx < image_histo->size; ++idx) {
|
||||
if (histograms[idx] == NULL) continue;
|
||||
UpdateHistogramCost(histograms[idx]);
|
||||
}
|
||||
}
|
||||
@ -624,16 +740,9 @@ typedef struct {
|
||||
int max_size;
|
||||
} HistoQueue;
|
||||
|
||||
static int HistoQueueInit(HistoQueue* const histo_queue, const int max_index) {
|
||||
static int HistoQueueInit(HistoQueue* const histo_queue, const int max_size) {
|
||||
histo_queue->size = 0;
|
||||
// max_index^2 for the queue size is safe. If you look at
|
||||
// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
|
||||
// data to the queue, you insert at most:
|
||||
// - max_index*(max_index-1)/2 (the first two for loops)
|
||||
// - max_index - 1 in the last for loop at the first iteration of the while
|
||||
// loop, max_index - 2 at the second iteration ... therefore
|
||||
// max_index*(max_index-1)/2 overall too
|
||||
histo_queue->max_size = max_index * max_index;
|
||||
histo_queue->max_size = max_size;
|
||||
// We allocate max_size + 1 because the last element at index "size" is
|
||||
// used as temporary data (and it could be up to max_size).
|
||||
histo_queue->queue = (HistogramPair*)WebPSafeMalloc(
|
||||
@ -674,6 +783,18 @@ static void HistoQueueUpdateHead(HistoQueue* const histo_queue,
|
||||
}
|
||||
}
|
||||
|
||||
// Update the cost diff and combo of a pair of histograms. This needs to be
|
||||
// called when the the histograms have been merged with a third one.
|
||||
static void HistoQueueUpdatePair(const VP8LHistogram* const h1,
|
||||
const VP8LHistogram* const h2,
|
||||
double threshold,
|
||||
HistogramPair* const pair) {
|
||||
const double sum_cost = h1->bit_cost_ + h2->bit_cost_;
|
||||
pair->cost_combo = 0.;
|
||||
GetCombinedHistogramEntropy(h1, h2, sum_cost + threshold, &pair->cost_combo);
|
||||
pair->cost_diff = pair->cost_combo - sum_cost;
|
||||
}
|
||||
|
||||
// Create a pair from indices "idx1" and "idx2" provided its cost
|
||||
// is inferior to "threshold", a negative entropy.
|
||||
// It returns the cost of the pair, or 0. if it superior to threshold.
|
||||
@ -683,8 +804,9 @@ static double HistoQueuePush(HistoQueue* const histo_queue,
|
||||
const VP8LHistogram* h1;
|
||||
const VP8LHistogram* h2;
|
||||
HistogramPair pair;
|
||||
double sum_cost;
|
||||
|
||||
// Stop here if the queue is full.
|
||||
if (histo_queue->size == histo_queue->max_size) return 0.;
|
||||
assert(threshold <= 0.);
|
||||
if (idx1 > idx2) {
|
||||
const int tmp = idx2;
|
||||
@ -695,16 +817,12 @@ static double HistoQueuePush(HistoQueue* const histo_queue,
|
||||
pair.idx2 = idx2;
|
||||
h1 = histograms[idx1];
|
||||
h2 = histograms[idx2];
|
||||
sum_cost = h1->bit_cost_ + h2->bit_cost_;
|
||||
pair.cost_combo = 0.;
|
||||
GetCombinedHistogramEntropy(h1, h2, sum_cost + threshold, &pair.cost_combo);
|
||||
pair.cost_diff = pair.cost_combo - sum_cost;
|
||||
|
||||
HistoQueueUpdatePair(h1, h2, threshold, &pair);
|
||||
|
||||
// Do not even consider the pair if it does not improve the entropy.
|
||||
if (pair.cost_diff >= threshold) return 0.;
|
||||
|
||||
// We cannot add more elements than the capacity.
|
||||
assert(histo_queue->size < histo_queue->max_size);
|
||||
histo_queue->queue[histo_queue->size++] = pair;
|
||||
HistoQueueUpdateHead(histo_queue, &histo_queue->queue[histo_queue->size - 1]);
|
||||
|
||||
@ -715,42 +833,43 @@ static double HistoQueuePush(HistoQueue* const histo_queue,
|
||||
|
||||
// Combines histograms by continuously choosing the one with the highest cost
|
||||
// reduction.
|
||||
static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo) {
|
||||
static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo,
|
||||
int* const num_used) {
|
||||
int ok = 0;
|
||||
int image_histo_size = image_histo->size;
|
||||
const int image_histo_size = image_histo->size;
|
||||
int i, j;
|
||||
VP8LHistogram** const histograms = image_histo->histograms;
|
||||
// Indexes of remaining histograms.
|
||||
int* const clusters =
|
||||
(int*)WebPSafeMalloc(image_histo_size, sizeof(*clusters));
|
||||
// Priority queue of histogram pairs.
|
||||
HistoQueue histo_queue;
|
||||
|
||||
if (!HistoQueueInit(&histo_queue, image_histo_size) || clusters == NULL) {
|
||||
// image_histo_size^2 for the queue size is safe. If you look at
|
||||
// HistogramCombineGreedy, and imagine that UpdateQueueFront always pushes
|
||||
// data to the queue, you insert at most:
|
||||
// - image_histo_size*(image_histo_size-1)/2 (the first two for loops)
|
||||
// - image_histo_size - 1 in the last for loop at the first iteration of
|
||||
// the while loop, image_histo_size - 2 at the second iteration ...
|
||||
// therefore image_histo_size*(image_histo_size-1)/2 overall too
|
||||
if (!HistoQueueInit(&histo_queue, image_histo_size * image_histo_size)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
for (i = 0; i < image_histo_size; ++i) {
|
||||
// Initialize clusters indexes.
|
||||
clusters[i] = i;
|
||||
if (image_histo->histograms[i] == NULL) continue;
|
||||
for (j = i + 1; j < image_histo_size; ++j) {
|
||||
// Initialize positions array.
|
||||
// Initialize queue.
|
||||
if (image_histo->histograms[j] == NULL) continue;
|
||||
HistoQueuePush(&histo_queue, histograms, i, j, 0.);
|
||||
}
|
||||
}
|
||||
|
||||
while (image_histo_size > 1 && histo_queue.size > 0) {
|
||||
while (histo_queue.size > 0) {
|
||||
const int idx1 = histo_queue.queue[0].idx1;
|
||||
const int idx2 = histo_queue.queue[0].idx2;
|
||||
HistogramAdd(histograms[idx2], histograms[idx1], histograms[idx1]);
|
||||
histograms[idx1]->bit_cost_ = histo_queue.queue[0].cost_combo;
|
||||
|
||||
// Remove merged histogram.
|
||||
for (i = 0; i + 1 < image_histo_size; ++i) {
|
||||
if (clusters[i] >= idx2) {
|
||||
clusters[i] = clusters[i + 1];
|
||||
}
|
||||
}
|
||||
--image_histo_size;
|
||||
HistogramSetRemoveHistogram(image_histo, idx2, num_used);
|
||||
|
||||
// Remove pairs intersecting the just combined best pair.
|
||||
for (i = 0; i < histo_queue.size;) {
|
||||
@ -765,24 +884,15 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo) {
|
||||
}
|
||||
|
||||
// Push new pairs formed with combined histogram to the queue.
|
||||
for (i = 0; i < image_histo_size; ++i) {
|
||||
if (clusters[i] != idx1) {
|
||||
HistoQueuePush(&histo_queue, histograms, idx1, clusters[i], 0.);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Move remaining histograms to the beginning of the array.
|
||||
for (i = 0; i < image_histo_size; ++i) {
|
||||
if (i != clusters[i]) { // swap the two histograms
|
||||
HistogramSwap(&histograms[i], &histograms[clusters[i]]);
|
||||
for (i = 0; i < image_histo->size; ++i) {
|
||||
if (i == idx1 || image_histo->histograms[i] == NULL) continue;
|
||||
HistoQueuePush(&histo_queue, image_histo->histograms, idx1, i, 0.);
|
||||
}
|
||||
}
|
||||
|
||||
image_histo->size = image_histo_size;
|
||||
ok = 1;
|
||||
|
||||
End:
|
||||
WebPSafeFree(clusters);
|
||||
HistoQueueClear(&histo_queue);
|
||||
return ok;
|
||||
}
|
||||
@ -790,47 +900,69 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo) {
|
||||
// Perform histogram aggregation using a stochastic approach.
|
||||
// 'do_greedy' is set to 1 if a greedy approach needs to be performed
|
||||
// afterwards, 0 otherwise.
|
||||
static int PairComparison(const void* idx1, const void* idx2) {
|
||||
// To be used with bsearch: <0 when *idx1<*idx2, >0 if >, 0 when ==.
|
||||
return (*(int*) idx1 - *(int*) idx2);
|
||||
}
|
||||
static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
||||
int min_cluster_size,
|
||||
int* const num_used, int min_cluster_size,
|
||||
int* const do_greedy) {
|
||||
int iter;
|
||||
int j, iter;
|
||||
uint32_t seed = 1;
|
||||
int tries_with_no_success = 0;
|
||||
int image_histo_size = image_histo->size;
|
||||
const int outer_iters = image_histo_size;
|
||||
const int outer_iters = *num_used;
|
||||
const int num_tries_no_success = outer_iters / 2;
|
||||
VP8LHistogram** const histograms = image_histo->histograms;
|
||||
// Priority queue of histogram pairs. Its size of "kCostHeapSizeSqrt"^2
|
||||
// Priority queue of histogram pairs. Its size of 'kHistoQueueSize'
|
||||
// impacts the quality of the compression and the speed: the smaller the
|
||||
// faster but the worse for the compression.
|
||||
HistoQueue histo_queue;
|
||||
const int kHistoQueueSizeSqrt = 3;
|
||||
const int kHistoQueueSize = 9;
|
||||
int ok = 0;
|
||||
// mapping from an index in image_histo with no NULL histogram to the full
|
||||
// blown image_histo.
|
||||
int* mappings;
|
||||
|
||||
if (!HistoQueueInit(&histo_queue, kHistoQueueSizeSqrt)) {
|
||||
if (*num_used < min_cluster_size) {
|
||||
*do_greedy = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
mappings = (int*) WebPSafeMalloc(*num_used, sizeof(*mappings));
|
||||
if (mappings == NULL || !HistoQueueInit(&histo_queue, kHistoQueueSize)) {
|
||||
goto End;
|
||||
}
|
||||
// Fill the initial mapping.
|
||||
for (j = 0, iter = 0; iter < image_histo->size; ++iter) {
|
||||
if (histograms[iter] == NULL) continue;
|
||||
mappings[j++] = iter;
|
||||
}
|
||||
assert(j == *num_used);
|
||||
|
||||
// Collapse similar histograms in 'image_histo'.
|
||||
++min_cluster_size;
|
||||
for (iter = 0; iter < outer_iters && image_histo_size >= min_cluster_size &&
|
||||
++tries_with_no_success < num_tries_no_success;
|
||||
for (iter = 0;
|
||||
iter < outer_iters && *num_used >= min_cluster_size &&
|
||||
++tries_with_no_success < num_tries_no_success;
|
||||
++iter) {
|
||||
int* mapping_index;
|
||||
double best_cost =
|
||||
(histo_queue.size == 0) ? 0. : histo_queue.queue[0].cost_diff;
|
||||
int best_idx1 = -1, best_idx2 = 1;
|
||||
int j;
|
||||
const uint32_t rand_range = (image_histo_size - 1) * image_histo_size;
|
||||
// image_histo_size / 2 was chosen empirically. Less means faster but worse
|
||||
const uint32_t rand_range = (*num_used - 1) * (*num_used);
|
||||
// (*num_used) / 2 was chosen empirically. Less means faster but worse
|
||||
// compression.
|
||||
const int num_tries = image_histo_size / 2;
|
||||
const int num_tries = (*num_used) / 2;
|
||||
|
||||
for (j = 0; j < num_tries; ++j) {
|
||||
// Pick random samples.
|
||||
for (j = 0; *num_used >= 2 && j < num_tries; ++j) {
|
||||
double curr_cost;
|
||||
// Choose two different histograms at random and try to combine them.
|
||||
const uint32_t tmp = MyRand(&seed) % rand_range;
|
||||
const uint32_t idx1 = tmp / (image_histo_size - 1);
|
||||
uint32_t idx2 = tmp % (image_histo_size - 1);
|
||||
uint32_t idx1 = tmp / (*num_used - 1);
|
||||
uint32_t idx2 = tmp % (*num_used - 1);
|
||||
if (idx2 >= idx1) ++idx2;
|
||||
idx1 = mappings[idx1];
|
||||
idx2 = mappings[idx2];
|
||||
|
||||
// Calculate cost reduction on combination.
|
||||
curr_cost =
|
||||
@ -843,18 +975,21 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
||||
}
|
||||
if (histo_queue.size == 0) continue;
|
||||
|
||||
// Merge the two best histograms.
|
||||
// Get the best histograms.
|
||||
best_idx1 = histo_queue.queue[0].idx1;
|
||||
best_idx2 = histo_queue.queue[0].idx2;
|
||||
assert(best_idx1 < best_idx2);
|
||||
HistogramAddEval(histograms[best_idx1], histograms[best_idx2],
|
||||
histograms[best_idx1], 0);
|
||||
// Swap the best_idx2 histogram with the last one (which is now unused).
|
||||
--image_histo_size;
|
||||
if (best_idx2 != image_histo_size) {
|
||||
HistogramSwap(&histograms[image_histo_size], &histograms[best_idx2]);
|
||||
}
|
||||
histograms[image_histo_size] = NULL;
|
||||
// Pop best_idx2 from mappings.
|
||||
mapping_index = (int*) bsearch(&best_idx2, mappings, *num_used,
|
||||
sizeof(best_idx2), &PairComparison);
|
||||
assert(mapping_index != NULL);
|
||||
memmove(mapping_index, mapping_index + 1, sizeof(*mapping_index) *
|
||||
((*num_used) - (mapping_index - mappings) - 1));
|
||||
// Merge the histograms and remove best_idx2 from the queue.
|
||||
HistogramAdd(histograms[best_idx2], histograms[best_idx1],
|
||||
histograms[best_idx1]);
|
||||
histograms[best_idx1]->bit_cost_ = histo_queue.queue[0].cost_combo;
|
||||
HistogramSetRemoveHistogram(image_histo, best_idx2, num_used);
|
||||
// Parse the queue and update each pair that deals with best_idx1,
|
||||
// best_idx2 or image_histo_size.
|
||||
for (j = 0; j < histo_queue.size;) {
|
||||
@ -877,12 +1012,6 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
||||
p->idx2 = best_idx1;
|
||||
do_eval = 1;
|
||||
}
|
||||
if (p->idx2 == image_histo_size) {
|
||||
// No need to re-evaluate here as it does not involve a pair
|
||||
// containing best_idx1 or best_idx2.
|
||||
p->idx2 = best_idx2;
|
||||
}
|
||||
assert(p->idx2 < image_histo_size);
|
||||
// Make sure the index order is respected.
|
||||
if (p->idx1 > p->idx2) {
|
||||
const int tmp = p->idx2;
|
||||
@ -891,8 +1020,7 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
||||
}
|
||||
if (do_eval) {
|
||||
// Re-evaluate the cost of an updated pair.
|
||||
GetCombinedHistogramEntropy(histograms[p->idx1], histograms[p->idx2], 0,
|
||||
&p->cost_diff);
|
||||
HistoQueueUpdatePair(histograms[p->idx1], histograms[p->idx2], 0., p);
|
||||
if (p->cost_diff >= 0.) {
|
||||
HistoQueuePopPair(&histo_queue, p);
|
||||
continue;
|
||||
@ -901,15 +1029,14 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
|
||||
HistoQueueUpdateHead(&histo_queue, p);
|
||||
++j;
|
||||
}
|
||||
|
||||
tries_with_no_success = 0;
|
||||
}
|
||||
image_histo->size = image_histo_size;
|
||||
*do_greedy = (image_histo->size <= min_cluster_size);
|
||||
*do_greedy = (*num_used <= min_cluster_size);
|
||||
ok = 1;
|
||||
|
||||
End:
|
||||
HistoQueueClear(&histo_queue);
|
||||
WebPSafeFree(mappings);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@ -917,23 +1044,29 @@ End:
|
||||
// Histogram refinement
|
||||
|
||||
// Find the best 'out' histogram for each of the 'in' histograms.
|
||||
// At call-time, 'out' contains the histograms of the clusters.
|
||||
// Note: we assume that out[]->bit_cost_ is already up-to-date.
|
||||
static void HistogramRemap(const VP8LHistogramSet* const in,
|
||||
const VP8LHistogramSet* const out,
|
||||
VP8LHistogramSet* const out,
|
||||
uint16_t* const symbols) {
|
||||
int i;
|
||||
VP8LHistogram** const in_histo = in->histograms;
|
||||
VP8LHistogram** const out_histo = out->histograms;
|
||||
const int in_size = in->size;
|
||||
const int in_size = out->max_size;
|
||||
const int out_size = out->size;
|
||||
if (out_size > 1) {
|
||||
for (i = 0; i < in_size; ++i) {
|
||||
int best_out = 0;
|
||||
double best_bits = MAX_COST;
|
||||
int k;
|
||||
if (in_histo[i] == NULL) {
|
||||
// Arbitrarily set to the previous value if unused to help future LZ77.
|
||||
symbols[i] = symbols[i - 1];
|
||||
continue;
|
||||
}
|
||||
for (k = 0; k < out_size; ++k) {
|
||||
const double cur_bits =
|
||||
HistogramAddThresh(out_histo[k], in_histo[i], best_bits);
|
||||
double cur_bits;
|
||||
cur_bits = HistogramAddThresh(out_histo[k], in_histo[i], best_bits);
|
||||
if (k == 0 || cur_bits < best_bits) {
|
||||
best_bits = cur_bits;
|
||||
best_out = k;
|
||||
@ -949,12 +1082,13 @@ static void HistogramRemap(const VP8LHistogramSet* const in,
|
||||
}
|
||||
|
||||
// Recompute each out based on raw and symbols.
|
||||
for (i = 0; i < out_size; ++i) {
|
||||
HistogramClear(out_histo[i]);
|
||||
}
|
||||
VP8LHistogramSetClear(out);
|
||||
out->size = out_size;
|
||||
|
||||
for (i = 0; i < in_size; ++i) {
|
||||
const int idx = symbols[i];
|
||||
int idx;
|
||||
if (in_histo[i] == NULL) continue;
|
||||
idx = symbols[i];
|
||||
HistogramAdd(in_histo[i], out_histo[idx], out_histo[idx]);
|
||||
}
|
||||
}
|
||||
@ -970,6 +1104,70 @@ static double GetCombineCostFactor(int histo_size, int quality) {
|
||||
return combine_cost_factor;
|
||||
}
|
||||
|
||||
// Given a HistogramSet 'set', the mapping of clusters 'cluster_mapping' and the
|
||||
// current assignment of the cells in 'symbols', merge the clusters and
|
||||
// assign the smallest possible clusters values.
|
||||
static void OptimizeHistogramSymbols(const VP8LHistogramSet* const set,
|
||||
uint16_t* const cluster_mappings,
|
||||
int num_clusters,
|
||||
uint16_t* const cluster_mappings_tmp,
|
||||
uint16_t* const symbols) {
|
||||
int i, cluster_max;
|
||||
int do_continue = 1;
|
||||
// First, assign the lowest cluster to each pixel.
|
||||
while (do_continue) {
|
||||
do_continue = 0;
|
||||
for (i = 0; i < num_clusters; ++i) {
|
||||
int k;
|
||||
k = cluster_mappings[i];
|
||||
while (k != cluster_mappings[k]) {
|
||||
cluster_mappings[k] = cluster_mappings[cluster_mappings[k]];
|
||||
k = cluster_mappings[k];
|
||||
}
|
||||
if (k != cluster_mappings[i]) {
|
||||
do_continue = 1;
|
||||
cluster_mappings[i] = k;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Create a mapping from a cluster id to its minimal version.
|
||||
cluster_max = 0;
|
||||
memset(cluster_mappings_tmp, 0,
|
||||
set->max_size * sizeof(*cluster_mappings_tmp));
|
||||
assert(cluster_mappings[0] == 0);
|
||||
// Re-map the ids.
|
||||
for (i = 0; i < set->max_size; ++i) {
|
||||
int cluster;
|
||||
if (symbols[i] == kInvalidHistogramSymbol) continue;
|
||||
cluster = cluster_mappings[symbols[i]];
|
||||
assert(symbols[i] < num_clusters);
|
||||
if (cluster > 0 && cluster_mappings_tmp[cluster] == 0) {
|
||||
++cluster_max;
|
||||
cluster_mappings_tmp[cluster] = cluster_max;
|
||||
}
|
||||
symbols[i] = cluster_mappings_tmp[cluster];
|
||||
}
|
||||
|
||||
// Make sure all cluster values are used.
|
||||
cluster_max = 0;
|
||||
for (i = 0; i < set->max_size; ++i) {
|
||||
if (symbols[i] == kInvalidHistogramSymbol) continue;
|
||||
if (symbols[i] <= cluster_max) continue;
|
||||
++cluster_max;
|
||||
assert(symbols[i] == cluster_max);
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveEmptyHistograms(VP8LHistogramSet* const image_histo) {
|
||||
uint32_t size;
|
||||
int i;
|
||||
for (i = 0, size = 0; i < image_histo->size; ++i) {
|
||||
if (image_histo->histograms[i] == NULL) continue;
|
||||
image_histo->histograms[size++] = image_histo->histograms[i];
|
||||
}
|
||||
image_histo->size = size;
|
||||
}
|
||||
|
||||
int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
const VP8LBackwardRefs* const refs,
|
||||
int quality, int low_effort,
|
||||
@ -987,28 +1185,37 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
// histograms of small sizes (as bin_map will be very sparse) and
|
||||
// maximum quality q==100 (to preserve the compression gains at that level).
|
||||
const int entropy_combine_num_bins = low_effort ? NUM_PARTITIONS : BIN_SIZE;
|
||||
const int entropy_combine =
|
||||
(orig_histo->size > entropy_combine_num_bins * 2) && (quality < 100);
|
||||
|
||||
if (orig_histo == NULL) goto Error;
|
||||
int entropy_combine;
|
||||
uint16_t* const map_tmp =
|
||||
WebPSafeMalloc(2 * image_histo_raw_size, sizeof(map_tmp));
|
||||
uint16_t* const cluster_mappings = map_tmp + image_histo_raw_size;
|
||||
int num_used = image_histo_raw_size;
|
||||
if (orig_histo == NULL || map_tmp == NULL) goto Error;
|
||||
|
||||
// Construct the histograms from backward references.
|
||||
HistogramBuild(xsize, histo_bits, refs, orig_histo);
|
||||
// Copies the histograms and computes its bit_cost.
|
||||
HistogramCopyAndAnalyze(orig_histo, image_histo);
|
||||
// histogram_symbols is optimized
|
||||
HistogramCopyAndAnalyze(orig_histo, image_histo, &num_used,
|
||||
histogram_symbols);
|
||||
|
||||
entropy_combine =
|
||||
(num_used > entropy_combine_num_bins * 2) && (quality < 100);
|
||||
|
||||
if (entropy_combine) {
|
||||
const int bin_map_size = orig_histo->size;
|
||||
// Reuse histogram_symbols storage. By definition, it's guaranteed to be ok.
|
||||
uint16_t* const bin_map = histogram_symbols;
|
||||
uint16_t* const bin_map = map_tmp;
|
||||
const double combine_cost_factor =
|
||||
GetCombineCostFactor(image_histo_raw_size, quality);
|
||||
const uint32_t num_clusters = num_used;
|
||||
|
||||
HistogramAnalyzeEntropyBin(orig_histo, bin_map, low_effort);
|
||||
HistogramAnalyzeEntropyBin(image_histo, bin_map, low_effort);
|
||||
// Collapse histograms with similar entropy.
|
||||
HistogramCombineEntropyBin(image_histo, tmp_histo, bin_map, bin_map_size,
|
||||
HistogramCombineEntropyBin(image_histo, &num_used, histogram_symbols,
|
||||
cluster_mappings, tmp_histo, bin_map,
|
||||
entropy_combine_num_bins, combine_cost_factor,
|
||||
low_effort);
|
||||
OptimizeHistogramSymbols(image_histo, cluster_mappings, num_clusters,
|
||||
map_tmp, histogram_symbols);
|
||||
}
|
||||
|
||||
// Don't combine the histograms using stochastic and greedy heuristics for
|
||||
@ -1018,21 +1225,26 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
|
||||
// cubic ramp between 1 and MAX_HISTO_GREEDY:
|
||||
const int threshold_size = (int)(1 + (x * x * x) * (MAX_HISTO_GREEDY - 1));
|
||||
int do_greedy;
|
||||
if (!HistogramCombineStochastic(image_histo, threshold_size, &do_greedy)) {
|
||||
if (!HistogramCombineStochastic(image_histo, &num_used, threshold_size,
|
||||
&do_greedy)) {
|
||||
goto Error;
|
||||
}
|
||||
if (do_greedy && !HistogramCombineGreedy(image_histo)) {
|
||||
goto Error;
|
||||
if (do_greedy) {
|
||||
RemoveEmptyHistograms(image_histo);
|
||||
if (!HistogramCombineGreedy(image_histo, &num_used)) {
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(vrabaud): Optimize HistogramRemap for low-effort compression mode.
|
||||
// Find the optimal map from original histograms to the final ones.
|
||||
RemoveEmptyHistograms(image_histo);
|
||||
HistogramRemap(orig_histo, image_histo, histogram_symbols);
|
||||
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
VP8LFreeHistogramSet(orig_histo);
|
||||
WebPSafeFree(map_tmp);
|
||||
return ok;
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ typedef struct {
|
||||
double literal_cost_; // Cached values of dominant entropy costs:
|
||||
double red_cost_; // literal, red & blue.
|
||||
double blue_cost_;
|
||||
uint8_t is_used_[5]; // 5 for literal, red, blue, alpha, distance
|
||||
} VP8LHistogram;
|
||||
|
||||
// Collection of histograms with fixed capacity, allocated as one
|
||||
@ -67,7 +68,9 @@ void VP8LHistogramCreate(VP8LHistogram* const p,
|
||||
int VP8LGetHistogramSize(int palette_code_bits);
|
||||
|
||||
// Set the palette_code_bits and reset the stats.
|
||||
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits);
|
||||
// If init_arrays is true, the arrays are also filled with 0's.
|
||||
void VP8LHistogramInit(VP8LHistogram* const p, int palette_code_bits,
|
||||
int init_arrays);
|
||||
|
||||
// Collect all the references into a histogram (without reset)
|
||||
void VP8LHistogramStoreRefs(const VP8LBackwardRefs* const refs,
|
||||
@ -83,6 +86,9 @@ void VP8LFreeHistogramSet(VP8LHistogramSet* const histo);
|
||||
// using 'cache_bits'. Return NULL in case of memory error.
|
||||
VP8LHistogramSet* VP8LAllocateHistogramSet(int size, int cache_bits);
|
||||
|
||||
// Set the histograms in set to 0.
|
||||
void VP8LHistogramSetClear(VP8LHistogramSet* const set);
|
||||
|
||||
// Allocate and initialize histogram object with specified 'cache_bits'.
|
||||
// Returns NULL in case of memory error.
|
||||
// Special case of VP8LAllocateHistogramSet, with size equals 1.
|
||||
@ -113,7 +119,7 @@ double VP8LBitsEntropy(const uint32_t* const array, int n);
|
||||
|
||||
// Estimate how many bits the combined entropy of literals and distance
|
||||
// approximately maps to.
|
||||
double VP8LHistogramEstimateBits(const VP8LHistogram* const p);
|
||||
double VP8LHistogramEstimateBits(VP8LHistogram* const p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ static void ImportLine(const uint8_t* src, int src_stride,
|
||||
for (; i < total_len; ++i) dst[i] = dst[len - 1];
|
||||
}
|
||||
|
||||
void VP8IteratorImport(VP8EncIterator* const it, uint8_t* tmp_32) {
|
||||
void VP8IteratorImport(VP8EncIterator* const it, uint8_t* const tmp_32) {
|
||||
const VP8Encoder* const enc = it->enc_;
|
||||
const int x = it->x_, y = it->y_;
|
||||
const WebPPicture* const pic = enc->pic_;
|
||||
|
@ -16,10 +16,6 @@
|
||||
#include "src/enc/vp8i_enc.h"
|
||||
#include "src/dsp/yuv.h"
|
||||
|
||||
static WEBP_INLINE uint32_t MakeARGB32(int r, int g, int b) {
|
||||
return (0xff000000u | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helper: clean up fully transparent area to help compressibility.
|
||||
|
||||
@ -195,6 +191,10 @@ void WebPCleanupTransparentAreaLossless(WebPPicture* const pic) {
|
||||
#define BLEND_10BIT(V0, V1, ALPHA) \
|
||||
((((V0) * (1020 - (ALPHA)) + (V1) * (ALPHA)) * 0x101 + 1024) >> 18)
|
||||
|
||||
static WEBP_INLINE uint32_t MakeARGB32(int r, int g, int b) {
|
||||
return (0xff000000u | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb) {
|
||||
const int red = (background_rgb >> 16) & 0xff;
|
||||
const int green = (background_rgb >> 8) & 0xff;
|
||||
@ -208,39 +208,44 @@ void WebPBlendAlpha(WebPPicture* pic, uint32_t background_rgb) {
|
||||
const int U0 = VP8RGBToU(4 * red, 4 * green, 4 * blue, 4 * YUV_HALF);
|
||||
const int V0 = VP8RGBToV(4 * red, 4 * green, 4 * blue, 4 * YUV_HALF);
|
||||
const int has_alpha = pic->colorspace & WEBP_CSP_ALPHA_BIT;
|
||||
if (!has_alpha || pic->a == NULL) return; // nothing to do
|
||||
uint8_t* y_ptr = pic->y;
|
||||
uint8_t* u_ptr = pic->u;
|
||||
uint8_t* v_ptr = pic->v;
|
||||
uint8_t* a_ptr = pic->a;
|
||||
if (!has_alpha || a_ptr == NULL) return; // nothing to do
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
// Luma blending
|
||||
uint8_t* const y_ptr = pic->y + y * pic->y_stride;
|
||||
uint8_t* const a_ptr = pic->a + y * pic->a_stride;
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
const int alpha = a_ptr[x];
|
||||
const uint8_t alpha = a_ptr[x];
|
||||
if (alpha < 0xff) {
|
||||
y_ptr[x] = BLEND(Y0, y_ptr[x], a_ptr[x]);
|
||||
y_ptr[x] = BLEND(Y0, y_ptr[x], alpha);
|
||||
}
|
||||
}
|
||||
// Chroma blending every even line
|
||||
if ((y & 1) == 0) {
|
||||
uint8_t* const u = pic->u + (y >> 1) * pic->uv_stride;
|
||||
uint8_t* const v = pic->v + (y >> 1) * pic->uv_stride;
|
||||
uint8_t* const a_ptr2 =
|
||||
(y + 1 == pic->height) ? a_ptr : a_ptr + pic->a_stride;
|
||||
for (x = 0; x < uv_width; ++x) {
|
||||
// Average four alpha values into a single blending weight.
|
||||
// TODO(skal): might lead to visible contouring. Can we do better?
|
||||
const int alpha =
|
||||
const uint32_t alpha =
|
||||
a_ptr[2 * x + 0] + a_ptr[2 * x + 1] +
|
||||
a_ptr2[2 * x + 0] + a_ptr2[2 * x + 1];
|
||||
u[x] = BLEND_10BIT(U0, u[x], alpha);
|
||||
v[x] = BLEND_10BIT(V0, v[x], alpha);
|
||||
u_ptr[x] = BLEND_10BIT(U0, u_ptr[x], alpha);
|
||||
v_ptr[x] = BLEND_10BIT(V0, v_ptr[x], alpha);
|
||||
}
|
||||
if (pic->width & 1) { // rightmost pixel
|
||||
const int alpha = 2 * (a_ptr[2 * x + 0] + a_ptr2[2 * x + 0]);
|
||||
u[x] = BLEND_10BIT(U0, u[x], alpha);
|
||||
v[x] = BLEND_10BIT(V0, v[x], alpha);
|
||||
const uint32_t alpha = 2 * (a_ptr[2 * x + 0] + a_ptr2[2 * x + 0]);
|
||||
u_ptr[x] = BLEND_10BIT(U0, u_ptr[x], alpha);
|
||||
v_ptr[x] = BLEND_10BIT(V0, v_ptr[x], alpha);
|
||||
}
|
||||
} else {
|
||||
u_ptr += pic->uv_stride;
|
||||
v_ptr += pic->uv_stride;
|
||||
}
|
||||
memset(a_ptr, 0xff, pic->width);
|
||||
memset(a_ptr, 0xff, pic->width); // reset alpha value to opaque
|
||||
a_ptr += pic->a_stride;
|
||||
y_ptr += pic->y_stride;
|
||||
}
|
||||
} else {
|
||||
uint32_t* argb = pic->argb;
|
||||
|
@ -177,12 +177,15 @@ static uint8_t NearLosslessComponent(uint8_t value, uint8_t predict,
|
||||
}
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint8_t NearLosslessDiff(uint8_t a, uint8_t b) {
|
||||
return (uint8_t)((((int)(a) - (int)(b))) & 0xff);
|
||||
}
|
||||
|
||||
// Quantize every component of the difference between the actual pixel value and
|
||||
// its prediction to a multiple of a quantization (a power of 2, not larger than
|
||||
// max_quantization which is a power of 2, smaller than max_diff). Take care if
|
||||
// value and predict have undergone subtract green, which means that red and
|
||||
// blue are represented as offsets from green.
|
||||
#define NEAR_LOSSLESS_DIFF(a, b) (uint8_t)((((int)(a) - (int)(b))) & 0xff)
|
||||
static uint32_t NearLossless(uint32_t value, uint32_t predict,
|
||||
int max_quantization, int max_diff,
|
||||
int used_subtract_green) {
|
||||
@ -199,7 +202,7 @@ static uint32_t NearLossless(uint32_t value, uint32_t predict,
|
||||
}
|
||||
if ((value >> 24) == 0 || (value >> 24) == 0xff) {
|
||||
// Preserve transparency of fully transparent or fully opaque pixels.
|
||||
a = NEAR_LOSSLESS_DIFF(value >> 24, predict >> 24);
|
||||
a = NearLosslessDiff(value >> 24, predict >> 24);
|
||||
} else {
|
||||
a = NearLosslessComponent(value >> 24, predict >> 24, 0xff, quantization);
|
||||
}
|
||||
@ -212,16 +215,15 @@ static uint32_t NearLossless(uint32_t value, uint32_t predict,
|
||||
// The amount by which green has been adjusted during quantization. It is
|
||||
// subtracted from red and blue for compensation, to avoid accumulating two
|
||||
// quantization errors in them.
|
||||
green_diff = NEAR_LOSSLESS_DIFF(new_green, value >> 8);
|
||||
green_diff = NearLosslessDiff(new_green, value >> 8);
|
||||
}
|
||||
r = NearLosslessComponent(NEAR_LOSSLESS_DIFF(value >> 16, green_diff),
|
||||
r = NearLosslessComponent(NearLosslessDiff(value >> 16, green_diff),
|
||||
(predict >> 16) & 0xff, 0xff - new_green,
|
||||
quantization);
|
||||
b = NearLosslessComponent(NEAR_LOSSLESS_DIFF(value, green_diff),
|
||||
b = NearLosslessComponent(NearLosslessDiff(value, green_diff),
|
||||
predict & 0xff, 0xff - new_green, quantization);
|
||||
return ((uint32_t)a << 24) | ((uint32_t)r << 16) | ((uint32_t)g << 8) | b;
|
||||
}
|
||||
#undef NEAR_LOSSLESS_DIFF
|
||||
#endif // (WEBP_NEAR_LOSSLESS == 1)
|
||||
|
||||
// Stores the difference between the pixel and its prediction in "out".
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <math.h>
|
||||
#include <stdlib.h> // for abs()
|
||||
|
||||
#include "src/dsp/quant.h"
|
||||
#include "src/enc/vp8i_enc.h"
|
||||
#include "src/enc/cost_enc.h"
|
||||
|
||||
@ -977,19 +978,6 @@ static void SwapOut(VP8EncIterator* const it) {
|
||||
SwapPtr(&it->yuv_out_, &it->yuv_out2_);
|
||||
}
|
||||
|
||||
static score_t IsFlat(const int16_t* levels, int num_blocks, score_t thresh) {
|
||||
score_t score = 0;
|
||||
while (num_blocks-- > 0) { // TODO(skal): refine positional scoring?
|
||||
int i;
|
||||
for (i = 1; i < 16; ++i) { // omit DC, we're only interested in AC
|
||||
score += (levels[i] != 0);
|
||||
if (score > thresh) return 0;
|
||||
}
|
||||
levels += 16;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void PickBestIntra16(VP8EncIterator* const it, VP8ModeScore* rd) {
|
||||
const int kNumBlocks = 16;
|
||||
VP8SegmentInfo* const dqm = &it->enc_->dqm_[it->mb_->segment_];
|
||||
|
@ -32,7 +32,7 @@ extern "C" {
|
||||
// version numbers
|
||||
#define ENC_MAJ_VERSION 1
|
||||
#define ENC_MIN_VERSION 0
|
||||
#define ENC_REV_VERSION 0
|
||||
#define ENC_REV_VERSION 2
|
||||
|
||||
enum { MAX_LF_LEVELS = 64, // Maximum loop filter level
|
||||
MAX_VARIABLE_LEVEL = 67, // last (inclusive) level with variable cost
|
||||
@ -278,7 +278,7 @@ int VP8IteratorIsDone(const VP8EncIterator* const it);
|
||||
// Import uncompressed samples from source.
|
||||
// If tmp_32 is not NULL, import boundary samples too.
|
||||
// tmp_32 is a 32-bytes scratch buffer that must be aligned in memory.
|
||||
void VP8IteratorImport(VP8EncIterator* const it, uint8_t* tmp_32);
|
||||
void VP8IteratorImport(VP8EncIterator* const it, uint8_t* const tmp_32);
|
||||
// export decimated samples
|
||||
void VP8IteratorExport(const VP8EncIterator* const it);
|
||||
// go to next macroblock. Returns false if not finished.
|
||||
@ -515,4 +515,4 @@ void WebPCleanupTransparentAreaLossless(WebPPicture* const pic);
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_ENC_VP8I_ENC_H_ */
|
||||
#endif // WEBP_ENC_VP8I_ENC_H_
|
||||
|
@ -462,6 +462,7 @@ static int GetHuffBitLengthsAndCodes(
|
||||
for (i = 0; i < histogram_image_size; ++i) {
|
||||
const VP8LHistogram* const histo = histogram_image->histograms[i];
|
||||
HuffmanTreeCode* const codes = &huffman_codes[5 * i];
|
||||
assert(histo != NULL);
|
||||
for (k = 0; k < 5; ++k) {
|
||||
const int num_symbols =
|
||||
(k == 0) ? VP8LHistogramNumCodes(histo->palette_code_bits_) :
|
||||
@ -809,6 +810,7 @@ static WebPEncodingError EncodeImageNoHuffman(VP8LBitWriter* const bw,
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
VP8LHistogramSetClear(histogram_image);
|
||||
|
||||
// Build histogram image and symbols from backward references.
|
||||
VP8LHistogramStoreRefs(refs, histogram_image->histograms[0]);
|
||||
@ -1248,14 +1250,20 @@ static WebPEncodingError MakeInputImageCopy(VP8LEncoder* const enc) {
|
||||
const WebPPicture* const picture = enc->pic_;
|
||||
const int width = picture->width;
|
||||
const int height = picture->height;
|
||||
int y;
|
||||
|
||||
err = AllocateTransformBuffer(enc, width, height);
|
||||
if (err != VP8_ENC_OK) return err;
|
||||
if (enc->argb_content_ == kEncoderARGB) return VP8_ENC_OK;
|
||||
for (y = 0; y < height; ++y) {
|
||||
memcpy(enc->argb_ + y * width,
|
||||
picture->argb + y * picture->argb_stride,
|
||||
width * sizeof(*enc->argb_));
|
||||
|
||||
{
|
||||
uint32_t* dst = enc->argb_;
|
||||
const uint32_t* src = picture->argb;
|
||||
int y;
|
||||
for (y = 0; y < height; ++y) {
|
||||
memcpy(dst, src, width * sizeof(*dst));
|
||||
dst += width;
|
||||
src += picture->argb_stride;
|
||||
}
|
||||
}
|
||||
enc->argb_content_ = kEncoderARGB;
|
||||
assert(enc->current_width_ == width);
|
||||
|
@ -115,4 +115,4 @@ void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_ENC_VP8LI_ENC_H_ */
|
||||
#endif // WEBP_ENC_VP8LI_ENC_H_
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user