mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-15 13:29:54 +02:00
Compare commits
499 Commits
v0.5.2-rc2
...
portable-i
Author | SHA1 | Date | |
---|---|---|---|
0d7614fddf | |||
88692490a5 | |||
0af22e17d6 | |||
08af967025 | |||
a26996116f | |||
5505a5b107 | |||
8ed24a564c | |||
0e8c3004be | |||
6fcc3a720d | |||
2371724d79 | |||
9d1e151bf5 | |||
a1ab868427 | |||
0b8ecc8cfa | |||
c646241391 | |||
cfaebe3e95 | |||
c0eb3ff7d4 | |||
415b98ffad | |||
09bcd9a397 | |||
e83df9d208 | |||
3387fb6fa6 | |||
599bddb658 | |||
28fbe808b9 | |||
c396e6701b | |||
96ef09107c | |||
bc01db116f | |||
d2adc08095 | |||
d6f90a3d83 | |||
cd01fc3944 | |||
9a1a3aa827 | |||
9eceff25c0 | |||
fe6184d706 | |||
cb6c3a2a36 | |||
ec666c7526 | |||
bafa90ccd8 | |||
e6e3ec335c | |||
168a3a9e28 | |||
ad4ca27449 | |||
3a5528713b | |||
b4cefba731 | |||
440945ca57 | |||
a37a7b00d5 | |||
a604ab5600 | |||
b005d916f8 | |||
586eda373d | |||
4026e34e3f | |||
4b21971337 | |||
3b62347b0f | |||
7ca0df1363 | |||
7b250459d6 | |||
e132072f0b | |||
5d7a50efee | |||
7b012987a2 | |||
f0569adb93 | |||
f1d5a397db | |||
f8c2ac15af | |||
a88c6522f6 | |||
8f6df1d0b9 | |||
355c3d1bc7 | |||
a1779a017b | |||
67de68b5d9 | |||
f209a5481e | |||
b903b80c30 | |||
498cad34be | |||
e4eb458741 | |||
af6deaffa0 | |||
7caef29b86 | |||
39e19f927c | |||
9bbc0891c6 | |||
e1118d624d | |||
186bc9b735 | |||
b588729740 | |||
f1784aee04 | |||
0d20abb36f | |||
972104b34b | |||
dd7e83cca7 | |||
d988eb7b39 | |||
dabda70733 | |||
4c1176432a | |||
defc98d72c | |||
d78ff78095 | |||
c8f14093ac | |||
497dc6a70d | |||
d78e5867ff | |||
481e91eb86 | |||
93b1275373 | |||
645f0c53de | |||
e91546054d | |||
818d795b09 | |||
d63e6f4b23 | |||
4d7084350e | |||
faf42213f4 | |||
b4d576fa9c | |||
cbc1b92117 | |||
e644c556c5 | |||
b62cdad287 | |||
da3e4dfb6f | |||
a9c701e04f | |||
adab8ce020 | |||
1b92b237ac | |||
1923ff0222 | |||
97cce5ba83 | |||
0dcd85b6c4 | |||
f768218966 | |||
52245424b0 | |||
690efd82f8 | |||
4bb1f607d7 | |||
285748be78 | |||
78fd199c3b | |||
ae836410bb | |||
d0b7404e00 | |||
134e314fd8 | |||
c08adb6fbc | |||
28c37ebd5a | |||
2cb58ab2d7 | |||
bb175a935e | |||
39eda6584f | |||
36b8274deb | |||
274daf5415 | |||
ec5036e475 | |||
18f0dfac82 | |||
4e2b0b50ea | |||
e2eeabff12 | |||
836607e68a | |||
9273e441da | |||
17e3c11f99 | |||
5f62487189 | |||
976adac1ce | |||
f8fad4fac1 | |||
27415d4102 | |||
4956618276 | |||
6f75a51b58 | |||
a5e4e3aff1 | |||
75a9c3c452 | |||
39cf6f4f36 | |||
699b04161a | |||
7d985bd1d0 | |||
6e7caf06ee | |||
833c92198c | |||
5183326ba8 | |||
99f6f462f5 | |||
80a2218668 | |||
a128dfff51 | |||
693bf74ec0 | |||
10d791ca70 | |||
fa63a96603 | |||
16be192f47 | |||
027151ca6c | |||
4105d565d3 | |||
9ee32a7506 | |||
ca9f7b7dd6 | |||
868aa6901f | |||
5b393f2d2a | |||
e0012bea23 | |||
84c2a7b01c | |||
1b0e4abf08 | |||
3226325016 | |||
b494fdec45 | |||
f153603900 | |||
e69ed29105 | |||
57d8de8a79 | |||
5cfd4ebc5e | |||
1e7ad88b85 | |||
17c7890cba | |||
be73378684 | |||
03cda0e494 | |||
aa893914fc | |||
31a92e972e | |||
dcf9d82a95 | |||
6524fcd614 | |||
6cf24a247d | |||
43d472aa18 | |||
50d1a848bc | |||
20a7fea064 | |||
415f3ffe3d | |||
3c6d1224b4 | |||
ee4a4141f5 | |||
32ed856f60 | |||
1c3190b6ed | |||
f4dc56fd77 | |||
4f3e3bbd44 | |||
2dc0bdcaee | |||
0d8e05880c | |||
b045013970 | |||
0ad3b4efa8 | |||
6451709e72 | |||
92504d214c | |||
c3e4b3a946 | |||
3363eb6d68 | |||
4d1312f2d5 | |||
36c42ea415 | |||
bb498a51e2 | |||
84cef16f47 | |||
919f9e2fd6 | |||
f1ae8af42f | |||
4689ce1635 | |||
79bf46f120 | |||
eb1dc89a5f | |||
c85b0dde6e | |||
43d3f01a2f | |||
668e1dd44f | |||
0e6b7f33ab | |||
29ed6f9a0b | |||
71c53f1aeb | |||
73f567ea8b | |||
9e14276f4c | |||
99965bac02 | |||
d4912238f7 | |||
ea4824097e | |||
2ede5a198a | |||
a345068aba | |||
1dc82a6bba | |||
8074b89eb3 | |||
749a45a520 | |||
74c053b57d | |||
0a3aeff75b | |||
1de931c669 | |||
9b3aca404d | |||
1c07a3c639 | |||
9ed5e3e5dd | |||
db013a8d5c | |||
fcd4784dcd | |||
fbb5c473b4 | |||
8fda56126e | |||
86bbd24552 | |||
7c2779e95a | |||
250c358662 | |||
c0648ac2ae | |||
0d55f60c91 | |||
49d0280df1 | |||
48b1e85fbe | |||
e3b8abbc9b | |||
28fe054e73 | |||
f44acd253b | |||
527844fee0 | |||
be0ef6395f | |||
8874b16275 | |||
d712e20de0 | |||
ecff04f625 | |||
259e98286a | |||
00b08c88c0 | |||
0e7f444702 | |||
b016cb91c5 | |||
1cb638010c | |||
875fafc191 | |||
3674d49e63 | |||
f04eb37603 | |||
341d711c43 | |||
abb5482731 | |||
67c25ad5b4 | |||
a4bbe4b38b | |||
3ebe1c0003 | |||
58fc507842 | |||
9cc421675b | |||
0aa1f35c0f | |||
cb9ec84b54 | |||
dc0c01fbd3 | |||
827d3c5038 | |||
1e2e25b0d4 | |||
273367c130 | |||
76bbcf2ed6 | |||
8ac1abfe13 | |||
cb215aed5c | |||
2423017a28 | |||
a9cc762196 | |||
fbba5bc2c1 | |||
9ae0b3f65a | |||
c1f97bd758 | |||
ea664b8995 | |||
1d5046d1f9 | |||
cec7201447 | |||
b3fb8bb602 | |||
76ebbfff28 | |||
95b12a08ae | |||
54ab2e758f | |||
fe12330c81 | |||
fbfb3bef7b | |||
d4b7d801db | |||
a5e3b22574 | |||
58a1f124c2 | |||
906c3b6392 | |||
d23abe4e9f | |||
2e6cb6f34e | |||
28e0bb7088 | |||
647045305a | |||
bded7848ea | |||
0e61a5134a | |||
1cc79e92ac | |||
03f40955a3 | |||
ea72cd60cb | |||
67879e6d48 | |||
34aee99026 | |||
a41296aef5 | |||
c85adb33d2 | |||
4239a1489c | |||
bc18ebad2e | |||
71e2f5cadf | |||
7474d46e45 | |||
67748b41db | |||
16951b1905 | |||
6540cd0eeb | |||
de568abfdb | |||
3c2a61b099 | |||
9ac063c37f | |||
22efabddb4 | |||
1d6e7bf39f | |||
0a3838ca77 | |||
c0699515af | |||
f90c60d129 | |||
3f182d36f4 | |||
342e15f0ce | |||
1147ab4ee7 | |||
e4cd4daf74 | |||
e715285611 | |||
de9fa5074e | |||
deb1b83199 | |||
cac9a36a23 | |||
4595e01fd0 | |||
fb52d4432a | |||
f048d38d38 | |||
31b1e34342 | |||
2f51b614b0 | |||
0104d730bf | |||
265abbe9b2 | |||
f7601aa686 | |||
ce8733209d | |||
2a2773ea29 | |||
9f5c8eca79 | |||
4eb5df28d1 | |||
11bc423ae5 | |||
273d035a44 | |||
4db82a178f | |||
e2affacc35 | |||
dc789ada44 | |||
539f5a688f | |||
aaf2a6a698 | |||
20ef99159e | |||
bc86b7a8a1 | |||
806f6279ae | |||
68ae5b671f | |||
28ce304344 | |||
b34abcb8b1 | |||
ba843a92e7 | |||
51b71fd295 | |||
fb01743a53 | |||
bfab894739 | |||
9310d19258 | |||
f79450ca02 | |||
cfdda7c6bf | |||
e36396ba75 | |||
18a9a0ab57 | |||
30d43706d3 | |||
36aa087b6d | |||
86a84b3598 | |||
b8384b53d6 | |||
1c36440094 | |||
eee0cce158 | |||
5f1caf2987 | |||
1effde7bcd | |||
a2fe9bf404 | |||
573cce270e | |||
21e7537abe | |||
053a1565c8 | |||
1377ac2ec1 | |||
7c1fb7d0ff | |||
bfff0bf329 | |||
64577de8ae | |||
a7be73280b | |||
50c3d7da9a | |||
d6228aed6a | |||
dd538b192d | |||
6cc48b1728 | |||
78363e9e51 | |||
ffd01929f1 | |||
c4f6d9c939 | |||
c27d821096 | |||
0779529616 | |||
c9b45863e2 | |||
490ae5b13d | |||
894232be56 | |||
8de08483b6 | |||
41cab7fe0f | |||
82c91c708e | |||
af1ad3e2dd | |||
dd7309e30c | |||
6105777e8c | |||
13ae011e4c | |||
4bda0cfba4 | |||
6029c7fe68 | |||
545c147fd8 | |||
5b46f7fc80 | |||
9e478f808e | |||
43bd895879 | |||
0887fc2d85 | |||
0de48e187d | |||
0a57ad0dc5 | |||
0a4699bcc9 | |||
29fedbf58b | |||
32dead4ee3 | |||
85cd5d061c | |||
6585075f8a | |||
c0a27fd2af | |||
57a5e3b6a5 | |||
7f1b897bee | |||
48c810b85c | |||
3884972e3f | |||
485cac1a88 | |||
005e15b10a | |||
6ab496ed22 | |||
8a4ebc6ab0 | |||
9d4f209f80 | |||
e44f5248ff | |||
27b5d991e2 | |||
74f6f9e793 | |||
aaf2530cc3 | |||
1269dc7cfb | |||
40872fb2e6 | |||
7b54e26bac | |||
d2223d8d6c | |||
bf16a4b4f8 | |||
ee1057e3b1 | |||
b551e587b3 | |||
d2e4484ef3 | |||
c7f66c82b3 | |||
98d8f295b1 | |||
39f4ffbcdc | |||
a86ce2b1e2 | |||
6fa9fe2482 | |||
0b2c58a91c | |||
d7ce4a2e3e | |||
386e4ba2f0 | |||
7b87e8485b | |||
d3ddacb625 | |||
eb98d8d87c | |||
ebee57f4d1 | |||
99542bbf3e | |||
da573cf490 | |||
bdda5bd4bf | |||
15ed462b2d | |||
7be5748963 | |||
57020525ed | |||
e8ab6a825a | |||
fee7b3d6ca | |||
1e7d4401dc | |||
4cecab63bd | |||
259f0434a5 | |||
ed34c39bfc | |||
33d8d0d4d3 | |||
c960b82e5c | |||
fe3cd28a53 | |||
45fbeba5cd | |||
4f33c82098 | |||
c379b55a93 | |||
5108d9aa00 | |||
ad497fbce3 | |||
0c0fb83211 | |||
9ac74f922e | |||
cb19dbc1a4 | |||
3f4042b52a | |||
5e2eb89e1f | |||
5b60db5c9d | |||
567e697776 | |||
c54ab8dd1a | |||
ec6f68c51e | |||
2a5c417c68 | |||
91b59e886b | |||
fe57273736 | |||
6b53ca876e | |||
b15d00d996 | |||
afe3cec813 | |||
fc8cad9f29 | |||
7b4b05e0dc | |||
c18787a0e9 | |||
479d19085d | |||
a80e8cfdf2 | |||
6c62841076 | |||
bbb6ecd9b0 | |||
7915396f40 | |||
652e944f69 | |||
c0991a141f | |||
48bf5ed134 | |||
bfef6c9f82 | |||
435308e029 | |||
dce64bfa1b | |||
429120d0af | |||
55b2fede7f | |||
701c772eed | |||
f918cb1013 | |||
6a19793777 | |||
293d786f31 | |||
0afa0ce2ff | |||
a6621bacf3 | |||
1ebf193c2c | |||
9ad2352d0d | |||
607510967f | |||
8ec7032bc2 | |||
472a049b4e | |||
a977b4b513 | |||
3591ba6684 | |||
e6ac450cbd |
5
.gitignore
vendored
5
.gitignore
vendored
@ -22,6 +22,7 @@ Makefile.in
|
||||
examples/anim_diff
|
||||
examples/[cdv]webp
|
||||
examples/gif2webp
|
||||
examples/img2webp
|
||||
examples/webpmux
|
||||
src/webp/config.h*
|
||||
src/webp/stamp-h1
|
||||
@ -34,3 +35,7 @@ src/webp/stamp-h1
|
||||
CMakeCache.txt
|
||||
CMakeFiles/
|
||||
cmake_install.cmake
|
||||
.gradle
|
||||
/build
|
||||
extras/get_disto
|
||||
extras/webp_quality
|
||||
|
2
AUTHORS
2
AUTHORS
@ -5,6 +5,7 @@ Contributors:
|
||||
- Hui Su (huisu at google dot com)
|
||||
- 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)
|
||||
- Jovan Zelincevic (jovan dot zelincevic at imgtec dot com)
|
||||
- Jyrki Alakuijala (jyrki at google dot com)
|
||||
@ -17,6 +18,7 @@ Contributors:
|
||||
- Mislav Bradac (mislavm at google dot com)
|
||||
- Nico Weber (thakis at chromium dot org)
|
||||
- Noel Chromium (noel at chromium dot org)
|
||||
- Owen Rodley (orodley at google dot com)
|
||||
- Parag Salasakar (img dot mips1 at gmail dot com)
|
||||
- Pascal Massimino (pascal dot massimino at gmail dot com)
|
||||
- Paweł Hajdan, Jr (phajdan dot jr at chromium dot org)
|
||||
|
115
Android.mk
115
Android.mk
@ -11,27 +11,39 @@ ifeq ($(APP_OPTIM),release)
|
||||
endif
|
||||
endif
|
||||
|
||||
# mips32 fails to build with clang from r14b
|
||||
# https://bugs.chromium.org/p/webp/issues/detail?id=343
|
||||
ifeq ($(findstring clang,$(NDK_TOOLCHAIN_VERSION)),clang)
|
||||
ifeq ($(TARGET_ARCH),mips)
|
||||
clang_version := $(shell $(TARGET_CC) --version)
|
||||
ifneq ($(findstring clang version 3,$(clang_version)),)
|
||||
WEBP_CFLAGS += -no-integrated-as
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),)
|
||||
# Setting LOCAL_ARM_NEON will enable -mfpu=neon which may cause illegal
|
||||
# instructions to be generated for armv7a code. Instead target the neon code
|
||||
# specifically.
|
||||
NEON := c.neon
|
||||
USE_CPUFEATURES := yes
|
||||
WEBP_CFLAGS += -DHAVE_CPU_FEATURES_H
|
||||
else
|
||||
NEON := c
|
||||
endif
|
||||
|
||||
dec_srcs := \
|
||||
src/dec/alpha.c \
|
||||
src/dec/buffer.c \
|
||||
src/dec/frame.c \
|
||||
src/dec/idec.c \
|
||||
src/dec/io.c \
|
||||
src/dec/quant.c \
|
||||
src/dec/tree.c \
|
||||
src/dec/vp8.c \
|
||||
src/dec/vp8l.c \
|
||||
src/dec/webp.c \
|
||||
src/dec/alpha_dec.c \
|
||||
src/dec/buffer_dec.c \
|
||||
src/dec/frame_dec.c \
|
||||
src/dec/idec_dec.c \
|
||||
src/dec/io_dec.c \
|
||||
src/dec/quant_dec.c \
|
||||
src/dec/tree_dec.c \
|
||||
src/dec/vp8_dec.c \
|
||||
src/dec/vp8l_dec.c \
|
||||
src/dec/webp_dec.c \
|
||||
|
||||
demux_srcs := \
|
||||
src/demux/anim_decode.c \
|
||||
@ -40,6 +52,7 @@ demux_srcs := \
|
||||
dsp_dec_srcs := \
|
||||
src/dsp/alpha_processing.c \
|
||||
src/dsp/alpha_processing_mips_dsp_r2.c \
|
||||
src/dsp/alpha_processing_neon.$(NEON) \
|
||||
src/dsp/alpha_processing_sse2.c \
|
||||
src/dsp/alpha_processing_sse41.c \
|
||||
src/dsp/argb.c \
|
||||
@ -56,23 +69,29 @@ dsp_dec_srcs := \
|
||||
src/dsp/dec_sse41.c \
|
||||
src/dsp/filters.c \
|
||||
src/dsp/filters_mips_dsp_r2.c \
|
||||
src/dsp/filters_msa.c \
|
||||
src/dsp/filters_neon.$(NEON) \
|
||||
src/dsp/filters_sse2.c \
|
||||
src/dsp/lossless.c \
|
||||
src/dsp/lossless_mips_dsp_r2.c \
|
||||
src/dsp/lossless_msa.c \
|
||||
src/dsp/lossless_neon.$(NEON) \
|
||||
src/dsp/lossless_sse2.c \
|
||||
src/dsp/rescaler.c \
|
||||
src/dsp/rescaler_mips32.c \
|
||||
src/dsp/rescaler_mips_dsp_r2.c \
|
||||
src/dsp/rescaler_msa.c \
|
||||
src/dsp/rescaler_neon.$(NEON) \
|
||||
src/dsp/rescaler_sse2.c \
|
||||
src/dsp/upsampling.c \
|
||||
src/dsp/upsampling_mips_dsp_r2.c \
|
||||
src/dsp/upsampling_msa.c \
|
||||
src/dsp/upsampling_neon.$(NEON) \
|
||||
src/dsp/upsampling_sse2.c \
|
||||
src/dsp/yuv.c \
|
||||
src/dsp/yuv_mips32.c \
|
||||
src/dsp/yuv_mips_dsp_r2.c \
|
||||
src/dsp/yuv_neon.$(NEON) \
|
||||
src/dsp/yuv_sse2.c \
|
||||
|
||||
dsp_enc_srcs := \
|
||||
@ -84,39 +103,45 @@ dsp_enc_srcs := \
|
||||
src/dsp/enc_avx2.c \
|
||||
src/dsp/enc_mips32.c \
|
||||
src/dsp/enc_mips_dsp_r2.c \
|
||||
src/dsp/enc_msa.c \
|
||||
src/dsp/enc_neon.$(NEON) \
|
||||
src/dsp/enc_sse2.c \
|
||||
src/dsp/enc_sse41.c \
|
||||
src/dsp/lossless_enc.c \
|
||||
src/dsp/lossless_enc_mips32.c \
|
||||
src/dsp/lossless_enc_mips_dsp_r2.c \
|
||||
src/dsp/lossless_enc_msa.c \
|
||||
src/dsp/lossless_enc_neon.$(NEON) \
|
||||
src/dsp/lossless_enc_sse2.c \
|
||||
src/dsp/lossless_enc_sse41.c \
|
||||
src/dsp/ssim.c \
|
||||
src/dsp/ssim_sse2.c \
|
||||
|
||||
enc_srcs := \
|
||||
src/enc/alpha.c \
|
||||
src/enc/analysis.c \
|
||||
src/enc/backward_references.c \
|
||||
src/enc/config.c \
|
||||
src/enc/cost.c \
|
||||
src/enc/delta_palettization.c \
|
||||
src/enc/filter.c \
|
||||
src/enc/frame.c \
|
||||
src/enc/histogram.c \
|
||||
src/enc/iterator.c \
|
||||
src/enc/near_lossless.c \
|
||||
src/enc/picture.c \
|
||||
src/enc/picture_csp.c \
|
||||
src/enc/picture_psnr.c \
|
||||
src/enc/picture_rescale.c \
|
||||
src/enc/picture_tools.c \
|
||||
src/enc/quant.c \
|
||||
src/enc/syntax.c \
|
||||
src/enc/token.c \
|
||||
src/enc/tree.c \
|
||||
src/enc/vp8l.c \
|
||||
src/enc/webpenc.c \
|
||||
src/enc/alpha_enc.c \
|
||||
src/enc/analysis_enc.c \
|
||||
src/enc/backward_references_cost_enc.c \
|
||||
src/enc/backward_references_enc.c \
|
||||
src/enc/config_enc.c \
|
||||
src/enc/cost_enc.c \
|
||||
src/enc/delta_palettization_enc.c \
|
||||
src/enc/filter_enc.c \
|
||||
src/enc/frame_enc.c \
|
||||
src/enc/histogram_enc.c \
|
||||
src/enc/iterator_enc.c \
|
||||
src/enc/near_lossless_enc.c \
|
||||
src/enc/picture_enc.c \
|
||||
src/enc/picture_csp_enc.c \
|
||||
src/enc/picture_psnr_enc.c \
|
||||
src/enc/picture_rescale_enc.c \
|
||||
src/enc/picture_tools_enc.c \
|
||||
src/enc/predictor_enc.c \
|
||||
src/enc/quant_enc.c \
|
||||
src/enc/syntax_enc.c \
|
||||
src/enc/token_enc.c \
|
||||
src/enc/tree_enc.c \
|
||||
src/enc/vp8l_enc.c \
|
||||
src/enc/webp_enc.c \
|
||||
|
||||
mux_srcs := \
|
||||
src/mux/anim_encode.c \
|
||||
@ -125,20 +150,20 @@ mux_srcs := \
|
||||
src/mux/muxread.c \
|
||||
|
||||
utils_dec_srcs := \
|
||||
src/utils/bit_reader.c \
|
||||
src/utils/color_cache.c \
|
||||
src/utils/filters.c \
|
||||
src/utils/huffman.c \
|
||||
src/utils/quant_levels_dec.c \
|
||||
src/utils/random.c \
|
||||
src/utils/rescaler.c \
|
||||
src/utils/thread.c \
|
||||
src/utils/bit_reader_utils.c \
|
||||
src/utils/color_cache_utils.c \
|
||||
src/utils/filters_utils.c \
|
||||
src/utils/huffman_utils.c \
|
||||
src/utils/quant_levels_dec_utils.c \
|
||||
src/utils/random_utils.c \
|
||||
src/utils/rescaler_utils.c \
|
||||
src/utils/thread_utils.c \
|
||||
src/utils/utils.c \
|
||||
|
||||
utils_enc_srcs := \
|
||||
src/utils/bit_writer.c \
|
||||
src/utils/huffman_encode.c \
|
||||
src/utils/quant_levels.c \
|
||||
src/utils/bit_writer_utils.c \
|
||||
src/utils/huffman_encode_utils.c \
|
||||
src/utils/quant_levels_utils.c \
|
||||
|
||||
################################################################################
|
||||
# libwebpdecoder
|
||||
@ -248,7 +273,9 @@ endif
|
||||
|
||||
################################################################################
|
||||
|
||||
include $(LOCAL_PATH)/examples/Android.mk
|
||||
WEBP_SRC_PATH := $(LOCAL_PATH)
|
||||
include $(WEBP_SRC_PATH)/imageio/Android.mk
|
||||
include $(WEBP_SRC_PATH)/examples/Android.mk
|
||||
|
||||
ifeq ($(USE_CPUFEATURES),yes)
|
||||
$(call import-module,android/cpufeatures)
|
||||
|
317
CMakeLists.txt
317
CMakeLists.txt
@ -3,12 +3,21 @@ cmake_minimum_required(VERSION 2.8.7)
|
||||
project(libwebp C)
|
||||
|
||||
# Options for coder / decoder executables.
|
||||
option(WEBP_ENABLE_SIMD "Enable any SIMD optimization." ON)
|
||||
option(WEBP_ENABLE_WASM "Enable WebAssembly optimizations." OFF)
|
||||
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_WEBP_JS "Emscripten build of webp.js." OFF)
|
||||
option(WEBP_EXPERIMENTAL_FEATURES "Build with experimental features." OFF)
|
||||
option(WEBP_FORCE_ALIGNED "Force aligned memory operations." OFF)
|
||||
option(WEBP_ENABLE_SWAP_16BIT_CSP "Enable byte swap for 16 bit colorspaces." OFF)
|
||||
|
||||
if(WEBP_BUILD_WEBP_JS OR WEBP_ENABLE_WASM)
|
||||
set(WEBP_ENABLE_SIMD OFF)
|
||||
endif()
|
||||
|
||||
set(WEBP_DEP_LIBRARIES)
|
||||
set(WEBP_DEP_INCLUDE_DIRS)
|
||||
|
||||
@ -20,11 +29,18 @@ endif()
|
||||
|
||||
include(cmake/config.h.cmake)
|
||||
|
||||
# Extract the version of the library.
|
||||
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/configure.ac SOURCE_FILE)
|
||||
string(REGEX MATCH "[0-9.]+" WEBP_VERSION ${SOURCE_FILE})
|
||||
|
||||
################################################################################
|
||||
# Options.
|
||||
if(WEBP_ENABLE_SWAP_16BIT_CSP)
|
||||
add_definitions(-DWEBP_SWAP_16BIT_CSP)
|
||||
endif()
|
||||
if(WEBP_ENABLE_WASM)
|
||||
add_definitions(-DWEBP_USE_WASM)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Android only.
|
||||
@ -38,48 +54,110 @@ if(ANDROID)
|
||||
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS}
|
||||
${ANDROID_NDK}/sources/android/cpufeatures
|
||||
)
|
||||
add_definitions(-DHAVE_CPU_FEATURES_H)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# WebP source files.
|
||||
# Read the Makefile.am to get the source files.
|
||||
set(WEBP_SRCS)
|
||||
|
||||
function(parse_Makefile_am FOLDER WEBP_SRCS)
|
||||
# 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 "_SOURCES \\+= [^\n]*"
|
||||
string(REGEX MATCHALL "${SRC_REGEX}_SOURCES[ ]*\\+?=[ ]+[0-9a-z\\._ ]*"
|
||||
FILES_PER_LINE ${MAKEFILE_AM}
|
||||
)
|
||||
set(SRCS ${WEBP_SRCS})
|
||||
set(SRCS ${${VAR}})
|
||||
foreach(FILES ${FILES_PER_LINE})
|
||||
string(SUBSTRING ${FILES} 12 -1 FILES)
|
||||
string(REGEX MATCHALL "[0-9a-z\\._]+"
|
||||
FILES ${FILES}
|
||||
)
|
||||
foreach(FILE ${FILES})
|
||||
list(APPEND SRCS ${FOLDER}/${FILE})
|
||||
endforeach()
|
||||
string(FIND ${FILES} "=" OFFSET)
|
||||
math(EXPR OFFSET "${OFFSET} + 2")
|
||||
string(SUBSTRING ${FILES} ${OFFSET} -1 FILES)
|
||||
if(FILES)
|
||||
string(REGEX MATCHALL "[0-9a-z\\._]+"
|
||||
FILES ${FILES}
|
||||
)
|
||||
foreach(FILE ${FILES})
|
||||
list(APPEND SRCS ${FOLDER}/${FILE})
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
set(WEBP_SRCS ${SRCS} PARENT_SCOPE)
|
||||
set(${VAR} ${SRCS} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/dec "${WEBP_SRCS}")
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/demux "${WEBP_SRCS}")
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/dsp "${WEBP_SRCS}")
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/enc "${WEBP_SRCS}")
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/src/utils "${WEBP_SRCS}")
|
||||
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_[^ ]*")
|
||||
|
||||
# Remove the files specific to SIMD we don't use.
|
||||
foreach(FILE ${WEBP_SIMD_FILES_NOT_TO_INCLUDE})
|
||||
list(REMOVE_ITEM WEBP_SRCS ${FILE})
|
||||
list(REMOVE_ITEM WEBP_DSP_ENC_SRCS ${FILE})
|
||||
list(REMOVE_ITEM WEBP_DSP_DEC_SRCS ${FILE})
|
||||
endforeach()
|
||||
|
||||
# Build the library.
|
||||
### Define the mandatory libraries.
|
||||
# Build the webpdecoder library.
|
||||
add_definitions(-Wall)
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/ ${WEBP_DEP_INCLUDE_DIRS})
|
||||
add_library(webp ${WEBP_SRCS})
|
||||
add_library(webpdecode OBJECT ${WEBP_DEC_SRCS})
|
||||
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_link_libraries(webpdecoder ${WEBP_DEP_LIBRARIES})
|
||||
|
||||
# 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_link_libraries(webp ${WEBP_DEP_LIBRARIES})
|
||||
|
||||
# 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)
|
||||
|
||||
# Build the webp demux library.
|
||||
add_library(webpdemux ${WEBP_DEMUX_SRCS})
|
||||
target_link_libraries(webpdemux webp)
|
||||
|
||||
# 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})
|
||||
set(${VAR} "${VERSION}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
parse_version(Makefile.am webp WEBP_WEBP_SOVERSION)
|
||||
set_target_properties(webp PROPERTIES VERSION ${WEBP_VERSION}
|
||||
SOVERSION ${WEBP_WEBP_SOVERSION})
|
||||
parse_version(Makefile.am webpdecoder WEBP_DECODER_SOVERSION)
|
||||
set_target_properties(webpdecoder PROPERTIES VERSION ${WEBP_VERSION}
|
||||
SOVERSION ${WEBP_DECODER_SOVERSION})
|
||||
parse_version(demux/Makefile.am webpdemux WEBP_DEMUX_SOVERSION)
|
||||
set_target_properties(webpdemux PROPERTIES VERSION ${WEBP_VERSION}
|
||||
SOVERSION ${WEBP_DEMUX_SOVERSION})
|
||||
|
||||
# Define the libraries to install.
|
||||
set(INSTALLED_LIBRARIES webpdecoder webp webpdemux)
|
||||
|
||||
### 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
|
||||
@ -89,63 +167,176 @@ math(EXPR WEBP_SIMD_FILES_TO_INCLUDE_RANGE
|
||||
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}
|
||||
)
|
||||
if(NOT ${SIMD_COMPILE_FLAG} STREQUAL "NOTFOUND")
|
||||
set_source_files_properties(${FILE} PROPERTIES
|
||||
COMPILE_FLAGS ${SIMD_COMPILE_FLAG}
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Build the executables if asked for.
|
||||
if(WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP)
|
||||
if(WEBP_BUILD_CWEBP OR WEBP_BUILD_DWEBP OR
|
||||
WEBP_BUILD_GIF2WEBP OR WEBP_BUILD_IMG2WEBP OR WEBP_BUILD_WEBP_JS)
|
||||
# Example utility library.
|
||||
set(exampleutil_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/example_util.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/example_util.h
|
||||
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_link_libraries(exampleutil webp ${WEBP_DEP_LIBRARIES})
|
||||
endif()
|
||||
add_library(exampleutil ${EXAMPLEUTIL_SRCS})
|
||||
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEIOUTILS_SRCS"
|
||||
"imageio_util_[^ ]*")
|
||||
add_library(imageioutil ${IMAGEIOUTILS_SRCS})
|
||||
target_link_libraries(imageioutil webp)
|
||||
|
||||
if(WEBP_BUILD_CWEBP)
|
||||
# Image-decoding utility library.
|
||||
set(exampledec_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/image_dec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/image_dec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/jpegdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/metadata.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/pngdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/tiffdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/webpdec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/wicdec.h)
|
||||
add_library(exampledec ${exampledec_SRCS})
|
||||
target_link_libraries(exampledec webp ${WEBP_DEP_LIBRARIES}
|
||||
${WEBP_DEP_IMG_LIBRARIES})
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEDEC_SRCS"
|
||||
"imagedec_[^ ]*")
|
||||
add_library(imagedec ${IMAGEDEC_SRCS})
|
||||
target_link_libraries(imagedec imageioutil webp ${WEBP_DEP_IMG_LIBRARIES})
|
||||
|
||||
# Image-encoding utility library.
|
||||
parse_Makefile_am(${CMAKE_CURRENT_SOURCE_DIR}/imageio "IMAGEENC_SRCS"
|
||||
"imageenc_[^ ]*")
|
||||
add_library(imageenc ${IMAGEENC_SRCS})
|
||||
target_link_libraries(imageenc webp)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_DWEBP)
|
||||
# dwebp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
add_executable(dwebp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/dwebp.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h
|
||||
)
|
||||
target_link_libraries(dwebp webp exampleutil ${WEBP_DEP_LIBRARIES}
|
||||
${WEBP_DEP_IMG_LIBRARIES}
|
||||
)
|
||||
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)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_CWEBP)
|
||||
# cwebp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
add_executable(cwebp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/cwebp.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/stopwatch.h)
|
||||
target_link_libraries(cwebp exampledec webp exampleutil
|
||||
${WEBP_DEP_LIBRARIES} ${WEBP_DEP_IMG_LIBRARIES}
|
||||
)
|
||||
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)
|
||||
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_version(mux/Makefile.am webpmux WEBP_MUX_SOVERSION)
|
||||
set_target_properties(webpmux PROPERTIES VERSION ${WEBP_VERSION}
|
||||
SOVERSION ${WEBP_MUX_SOVERSION})
|
||||
list(APPEND INSTALLED_LIBRARIES webpmux)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_GIF2WEBP)
|
||||
# gif2webp
|
||||
include_directories(${WEBP_DEP_GIF_INCLUDE_DIRS})
|
||||
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)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_IMG2WEBP)
|
||||
# img2webp
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
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)
|
||||
endif()
|
||||
|
||||
if (WEBP_BUILD_WEBPINFO)
|
||||
# webpinfo
|
||||
include_directories(${WEBP_DEP_IMG_INCLUDE_DIRS})
|
||||
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)
|
||||
endif()
|
||||
|
||||
if(WEBP_BUILD_WEBP_JS)
|
||||
# JavaScript version
|
||||
add_executable(webp_js
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extras/webp_to_sdl.c)
|
||||
target_link_libraries(webp_js webpdecoder SDL)
|
||||
set_target_properties(webp_js PROPERTIES LINK_FLAGS
|
||||
"-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0")
|
||||
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)
|
||||
target_link_libraries(webp_wasm webpdecoder SDL)
|
||||
set_target_properties(webp_wasm PROPERTIES LINK_FLAGS
|
||||
"-s WASM=1 -s 'BINARYEN_METHOD=\"native-wasm\"' \
|
||||
-s EXPORTED_FUNCTIONS='[\"_WebpToSDL\"]' -s INVOKE_RUN=0")
|
||||
target_compile_definitions(webp_wasm PUBLIC EMSCRIPTEN WEBP_HAVE_SDL)
|
||||
|
||||
target_compile_definitions(webpdecoder PUBLIC EMSCRIPTEN)
|
||||
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)
|
||||
install(TARGETS ${INSTALLED_LIBRARIES}
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
# Create the CMake version file.
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/WebPConfigVersion.cmake"
|
||||
VERSION ${WEBP_VERSION}
|
||||
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 the generated CMake files.
|
||||
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")
|
||||
list(LENGTH MAN_PAGES MAN_PAGES_LENGTH)
|
||||
math(EXPR MAN_PAGES_RANGE "${MAN_PAGES_LENGTH} - 1")
|
||||
|
||||
foreach(I_MAN RANGE ${MAN_PAGES_RANGE})
|
||||
list(GET EXEC_BUILDS ${I_MAN} EXEC_BUILD)
|
||||
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
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -1,3 +1,9 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
SUBDIRS = src examples man
|
||||
SUBDIRS = src imageio man
|
||||
EXTRA_DIST = COPYING autogen.sh
|
||||
|
||||
if WANT_EXTRAS
|
||||
SUBDIRS += extras
|
||||
endif
|
||||
|
||||
SUBDIRS += examples
|
||||
|
196
Makefile.vc
196
Makefile.vc
@ -37,6 +37,8 @@ LNKDLL = link.exe /DLL $(NOLOGO)
|
||||
LNKEXE = link.exe $(NOLOGO)
|
||||
LNKLIB = lib.exe $(NOLOGO)
|
||||
MT = mt.exe $(NOLOGO)
|
||||
RCNODBG = rc.exe $(NOLOGO) /l"0x0409" # 0x409 = U.S. English
|
||||
RCDEBUG = $(RCNODBG) /D_DEBUG
|
||||
|
||||
!IF "$(ARCH)" == "ARM"
|
||||
CFLAGS = $(CFLAGS) /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP /DWEBP_USE_THREAD
|
||||
@ -82,6 +84,8 @@ OUTPUT_DIRS = $(DIRBIN) $(DIRINC) $(DIRLIB) \
|
||||
$(DIROBJ)\dsp \
|
||||
$(DIROBJ)\enc \
|
||||
$(DIROBJ)\examples \
|
||||
$(DIROBJ)\extras \
|
||||
$(DIROBJ)\imageio \
|
||||
$(DIROBJ)\mux \
|
||||
$(DIROBJ)\utils \
|
||||
|
||||
@ -99,9 +103,11 @@ LIBWEBPMUX_BASENAME = $(LIBWEBPMUX_BASENAME)_debug
|
||||
LIBWEBPDEMUX_BASENAME = $(LIBWEBPDEMUX_BASENAME)_debug
|
||||
!ELSE IF "$(CFG)" == "release-dynamic"
|
||||
CC = $(CCNODBG)
|
||||
RC = $(RCNODBG)
|
||||
DLLBUILD = TRUE
|
||||
!ELSE IF "$(CFG)" == "debug-dynamic"
|
||||
CC = $(CCDEBUG)
|
||||
RC = $(RCDEBUG)
|
||||
RTLIB = $(RTLIBD)
|
||||
DLLBUILD = TRUE
|
||||
LIBWEBPDECODER_BASENAME = $(LIBWEBPDECODER_BASENAME)_debug
|
||||
@ -169,16 +175,16 @@ CFGSET = TRUE
|
||||
#
|
||||
|
||||
DEC_OBJS = \
|
||||
$(DIROBJ)\dec\alpha.obj \
|
||||
$(DIROBJ)\dec\buffer.obj \
|
||||
$(DIROBJ)\dec\frame.obj \
|
||||
$(DIROBJ)\dec\idec.obj \
|
||||
$(DIROBJ)\dec\io.obj \
|
||||
$(DIROBJ)\dec\quant.obj \
|
||||
$(DIROBJ)\dec\tree.obj \
|
||||
$(DIROBJ)\dec\vp8.obj \
|
||||
$(DIROBJ)\dec\vp8l.obj \
|
||||
$(DIROBJ)\dec\webp.obj \
|
||||
$(DIROBJ)\dec\alpha_dec.obj \
|
||||
$(DIROBJ)\dec\buffer_dec.obj \
|
||||
$(DIROBJ)\dec\frame_dec.obj \
|
||||
$(DIROBJ)\dec\idec_dec.obj \
|
||||
$(DIROBJ)\dec\io_dec.obj \
|
||||
$(DIROBJ)\dec\quant_dec.obj \
|
||||
$(DIROBJ)\dec\tree_dec.obj \
|
||||
$(DIROBJ)\dec\vp8_dec.obj \
|
||||
$(DIROBJ)\dec\vp8l_dec.obj \
|
||||
$(DIROBJ)\dec\webp_dec.obj \
|
||||
|
||||
DEMUX_OBJS = \
|
||||
$(DIROBJ)\demux\anim_decode.obj \
|
||||
@ -187,6 +193,7 @@ DEMUX_OBJS = \
|
||||
DSP_DEC_OBJS = \
|
||||
$(DIROBJ)\dsp\alpha_processing.obj \
|
||||
$(DIROBJ)\dsp\alpha_processing_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\alpha_processing_neon.obj \
|
||||
$(DIROBJ)\dsp\alpha_processing_sse2.obj \
|
||||
$(DIROBJ)\dsp\alpha_processing_sse41.obj \
|
||||
$(DIROBJ)\dsp\cpu.obj \
|
||||
@ -200,23 +207,29 @@ DSP_DEC_OBJS = \
|
||||
$(DIROBJ)\dsp\dec_sse41.obj \
|
||||
$(DIROBJ)\dsp\filters.obj \
|
||||
$(DIROBJ)\dsp\filters_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\filters_msa.obj \
|
||||
$(DIROBJ)\dsp\filters_neon.obj \
|
||||
$(DIROBJ)\dsp\filters_sse2.obj \
|
||||
$(DIROBJ)\dsp\lossless.obj \
|
||||
$(DIROBJ)\dsp\lossless_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\lossless_msa.obj \
|
||||
$(DIROBJ)\dsp\lossless_neon.obj \
|
||||
$(DIROBJ)\dsp\lossless_sse2.obj \
|
||||
$(DIROBJ)\dsp\rescaler.obj \
|
||||
$(DIROBJ)\dsp\rescaler_mips32.obj \
|
||||
$(DIROBJ)\dsp\rescaler_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\rescaler_msa.obj \
|
||||
$(DIROBJ)\dsp\rescaler_neon.obj \
|
||||
$(DIROBJ)\dsp\rescaler_sse2.obj \
|
||||
$(DIROBJ)\dsp\upsampling.obj \
|
||||
$(DIROBJ)\dsp\upsampling_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\upsampling_msa.obj \
|
||||
$(DIROBJ)\dsp\upsampling_neon.obj \
|
||||
$(DIROBJ)\dsp\upsampling_sse2.obj \
|
||||
$(DIROBJ)\dsp\yuv.obj \
|
||||
$(DIROBJ)\dsp\yuv_mips32.obj \
|
||||
$(DIROBJ)\dsp\yuv_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\yuv_neon.obj \
|
||||
$(DIROBJ)\dsp\yuv_sse2.obj \
|
||||
|
||||
DSP_ENC_OBJS = \
|
||||
@ -231,27 +244,35 @@ DSP_ENC_OBJS = \
|
||||
$(DIROBJ)\dsp\enc_avx2.obj \
|
||||
$(DIROBJ)\dsp\enc_mips32.obj \
|
||||
$(DIROBJ)\dsp\enc_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\enc_msa.obj \
|
||||
$(DIROBJ)\dsp\enc_neon.obj \
|
||||
$(DIROBJ)\dsp\enc_sse2.obj \
|
||||
$(DIROBJ)\dsp\enc_sse41.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_mips32.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_mips_dsp_r2.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_msa.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_neon.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_sse2.obj \
|
||||
$(DIROBJ)\dsp\lossless_enc_sse41.obj \
|
||||
$(DIROBJ)\dsp\ssim.obj \
|
||||
$(DIROBJ)\dsp\ssim_sse2.obj \
|
||||
|
||||
EX_ANIM_UTIL_OBJS = \
|
||||
$(DIROBJ)\examples\anim_util.obj \
|
||||
|
||||
EX_FORMAT_DEC_OBJS = \
|
||||
$(DIROBJ)\examples\image_dec.obj \
|
||||
$(DIROBJ)\examples\jpegdec.obj \
|
||||
$(DIROBJ)\examples\metadata.obj \
|
||||
$(DIROBJ)\examples\pngdec.obj \
|
||||
$(DIROBJ)\examples\tiffdec.obj \
|
||||
$(DIROBJ)\examples\webpdec.obj \
|
||||
$(DIROBJ)\examples\wicdec.obj \
|
||||
IMAGEIO_DEC_OBJS = \
|
||||
$(DIROBJ)\imageio\image_dec.obj \
|
||||
$(DIROBJ)\imageio\jpegdec.obj \
|
||||
$(DIROBJ)\imageio\metadata.obj \
|
||||
$(DIROBJ)\imageio\pngdec.obj \
|
||||
$(DIROBJ)\imageio\pnmdec.obj \
|
||||
$(DIROBJ)\imageio\tiffdec.obj \
|
||||
$(DIROBJ)\imageio\webpdec.obj \
|
||||
$(DIROBJ)\imageio\wicdec.obj \
|
||||
|
||||
IMAGEIO_ENC_OBJS = \
|
||||
$(DIROBJ)\imageio\image_enc.obj \
|
||||
|
||||
EX_GIF_DEC_OBJS = \
|
||||
$(DIROBJ)\examples\gifdec.obj \
|
||||
@ -260,28 +281,37 @@ EX_UTIL_OBJS = \
|
||||
$(DIROBJ)\examples\example_util.obj \
|
||||
|
||||
ENC_OBJS = \
|
||||
$(DIROBJ)\enc\alpha.obj \
|
||||
$(DIROBJ)\enc\analysis.obj \
|
||||
$(DIROBJ)\enc\backward_references.obj \
|
||||
$(DIROBJ)\enc\config.obj \
|
||||
$(DIROBJ)\enc\cost.obj \
|
||||
$(DIROBJ)\enc\delta_palettization.obj \
|
||||
$(DIROBJ)\enc\filter.obj \
|
||||
$(DIROBJ)\enc\frame.obj \
|
||||
$(DIROBJ)\enc\histogram.obj \
|
||||
$(DIROBJ)\enc\iterator.obj \
|
||||
$(DIROBJ)\enc\near_lossless.obj \
|
||||
$(DIROBJ)\enc\picture.obj \
|
||||
$(DIROBJ)\enc\picture_csp.obj \
|
||||
$(DIROBJ)\enc\picture_psnr.obj \
|
||||
$(DIROBJ)\enc\picture_rescale.obj \
|
||||
$(DIROBJ)\enc\picture_tools.obj \
|
||||
$(DIROBJ)\enc\quant.obj \
|
||||
$(DIROBJ)\enc\syntax.obj \
|
||||
$(DIROBJ)\enc\token.obj \
|
||||
$(DIROBJ)\enc\tree.obj \
|
||||
$(DIROBJ)\enc\vp8l.obj \
|
||||
$(DIROBJ)\enc\webpenc.obj \
|
||||
$(DIROBJ)\enc\alpha_enc.obj \
|
||||
$(DIROBJ)\enc\analysis_enc.obj \
|
||||
$(DIROBJ)\enc\backward_references_cost_enc.obj \
|
||||
$(DIROBJ)\enc\backward_references_enc.obj \
|
||||
$(DIROBJ)\enc\config_enc.obj \
|
||||
$(DIROBJ)\enc\cost_enc.obj \
|
||||
$(DIROBJ)\enc\delta_palettization_enc.obj \
|
||||
$(DIROBJ)\enc\filter_enc.obj \
|
||||
$(DIROBJ)\enc\frame_enc.obj \
|
||||
$(DIROBJ)\enc\histogram_enc.obj \
|
||||
$(DIROBJ)\enc\iterator_enc.obj \
|
||||
$(DIROBJ)\enc\near_lossless_enc.obj \
|
||||
$(DIROBJ)\enc\picture_enc.obj \
|
||||
$(DIROBJ)\enc\picture_csp_enc.obj \
|
||||
$(DIROBJ)\enc\picture_psnr_enc.obj \
|
||||
$(DIROBJ)\enc\picture_rescale_enc.obj \
|
||||
$(DIROBJ)\enc\picture_tools_enc.obj \
|
||||
$(DIROBJ)\enc\predictor_enc.obj \
|
||||
$(DIROBJ)\enc\quant_enc.obj \
|
||||
$(DIROBJ)\enc\syntax_enc.obj \
|
||||
$(DIROBJ)\enc\token_enc.obj \
|
||||
$(DIROBJ)\enc\tree_enc.obj \
|
||||
$(DIROBJ)\enc\vp8l_enc.obj \
|
||||
$(DIROBJ)\enc\webp_enc.obj \
|
||||
|
||||
EXTRAS_OBJS = \
|
||||
$(DIROBJ)\extras\extras.obj \
|
||||
$(DIROBJ)\extras\quality_estimate.obj \
|
||||
|
||||
IMAGEIO_UTIL_OBJS = \
|
||||
$(DIROBJ)\imageio\imageio_util.obj \
|
||||
|
||||
MUX_OBJS = \
|
||||
$(DIROBJ)\mux\anim_encode.obj \
|
||||
@ -290,20 +320,20 @@ MUX_OBJS = \
|
||||
$(DIROBJ)\mux\muxread.obj \
|
||||
|
||||
UTILS_DEC_OBJS = \
|
||||
$(DIROBJ)\utils\bit_reader.obj \
|
||||
$(DIROBJ)\utils\color_cache.obj \
|
||||
$(DIROBJ)\utils\filters.obj \
|
||||
$(DIROBJ)\utils\huffman.obj \
|
||||
$(DIROBJ)\utils\quant_levels_dec.obj \
|
||||
$(DIROBJ)\utils\rescaler.obj \
|
||||
$(DIROBJ)\utils\random.obj \
|
||||
$(DIROBJ)\utils\thread.obj \
|
||||
$(DIROBJ)\utils\bit_reader_utils.obj \
|
||||
$(DIROBJ)\utils\color_cache_utils.obj \
|
||||
$(DIROBJ)\utils\filters_utils.obj \
|
||||
$(DIROBJ)\utils\huffman_utils.obj \
|
||||
$(DIROBJ)\utils\quant_levels_dec_utils.obj \
|
||||
$(DIROBJ)\utils\rescaler_utils.obj \
|
||||
$(DIROBJ)\utils\random_utils.obj \
|
||||
$(DIROBJ)\utils\thread_utils.obj \
|
||||
$(DIROBJ)\utils\utils.obj \
|
||||
|
||||
UTILS_ENC_OBJS = \
|
||||
$(DIROBJ)\utils\bit_writer.obj \
|
||||
$(DIROBJ)\utils\huffman_encode.obj \
|
||||
$(DIROBJ)\utils\quant_levels.obj \
|
||||
$(DIROBJ)\utils\bit_writer_utils.obj \
|
||||
$(DIROBJ)\utils\huffman_encode_utils.obj \
|
||||
$(DIROBJ)\utils\quant_levels_utils.obj \
|
||||
|
||||
LIBWEBPDECODER_OBJS = $(DEC_OBJS) $(DSP_DEC_OBJS) $(UTILS_DEC_OBJS)
|
||||
LIBWEBP_OBJS = $(LIBWEBPDECODER_OBJS) $(ENC_OBJS) $(DSP_ENC_OBJS) \
|
||||
@ -317,7 +347,10 @@ ex: $(OUT_LIBS)
|
||||
all: ex
|
||||
!ELSE
|
||||
OUT_EXAMPLES = $(DIRBIN)\cwebp.exe $(DIRBIN)\dwebp.exe
|
||||
EXTRA_EXAMPLES = $(DIRBIN)\vwebp.exe $(DIRBIN)\webpmux.exe
|
||||
EXTRA_EXAMPLES = $(DIRBIN)\vwebp.exe $(DIRBIN)\webpmux.exe \
|
||||
$(DIRBIN)\img2webp.exe $(DIRBIN)\get_disto.exe \
|
||||
$(DIRBIN)\webp_quality.exe $(DIRBIN)\vwebp_sdl.exe \
|
||||
$(DIRBIN)\webpinfo.exe
|
||||
|
||||
ex: $(OUT_LIBS) $(OUT_EXAMPLES)
|
||||
all: ex $(EXTRA_EXAMPLES)
|
||||
@ -327,18 +360,38 @@ gif2webp: $(DIRBIN)\gif2webp.exe
|
||||
anim_diff: $(DIRBIN)\anim_diff.exe
|
||||
|
||||
$(DIRBIN)\anim_diff.exe: $(DIROBJ)\examples\anim_diff.obj $(EX_ANIM_UTIL_OBJS)
|
||||
$(DIRBIN)\anim_diff.exe: $(EX_UTIL_OBJS)
|
||||
$(DIRBIN)\anim_diff.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\anim_diff.exe: $(EX_GIF_DEC_OBJS) $(LIBWEBPDEMUX) $(LIBWEBP)
|
||||
$(DIRBIN)\cwebp.exe: $(DIROBJ)\examples\cwebp.obj $(EX_FORMAT_DEC_OBJS)
|
||||
$(DIRBIN)\dwebp.exe: $(DIROBJ)\examples\dwebp.obj
|
||||
$(DIRBIN)\cwebp.exe: $(DIROBJ)\examples\cwebp.obj $(IMAGEIO_DEC_OBJS)
|
||||
$(DIRBIN)\cwebp.exe: $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\dwebp.exe: $(DIROBJ)\examples\dwebp.obj $(IMAGEIO_DEC_OBJS)
|
||||
$(DIRBIN)\dwebp.exe: $(IMAGEIO_ENC_OBJS)
|
||||
$(DIRBIN)\dwebp.exe: $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\gif2webp.exe: $(DIROBJ)\examples\gif2webp.obj $(EX_GIF_DEC_OBJS)
|
||||
$(DIRBIN)\gif2webp.exe: $(EX_UTIL_OBJS) $(LIBWEBPMUX) $(LIBWEBP)
|
||||
$(DIRBIN)\vwebp.exe: $(DIROBJ)\examples\vwebp.obj
|
||||
$(DIRBIN)\vwebp.exe: $(EX_UTIL_OBJS) $(LIBWEBPDEMUX) $(LIBWEBP)
|
||||
$(DIRBIN)\gif2webp.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS) $(LIBWEBPMUX)
|
||||
$(DIRBIN)\gif2webp.exe: $(LIBWEBP)
|
||||
$(DIRBIN)\vwebp.exe: $(DIROBJ)\examples\vwebp.obj $(EX_UTIL_OBJS)
|
||||
$(DIRBIN)\vwebp.exe: $(IMAGEIO_UTIL_OBJS) $(LIBWEBPDEMUX) $(LIBWEBP)
|
||||
$(DIRBIN)\vwebp_sdl.exe: $(DIROBJ)\extras\vwebp_sdl.obj
|
||||
$(DIRBIN)\vwebp_sdl.exe: $(DIROBJ)\extras\webp_to_sdl.obj
|
||||
$(DIRBIN)\vwebp_sdl.exe: $(IMAGEIO_UTIL_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\webpmux.exe: $(DIROBJ)\examples\webpmux.obj $(LIBWEBPMUX)
|
||||
$(DIRBIN)\webpmux.exe: $(EX_UTIL_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\webpmux.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\img2webp.exe: $(DIROBJ)\examples\img2webp.obj $(LIBWEBPMUX)
|
||||
$(DIRBIN)\img2webp.exe: $(IMAGEIO_DEC_OBJS)
|
||||
$(DIRBIN)\img2webp.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\get_disto.exe: $(DIROBJ)\extras\get_disto.obj
|
||||
$(DIRBIN)\get_disto.exe: $(IMAGEIO_DEC_OBJS) $(IMAGEIO_UTIL_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\webp_quality.exe: $(DIROBJ)\extras\webp_quality.obj
|
||||
$(DIRBIN)\webp_quality.exe: $(IMAGEIO_UTIL_OBJS)
|
||||
$(DIRBIN)\webp_quality.exe: $(EXTRAS_OBJS) $(LIBWEBP)
|
||||
$(DIRBIN)\webpinfo.exe: $(DIROBJ)\examples\webpinfo.obj
|
||||
$(DIRBIN)\webpinfo.exe: $(IMAGEIO_DEC_OBJS)
|
||||
$(DIRBIN)\webpinfo.exe: $(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS) $(LIBWEBP)
|
||||
|
||||
$(OUT_EXAMPLES): $(EX_UTIL_OBJS) $(LIBWEBP)
|
||||
$(EX_UTIL_OBJS) $(EX_FORMAT_DEC_OBJS): $(OUTPUT_DIRS)
|
||||
$(EX_UTIL_OBJS) $(IMAGEIO_UTIL_OBJS): $(OUTPUT_DIRS)
|
||||
$(IMAGEIO_DEC_OBJS) $(IMAGEIO_ENC_OBJS) $(EXTRAS_OBJS): $(OUTPUT_DIRS)
|
||||
!ENDIF # ARCH == ARM
|
||||
|
||||
experimental:
|
||||
@ -360,8 +413,17 @@ $(LIBWEBP_OBJS) $(LIBWEBPMUX_OBJS) $(LIBWEBPDEMUX_OBJS): \
|
||||
{$(DIROBJ)}.c{$(DIROBJ)}.obj:
|
||||
$(CC) $(CFLAGS) /Fd$(LIBWEBP_PDBNAME) /Fo$@ $<
|
||||
|
||||
$(LIBWEBPMUX): $(LIBWEBP)
|
||||
$(LIBWEBPDEMUX): $(LIBWEBP)
|
||||
{src}.rc{$(DIROBJ)}.res:
|
||||
$(RC) /fo$@ $<
|
||||
{src\demux}.rc{$(DIROBJ)\demux}.res:
|
||||
$(RC) /fo$@ $<
|
||||
{src\mux}.rc{$(DIROBJ)\mux}.res:
|
||||
$(RC) /fo$@ $<
|
||||
|
||||
$(LIBWEBP): $(DIROBJ)\$(LIBWEBP_BASENAME:_debug=).res
|
||||
$(LIBWEBPDECODER): $(DIROBJ)\$(LIBWEBPDECODER_BASENAME:_debug=).res
|
||||
$(LIBWEBPMUX): $(LIBWEBP) $(DIROBJ)\mux\$(LIBWEBPMUX_BASENAME:_debug=).res
|
||||
$(LIBWEBPDEMUX): $(LIBWEBP) $(DIROBJ)\demux\$(LIBWEBPDEMUX_BASENAME:_debug=).res
|
||||
|
||||
$(LIBWEBPDECODER) $(LIBWEBP) $(LIBWEBPMUX) $(LIBWEBPDEMUX):
|
||||
$(LNKDLL) /out:$(DIRBIN)\$(@B:_dll=.dll) /implib:$@ $(LFLAGS) $**
|
||||
@ -406,6 +468,10 @@ $(DIROBJ)\examples\gifdec.obj: examples\gifdec.c
|
||||
# Batch rules
|
||||
{examples}.c{$(DIROBJ)\examples}.obj::
|
||||
$(CC) $(CFLAGS) /Fd$(DIROBJ)\examples\ /Fo$(DIROBJ)\examples\ $<
|
||||
{extras}.c{$(DIROBJ)\extras}.obj::
|
||||
$(CC) $(CFLAGS) /Fd$(DIROBJ)\extras\ /Fo$(DIROBJ)\extras\ $<
|
||||
{imageio}.c{$(DIROBJ)\imageio}.obj::
|
||||
$(CC) $(CFLAGS) /Fd$(DIROBJ)\imageio\ /Fo$(DIROBJ)\imageio\ $<
|
||||
{src\dec}.c{$(DIROBJ)\dec}.obj::
|
||||
$(CC) $(CFLAGS) /Fd$(LIBWEBP_PDBNAME) /Fo$(DIROBJ)\dec\ $<
|
||||
{src\demux}.c{$(DIROBJ)\demux}.obj::
|
||||
@ -425,6 +491,12 @@ $(DIROBJ)\examples\gifdec.obj: examples\gifdec.c
|
||||
$(MT) -manifest $@.manifest -outputresource:$@;1
|
||||
del $@.manifest
|
||||
|
||||
{$(DIROBJ)\extras}.obj{$(DIRBIN)}.exe:
|
||||
$(LNKEXE) $(LDFLAGS) /OUT:$@ $** \
|
||||
ole32.lib windowscodecs.lib shlwapi.lib
|
||||
$(MT) -manifest $@.manifest -outputresource:$@;1
|
||||
del $@.manifest
|
||||
|
||||
clean::
|
||||
@-erase /s $(DIROBJ)\*.dll 2> NUL
|
||||
@-erase /s $(DIROBJ)\*.exp 2> NUL
|
||||
|
15
NEWS
15
NEWS
@ -1,3 +1,18 @@
|
||||
- 1/26/2017: version 0.6.0
|
||||
* lossless performance and compression improvements
|
||||
* miscellaneous performance improvements (SSE2, NEON, MSA)
|
||||
* webpmux gained a -duration option allowing for frame timing modification
|
||||
* new img2webp utility allowing a sequence of images to be converted to
|
||||
animated webp
|
||||
* API changes:
|
||||
- libwebp:
|
||||
WebPPictureSharpARGBToYUVA
|
||||
WebPPlaneDistortion
|
||||
- libwebpmux / gif2webp:
|
||||
WebPAnimEncoderOptions: kmax <= 0 now disables keyframes, kmax == 1
|
||||
forces all keyframes. See mux.h and the gif2webp
|
||||
manpage for details.
|
||||
|
||||
- 12/13/2016: version 0.5.2
|
||||
This is a binary compatible release.
|
||||
This release covers CVE-2016-8888 and CVE-2016-9085.
|
||||
|
50
README
50
README
@ -4,7 +4,7 @@
|
||||
\__\__/\____/\_____/__/ ____ ___
|
||||
/ _/ / \ \ / _ \/ _/
|
||||
/ \_/ / / \ \ __/ \__
|
||||
\____/____/\_____/_____/____/v0.5.2
|
||||
\____/____/\_____/_____/____/v0.6.0
|
||||
|
||||
Description:
|
||||
============
|
||||
@ -113,8 +113,8 @@ make install
|
||||
|
||||
CMake:
|
||||
------
|
||||
The support for CMake is minimal: it only helps you compile libwebp, cwebp and
|
||||
dwebp.
|
||||
With CMake, you can compile libwebp, cwebp, dwebp, gif2web, img2webp and the
|
||||
JS bindings.
|
||||
|
||||
Prerequisites:
|
||||
A compiler (e.g., gcc with autotools) and CMake.
|
||||
@ -123,18 +123,25 @@ minimal build:
|
||||
$ sudo apt-get install build-essential cmake
|
||||
|
||||
When building from git sources, you will need to run cmake to generate the
|
||||
configure script.
|
||||
makefiles.
|
||||
|
||||
mkdir build && cd build && cmake ../
|
||||
make
|
||||
make install
|
||||
|
||||
If you also want cwebp or dwebp, you will need to enable them through CMake:
|
||||
If you also want any of the executables, you will need to enable them through
|
||||
CMake, e.g.:
|
||||
|
||||
cmake -DWEBP_BUILD_CWEBP=ON -DWEBP_BUILD_DWEBP=ON ../
|
||||
|
||||
or through your favorite interface (like ccmake or cmake-qt-gui).
|
||||
|
||||
Finally, once installed, you can also use WebP in your CMake project by doing:
|
||||
|
||||
find_package(WebP)
|
||||
|
||||
which will define the CMake variables WebP_INCLUDE_DIRS and WebP_LIBRARIES.
|
||||
|
||||
Gradle:
|
||||
-------
|
||||
The support for Gradle is minimal: it only helps you compile libwebp, cwebp and
|
||||
@ -241,6 +248,7 @@ Options:
|
||||
-sharpness <int> ....... filter sharpness (0:most .. 7:least sharp), default=0
|
||||
-strong ................ use strong filter instead of simple (default)
|
||||
-nostrong .............. use simple filter instead of strong
|
||||
-sharp_yuv ............. use sharper (and slower) RGB->YUV conversion
|
||||
-partition_limit <int> . limit quality to fit the 512k limit on
|
||||
the first partition (0=no degradation ... 100=full)
|
||||
-pass <int> ............ analysis pass number (1..10)
|
||||
@ -384,6 +392,7 @@ Options are:
|
||||
Keyboard shortcuts:
|
||||
'c' ................ toggle use of color profile
|
||||
'i' ................ overlay file information
|
||||
'd' ................ disable blending & disposal (debug)
|
||||
'q' / 'Q' / ESC .... quit
|
||||
|
||||
Building:
|
||||
@ -412,6 +421,37 @@ $ make -f makefile.unix examples/vwebp
|
||||
> nmake /f Makefile.vc CFG=release-static \
|
||||
../obj/x64/release-static/bin/vwebp.exe
|
||||
|
||||
Animation creation tool:
|
||||
========================
|
||||
The utility 'img2webp' can turn a sequence of input images (PNG, JPEG, ...)
|
||||
into an animated WebP file. It offers fine control over duration, encoding
|
||||
modes, etc.
|
||||
|
||||
Usage:
|
||||
|
||||
img2webp [file-level options] [image files...] [per-frame options...]
|
||||
|
||||
File-level options (only used at the start of compression):
|
||||
-min_size ............ minimize size
|
||||
-loop <int> .......... loop count (default: 0, = infinite loop)
|
||||
-kmax <int> .......... maximum number of frame between key-frames
|
||||
(0=only keyframes)
|
||||
-kmin <int> .......... minimum number of frame between key-frames
|
||||
(0=disable key-frames altogether)
|
||||
-mixed ............... use mixed lossy/lossless automatic mode
|
||||
-v ................... verbose mode
|
||||
-h ................... this help
|
||||
|
||||
Per-frame options (only used for subsequent images input):
|
||||
-d <int> ............. frame duration in ms (default: 100)
|
||||
-lossless ........... use lossless mode (default)
|
||||
-lossy ... ........... use lossy mode
|
||||
-q <float> ........... quality
|
||||
-m <int> ............. method to use
|
||||
|
||||
example: img2webp -loop 2 in0.png -lossy in1.jpg
|
||||
-d 80 in2.tiff -o out.webp
|
||||
|
||||
Animated GIF conversion:
|
||||
========================
|
||||
Animated GIF files can be converted to WebP files with animation using the
|
||||
|
15
README.mux
15
README.mux
@ -1,7 +1,7 @@
|
||||
__ __ ____ ____ ____ __ __ _ __ __
|
||||
/ \\/ \/ _ \/ _ \/ _ \/ \ \/ \___/_ / _\
|
||||
\ / __/ _ \ __/ / / (_/ /__
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v0.3.2
|
||||
\__\__/\_____/_____/__/ \__//_/\_____/__/___/v0.4.0
|
||||
|
||||
|
||||
Description:
|
||||
@ -25,6 +25,8 @@ A list of options is available using the -help command line flag:
|
||||
> webpmux -help
|
||||
Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT
|
||||
webpmux -set SET_OPTIONS INPUT -o OUTPUT
|
||||
webpmux -duration DURATION_OPTIONS [-duration ...]
|
||||
INPUT -o OUTPUT
|
||||
webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT
|
||||
webpmux -frame FRAME_OPTIONS [-frame...] [-loop LOOP_COUNT]
|
||||
[-bgcolor BACKGROUND_COLOR] -o OUTPUT
|
||||
@ -48,6 +50,17 @@ SET_OPTIONS:
|
||||
'file.exif' contains the EXIF metadata to be set
|
||||
'file.xmp' contains the XMP metadata to be set
|
||||
|
||||
DURATION_OPTIONS:
|
||||
Set duration of selected frames:
|
||||
duration set duration for each frames
|
||||
duration,frame set duration of a particular frame
|
||||
duration,start,end set duration of frames in the
|
||||
interval [start,end])
|
||||
where: 'duration' is the duration in milliseconds
|
||||
'start' is the start frame index
|
||||
'end' is the inclusive end frame index
|
||||
The special 'end' value '0' means: last frame.
|
||||
|
||||
STRIP_OPTIONS:
|
||||
Strip color profile/metadata:
|
||||
icc strip ICC profile
|
||||
|
91
README.wasm
Normal file
91
README.wasm
Normal file
@ -0,0 +1,91 @@
|
||||
Description:
|
||||
============
|
||||
|
||||
This file describes the compilation of libwebp using portable intrinsics /
|
||||
WebAssembly (wasm) to native targets using clang and CMake.
|
||||
|
||||
Prerequisites:
|
||||
==============
|
||||
|
||||
- cmake 2.8+
|
||||
|
||||
- clang 3.9+ for portable intrinsics support; as wasm progresses a tip of tree
|
||||
build may be necessary.
|
||||
|
||||
Building:
|
||||
=========
|
||||
|
||||
- configure the project with CMake using:
|
||||
|
||||
$ mkdir -p build && \
|
||||
cd build && \
|
||||
cmake -DWEBP_BUILD_DWEBP=1 -DCMAKE_C_COMPILER=clang -DWEBP_ENABLE_WASM=1 ../
|
||||
|
||||
- compile dwebp using 'make'.
|
||||
|
||||
- Note this currently generates native executables only and is incompatible
|
||||
with -DWEBP_BUILD_WEBP_JS.
|
||||
|
||||
Build options:
|
||||
==============
|
||||
|
||||
- platform specific multiply high (mulhi) implementation, disabled by default.
|
||||
arm: -DCMAKE_C_FLAGS='-DENABLE_NEON_BUILTIN_MULHI_INT16X8 ...'
|
||||
x86: -DCMAKE_C_FLAGS='-DENABLE_X86_BUILTIN_MULHI_INT16X8 ...'
|
||||
|
||||
Cross compilation:
|
||||
==================
|
||||
|
||||
- arm toolchains can be obtained from:
|
||||
http://www.linaro.org/downloads/
|
||||
|
||||
- the android ndk can be obtained from:
|
||||
https://developer.android.com/ndk/downloads/index.html
|
||||
|
||||
armv7:
|
||||
------
|
||||
|
||||
Android:
|
||||
$ ./android-ndk-r15b/build/tools/make_standalone_toolchain.py \
|
||||
--arch arm --api 24 --stl gnustl --install-dir /opt/android-arm-24
|
||||
$ mkdir -p build && cd build
|
||||
$ cmake ../libwebp \
|
||||
-DWEBP_BUILD_DWEBP=1 \
|
||||
-DCMAKE_C_COMPILER=/opt/android-arm-24/bin/clang \
|
||||
-DCMAKE_PREFIX_PATH=/opt/android-arm-24/sysroot/usr/lib \
|
||||
-DCMAKE_C_FLAGS=-fPIE \
|
||||
-DCMAKE_EXE_LINKER_FLAGS=-Wl,-pie \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DWEBP_ENABLE_WASM=1
|
||||
|
||||
Linux:
|
||||
$ gcc_arm=/opt/gcc-arm; target=arm-linux-gnueabihf
|
||||
$ mkdir -p build && cd build
|
||||
$ cmake ../libwebp -DWEBP_BUILD_DWEBP=1 -DWEBP_ENABLE_WASM=1 \
|
||||
-DCMAKE_C_COMPILER=clang \
|
||||
-DCMAKE_C_FLAGS="--target=$target --gcc-toolchain=$gcc_arm --sysroot=$gcc_arm/$target/libc -march=armv7-a -mfpu=neon" \
|
||||
-DCMAKE_PREFIX_PATH=$gcc_arm/$target/libc/usr
|
||||
|
||||
aarch64 / arm64:
|
||||
----------------
|
||||
|
||||
Android:
|
||||
$ ./android-ndk-r15b/build/tools/make_standalone_toolchain.py \
|
||||
--arch arm64 --api 24 --stl gnustl --install-dir /opt/android-arm64-24
|
||||
$ mkdir -p build && cd build
|
||||
$ cmake ../libwebp \
|
||||
-DWEBP_BUILD_DWEBP=1 \
|
||||
-DCMAKE_C_COMPILER=/opt/android-arm64-24/bin/clang \
|
||||
-DCMAKE_PREFIX_PATH=/opt/android-arm64-24/sysroot/usr/lib \
|
||||
-DCMAKE_C_FLAGS=-fPIE \
|
||||
-DCMAKE_EXE_LINKER_FLAGS=-Wl,-pie \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DWEBP_ENABLE_WASM=1
|
||||
|
||||
Linux:
|
||||
$ gcc_arm=/opt/gcc-aarch64; target=aarch64-linux-gnu
|
||||
$ mkdir -p build && cd build
|
||||
$ cmake ../libwebp -DWEBP_BUILD_DWEBP=1 -DWEBP_ENABLE_WASM=1 \
|
||||
-DCMAKE_C_COMPILER=clang \
|
||||
-DCMAKE_C_FLAGS="--target=$target --gcc-toolchain=$gcc_arm --sysroot=$gcc_arm/$target/libc" \
|
||||
-DCMAKE_PREFIX_PATH=$gcc_arm/$target/libc/usr
|
80
README.webp_js
Normal file
80
README.webp_js
Normal file
@ -0,0 +1,80 @@
|
||||
__ __ ____ ____ ____ __ ____
|
||||
/ \\/ \ _ \ _ \ _ \ (__)/ __\
|
||||
\ / __/ _ \ __/ _) \_ \
|
||||
\__\__/_____/____/_/ /____/____/
|
||||
|
||||
Description:
|
||||
============
|
||||
|
||||
This file describes the compilation of libwebp into a JavaScript decoder
|
||||
using Emscripten and CMake.
|
||||
|
||||
- install the Emscripten SDK following the procedure described at:
|
||||
https://kripken.github.io/emscripten-site/docs/getting_started/downloads.html
|
||||
After installation, you should have some global variable positioned to the
|
||||
location of the SDK. In particular, $EMSCRIPTEN should point to the
|
||||
top-level directory containing Emscripten tools.
|
||||
|
||||
- make sure the file $EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake is
|
||||
accessible. This is the toolchain file used by CMake to invoke Emscripten.
|
||||
|
||||
- configure the project 'WEBP_JS' with CMake using:
|
||||
|
||||
cd webp_js && \
|
||||
cmake -DWEBP_BUILD_WEBP_JS=ON \
|
||||
-DEMSCRIPTEN_GENERATE_BITCODE_STATIC_LIBRARIES=1 \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake \
|
||||
../
|
||||
|
||||
- compile webp.js using 'make'.
|
||||
|
||||
- that's it! Upon completion, you should have the webp.js and
|
||||
webp.js.mem files generated.
|
||||
|
||||
- Note this generates both webp_js and webp_wasm without any SIMD enabled due
|
||||
to bugs with this toolchain associated with the SSE2 code.
|
||||
-DWEBP_ENABLE_WASM is currently meant to generate native (x86, arm)
|
||||
executables (dwebp, cwebp) and is incompatible with -DWEBP_BUILD_WEBP_JS.
|
||||
|
||||
The callable JavaScript function is WebPToSDL(), which decodes a raw WebP
|
||||
bitstream into a canvas. See webp_js/index.html for a simple usage sample.
|
||||
|
||||
Demo HTML page:
|
||||
===============
|
||||
|
||||
The HTML page webp_js/index.html requires an HTTP server to serve the WebP
|
||||
image example. It's easy to just use Python for that.
|
||||
|
||||
cd webp_js && python -m SimpleHTTPServer 8080
|
||||
|
||||
and then navigate to http://localhost:8080 in your favorite browser.
|
||||
|
||||
|
||||
Web-Assembly (WASM) version:
|
||||
============================
|
||||
|
||||
CMakeLists.txt is configured to build the WASM version when using
|
||||
the option WEBP_BUILD_WEBP_JS=ON. The compilation step will assemble
|
||||
the files 'webp_wasm.js', 'webp_wasm.wasm' in the webp_js/ directory.
|
||||
See webp_js/index_wasm.html for a simple demo page using the WASM version
|
||||
of the library.
|
||||
|
||||
You will need a fairly recent version of Emscripten (at least 1.37.8) and of
|
||||
your WASM-enabled browser to run this version. Consider it very experimental!
|
||||
|
||||
Caveat:
|
||||
=======
|
||||
|
||||
- First decoding using the library is usually slower, due to just-in-time
|
||||
compilation.
|
||||
|
||||
- Some versions of llvm produce the following compile error when SSE2 is
|
||||
enabled.
|
||||
|
||||
"Unsupported: %516 = bitcast <8 x i16> %481 to i128
|
||||
LLVM ERROR: BitCast Instruction not yet supported for integer types larger than 64 bits"
|
||||
|
||||
The corresponding Emscripten bug is at:
|
||||
https://github.com/kripken/emscripten/issues/3788
|
||||
|
||||
Therefore, SSE2 optimization is currently disabled in CMakeLists.txt.
|
192
build.gradle
192
build.gradle
@ -74,9 +74,17 @@ model {
|
||||
cCompiler.args "-frename-registers -s"
|
||||
}
|
||||
}
|
||||
// mips32 fails to build with clang from r14b
|
||||
// https://bugs.chromium.org/p/webp/issues/detail?id=343
|
||||
if (toolChain in Clang) {
|
||||
if (getTargetPlatform() == "mips") {
|
||||
cCompiler.args "-no-integrated-as"
|
||||
}
|
||||
}
|
||||
// Check for NEON usage.
|
||||
if (getTargetPlatform() == "arm" || getTargetPlatform() == "arm64") {
|
||||
NEON = "c.neon"
|
||||
cCompiler.define "HAVE_CPU_FEATURES_H"
|
||||
} else {
|
||||
NEON = "c"
|
||||
}
|
||||
@ -96,19 +104,20 @@ model {
|
||||
c {
|
||||
source {
|
||||
srcDir "src/dec"
|
||||
include "alpha.c"
|
||||
include "buffer.c"
|
||||
include "frame.c"
|
||||
include "idec.c"
|
||||
include "io.c"
|
||||
include "quant.c"
|
||||
include "tree.c"
|
||||
include "vp8.c"
|
||||
include "vp8l.c"
|
||||
include "webp.c"
|
||||
include "alpha_dec.c"
|
||||
include "buffer_dec.c"
|
||||
include "frame_dec.c"
|
||||
include "idec_dec.c"
|
||||
include "io_dec.c"
|
||||
include "quant_dec.c"
|
||||
include "tree_dec.c"
|
||||
include "vp8_dec.c"
|
||||
include "vp8l_dec.c"
|
||||
include "webp_dec.c"
|
||||
srcDir "src/dsp"
|
||||
include "alpha_processing.c"
|
||||
include "alpha_processing_mips_dsp_r2.c"
|
||||
include "alpha_processing_neon.$NEON"
|
||||
include "alpha_processing_sse2.c"
|
||||
include "alpha_processing_sse41.c"
|
||||
include "argb.c"
|
||||
@ -125,34 +134,39 @@ model {
|
||||
include "dec_sse41.c"
|
||||
include "filters.c"
|
||||
include "filters_mips_dsp_r2.c"
|
||||
include "filters_msa.c"
|
||||
include "filters_neon.$NEON"
|
||||
include "filters_sse2.c"
|
||||
include "lossless.c"
|
||||
include "lossless_mips_dsp_r2.c"
|
||||
include "lossless_msa.c"
|
||||
include "lossless_neon.$NEON"
|
||||
include "lossless_sse2.c"
|
||||
include "rescaler.c"
|
||||
include "rescaler_mips32.c"
|
||||
include "rescaler_mips_dsp_r2.c"
|
||||
include "rescaler_msa.c"
|
||||
include "rescaler_neon.$NEON"
|
||||
include "rescaler_sse2.c"
|
||||
include "upsampling.c"
|
||||
include "upsampling_mips_dsp_r2.c"
|
||||
include "upsampling_msa.c"
|
||||
include "upsampling_neon.$NEON"
|
||||
include "upsampling_sse2.c"
|
||||
include "yuv.c"
|
||||
include "yuv_mips32.c"
|
||||
include "yuv_mips_dsp_r2.c"
|
||||
include "yuv_neon.$NEON"
|
||||
include "yuv_sse2.c"
|
||||
srcDir "src/utils"
|
||||
include "ans.c"
|
||||
include "bit_reader.c"
|
||||
include "color_cache.c"
|
||||
include "filters.c"
|
||||
include "huffman.c"
|
||||
include "quant_levels_dec.c"
|
||||
include "random.c"
|
||||
include "rescaler.c"
|
||||
include "thread.c"
|
||||
include "bit_reader_utils.c"
|
||||
include "color_cache_utils.c"
|
||||
include "filters_utils.c"
|
||||
include "huffman_utils.c"
|
||||
include "quant_levels_dec_utils.c"
|
||||
include "random_utils.c"
|
||||
include "rescaler_utils.c"
|
||||
include "thread_utils.c"
|
||||
include "utils.c"
|
||||
srcDir "src/dsp"
|
||||
include "cost.c"
|
||||
@ -163,42 +177,48 @@ model {
|
||||
include "enc_avx2.c"
|
||||
include "enc_mips32.c"
|
||||
include "enc_mips_dsp_r2.c"
|
||||
include "enc_msa.c"
|
||||
include "enc_neon.$NEON"
|
||||
include "enc_sse2.c"
|
||||
include "enc_sse41.c"
|
||||
include "lossless_enc.c"
|
||||
include "lossless_enc_mips32.c"
|
||||
include "lossless_enc_mips_dsp_r2.c"
|
||||
include "lossless_enc_msa.c"
|
||||
include "lossless_enc_neon.$NEON"
|
||||
include "lossless_enc_sse2.c"
|
||||
include "lossless_enc_sse41.c"
|
||||
include "ssim.c"
|
||||
include "ssim_sse2.c"
|
||||
srcDir "src/enc"
|
||||
include "alpha.c"
|
||||
include "analysis.c"
|
||||
include "backward_references.c"
|
||||
include "config.c"
|
||||
include "cost.c"
|
||||
include "delta_palettization.c"
|
||||
include "filter.c"
|
||||
include "frame.c"
|
||||
include "histogram.c"
|
||||
include "iterator.c"
|
||||
include "near_lossless.c"
|
||||
include "picture.c"
|
||||
include "picture_csp.c"
|
||||
include "picture_psnr.c"
|
||||
include "picture_rescale.c"
|
||||
include "picture_tools.c"
|
||||
include "quant.c"
|
||||
include "syntax.c"
|
||||
include "token.c"
|
||||
include "tree.c"
|
||||
include "vp8l.c"
|
||||
include "webpenc.c"
|
||||
include "alpha_enc.c"
|
||||
include "analysis_enc.c"
|
||||
include "backward_references_cost_enc.c"
|
||||
include "backward_references_enc.c"
|
||||
include "config_enc.c"
|
||||
include "cost_enc.c"
|
||||
include "delta_palettization_enc.c"
|
||||
include "filter_enc.c"
|
||||
include "frame_enc.c"
|
||||
include "histogram_enc.c"
|
||||
include "iterator_enc.c"
|
||||
include "near_lossless_enc.c"
|
||||
include "picture_enc.c"
|
||||
include "picture_csp_enc.c"
|
||||
include "picture_psnr_enc.c"
|
||||
include "picture_rescale_enc.c"
|
||||
include "picture_tools_enc.c"
|
||||
include "predictor_enc.c"
|
||||
include "quant_enc.c"
|
||||
include "syntax_enc.c"
|
||||
include "token_enc.c"
|
||||
include "tree_enc.c"
|
||||
include "vp8l_enc.c"
|
||||
include "webp_enc.c"
|
||||
srcDir "src/utils"
|
||||
include "bit_writer.c"
|
||||
include "huffman_encode.c"
|
||||
include "quant_levels.c"
|
||||
include "bit_writer_utils.c"
|
||||
include "huffman_encode_utils.c"
|
||||
include "quant_levels_utils.c"
|
||||
}
|
||||
exportedHeaders {
|
||||
srcDir "src"
|
||||
@ -250,7 +270,7 @@ model {
|
||||
}
|
||||
}
|
||||
|
||||
example_dec(NativeLibrarySpec) {
|
||||
imageio_util(NativeLibrarySpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "webp", linkage: "static"
|
||||
@ -259,22 +279,58 @@ model {
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./examples"
|
||||
srcDir "./imageio"
|
||||
include "imageio_util.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imagedec(NativeLibrarySpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "webp", linkage: "static"
|
||||
}
|
||||
}
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./imageio"
|
||||
include "image_dec.c"
|
||||
include "jpegdec.c"
|
||||
include "metadata.c"
|
||||
include "pngdec.c"
|
||||
include "pnmdec.c"
|
||||
include "tiffdec.c"
|
||||
include "webpdec.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
imageenc(NativeLibrarySpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "webp", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
}
|
||||
}
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./imageio"
|
||||
include "image_enc.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cwebp(NativeExecutableSpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "example_dec", linkage: "static"
|
||||
lib library: "imagedec", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
lib library: "webp", linkage: "static"
|
||||
}
|
||||
}
|
||||
@ -292,6 +348,9 @@ model {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "imagedec", linkage: "static"
|
||||
lib library: "imageenc", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
lib library: "webp"
|
||||
}
|
||||
}
|
||||
@ -309,6 +368,7 @@ model {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
lib library: "webpmux", linkage: "static"
|
||||
lib library: "webp"
|
||||
}
|
||||
@ -322,6 +382,44 @@ model {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
img2webp_example(NativeExecutableSpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "imagedec", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
lib library: "webpmux", linkage: "static"
|
||||
lib library: "webp"
|
||||
}
|
||||
}
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./examples"
|
||||
include "img2webp.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
webpinfo_example(NativeExecutableSpec) {
|
||||
binaries {
|
||||
all {
|
||||
lib library: "example_util", linkage: "static"
|
||||
lib library: "imageio_util", linkage: "static"
|
||||
lib library: "webp"
|
||||
}
|
||||
}
|
||||
sources {
|
||||
c {
|
||||
source {
|
||||
srcDir "./examples"
|
||||
include "webpinfo.c"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks {
|
||||
// Task to test all possible configurations.
|
||||
|
6
cmake/WebPConfig.cmake.in
Normal file
6
cmake/WebPConfig.cmake.in
Normal file
@ -0,0 +1,6 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(WebP_INCLUDE_DIRS "webp")
|
||||
set(WEBP_INCLUDE_DIRS ${WebP_INCLUDE_DIRS})
|
||||
set(WebP_LIBRARIES "@INSTALLED_LIBRARIES@")
|
||||
set(WEBP_LIBRARIES "${WebP_LIBRARIES}")
|
@ -65,7 +65,7 @@ endif()
|
||||
# Find the standard image libraries.
|
||||
set(WEBP_DEP_IMG_LIBRARIES)
|
||||
set(WEBP_DEP_IMG_INCLUDE_DIRS)
|
||||
foreach(I_LIB PNG JPEG TIFF GIF)
|
||||
foreach(I_LIB PNG JPEG TIFF)
|
||||
find_package(${I_LIB})
|
||||
set(WEBP_HAVE_${I_LIB} ${${I_LIB}_FOUND})
|
||||
if(${I_LIB}_FOUND)
|
||||
@ -74,6 +74,16 @@ foreach(I_LIB PNG JPEG TIFF GIF)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# GIF detection, gifdec isn't part of the imageio lib.
|
||||
set(WEBP_DEP_GIF_LIBRARIES)
|
||||
set(WEBP_DEP_GIF_INCLUDE_DIRS)
|
||||
find_package(GIF)
|
||||
set(WEBP_HAVE_GIF ${GIF_FOUND})
|
||||
if(GIF_FOUND)
|
||||
list(APPEND WEBP_DEP_GIF_LIBRARIES ${GIF_LIBRARIES})
|
||||
list(APPEND WEBP_DEP_GIF_INCLUDE_DIRS ${GIF_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
## Check for specific headers.
|
||||
include(CheckIncludeFiles)
|
||||
check_include_files("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
|
||||
|
@ -103,9 +103,6 @@
|
||||
/* Enable experimental code */
|
||||
#cmakedefine WEBP_EXPERIMENTAL_FEATURES 1
|
||||
|
||||
/* Define to 1 to force aligned memory operations */
|
||||
#cmakedefine WEBP_FORCE_ALIGNED 1
|
||||
|
||||
/* Set to 1 if AVX2 is supported */
|
||||
#cmakedefine WEBP_HAVE_AVX2 1
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
## Check for SIMD extensions.
|
||||
|
||||
function(webp_check_compiler_flag WEBP_SIMD_FLAG)
|
||||
function(webp_check_compiler_flag WEBP_SIMD_FLAG ENABLE_SIMD)
|
||||
if(NOT ENABLE_SIMD)
|
||||
message(STATUS "Disabling ${WEBP_SIMD_FLAG} optimization.")
|
||||
set(WEBP_HAVE_${WEBP_SIMD_FLAG} 0 PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
unset(WEBP_HAVE_FLAG_${WEBP_SIMD_FLAG} CACHE)
|
||||
check_c_source_compiles("
|
||||
#include \"${CMAKE_CURRENT_LIST_DIR}/../src/dsp/dsp.h\"
|
||||
@ -56,11 +61,11 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
# (especially on Android).
|
||||
unset(WEBP_HAVE_${WEBP_SIMD_FLAG} CACHE)
|
||||
set(CMAKE_REQUIRED_FLAGS)
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||
if(NOT WEBP_HAVE_${WEBP_SIMD_FLAG})
|
||||
list(GET SIMD_ENABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||
set(CMAKE_REQUIRED_FLAGS ${SIMD_COMPILE_FLAG})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG})
|
||||
webp_check_compiler_flag(${WEBP_SIMD_FLAG} ${WEBP_ENABLE_SIMD})
|
||||
else()
|
||||
set(SIMD_COMPILE_FLAG " ")
|
||||
endif()
|
||||
@ -80,13 +85,33 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
foreach(FILE ${SIMD_FILES})
|
||||
list(APPEND WEBP_SIMD_FILES_NOT_TO_INCLUDE ${FILE})
|
||||
endforeach()
|
||||
# Explicitly disable SIMD.
|
||||
if(SIMD_DISABLE_FLAGS)
|
||||
# Explicitly disable SIMD. Avoid this with WASM to avoid an ICE with clang:
|
||||
# https://bugs.chromium.org/p/webp/issues/detail?id=350
|
||||
# WASM overrides the native SIMD so building it in is harmless aside from
|
||||
# binary size.
|
||||
if(NOT WEBP_ENABLE_WASM AND SIMD_DISABLE_FLAGS)
|
||||
list(GET SIMD_DISABLE_FLAGS ${I_SIMD} SIMD_COMPILE_FLAG)
|
||||
include(CheckCCompilerFlag)
|
||||
if(SIMD_COMPILE_FLAG)
|
||||
unset(HAS_COMPILE_FLAG CACHE)
|
||||
check_c_compiler_flag(${SIMD_COMPILE_FLAG} HAS_COMPILE_FLAG)
|
||||
if(HAS_COMPILE_FLAG)
|
||||
# Do one more check for Clang to circumvent CMake issue 13194.
|
||||
if(COMMAND check_compiler_flag_common_patterns)
|
||||
# Only in CMake 3.0 and above.
|
||||
check_compiler_flag_common_patterns(COMMON_PATTERNS)
|
||||
else()
|
||||
set(COMMON_PATTERNS)
|
||||
endif()
|
||||
set(CMAKE_REQUIRED_DEFINITIONS ${SIMD_COMPILE_FLAG})
|
||||
check_c_source_compiles("int main(void) {return 0;}" FLAG2
|
||||
FAIL_REGEX "warning: argument unused during compilation:"
|
||||
${COMMON_PATTERNS}
|
||||
)
|
||||
if(NOT FLAG2)
|
||||
unset(HAS_COMPILE_FLAG CACHE)
|
||||
endif()
|
||||
endif()
|
||||
if(HAS_COMPILE_FLAG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SIMD_COMPILE_FLAG}")
|
||||
endif()
|
||||
@ -94,3 +119,13 @@ foreach(I_SIMD RANGE ${WEBP_SIMD_FLAGS_RANGE})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
## Add *_wasm.c files if enabled.
|
||||
if(WEBP_ENABLE_WASM)
|
||||
file(GLOB SIMD_FILES "${CMAKE_CURRENT_LIST_DIR}/../"
|
||||
"src/dsp/*_wasm.c"
|
||||
)
|
||||
foreach(FILE ${SIMD_FILES})
|
||||
list(APPEND WEBP_SIMD_FILES_TO_INCLUDE ${FILE})
|
||||
endforeach()
|
||||
endif()
|
||||
|
88
configure.ac
88
configure.ac
@ -1,4 +1,4 @@
|
||||
AC_INIT([libwebp], [0.5.2],
|
||||
AC_INIT([libwebp], [0.6.0],
|
||||
[https://bugs.chromium.org/p/webp],,
|
||||
[http://developers.google.com/speed/webp])
|
||||
AC_CANONICAL_HOST
|
||||
@ -67,6 +67,7 @@ AC_DEFUN([TEST_AND_ADD_CFLAGS],
|
||||
CFLAGS="$SAVED_CFLAGS"])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-fvisibility=hidden])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wall])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wconstant-conversion])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wdeclaration-after-statement])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wextra])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wfloat-conversion])
|
||||
@ -75,6 +76,7 @@ TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wformat -Wformat-security])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wmissing-declarations])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wmissing-prototypes])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wold-style-definition])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wparentheses-equality])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshadow])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wshorten-64-to-32])
|
||||
TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wunreachable-code])
|
||||
@ -241,9 +243,13 @@ AS_IF([test "x$enable_neon" != "xno"], [
|
||||
NEON_FLAGS=""],
|
||||
[AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1],
|
||||
[Set to 1 if runtime detection of NEON is enabled])])])
|
||||
;;
|
||||
esac
|
||||
AC_SUBST([NEON_FLAGS])])
|
||||
|
||||
case "$host_os" in
|
||||
*android*) AC_CHECK_HEADERS([cpu-features.h]) ;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
AC_SUBST([NEON_FLAGS])])
|
||||
|
||||
dnl === CLEAR_LIBVARS([var_pfx])
|
||||
dnl === Clears <var_pfx>_{INCLUDES,LIBS}.
|
||||
@ -428,6 +434,44 @@ AS_IF([test "x$enable_gl" != "xno"], [
|
||||
])
|
||||
AM_CONDITIONAL([BUILD_VWEBP], [test "$build_vwebp" = "yes"])
|
||||
|
||||
dnl === check for SDL support ===
|
||||
|
||||
AC_ARG_ENABLE([sdl],
|
||||
AS_HELP_STRING([--disable-sdl],
|
||||
[Disable detection of SDL support
|
||||
@<:@default=auto@:>@]))
|
||||
AS_IF([test "x$enable_sdl" != "xno"], [
|
||||
CLEAR_LIBVARS([SDL])
|
||||
WITHLIB_OPTION([sdl], [SDL])
|
||||
|
||||
$sdl_header = "no";
|
||||
LIBCHECK_PROLOGUE([SDL])
|
||||
AC_CHECK_HEADER([SDL/SDL.h], [sdl_header="SDL_SDL.h"],
|
||||
[AC_CHECK_HEADER([SDL.h], [sdl_header="SDL.h"],
|
||||
[AC_MSG_WARN(SDL library not available - no sdl.h)])])
|
||||
if test x"$sdl_header" != "xno" ; then
|
||||
AC_CHECK_LIB(SDL, SDL_Init,
|
||||
[SDL_LIBS="-lSDL"
|
||||
SDL_INCLUDES="-DWEBP_HAVE_SDL"
|
||||
AC_DEFINE(WEBP_HAVE_SDL, [1],
|
||||
[Set to 1 if SDL library is installed])
|
||||
sdl_support=yes
|
||||
],
|
||||
AC_MSG_WARN(Optional SDL library not found),
|
||||
[$MATH_LIBS]),
|
||||
if test x"$sdl_header" == "xSDL.h" ; then
|
||||
SDL_INCLUDES="$SDL_INCLUDES -DWEBP_HAVE_JUST_SDL_H"
|
||||
fi
|
||||
fi
|
||||
LIBCHECK_EPILOGUE([SDL])
|
||||
|
||||
if test "$sdl_support" = "yes" ; then
|
||||
build_vwebp_sdl=yes
|
||||
fi
|
||||
])
|
||||
|
||||
AM_CONDITIONAL([BUILD_VWEBP_SDL], [test "$build_vwebp_sdl" = "yes"])
|
||||
|
||||
dnl === check for PNG support ===
|
||||
|
||||
AC_ARG_ENABLE([png], AS_HELP_STRING([--disable-png],
|
||||
@ -556,6 +600,16 @@ AS_IF([test "x$enable_gif" != "xno"], [
|
||||
AM_CONDITIONAL([BUILD_ANIMDIFF], [test "${build_animdiff}" = "yes"])
|
||||
AM_CONDITIONAL([BUILD_GIF2WEBP], [test "${build_gif2webp}" = "yes"])
|
||||
|
||||
if test "$enable_libwebpmux" = "yes"; then
|
||||
build_img2webp=yes
|
||||
fi
|
||||
AM_CONDITIONAL([BUILD_IMG2WEBP], [test "${build_img2webp}" = "yes"])
|
||||
|
||||
if test "$enable_libwebpmux" = "yes"; then
|
||||
build_webpinfo=yes
|
||||
fi
|
||||
AM_CONDITIONAL([BUILD_WEBPINFO], [test "${build_webpinfo}" = "yes"])
|
||||
|
||||
dnl === check for WIC support ===
|
||||
|
||||
AC_ARG_ENABLE([wic],
|
||||
@ -608,19 +662,6 @@ if test "$enable_wic" = "yes"; then
|
||||
fi
|
||||
esac
|
||||
|
||||
dnl === If --enable-aligned is defined, define WEBP_FORCE_ALIGNED
|
||||
|
||||
AC_MSG_CHECKING(if --enable-aligned option is specified)
|
||||
AC_ARG_ENABLE([aligned],
|
||||
AS_HELP_STRING([--enable-aligned],
|
||||
[Force aligned memory operations in non-dsp code
|
||||
(may be slower)]))
|
||||
if test "$enable_aligned" = "yes"; then
|
||||
AC_DEFINE(WEBP_FORCE_ALIGNED, [1],
|
||||
[Define to 1 to force aligned memory operations])
|
||||
fi
|
||||
AC_MSG_RESULT(${enable_aligned-no})
|
||||
|
||||
dnl === If --enable-swap-16bit-csp is defined, add -DWEBP_SWAP_16BIT_CSP
|
||||
|
||||
USE_SWAP_16BIT_CSP=""
|
||||
@ -684,13 +725,12 @@ dnl =========================
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_HEADERS([src/webp/config.h])
|
||||
AC_CONFIG_FILES([Makefile src/Makefile man/Makefile \
|
||||
examples/Makefile src/dec/Makefile \
|
||||
src/enc/Makefile src/dsp/Makefile \
|
||||
examples/Makefile extras/Makefile imageio/Makefile \
|
||||
src/dec/Makefile src/enc/Makefile src/dsp/Makefile \
|
||||
src/demux/Makefile src/mux/Makefile \
|
||||
src/utils/Makefile src/extras/Makefile \
|
||||
src/utils/Makefile \
|
||||
src/libwebp.pc src/libwebpdecoder.pc \
|
||||
src/demux/libwebpdemux.pc src/mux/libwebpmux.pc \
|
||||
src/extras/libwebpextras.pc])
|
||||
src/demux/libwebpdemux.pc src/mux/libwebpmux.pc])
|
||||
|
||||
|
||||
AC_OUTPUT
|
||||
@ -724,6 +764,10 @@ dwebp : yes
|
||||
GIF support : ${gif_support-no}
|
||||
anim_diff : ${build_animdiff-no}
|
||||
gif2webp : ${build_gif2webp-no}
|
||||
img2webp : ${build_img2webp-no}
|
||||
webpmux : ${enable_libwebpmux-no}
|
||||
vwebp : ${build_vwebp-no}
|
||||
webpinfo : ${build_webpinfo-no}
|
||||
SDL support : ${sdl_support-no}
|
||||
vwebp_sdl : ${build_vwebp_sdl-no}
|
||||
])
|
||||
|
@ -15,27 +15,6 @@ LOCAL_MODULE := example_util
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
|
||||
################################################################################
|
||||
# libexample_dec
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
image_dec.c \
|
||||
jpegdec.c \
|
||||
metadata.c \
|
||||
pngdec.c \
|
||||
tiffdec.c \
|
||||
webpdec.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
|
||||
LOCAL_MODULE := example_dec
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
################################################################################
|
||||
# cwebp
|
||||
|
||||
@ -48,7 +27,7 @@ LOCAL_SRC_FILES := \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util example_dec webp
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util imagedec webp
|
||||
|
||||
LOCAL_MODULE := cwebp
|
||||
|
||||
@ -64,7 +43,7 @@ LOCAL_SRC_FILES := \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util webp
|
||||
LOCAL_STATIC_LIBRARIES := example_util imagedec imageenc webp
|
||||
|
||||
LOCAL_MODULE := dwebp
|
||||
|
||||
@ -80,8 +59,40 @@ LOCAL_SRC_FILES := \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util webpmux webp
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util webpmux webp
|
||||
|
||||
LOCAL_MODULE := webpmux_example
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
################################################################################
|
||||
# img2webp
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
img2webp.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := example_util imageio_util imagedec webpmux webp
|
||||
|
||||
LOCAL_MODULE := img2webp_example
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
################################################################################
|
||||
# webpinfo
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
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
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
@ -1,70 +1,83 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
|
||||
bin_PROGRAMS = dwebp cwebp
|
||||
if BUILD_VWEBP
|
||||
bin_PROGRAMS += vwebp
|
||||
if BUILD_ANIMDIFF
|
||||
noinst_PROGRAMS = anim_diff
|
||||
endif
|
||||
if BUILD_GIF2WEBP
|
||||
bin_PROGRAMS += gif2webp
|
||||
endif
|
||||
if BUILD_IMG2WEBP
|
||||
bin_PROGRAMS += img2webp
|
||||
endif
|
||||
if WANT_MUX
|
||||
bin_PROGRAMS += webpmux
|
||||
endif
|
||||
|
||||
if BUILD_GIF2WEBP
|
||||
bin_PROGRAMS += gif2webp
|
||||
if BUILD_VWEBP
|
||||
bin_PROGRAMS += vwebp
|
||||
endif
|
||||
if BUILD_WEBPINFO
|
||||
bin_PROGRAMS += webpinfo
|
||||
endif
|
||||
|
||||
noinst_LTLIBRARIES = libexampleutil.la libexampledec.la
|
||||
noinst_LTLIBRARIES = libexample_util.la
|
||||
|
||||
libexampleutil_la_SOURCES = example_util.c example_util.h stopwatch.h
|
||||
|
||||
libexampledec_la_SOURCES = image_dec.c image_dec.h
|
||||
libexampledec_la_SOURCES += jpegdec.c jpegdec.h
|
||||
libexampledec_la_SOURCES += metadata.c metadata.h
|
||||
libexampledec_la_SOURCES += pngdec.c pngdec.h
|
||||
libexampledec_la_SOURCES += tiffdec.c tiffdec.h
|
||||
libexampledec_la_SOURCES += webpdec.c webpdec.h
|
||||
libexampledec_la_SOURCES += wicdec.c wicdec.h
|
||||
libexampledec_la_CPPFLAGS = $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
|
||||
libexampledec_la_CPPFLAGS += $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
|
||||
if BUILD_ANIMDIFF
|
||||
noinst_PROGRAMS = anim_diff
|
||||
endif
|
||||
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_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) $(GIF_INCLUDES)
|
||||
anim_diff_LDADD = ../src/demux/libwebpdemux.la
|
||||
anim_diff_LDADD += libexampleutil.la
|
||||
anim_diff_LDADD += libexample_util.la ../imageio/libimageio_util.la
|
||||
anim_diff_LDADD += $(GIF_LIBS) -lm
|
||||
|
||||
cwebp_SOURCES = cwebp.c stopwatch.h
|
||||
cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
cwebp_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
cwebp_LDADD += ../imageio/libimagedec.la ../src/libwebp.la
|
||||
cwebp_LDADD += $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS)
|
||||
|
||||
dwebp_SOURCES = dwebp.c stopwatch.h
|
||||
dwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
dwebp_CPPFLAGS += $(JPEG_INCLUDES) $(PNG_INCLUDES)
|
||||
dwebp_LDADD = libexampleutil.la $(PNG_LIBS) $(JPEG_LIBS)
|
||||
|
||||
cwebp_SOURCES = cwebp.c stopwatch.h
|
||||
cwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
cwebp_LDADD = libexampleutil.la libexampledec.la ../src/libwebp.la
|
||||
cwebp_LDADD += $(JPEG_LIBS) $(PNG_LIBS) $(TIFF_LIBS)
|
||||
dwebp_LDADD = libexample_util.la
|
||||
dwebp_LDADD += ../imageio/libimagedec.la
|
||||
dwebp_LDADD += ../imageio/libimageenc.la
|
||||
dwebp_LDADD += ../imageio/libimageio_util.la
|
||||
dwebp_LDADD += ../src/libwebp.la
|
||||
dwebp_LDADD +=$(PNG_LIBS) $(JPEG_LIBS)
|
||||
|
||||
gif2webp_SOURCES = gif2webp.c gifdec.c gifdec.h
|
||||
gif2webp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) $(GIF_INCLUDES)
|
||||
gif2webp_LDADD = libexampleutil.la ../src/mux/libwebpmux.la ../src/libwebp.la
|
||||
gif2webp_LDADD += $(GIF_LIBS)
|
||||
|
||||
webpmux_SOURCES = webpmux.c
|
||||
webpmux_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
webpmux_LDADD = libexampleutil.la ../src/mux/libwebpmux.la ../src/libwebp.la
|
||||
gif2webp_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
gif2webp_LDADD += ../src/mux/libwebpmux.la ../src/libwebp.la $(GIF_LIBS)
|
||||
|
||||
vwebp_SOURCES = vwebp.c
|
||||
vwebp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE) $(GL_INCLUDES)
|
||||
vwebp_LDADD = libexampleutil.la ../src/demux/libwebpdemux.la $(GL_LIBS)
|
||||
vwebp_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
vwebp_LDADD += ../src/demux/libwebpdemux.la $(GL_LIBS)
|
||||
|
||||
webpmux_SOURCES = webpmux.c
|
||||
webpmux_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
webpmux_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
webpmux_LDADD += ../src/mux/libwebpmux.la ../src/libwebp.la
|
||||
|
||||
img2webp_SOURCES = img2webp.c
|
||||
img2webp_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
img2webp_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
img2webp_LDADD += ../imageio/libimagedec.la
|
||||
img2webp_LDADD += ../src/mux/libwebpmux.la ../src/libwebp.la
|
||||
img2webp_LDADD += $(PNG_LIBS) $(JPEG_LIBS) $(TIFF_LIBS)
|
||||
|
||||
webpinfo_SOURCES = webpinfo.c
|
||||
webpinfo_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
webpinfo_LDADD = libexample_util.la ../imageio/libimageio_util.la
|
||||
webpinfo_LDADD += ../src/libwebp.la
|
||||
|
||||
if BUILD_LIBWEBPDECODER
|
||||
anim_diff_LDADD += ../src/libwebpdecoder.la
|
||||
dwebp_LDADD += ../src/libwebpdecoder.la
|
||||
vwebp_LDADD += ../src/libwebpdecoder.la
|
||||
else
|
||||
anim_diff_LDADD += ../src/libwebp.la
|
||||
dwebp_LDADD += ../src/libwebp.la
|
||||
vwebp_LDADD += ../src/libwebp.la
|
||||
endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "webp/format_constants.h"
|
||||
#include "webp/decode.h"
|
||||
#include "webp/demux.h"
|
||||
#include "./example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -150,6 +150,7 @@ static int DumpFrame(const char filename[], const char dump_folder[],
|
||||
const char* base_name = NULL;
|
||||
char* file_name = NULL;
|
||||
FILE* f = NULL;
|
||||
const char* row;
|
||||
|
||||
base_name = strrchr(filename, '/');
|
||||
base_name = (base_name == NULL) ? filename : base_name + 1;
|
||||
@ -176,12 +177,13 @@ static int DumpFrame(const char filename[], const char dump_folder[],
|
||||
fprintf(stderr, "Write error for file %s\n", file_name);
|
||||
goto End;
|
||||
}
|
||||
row = (const char*)rgba;
|
||||
for (y = 0; y < canvas_height; ++y) {
|
||||
if (fwrite((const char*)(rgba) + y * canvas_width * kNumChannels,
|
||||
canvas_width * kNumChannels, 1, f) != 1) {
|
||||
if (fwrite(row, canvas_width * kNumChannels, 1, f) != 1) {
|
||||
fprintf(stderr, "Error writing to file: %s\n", file_name);
|
||||
goto End;
|
||||
}
|
||||
row += canvas_width * kNumChannels;
|
||||
}
|
||||
ok = 1;
|
||||
End:
|
||||
@ -704,7 +706,7 @@ int ReadAnimatedImage(const char filename[], AnimatedImage* const image,
|
||||
WebPDataInit(&webp_data);
|
||||
memset(image, 0, sizeof(*image));
|
||||
|
||||
if (!ExUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) {
|
||||
if (!ImgIoUtilReadFile(filename, &webp_data.bytes, &webp_data.size)) {
|
||||
fprintf(stderr, "Error reading file: %s\n", filename);
|
||||
return 0;
|
||||
}
|
||||
@ -743,7 +745,7 @@ void GetDiffAndPSNR(const uint8_t rgba1[], const uint8_t rgba2[],
|
||||
for (y = 0; y < height; ++y) {
|
||||
for (x = 0; x < stride; x += kNumChannels) {
|
||||
int k;
|
||||
const size_t offset = y * stride + x;
|
||||
const size_t offset = (size_t)y * stride + x;
|
||||
const int alpha1 = rgba1[offset + kAlphaChannel];
|
||||
const int alpha2 = rgba2[offset + kAlphaChannel];
|
||||
Accumulate(alpha1, alpha2, &f_max_diff, &sse);
|
||||
|
@ -20,8 +20,9 @@
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include "./example_util.h"
|
||||
#include "./image_dec.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
@ -59,12 +60,12 @@ static int ReadYUV(const uint8_t* const data, size_t data_size,
|
||||
|
||||
pic->use_argb = 0;
|
||||
if (!WebPPictureAlloc(pic)) return 0;
|
||||
ExUtilCopyPlane(data, pic->width, pic->y, pic->y_stride,
|
||||
pic->width, pic->height);
|
||||
ExUtilCopyPlane(data + y_plane_size, uv_width,
|
||||
pic->u, pic->uv_stride, uv_width, uv_height);
|
||||
ExUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width,
|
||||
pic->v, pic->uv_stride, uv_width, uv_height);
|
||||
ImgIoUtilCopyPlane(data, pic->width, pic->y, pic->y_stride,
|
||||
pic->width, pic->height);
|
||||
ImgIoUtilCopyPlane(data + y_plane_size, uv_width,
|
||||
pic->u, pic->uv_stride, uv_width, uv_height);
|
||||
ImgIoUtilCopyPlane(data + y_plane_size + uv_plane_size, uv_width,
|
||||
pic->v, pic->uv_stride, uv_width, uv_height);
|
||||
return use_argb ? WebPPictureYUVAToARGB(pic) : 1;
|
||||
}
|
||||
|
||||
@ -76,13 +77,13 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
if (pic->width != 0 && pic->height != 0) {
|
||||
ok = ExUtilReadFile(filename, &data, &data_size);
|
||||
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
ok = ok && ReadYUV(data, data_size, pic);
|
||||
} else {
|
||||
// If no size specified, try to decode it using WIC.
|
||||
ok = ReadPictureWithWIC(filename, pic, keep_alpha, metadata);
|
||||
if (!ok) {
|
||||
ok = ExUtilReadFile(filename, &data, &data_size);
|
||||
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
ok = ok && ReadWebP(data, data_size, pic, keep_alpha, metadata);
|
||||
}
|
||||
}
|
||||
@ -101,12 +102,12 @@ static int ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
size_t data_size = 0;
|
||||
int ok = 0;
|
||||
|
||||
ok = ExUtilReadFile(filename, &data, &data_size);
|
||||
ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
if (!ok) goto End;
|
||||
|
||||
if (pic->width == 0 || pic->height == 0) {
|
||||
WebPImageReader reader = WebPGuessImageReader(data, data_size);
|
||||
ok = (reader != NULL) && reader(data, data_size, pic, keep_alpha, metadata);
|
||||
ok = reader(data, data_size, pic, keep_alpha, metadata);
|
||||
} else {
|
||||
// If image size is specified, infer it as YUV format.
|
||||
ok = ReadYUV(data, data_size, pic);
|
||||
@ -296,6 +297,10 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) {
|
||||
const int uv_width = (picture->width + 1) / 2;
|
||||
const int uv_height = (picture->height + 1) / 2;
|
||||
const int stride = (picture->width + 1) & ~1;
|
||||
const uint8_t* src_y = picture->y;
|
||||
const uint8_t* src_u = picture->u;
|
||||
const uint8_t* src_v = picture->v;
|
||||
const uint8_t* src_a = picture->a;
|
||||
const int alpha_height =
|
||||
WebPPictureHasTransparency(picture) ? picture->height : 0;
|
||||
const int height = picture->height + uv_height + alpha_height;
|
||||
@ -303,20 +308,20 @@ static int DumpPicture(const WebPPicture* const picture, const char* PGM_name) {
|
||||
if (f == NULL) return 0;
|
||||
fprintf(f, "P5\n%d %d\n255\n", stride, height);
|
||||
for (y = 0; y < picture->height; ++y) {
|
||||
if (fwrite(picture->y + y * picture->y_stride, picture->width, 1, f) != 1)
|
||||
return 0;
|
||||
if (fwrite(src_y, picture->width, 1, f) != 1) return 0;
|
||||
if (picture->width & 1) fputc(0, f); // pad
|
||||
src_y += picture->y_stride;
|
||||
}
|
||||
for (y = 0; y < uv_height; ++y) {
|
||||
if (fwrite(picture->u + y * picture->uv_stride, uv_width, 1, f) != 1)
|
||||
return 0;
|
||||
if (fwrite(picture->v + y * picture->uv_stride, uv_width, 1, f) != 1)
|
||||
return 0;
|
||||
if (fwrite(src_u, uv_width, 1, f) != 1) return 0;
|
||||
if (fwrite(src_v, uv_width, 1, f) != 1) return 0;
|
||||
src_u += picture->uv_stride;
|
||||
src_v += picture->uv_stride;
|
||||
}
|
||||
for (y = 0; y < alpha_height; ++y) {
|
||||
if (fwrite(picture->a + y * picture->a_stride, picture->width, 1, f) != 1)
|
||||
return 0;
|
||||
if (fwrite(src_a, picture->width, 1, f) != 1) return 0;
|
||||
if (picture->width & 1) fputc(0, f); // pad
|
||||
src_a += picture->a_stride;
|
||||
}
|
||||
fclose(f);
|
||||
return 1;
|
||||
@ -544,6 +549,8 @@ static void HelpLong(void) {
|
||||
printf(" -strong ................ use strong filter instead "
|
||||
"of simple (default)\n");
|
||||
printf(" -nostrong .............. use simple filter instead of strong\n");
|
||||
printf(" -sharp_yuv ............. use sharper (and slower) RGB->YUV "
|
||||
"conversion\n");
|
||||
printf(" -partition_limit <int> . limit quality to fit the 512k limit on\n");
|
||||
printf(" "
|
||||
"the first partition (0=no degradation ... 100=full)\n");
|
||||
@ -572,8 +579,8 @@ static void HelpLong(void) {
|
||||
printf(" -near_lossless <int> ... use near-lossless image\n"
|
||||
" preprocessing (0..100=off), "
|
||||
"default=100\n");
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
printf(" -delta_palettization ... use delta palettization\n");
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES /* not documented yet */
|
||||
printf(" -delta_palette ......... use delta palettization\n");
|
||||
#endif // WEBP_EXPERIMENTAL_FEATURES
|
||||
printf(" -hint <string> ......... specify image characteristics hint,\n");
|
||||
printf(" one of: photo, picture or graph\n");
|
||||
@ -744,9 +751,9 @@ int main(int argc, const char *argv[]) {
|
||||
config.near_lossless = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
config.lossless = 1; // use near-lossless only with lossless
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
} else if (!strcmp(argv[c], "-delta_palettization")) {
|
||||
config.delta_palettization = 1;
|
||||
config.lossless = 1; // use delta-palettization only with lossless
|
||||
} else if (!strcmp(argv[c], "-delta_palette")) {
|
||||
config.use_delta_palette = 1;
|
||||
config.lossless = 1; // delta-palette is for lossless only
|
||||
#endif // WEBP_EXPERIMENTAL_FEATURES
|
||||
} else if (!strcmp(argv[c], "-hint") && c < argc - 1) {
|
||||
++c;
|
||||
@ -782,6 +789,8 @@ int main(int argc, const char *argv[]) {
|
||||
config.filter_type = 0;
|
||||
} else if (!strcmp(argv[c], "-sharpness") && c < argc - 1) {
|
||||
config.filter_sharpness = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-sharp_yuv")) {
|
||||
config.use_sharp_yuv = 1;
|
||||
} else if (!strcmp(argv[c], "-pass") && c < argc - 1) {
|
||||
config.pass = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-pre") && c < argc - 1) {
|
||||
@ -940,7 +949,8 @@ int main(int argc, const char *argv[]) {
|
||||
// Read the input. We need to decide if we prefer ARGB or YUVA
|
||||
// samples, depending on the expected compression mode (this saves
|
||||
// some conversion steps).
|
||||
picture.use_argb = (config.lossless || config.preprocessing > 0 ||
|
||||
picture.use_argb = (config.lossless || config.use_sharp_yuv ||
|
||||
config.preprocessing > 0 ||
|
||||
crop || (resize_w | resize_h) > 0);
|
||||
if (verbose) {
|
||||
StopwatchReset(&stop_watch);
|
||||
@ -964,7 +974,7 @@ int main(int argc, const char *argv[]) {
|
||||
// Open the output
|
||||
if (out_file != NULL) {
|
||||
const int use_stdout = !strcmp(out_file, "-");
|
||||
out = use_stdout ? ExUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
|
||||
out = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "Error! Cannot open output file '%s'\n", out_file);
|
||||
goto Error;
|
||||
@ -1088,20 +1098,6 @@ int main(int argc, const char *argv[]) {
|
||||
if (print_distortion >= 0) { // print distortion
|
||||
static const char* distortion_names[] = { "PSNR", "SSIM", "LSIM" };
|
||||
float values[5];
|
||||
if (picture.use_argb != original_picture.use_argb) {
|
||||
// Somehow, the WebPEncode() call converted the original picture.
|
||||
// We need to make both match before calling WebPPictureDistortion().
|
||||
int ok = 0;
|
||||
if (picture.use_argb) {
|
||||
ok = WebPPictureYUVAToARGB(&original_picture);
|
||||
} else {
|
||||
ok = WebPPictureARGBToYUVA(&original_picture, WEBP_YUV420A);
|
||||
}
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error while converting original picture.\n");
|
||||
goto Error;
|
||||
}
|
||||
}
|
||||
if (!WebPPictureDistortion(&picture, &original_picture,
|
||||
print_distortion, values)) {
|
||||
fprintf(stderr, "Error while computing the distortion.\n");
|
||||
@ -1109,13 +1105,8 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
if (!short_output) {
|
||||
fprintf(stderr, "%s: ", distortion_names[print_distortion]);
|
||||
if (picture.use_argb) {
|
||||
fprintf(stderr, "B:%.2f G:%.2f R:%.2f A:%.2f Total:%.2f\n",
|
||||
values[0], values[1], values[2], values[3], values[4]);
|
||||
} else {
|
||||
fprintf(stderr, "Y:%.2f U:%.2f V:%.2f A:%.2f Total:%.2f\n",
|
||||
values[0], values[1], values[2], values[3], values[4]);
|
||||
}
|
||||
fprintf(stderr, "B:%.2f G:%.2f R:%.2f A:%.2f Total:%.2f\n",
|
||||
values[0], values[1], values[2], values[3], values[4]);
|
||||
} else {
|
||||
fprintf(stderr, "%7d %.4f\n", picture.stats->coded_size, values[4]);
|
||||
}
|
||||
|
528
examples/dwebp.c
528
examples/dwebp.c
@ -20,27 +20,9 @@
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#ifdef WEBP_HAVE_PNG
|
||||
#include <png.h>
|
||||
#include <setjmp.h> // note: this must be included *after* png.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
#ifdef __MINGW32__
|
||||
#define INITGUID // Without this GUIDs are declared extern and fail to link
|
||||
#endif
|
||||
#define CINTERFACE
|
||||
#define COBJMACROS
|
||||
#define _WIN32_IE 0x500 // Workaround bug in shlwapi.h when compiling C++
|
||||
// code with COBJMACROS.
|
||||
#include <ole2.h> // CreateStreamOnHGlobal()
|
||||
#include <shlwapi.h>
|
||||
#include <windows.h>
|
||||
#include <wincodec.h>
|
||||
#endif
|
||||
|
||||
#include "webp/decode.h"
|
||||
#include "./example_util.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/image_enc.h"
|
||||
#include "../imageio/webpdec.h"
|
||||
#include "./stopwatch.h"
|
||||
|
||||
static int verbose = 0;
|
||||
@ -57,486 +39,18 @@ extern void* VP8GetCPUInfo; // opaque forward declaration.
|
||||
#endif
|
||||
#endif // WEBP_DLL
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Output types
|
||||
typedef enum {
|
||||
PNG = 0,
|
||||
PAM,
|
||||
PPM,
|
||||
PGM,
|
||||
BMP,
|
||||
TIFF,
|
||||
RAW_YUV,
|
||||
ALPHA_PLANE_ONLY, // this is for experimenting only
|
||||
// forced colorspace output (for testing, mostly)
|
||||
RGB, RGBA, BGR, BGRA, ARGB,
|
||||
RGBA_4444, RGB_565,
|
||||
rgbA, bgrA, Argb, rgbA_4444,
|
||||
YUV, YUVA
|
||||
} OutputFileFormat;
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
|
||||
#define IFS(fn) \
|
||||
do { \
|
||||
if (SUCCEEDED(hr)) { \
|
||||
hr = (fn); \
|
||||
if (FAILED(hr)) fprintf(stderr, #fn " failed %08lx\n", hr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MAKE_REFGUID(x) (x)
|
||||
#else
|
||||
#define MAKE_REFGUID(x) &(x)
|
||||
#endif
|
||||
|
||||
static HRESULT CreateOutputStream(const char* out_file_name,
|
||||
int write_to_mem, IStream** stream) {
|
||||
HRESULT hr = S_OK;
|
||||
if (write_to_mem) {
|
||||
// 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));
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
fprintf(stderr, "Error opening output file %s (%08lx)\n",
|
||||
out_file_name, hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WriteUsingWIC(const char* out_file_name, int use_stdout,
|
||||
REFGUID container_guid,
|
||||
uint8_t* rgb, int stride,
|
||||
uint32_t width, uint32_t height, int has_alpha) {
|
||||
HRESULT hr = S_OK;
|
||||
IWICImagingFactory* factory = NULL;
|
||||
IWICBitmapFrameEncode* frame = NULL;
|
||||
IWICBitmapEncoder* encoder = NULL;
|
||||
IStream* stream = NULL;
|
||||
WICPixelFormatGUID pixel_format = has_alpha ? GUID_WICPixelFormat32bppBGRA
|
||||
: GUID_WICPixelFormat24bppBGR;
|
||||
|
||||
IFS(CoInitialize(NULL));
|
||||
IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
MAKE_REFGUID(IID_IWICImagingFactory),
|
||||
(LPVOID*)&factory));
|
||||
if (hr == REGDB_E_CLASSNOTREG) {
|
||||
fprintf(stderr,
|
||||
"Couldn't access Windows Imaging Component (are you running "
|
||||
"Windows XP SP3 or newer?). PNG support not available. "
|
||||
"Use -ppm or -pgm for available PPM and PGM formats.\n");
|
||||
}
|
||||
IFS(CreateOutputStream(out_file_name, use_stdout, &stream));
|
||||
IFS(IWICImagingFactory_CreateEncoder(factory, container_guid, NULL,
|
||||
&encoder));
|
||||
IFS(IWICBitmapEncoder_Initialize(encoder, stream,
|
||||
WICBitmapEncoderNoCache));
|
||||
IFS(IWICBitmapEncoder_CreateNewFrame(encoder, &frame, NULL));
|
||||
IFS(IWICBitmapFrameEncode_Initialize(frame, NULL));
|
||||
IFS(IWICBitmapFrameEncode_SetSize(frame, width, height));
|
||||
IFS(IWICBitmapFrameEncode_SetPixelFormat(frame, &pixel_format));
|
||||
IFS(IWICBitmapFrameEncode_WritePixels(frame, height, stride,
|
||||
height * stride, rgb));
|
||||
IFS(IWICBitmapFrameEncode_Commit(frame));
|
||||
IFS(IWICBitmapEncoder_Commit(encoder));
|
||||
|
||||
if (SUCCEEDED(hr) && use_stdout) {
|
||||
HGLOBAL image;
|
||||
IFS(GetHGlobalFromStream(stream, &image));
|
||||
if (SUCCEEDED(hr)) {
|
||||
HANDLE std_output = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD mode;
|
||||
const BOOL update_mode = GetConsoleMode(std_output, &mode);
|
||||
const void* const image_mem = GlobalLock(image);
|
||||
DWORD bytes_written = 0;
|
||||
|
||||
// Clear output processing if necessary, then output the image.
|
||||
if (update_mode) SetConsoleMode(std_output, 0);
|
||||
if (!WriteFile(std_output, image_mem, (DWORD)GlobalSize(image),
|
||||
&bytes_written, NULL) ||
|
||||
bytes_written != GlobalSize(image)) {
|
||||
hr = E_FAIL;
|
||||
}
|
||||
if (update_mode) SetConsoleMode(std_output, mode);
|
||||
GlobalUnlock(image);
|
||||
}
|
||||
}
|
||||
|
||||
if (frame != NULL) IUnknown_Release(frame);
|
||||
if (encoder != NULL) IUnknown_Release(encoder);
|
||||
if (factory != NULL) IUnknown_Release(factory);
|
||||
if (stream != NULL) IUnknown_Release(stream);
|
||||
return hr;
|
||||
}
|
||||
|
||||
static int WritePNG(const char* out_file_name, int use_stdout,
|
||||
const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
uint8_t* const rgb = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
|
||||
return SUCCEEDED(WriteUsingWIC(out_file_name, use_stdout,
|
||||
MAKE_REFGUID(GUID_ContainerFormatPng),
|
||||
rgb, stride, width, height, has_alpha));
|
||||
}
|
||||
|
||||
#elif defined(WEBP_HAVE_PNG) // !HAVE_WINCODEC_H
|
||||
static void PNGAPI PNGErrorFunction(png_structp png, png_const_charp dummy) {
|
||||
(void)dummy; // remove variable-unused warning
|
||||
longjmp(png_jmpbuf(png), 1);
|
||||
}
|
||||
|
||||
static int WritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
uint8_t* const rgb = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
volatile png_structp png;
|
||||
volatile png_infop info;
|
||||
png_uint_32 y;
|
||||
|
||||
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
NULL, PNGErrorFunction, NULL);
|
||||
if (png == NULL) {
|
||||
return 0;
|
||||
}
|
||||
info = png_create_info_struct(png);
|
||||
if (info == NULL) {
|
||||
png_destroy_write_struct((png_structpp)&png, NULL);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_jmpbuf(png))) {
|
||||
png_destroy_write_struct((png_structpp)&png, (png_infopp)&info);
|
||||
return 0;
|
||||
}
|
||||
png_init_io(png, out_file);
|
||||
png_set_IHDR(png, info, width, height, 8,
|
||||
has_alpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
png_write_info(png, info);
|
||||
for (y = 0; y < height; ++y) {
|
||||
png_bytep row = rgb + y * stride;
|
||||
png_write_rows(png, &row, 1);
|
||||
}
|
||||
png_write_end(png, info);
|
||||
png_destroy_write_struct((png_structpp)&png, (png_infopp)&info);
|
||||
return 1;
|
||||
}
|
||||
#else // !HAVE_WINCODEC_H && !WEBP_HAVE_PNG
|
||||
static int WritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
|
||||
(void)out_file;
|
||||
(void)buffer;
|
||||
fprintf(stderr, "PNG support not compiled. Please install the libpng "
|
||||
"development package before building.\n");
|
||||
fprintf(stderr, "You can run with -ppm flag to decode in PPM format.\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int WritePPM(FILE* fout, const WebPDecBuffer* const buffer, int alpha) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* const rgb = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const size_t bytes_per_px = alpha ? 4 : 3;
|
||||
uint32_t y;
|
||||
|
||||
if (alpha) {
|
||||
fprintf(fout, "P7\nWIDTH %u\nHEIGHT %u\nDEPTH 4\nMAXVAL 255\n"
|
||||
"TUPLTYPE RGB_ALPHA\nENDHDR\n", width, height);
|
||||
} else {
|
||||
fprintf(fout, "P6\n%u %u\n255\n", width, height);
|
||||
}
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgb + y * stride, width, bytes_per_px, fout) != bytes_per_px) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Save 16b mode (RGBA4444, RGB565, ...) for debugging purpose.
|
||||
static int Write16bAsPGM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* const rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint32_t bytes_per_px = 2;
|
||||
uint32_t y;
|
||||
|
||||
fprintf(fout, "P5\n%u %u\n255\n", width * bytes_per_px, height);
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba + y * stride, width, bytes_per_px, fout) != bytes_per_px) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void PutLE16(uint8_t* const dst, uint32_t value) {
|
||||
dst[0] = (value >> 0) & 0xff;
|
||||
dst[1] = (value >> 8) & 0xff;
|
||||
}
|
||||
|
||||
static void PutLE32(uint8_t* const dst, uint32_t value) {
|
||||
PutLE16(dst + 0, (value >> 0) & 0xffff);
|
||||
PutLE16(dst + 2, (value >> 16) & 0xffff);
|
||||
}
|
||||
|
||||
#define BMP_HEADER_SIZE 54
|
||||
static int WriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* const rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint32_t bytes_per_px = has_alpha ? 4 : 3;
|
||||
uint32_t y;
|
||||
const uint32_t line_size = bytes_per_px * width;
|
||||
const uint32_t bmp_stride = (line_size + 3) & ~3; // pad to 4
|
||||
const uint32_t total_size = bmp_stride * height + BMP_HEADER_SIZE;
|
||||
uint8_t bmp_header[BMP_HEADER_SIZE] = { 0 };
|
||||
|
||||
// bitmap file header
|
||||
PutLE16(bmp_header + 0, 0x4d42); // signature 'BM'
|
||||
PutLE32(bmp_header + 2, total_size); // size including header
|
||||
PutLE32(bmp_header + 6, 0); // reserved
|
||||
PutLE32(bmp_header + 10, BMP_HEADER_SIZE); // offset to pixel array
|
||||
// bitmap info header
|
||||
PutLE32(bmp_header + 14, 40); // DIB header size
|
||||
PutLE32(bmp_header + 18, width); // dimensions
|
||||
PutLE32(bmp_header + 22, -(int)height); // vertical flip!
|
||||
PutLE16(bmp_header + 26, 1); // number of planes
|
||||
PutLE16(bmp_header + 28, bytes_per_px * 8); // bits per pixel
|
||||
PutLE32(bmp_header + 30, 0); // no compression (BI_RGB)
|
||||
PutLE32(bmp_header + 34, 0); // image size (dummy)
|
||||
PutLE32(bmp_header + 38, 2400); // x pixels/meter
|
||||
PutLE32(bmp_header + 42, 2400); // y pixels/meter
|
||||
PutLE32(bmp_header + 46, 0); // number of palette colors
|
||||
PutLE32(bmp_header + 50, 0); // important color count
|
||||
|
||||
// TODO(skal): color profile
|
||||
|
||||
// write header
|
||||
if (fwrite(bmp_header, sizeof(bmp_header), 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// write pixel array
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba + y * stride, line_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
// write padding zeroes
|
||||
if (bmp_stride != line_size) {
|
||||
const uint8_t zeroes[3] = { 0 };
|
||||
if (fwrite(zeroes, bmp_stride - line_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#undef BMP_HEADER_SIZE
|
||||
|
||||
#define NUM_IFD_ENTRIES 15
|
||||
#define EXTRA_DATA_SIZE 16
|
||||
// 10b for signature/header + n * 12b entries + 4b for IFD terminator:
|
||||
#define EXTRA_DATA_OFFSET (10 + 12 * NUM_IFD_ENTRIES + 4)
|
||||
#define TIFF_HEADER_SIZE (EXTRA_DATA_OFFSET + EXTRA_DATA_SIZE)
|
||||
|
||||
static int WriteTIFF(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* const rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint8_t bytes_per_px = has_alpha ? 4 : 3;
|
||||
// For non-alpha case, we omit tag 0x152 (ExtraSamples).
|
||||
const uint8_t num_ifd_entries = has_alpha ? NUM_IFD_ENTRIES
|
||||
: NUM_IFD_ENTRIES - 1;
|
||||
uint8_t tiff_header[TIFF_HEADER_SIZE] = {
|
||||
0x49, 0x49, 0x2a, 0x00, // little endian signature
|
||||
8, 0, 0, 0, // offset to the unique IFD that follows
|
||||
// IFD (offset = 8). Entries must be written in increasing tag order.
|
||||
num_ifd_entries, 0, // Number of entries in the IFD (12 bytes each).
|
||||
0x00, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 10: Width (TBD)
|
||||
0x01, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 22: Height (TBD)
|
||||
0x02, 0x01, 3, 0, bytes_per_px, 0, 0, 0, // 34: BitsPerSample: 8888
|
||||
EXTRA_DATA_OFFSET + 0, 0, 0, 0,
|
||||
0x03, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 46: Compression: none
|
||||
0x06, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 58: Photometric: RGB
|
||||
0x11, 0x01, 4, 0, 1, 0, 0, 0, // 70: Strips offset:
|
||||
TIFF_HEADER_SIZE, 0, 0, 0, // data follows header
|
||||
0x12, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 82: Orientation: topleft
|
||||
0x15, 0x01, 3, 0, 1, 0, 0, 0, // 94: SamplesPerPixels
|
||||
bytes_per_px, 0, 0, 0,
|
||||
0x16, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 106: Rows per strip (TBD)
|
||||
0x17, 0x01, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 118: StripByteCount (TBD)
|
||||
0x1a, 0x01, 5, 0, 1, 0, 0, 0, // 130: X-resolution
|
||||
EXTRA_DATA_OFFSET + 8, 0, 0, 0,
|
||||
0x1b, 0x01, 5, 0, 1, 0, 0, 0, // 142: Y-resolution
|
||||
EXTRA_DATA_OFFSET + 8, 0, 0, 0,
|
||||
0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 154: PlanarConfiguration
|
||||
0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 166: ResolutionUnit (inch)
|
||||
0x52, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 178: ExtraSamples: rgbA
|
||||
0, 0, 0, 0, // 190: IFD terminator
|
||||
// EXTRA_DATA_OFFSET:
|
||||
8, 0, 8, 0, 8, 0, 8, 0, // BitsPerSample
|
||||
72, 0, 0, 0, 1, 0, 0, 0 // 72 pixels/inch, for X/Y-resolution
|
||||
};
|
||||
uint32_t y;
|
||||
|
||||
// Fill placeholders in IFD:
|
||||
PutLE32(tiff_header + 10 + 8, width);
|
||||
PutLE32(tiff_header + 22 + 8, height);
|
||||
PutLE32(tiff_header + 106 + 8, height);
|
||||
PutLE32(tiff_header + 118 + 8, width * bytes_per_px * height);
|
||||
if (!has_alpha) PutLE32(tiff_header + 178, 0); // IFD terminator
|
||||
|
||||
// write header
|
||||
if (fwrite(tiff_header, sizeof(tiff_header), 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
// write pixel values
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba + y * stride, bytes_per_px, width, fout) != width) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#undef TIFF_HEADER_SIZE
|
||||
#undef EXTRA_DATA_OFFSET
|
||||
#undef EXTRA_DATA_SIZE
|
||||
#undef NUM_IFD_ENTRIES
|
||||
|
||||
static int WriteAlphaPlane(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* const a = buffer->u.YUVA.a;
|
||||
const int a_stride = buffer->u.YUVA.a_stride;
|
||||
uint32_t y;
|
||||
assert(a != NULL);
|
||||
fprintf(fout, "P5\n%u %u\n255\n", width, height);
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(a + y * a_stride, width, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// format=PGM: save a grayscale PGM file using the IMC4 layout
|
||||
// (http://www.fourcc.org/yuv.php#IMC4). This is a very convenient format for
|
||||
// viewing the samples, esp. for odd dimensions.
|
||||
// format=RAW_YUV: just save the Y/U/V/A planes sequentially without header.
|
||||
static int WritePGMOrYUV(FILE* fout, const WebPDecBuffer* const buffer,
|
||||
OutputFileFormat format) {
|
||||
const int width = buffer->width;
|
||||
const int height = buffer->height;
|
||||
const WebPYUVABuffer* const yuv = &buffer->u.YUVA;
|
||||
int ok = 1;
|
||||
int y;
|
||||
const int pad = (format == RAW_YUV) ? 0 : 1;
|
||||
const int uv_width = (width + 1) / 2;
|
||||
const int uv_height = (height + 1) / 2;
|
||||
const int out_stride = (width + pad) & ~pad;
|
||||
const int a_height = yuv->a ? height : 0;
|
||||
if (format == PGM) {
|
||||
fprintf(fout, "P5\n%d %d\n255\n",
|
||||
out_stride, height + uv_height + a_height);
|
||||
}
|
||||
for (y = 0; ok && y < height; ++y) {
|
||||
ok &= (fwrite(yuv->y + y * yuv->y_stride, width, 1, fout) == 1);
|
||||
if (format == PGM) {
|
||||
if (width & 1) fputc(0, fout); // padding byte
|
||||
}
|
||||
}
|
||||
if (format == PGM) { // IMC4 layout
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(yuv->u + y * yuv->u_stride, uv_width, 1, fout) == 1);
|
||||
ok &= (fwrite(yuv->v + y * yuv->v_stride, uv_width, 1, fout) == 1);
|
||||
}
|
||||
} else {
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(yuv->u + y * yuv->u_stride, uv_width, 1, fout) == 1);
|
||||
}
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(yuv->v + y * yuv->v_stride, uv_width, 1, fout) == 1);
|
||||
}
|
||||
}
|
||||
for (y = 0; ok && y < a_height; ++y) {
|
||||
ok &= (fwrite(yuv->a + y * yuv->a_stride, width, 1, fout) == 1);
|
||||
if (format == PGM) {
|
||||
if (width & 1) fputc(0, fout); // padding byte
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int SaveOutput(const WebPDecBuffer* const buffer,
|
||||
OutputFileFormat format, const char* const out_file) {
|
||||
FILE* fout = NULL;
|
||||
int needs_open_file = 1;
|
||||
const int use_stdout = !strcmp(out_file, "-");
|
||||
WebPOutputFileFormat format, const char* const out_file) {
|
||||
const int use_stdout = (out_file != NULL) && !strcmp(out_file, "-");
|
||||
int ok = 1;
|
||||
Stopwatch stop_watch;
|
||||
|
||||
if (verbose) {
|
||||
StopwatchReset(&stop_watch);
|
||||
}
|
||||
ok = WebPSaveImage(buffer, format, out_file);
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
needs_open_file = (format != PNG);
|
||||
#endif
|
||||
|
||||
if (needs_open_file) {
|
||||
fout = use_stdout ? ExUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
|
||||
if (fout == NULL) {
|
||||
fprintf(stderr, "Error opening output file %s\n", out_file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (format == PNG ||
|
||||
format == RGBA || format == BGRA || format == ARGB ||
|
||||
format == rgbA || format == bgrA || format == Argb) {
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
ok &= WritePNG(out_file, use_stdout, buffer);
|
||||
#else
|
||||
ok &= WritePNG(fout, buffer);
|
||||
#endif
|
||||
} else if (format == PAM) {
|
||||
ok &= WritePPM(fout, buffer, 1);
|
||||
} else if (format == PPM || format == RGB || format == BGR) {
|
||||
ok &= WritePPM(fout, buffer, 0);
|
||||
} else if (format == RGBA_4444 || format == RGB_565 || format == rgbA_4444) {
|
||||
ok &= Write16bAsPGM(fout, buffer);
|
||||
} else if (format == BMP) {
|
||||
ok &= WriteBMP(fout, buffer);
|
||||
} else if (format == TIFF) {
|
||||
ok &= WriteTIFF(fout, buffer);
|
||||
} else if (format == PGM || format == RAW_YUV ||
|
||||
format == YUV || format == YUVA) {
|
||||
ok &= WritePGMOrYUV(fout, buffer, format == RAW_YUV ? RAW_YUV : PGM);
|
||||
} else if (format == ALPHA_PLANE_ONLY) {
|
||||
ok &= WriteAlphaPlane(fout, buffer);
|
||||
}
|
||||
if (fout != NULL && fout != stdout) {
|
||||
fclose(fout);
|
||||
}
|
||||
if (ok) {
|
||||
if (!quiet) {
|
||||
if (use_stdout) {
|
||||
@ -598,7 +112,7 @@ static const char* const kFormatType[] = {
|
||||
};
|
||||
|
||||
static uint8_t* AllocateExternalBuffer(WebPDecoderConfig* config,
|
||||
OutputFileFormat format,
|
||||
WebPOutputFileFormat format,
|
||||
int use_external_memory) {
|
||||
uint8_t* external_buffer = NULL;
|
||||
WebPDecBuffer* const output_buffer = &config->output;
|
||||
@ -669,7 +183,7 @@ int main(int argc, const char *argv[]) {
|
||||
WebPDecoderConfig config;
|
||||
WebPDecBuffer* const output_buffer = &config.output;
|
||||
WebPBitstreamFeatures* const bitstream = &config.input;
|
||||
OutputFileFormat format = PNG;
|
||||
WebPOutputFileFormat format = PNG;
|
||||
uint8_t* external_buffer = NULL;
|
||||
int use_external_memory = 0;
|
||||
const uint8_t* data = NULL;
|
||||
@ -797,7 +311,7 @@ int main(int argc, const char *argv[]) {
|
||||
{
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
size_t data_size = 0;
|
||||
if (!ExUtilLoadWebP(in_file, &data, &data_size, bitstream)) {
|
||||
if (!LoadWebP(in_file, &data, &data_size, bitstream)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -818,9 +332,8 @@ int main(int argc, const char *argv[]) {
|
||||
case BMP:
|
||||
output_buffer->colorspace = bitstream->has_alpha ? MODE_BGRA : MODE_BGR;
|
||||
break;
|
||||
case TIFF: // note: force pre-multiplied alpha
|
||||
output_buffer->colorspace =
|
||||
bitstream->has_alpha ? MODE_rgbA : MODE_RGB;
|
||||
case TIFF:
|
||||
output_buffer->colorspace = bitstream->has_alpha ? MODE_RGBA : MODE_RGB;
|
||||
break;
|
||||
case PGM:
|
||||
case RAW_YUV:
|
||||
@ -852,15 +365,24 @@ int main(int argc, const char *argv[]) {
|
||||
if (external_buffer == NULL) goto Exit;
|
||||
}
|
||||
|
||||
if (incremental) {
|
||||
status = ExUtilDecodeWebPIncremental(data, data_size, verbose, &config);
|
||||
} else {
|
||||
status = ExUtilDecodeWebP(data, data_size, verbose, &config);
|
||||
{
|
||||
Stopwatch stop_watch;
|
||||
if (verbose) StopwatchReset(&stop_watch);
|
||||
|
||||
if (incremental) {
|
||||
status = DecodeWebPIncremental(data, data_size, &config);
|
||||
} else {
|
||||
status = DecodeWebP(data, data_size, &config);
|
||||
}
|
||||
if (verbose) {
|
||||
const double decode_time = StopwatchReadAndReset(&stop_watch);
|
||||
fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time);
|
||||
}
|
||||
}
|
||||
|
||||
ok = (status == VP8_STATUS_OK);
|
||||
if (!ok) {
|
||||
ExUtilPrintWebPError(in_file, status);
|
||||
PrintWebPError(in_file, status);
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,10 @@
|
||||
|
||||
#include "./example_util.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <fcntl.h> // for _O_BINARY
|
||||
#include <io.h> // for _setmode()
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/decode.h"
|
||||
#include "./stopwatch.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// String parsing
|
||||
|
||||
@ -41,6 +34,18 @@ int ExUtilGetInt(const char* const v, int base, int* const error) {
|
||||
return (int)ExUtilGetUInt(v, base, error);
|
||||
}
|
||||
|
||||
int ExUtilGetInts(const char* v, int base, int max_output, int output[]) {
|
||||
int n, error = 0;
|
||||
for (n = 0; v != NULL && n < max_output; ++n) {
|
||||
const int value = ExUtilGetInt(v, base, &error);
|
||||
if (error) return -1;
|
||||
output[n] = value;
|
||||
v = strchr(v, ',');
|
||||
if (v != NULL) ++v; // skip over the trailing ','
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
float ExUtilGetFloat(const char* const v, int* const error) {
|
||||
char* end = NULL;
|
||||
const float f = (v != NULL) ? (float)strtod(v, &end) : 0.f;
|
||||
@ -51,238 +56,3 @@ float ExUtilGetFloat(const char* const v, int* const error) {
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File I/O
|
||||
|
||||
FILE* ExUtilSetBinaryMode(FILE* file) {
|
||||
#if defined(_WIN32)
|
||||
if (_setmode(_fileno(file), _O_BINARY) == -1) {
|
||||
fprintf(stderr, "Failed to reopen file in O_BINARY mode.\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return file;
|
||||
}
|
||||
|
||||
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size) {
|
||||
static const size_t kBlockSize = 16384; // default initial size
|
||||
size_t max_size = 0;
|
||||
size_t size = 0;
|
||||
uint8_t* input = NULL;
|
||||
|
||||
if (data == NULL || data_size == NULL) return 0;
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
|
||||
if (!ExUtilSetBinaryMode(stdin)) return 0;
|
||||
|
||||
while (!feof(stdin)) {
|
||||
// We double the buffer size each time and read as much as possible.
|
||||
const size_t extra_size = (max_size == 0) ? kBlockSize : max_size;
|
||||
void* const new_data = realloc(input, max_size + extra_size);
|
||||
if (new_data == NULL) goto Error;
|
||||
input = (uint8_t*)new_data;
|
||||
max_size += extra_size;
|
||||
size += fread(input + size, 1, extra_size, stdin);
|
||||
if (size < max_size) break;
|
||||
}
|
||||
if (ferror(stdin)) goto Error;
|
||||
*data = input;
|
||||
*data_size = size;
|
||||
return 1;
|
||||
|
||||
Error:
|
||||
free(input);
|
||||
fprintf(stderr, "Could not read from stdin\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ExUtilReadFile(const char* const file_name,
|
||||
const uint8_t** data, size_t* data_size) {
|
||||
int ok;
|
||||
void* file_data;
|
||||
size_t file_size;
|
||||
FILE* in;
|
||||
const int from_stdin = (file_name == NULL) || !strcmp(file_name, "-");
|
||||
|
||||
if (from_stdin) return ExUtilReadFromStdin(data, data_size);
|
||||
|
||||
if (data == NULL || data_size == NULL) return 0;
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
|
||||
in = fopen(file_name, "rb");
|
||||
if (in == NULL) {
|
||||
fprintf(stderr, "cannot open input file '%s'\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
fseek(in, 0, SEEK_END);
|
||||
file_size = ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
file_data = malloc(file_size);
|
||||
if (file_data == NULL) 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);
|
||||
free(file_data);
|
||||
return 0;
|
||||
}
|
||||
*data = (uint8_t*)file_data;
|
||||
*data_size = file_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ExUtilWriteFile(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, "-");
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
out = to_stdout ? stdout : fopen(file_name, "wb");
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "Error! Cannot open output file '%s'\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
ok = (fwrite(data, data_size, 1, out) == 1);
|
||||
if (out != stdout) fclose(out);
|
||||
return ok;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WebP decoding
|
||||
|
||||
static const char* const kStatusMessages[VP8_STATUS_NOT_ENOUGH_DATA + 1] = {
|
||||
"OK", "OUT_OF_MEMORY", "INVALID_PARAM", "BITSTREAM_ERROR",
|
||||
"UNSUPPORTED_FEATURE", "SUSPENDED", "USER_ABORT", "NOT_ENOUGH_DATA"
|
||||
};
|
||||
|
||||
static void PrintAnimationWarning(const WebPDecoderConfig* const config) {
|
||||
if (config->input.has_animation) {
|
||||
fprintf(stderr,
|
||||
"Error! Decoding of an animated WebP file is not supported.\n"
|
||||
" Use webpmux to extract the individual frames or\n"
|
||||
" vwebp to view this image.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ExUtilPrintWebPError(const char* const in_file, int status) {
|
||||
fprintf(stderr, "Decoding of %s failed.\n", in_file);
|
||||
fprintf(stderr, "Status: %d", status);
|
||||
if (status >= VP8_STATUS_OK && status <= VP8_STATUS_NOT_ENOUGH_DATA) {
|
||||
fprintf(stderr, "(%s)", kStatusMessages[status]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int ExUtilLoadWebP(const char* const in_file,
|
||||
const uint8_t** data, size_t* data_size,
|
||||
WebPBitstreamFeatures* bitstream) {
|
||||
VP8StatusCode status;
|
||||
WebPBitstreamFeatures local_features;
|
||||
if (!ExUtilReadFile(in_file, data, data_size)) return 0;
|
||||
|
||||
if (bitstream == NULL) {
|
||||
bitstream = &local_features;
|
||||
}
|
||||
|
||||
status = WebPGetFeatures(*data, *data_size, bitstream);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
free((void*)*data);
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
ExUtilPrintWebPError(in_file, status);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
|
||||
int verbose, WebPDecoderConfig* const config) {
|
||||
Stopwatch stop_watch;
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
if (config == NULL) return VP8_STATUS_INVALID_PARAM;
|
||||
|
||||
PrintAnimationWarning(config);
|
||||
|
||||
StopwatchReset(&stop_watch);
|
||||
|
||||
// Decoding call.
|
||||
status = WebPDecode(data, data_size, config);
|
||||
|
||||
if (verbose) {
|
||||
const double decode_time = StopwatchReadAndReset(&stop_watch);
|
||||
fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
VP8StatusCode ExUtilDecodeWebPIncremental(
|
||||
const uint8_t* const data, size_t data_size,
|
||||
int verbose, WebPDecoderConfig* const config) {
|
||||
Stopwatch stop_watch;
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
if (config == NULL) return VP8_STATUS_INVALID_PARAM;
|
||||
|
||||
PrintAnimationWarning(config);
|
||||
|
||||
StopwatchReset(&stop_watch);
|
||||
|
||||
// Decoding call.
|
||||
{
|
||||
WebPIDecoder* const idec = WebPIDecode(data, data_size, config);
|
||||
if (idec == NULL) {
|
||||
fprintf(stderr, "Failed during WebPINewDecoder().\n");
|
||||
return VP8_STATUS_OUT_OF_MEMORY;
|
||||
} else {
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
size_t size = 0;
|
||||
const size_t incr = 2 + (data_size / 20);
|
||||
while (size < data_size) {
|
||||
size_t next_size = size + (rand() % incr);
|
||||
if (next_size > data_size) next_size = data_size;
|
||||
status = WebPIUpdate(idec, data, next_size);
|
||||
if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) break;
|
||||
size = next_size;
|
||||
}
|
||||
#else
|
||||
status = WebPIUpdate(idec, data, data_size);
|
||||
#endif
|
||||
WebPIDelete(idec);
|
||||
}
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
const double decode_time = StopwatchReadAndReset(&stop_watch);
|
||||
fprintf(stderr, "Time to decode picture: %.3fs\n", decode_time);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ExUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height) {
|
||||
while (height-- > 0) {
|
||||
memcpy(dst, src, width * sizeof(*dst));
|
||||
src += src_stride;
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
|
||||
const uint64_t total_size = nmemb * size;
|
||||
return (total_size == (size_t)total_size);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -13,8 +13,7 @@
|
||||
#ifndef WEBP_EXAMPLES_EXAMPLE_UTIL_H_
|
||||
#define WEBP_EXAMPLES_EXAMPLE_UTIL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "webp/decode.h"
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -30,68 +29,11 @@ uint32_t ExUtilGetUInt(const char* const v, int base, int* const error);
|
||||
int ExUtilGetInt(const char* const v, int base, int* const error);
|
||||
float ExUtilGetFloat(const char* const v, int* const error);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// File I/O
|
||||
|
||||
// Reopen file in binary (O_BINARY) mode.
|
||||
// Returns 'file' on success, NULL otherwise.
|
||||
FILE* ExUtilSetBinaryMode(FILE* file);
|
||||
|
||||
// Allocates storage for entire file 'file_name' and returns contents and size
|
||||
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
|
||||
// be deleted using free().
|
||||
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
|
||||
// the function ExUtilReadFromStdin().
|
||||
int ExUtilReadFile(const char* const file_name,
|
||||
const uint8_t** data, size_t* data_size);
|
||||
|
||||
// Same as ExUtilReadFile(), but reads until EOF from stdin instead.
|
||||
int ExUtilReadFromStdin(const uint8_t** data, size_t* data_size);
|
||||
|
||||
// Write a data segment into a file named 'file_name'. Returns true if ok.
|
||||
// If 'file_name' is NULL or equal to "-", output is written to stdout.
|
||||
int ExUtilWriteFile(const char* const file_name,
|
||||
const uint8_t* data, size_t data_size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Copy width x height pixels from 'src' to 'dst' honoring the strides.
|
||||
void ExUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Returns 0 in case of overflow of nmemb * size.
|
||||
int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WebP decoding
|
||||
|
||||
// Prints an informative error message regarding decode failure of 'in_file'.
|
||||
// 'status' is treated as a VP8StatusCode and if valid will be printed as a
|
||||
// text string.
|
||||
void ExUtilPrintWebPError(const char* const in_file, int status);
|
||||
|
||||
// Reads a WebP from 'in_file', returning the contents and size in 'data' and
|
||||
// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
|
||||
// Returns true on success.
|
||||
int ExUtilLoadWebP(const char* const in_file,
|
||||
const uint8_t** data, size_t* data_size,
|
||||
WebPBitstreamFeatures* bitstream);
|
||||
|
||||
// Decodes the WebP contained in 'data'.
|
||||
// 'config' is a structure previously initialized by WebPInitDecoderConfig().
|
||||
// 'config->output' should have the desired colorspace selected. 'verbose' will
|
||||
// cause decode timing to be reported.
|
||||
// Returns the decoder status. On success 'config->output' will contain the
|
||||
// decoded picture.
|
||||
VP8StatusCode ExUtilDecodeWebP(const uint8_t* const data, size_t data_size,
|
||||
int verbose, WebPDecoderConfig* const config);
|
||||
|
||||
// Same as ExUtilDecodeWebP(), but using the incremental decoder.
|
||||
VP8StatusCode ExUtilDecodeWebPIncremental(
|
||||
const uint8_t* const data, size_t data_size,
|
||||
int verbose, WebPDecoderConfig* const config);
|
||||
// This variant of ExUtilGetInt() will parse multiple integers from a
|
||||
// comma-separated list. Up to 'max_output' integers are parsed.
|
||||
// The result is placed in the output[] array, and the number of integers
|
||||
// actually parsed is returned, or -1 if an error occurred.
|
||||
int ExUtilGetInts(const char* v, int base, int max_output, int output[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
@ -26,7 +26,8 @@
|
||||
#include <gif_lib.h>
|
||||
#include "webp/encode.h"
|
||||
#include "webp/mux.h"
|
||||
#include "./example_util.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./gifdec.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -501,7 +502,7 @@ int main(int argc, const char *argv[]) {
|
||||
}
|
||||
|
||||
if (out_file != NULL) {
|
||||
if (!ExUtilWriteFile(out_file, webp_data.bytes, webp_data.size)) {
|
||||
if (!ImgIoUtilWriteFile(out_file, webp_data.bytes, webp_data.size)) {
|
||||
fprintf(stderr, "Error writing output file: %s\n", out_file);
|
||||
goto End;
|
||||
}
|
||||
|
@ -21,18 +21,24 @@
|
||||
#include "webp/encode.h"
|
||||
#include "webp/mux_types.h"
|
||||
|
||||
#define GIF_TRANSPARENT_COLOR 0x00000000
|
||||
#define GIF_WHITE_COLOR 0xffffffff
|
||||
#define GIF_TRANSPARENT_COLOR 0x00000000u
|
||||
#define GIF_WHITE_COLOR 0xffffffffu
|
||||
#define GIF_TRANSPARENT_MASK 0x01
|
||||
#define GIF_DISPOSE_MASK 0x07
|
||||
#define GIF_DISPOSE_SHIFT 2
|
||||
|
||||
// from utils/utils.h
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern void WebPCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride,
|
||||
int width, int height);
|
||||
extern void WebPCopyPixels(const WebPPicture* const src,
|
||||
WebPPicture* const dst);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void GIFGetBackgroundColor(const ColorMapObject* const color_map,
|
||||
int bgcolor_index, int transparent_index,
|
||||
@ -48,7 +54,7 @@ void GIFGetBackgroundColor(const ColorMapObject* const color_map,
|
||||
"white background.\n");
|
||||
} else {
|
||||
const GifColorType color = color_map->Colors[bgcolor_index];
|
||||
*bgcolor = (0xff << 24)
|
||||
*bgcolor = (0xffu << 24)
|
||||
| (color.Red << 16)
|
||||
| (color.Green << 8)
|
||||
| (color.Blue << 0);
|
||||
|
300
examples/img2webp.c
Normal file
300
examples/img2webp.c
Normal file
@ -0,0 +1,300 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// generate an animated WebP out of a sequence of images
|
||||
// (PNG, JPEG, ...)
|
||||
//
|
||||
// Example usage:
|
||||
// img2webp -o out.webp -q 40 -mixed -duration 40 input??.png
|
||||
//
|
||||
// Author: skal@google.com (Pascal Massimino)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
#include "./stopwatch.h"
|
||||
#include "webp/encode.h"
|
||||
#include "webp/mux.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static void Help(void) {
|
||||
printf("Usage:\n\n");
|
||||
printf(" img2webp [file-level options] [image files...] "
|
||||
"[per-frame options...]\n");
|
||||
printf("\n");
|
||||
|
||||
printf("File-level options (only used at the start of compression):\n");
|
||||
printf(" -min_size ............ minimize size\n");
|
||||
printf(" -loop <int> .......... loop count (default: 0, = infinite loop)\n");
|
||||
printf(" -kmax <int> .......... maximum number of frame between key-frames\n"
|
||||
" (0=only keyframes)\n");
|
||||
printf(" -kmin <int> .......... minimum number of frame between key-frames\n"
|
||||
" (0=disable key-frames altogether)\n");
|
||||
printf(" -mixed ............... use mixed lossy/lossless automatic mode\n");
|
||||
printf(" -v ................... verbose mode\n");
|
||||
printf(" -h ................... this help\n");
|
||||
printf("\n");
|
||||
|
||||
printf("Per-frame options (only used for subsequent images input):\n");
|
||||
printf(" -d <int> ............. frame duration in ms (default: 100)\n");
|
||||
printf(" -lossless ........... use lossless mode (default)\n");
|
||||
printf(" -lossy ... ........... use lossy mode\n");
|
||||
printf(" -q <float> ........... quality\n");
|
||||
printf(" -m <int> ............. method to use\n");
|
||||
|
||||
printf("\n");
|
||||
printf("example: img2webp -loop 2 in0.png -lossy in1.jpg\n"
|
||||
" -d 80 in2.tiff -o out.webp\n");
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static int ReadImage(const char filename[], WebPPicture* const pic) {
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
WebPImageReader reader;
|
||||
int ok;
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
// Try to decode the file using WIC falling back to the other readers for
|
||||
// e.g., WebP.
|
||||
ok = ReadPictureWithWIC(filename, pic, 1, NULL);
|
||||
if (ok) return 1;
|
||||
#endif
|
||||
if (!ImgIoUtilReadFile(filename, &data, &data_size)) return 0;
|
||||
reader = WebPGuessImageReader(data, data_size);
|
||||
ok = reader(data, data_size, pic, 1, NULL);
|
||||
free((void*)data);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int SetLoopCount(int loop_count, WebPData* const webp_data) {
|
||||
int ok = 1;
|
||||
WebPMuxError err;
|
||||
uint32_t features;
|
||||
WebPMuxAnimParams new_params;
|
||||
WebPMux* const mux = WebPMuxCreate(webp_data, 1);
|
||||
if (mux == NULL) return 0;
|
||||
|
||||
err = WebPMuxGetFeatures(mux, &features);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
if (!ok || !(features & ANIMATION_FLAG)) goto End;
|
||||
|
||||
err = WebPMuxGetAnimationParams(mux, &new_params);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
if (ok) {
|
||||
new_params.loop_count = loop_count;
|
||||
err = WebPMuxSetAnimationParams(mux, &new_params);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
}
|
||||
if (ok) {
|
||||
WebPDataClear(webp_data);
|
||||
err = WebPMuxAssemble(mux, webp_data);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
}
|
||||
|
||||
End:
|
||||
WebPMuxDelete(mux);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error during loop-count setting\n");
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
const char* output = NULL;
|
||||
WebPAnimEncoder* enc = NULL;
|
||||
int verbose = 0;
|
||||
int pic_num = 0;
|
||||
int duration = 100;
|
||||
int timestamp_ms = 0;
|
||||
int ok = 1;
|
||||
int loop_count = 0;
|
||||
int width = 0, height = 0;
|
||||
WebPAnimEncoderOptions anim_config;
|
||||
WebPConfig config;
|
||||
WebPPicture pic;
|
||||
WebPData webp_data;
|
||||
int c;
|
||||
int have_input = 0;
|
||||
|
||||
WebPDataInit(&webp_data);
|
||||
if (!WebPAnimEncoderOptionsInit(&anim_config) ||
|
||||
!WebPConfigInit(&config) ||
|
||||
!WebPPictureInit(&pic)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 1st pass of option parsing
|
||||
for (c = 1; ok && c < argc; ++c) {
|
||||
if (argv[c][0] == '-') {
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-o") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
output = argv[++c];
|
||||
} else if (!strcmp(argv[c], "-kmin") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
anim_config.kmin = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-kmax") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
anim_config.kmax = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-loop") && c + 1 < argc) {
|
||||
argv[c] = NULL;
|
||||
loop_count = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
if (loop_count < 0) {
|
||||
fprintf(stderr, "Invalid non-positive loop-count (%d)\n", loop_count);
|
||||
parse_error = 1;
|
||||
}
|
||||
} else if (!strcmp(argv[c], "-min_size")) {
|
||||
anim_config.minimize_size = 1;
|
||||
} else if (!strcmp(argv[c], "-mixed")) {
|
||||
anim_config.allow_mixed = 1;
|
||||
config.lossless = 0;
|
||||
} else if (!strcmp(argv[c], "-v")) {
|
||||
verbose = 1;
|
||||
} else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
|
||||
Help();
|
||||
return 0;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
ok = !parse_error;
|
||||
if (!ok) goto End;
|
||||
argv[c] = NULL; // mark option as 'parsed' during 1st pass
|
||||
} else {
|
||||
have_input |= 1;
|
||||
}
|
||||
}
|
||||
if (!have_input) {
|
||||
fprintf(stderr, "No input file(s) for generating animation!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// image-reading pass
|
||||
pic_num = 0;
|
||||
config.lossless = 1;
|
||||
for (c = 1; ok && c < argc; ++c) {
|
||||
if (argv[c] == NULL) continue;
|
||||
if (argv[c][0] == '-') { // parse local options
|
||||
int parse_error = 0;
|
||||
if (!strcmp(argv[c], "-lossy")) {
|
||||
if (!anim_config.allow_mixed) config.lossless = 0;
|
||||
} else if (!strcmp(argv[c], "-lossless")) {
|
||||
if (!anim_config.allow_mixed) config.lossless = 1;
|
||||
} else if (!strcmp(argv[c], "-q") && c + 1 < argc) {
|
||||
config.quality = ExUtilGetFloat(argv[++c], &parse_error);
|
||||
} else if (!strcmp(argv[c], "-m") && c + 1 < argc) {
|
||||
config.method = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
} else if (!strcmp(argv[c], "-d") && c + 1 < argc) {
|
||||
duration = ExUtilGetInt(argv[++c], 0, &parse_error);
|
||||
if (duration <= 0) {
|
||||
fprintf(stderr, "Invalid negative duration (%d)\n", duration);
|
||||
parse_error = 1;
|
||||
}
|
||||
} else {
|
||||
parse_error = 1; // shouldn't be here.
|
||||
fprintf(stderr, "Unknown option [%s]\n", argv[c]);
|
||||
}
|
||||
ok = !parse_error;
|
||||
if (!ok) goto End;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = WebPValidateConfig(&config);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Invalid configuration.\n");
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
|
||||
// read next input image
|
||||
pic.use_argb = 1;
|
||||
ok = ReadImage(argv[c], &pic);
|
||||
if (!ok) goto End;
|
||||
|
||||
if (enc == NULL) {
|
||||
width = pic.width;
|
||||
height = pic.height;
|
||||
enc = WebPAnimEncoderNew(width, height, &anim_config);
|
||||
ok = (enc != NULL);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Could not create WebPAnimEncoder object.\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = (width == pic.width && height == pic.height);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Frame #%d dimension mismatched! "
|
||||
"Got %d x %d. Was expecting %d x %d.\n",
|
||||
pic_num, pic.width, pic.height, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
ok = WebPAnimEncoderAdd(enc, &pic, timestamp_ms, &config);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error while adding frame #%d\n", pic_num);
|
||||
}
|
||||
}
|
||||
WebPPictureFree(&pic);
|
||||
if (!ok) goto End;
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "Added frame #%3d at time %4d (file: %s)\n",
|
||||
pic_num, timestamp_ms, argv[c]);
|
||||
}
|
||||
timestamp_ms += duration;
|
||||
++pic_num;
|
||||
}
|
||||
|
||||
// add a last fake frame to signal the last duration
|
||||
ok = ok && WebPAnimEncoderAdd(enc, NULL, timestamp_ms, NULL);
|
||||
ok = ok && WebPAnimEncoderAssemble(enc, &webp_data);
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error during final animation assembly.\n");
|
||||
}
|
||||
|
||||
End:
|
||||
// free resources
|
||||
WebPAnimEncoderDelete(enc);
|
||||
|
||||
if (ok && loop_count > 0) { // Re-mux to add loop count.
|
||||
ok = SetLoopCount(loop_count, &webp_data);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
if (output != NULL) {
|
||||
ok = ImgIoUtilWriteFile(output, webp_data.bytes, webp_data.size);
|
||||
if (ok) fprintf(stderr, "output file: %s ", output);
|
||||
} else {
|
||||
fprintf(stderr, "[no output file specified] ");
|
||||
}
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
fprintf(stderr, "[%d frames, %u bytes].\n",
|
||||
pic_num, (unsigned int)webp_data.size);
|
||||
}
|
||||
|
||||
WebPDataClear(&webp_data);
|
||||
return ok ? 0 : 1;
|
||||
}
|
@ -40,7 +40,8 @@
|
||||
#include "webp/decode.h"
|
||||
#include "webp/demux.h"
|
||||
|
||||
#include "./example_util.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#define snprintf _snprintf
|
||||
@ -53,6 +54,7 @@ static struct {
|
||||
int done;
|
||||
int decoding_error;
|
||||
int print_info;
|
||||
int only_deltas;
|
||||
int use_color_profile;
|
||||
|
||||
int canvas_width, canvas_height;
|
||||
@ -251,6 +253,9 @@ static void HandleKey(unsigned char key, int pos_x, int pos_y) {
|
||||
// more involved though (need to save the previous frame).
|
||||
if (!kParams.has_animation) ClearPreviousFrame();
|
||||
glutPostRedisplay();
|
||||
} else if (key == 'd') {
|
||||
kParams.only_deltas = 1 - kParams.only_deltas;
|
||||
glutPostRedisplay();
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,7 +319,9 @@ static void HandleDisplay(void) {
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, pic->u.RGBA.stride / 4);
|
||||
|
||||
if (prev->dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ||
|
||||
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;
|
||||
@ -371,13 +378,13 @@ static void HandleDisplay(void) {
|
||||
}
|
||||
}
|
||||
glPopMatrix();
|
||||
glFlush();
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
static void StartDisplay(void) {
|
||||
const int width = kParams.canvas_width;
|
||||
const int height = kParams.canvas_height;
|
||||
glutInitDisplayMode(GLUT_RGBA);
|
||||
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
|
||||
glutInitWindowSize(width, height);
|
||||
glutCreateWindow("WebP viewer");
|
||||
glutDisplayFunc(HandleDisplay);
|
||||
@ -414,6 +421,7 @@ static void Help(void) {
|
||||
"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"
|
||||
);
|
||||
}
|
||||
@ -482,8 +490,8 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ExUtilReadFile(kParams.file_name,
|
||||
&kParams.data.bytes, &kParams.data.size)) {
|
||||
if (!ImgIoUtilReadFile(kParams.file_name,
|
||||
&kParams.data.bytes, &kParams.data.size)) {
|
||||
goto Error;
|
||||
}
|
||||
|
||||
@ -498,10 +506,6 @@ int main(int argc, char *argv[]) {
|
||||
goto Error;
|
||||
}
|
||||
|
||||
if (WebPDemuxGetI(kParams.dmux, WEBP_FF_FORMAT_FLAGS) & FRAGMENTS_FLAG) {
|
||||
fprintf(stderr, "Image fragments are not supported for now!\n");
|
||||
goto Error;
|
||||
}
|
||||
kParams.canvas_width = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_WIDTH);
|
||||
kParams.canvas_height = WebPDemuxGetI(kParams.dmux, WEBP_FF_CANVAS_HEIGHT);
|
||||
if (kParams.print_info) {
|
||||
|
@ -1,95 +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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// WebP decode.
|
||||
|
||||
#include "./webpdec.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webp/decode.h"
|
||||
#include "webp/encode.h"
|
||||
#include "./example_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
int ReadWebP(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic,
|
||||
int keep_alpha, Metadata* const metadata) {
|
||||
int ok = 0;
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
WebPDecoderConfig config;
|
||||
WebPDecBuffer* const output_buffer = &config.output;
|
||||
WebPBitstreamFeatures* const bitstream = &config.input;
|
||||
|
||||
// TODO(jzern): add Exif/XMP/ICC extraction.
|
||||
if (metadata != NULL) {
|
||||
fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n");
|
||||
}
|
||||
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = WebPGetFeatures(data, data_size, bitstream);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
ExUtilPrintWebPError("input data", status);
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
const int has_alpha = keep_alpha && bitstream->has_alpha;
|
||||
if (pic->use_argb) {
|
||||
output_buffer->colorspace = has_alpha ? MODE_RGBA : MODE_RGB;
|
||||
} else {
|
||||
output_buffer->colorspace = has_alpha ? MODE_YUVA : MODE_YUV;
|
||||
}
|
||||
|
||||
status = ExUtilDecodeWebP(data, data_size, 0, &config);
|
||||
if (status == VP8_STATUS_OK) {
|
||||
pic->width = output_buffer->width;
|
||||
pic->height = output_buffer->height;
|
||||
if (pic->use_argb) {
|
||||
const uint8_t* const rgba = output_buffer->u.RGBA.rgba;
|
||||
const int stride = output_buffer->u.RGBA.stride;
|
||||
ok = has_alpha ? WebPPictureImportRGBA(pic, rgba, stride)
|
||||
: WebPPictureImportRGB(pic, rgba, stride);
|
||||
} else {
|
||||
pic->colorspace = has_alpha ? WEBP_YUV420A : WEBP_YUV420;
|
||||
ok = WebPPictureAlloc(pic);
|
||||
if (!ok) {
|
||||
status = VP8_STATUS_OUT_OF_MEMORY;
|
||||
} else {
|
||||
const WebPYUVABuffer* const yuva = &output_buffer->u.YUVA;
|
||||
const int uv_width = (pic->width + 1) >> 1;
|
||||
const int uv_height = (pic->height + 1) >> 1;
|
||||
ExUtilCopyPlane(yuva->y, yuva->y_stride,
|
||||
pic->y, pic->y_stride, pic->width, pic->height);
|
||||
ExUtilCopyPlane(yuva->u, yuva->u_stride,
|
||||
pic->u, pic->uv_stride, uv_width, uv_height);
|
||||
ExUtilCopyPlane(yuva->v, yuva->v_stride,
|
||||
pic->v, pic->uv_stride, uv_width, uv_height);
|
||||
if (has_alpha) {
|
||||
ExUtilCopyPlane(yuva->a, yuva->a_stride,
|
||||
pic->a, pic->a_stride, pic->width, pic->height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status != VP8_STATUS_OK) {
|
||||
ExUtilPrintWebPError("input data", status);
|
||||
}
|
||||
|
||||
WebPFreeDecBuffer(output_buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
@ -1,37 +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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// WebP decode.
|
||||
|
||||
#ifndef WEBP_EXAMPLES_WEBPDEC_H_
|
||||
#define WEBP_EXAMPLES_WEBPDEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Metadata;
|
||||
struct WebPPicture;
|
||||
|
||||
// Reads a WebP from 'in_file', returning the decoded output in 'pic'.
|
||||
// Output is RGBA or YUVA, depending on pic->use_argb value.
|
||||
// If 'keep_alpha' is true and the WebP has an alpha channel, the output is RGBA
|
||||
// or YUVA. Otherwise, alpha channel is dropped and output is RGB or YUV.
|
||||
// Returns true on success.
|
||||
int ReadWebP(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
int keep_alpha, struct Metadata* const metadata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_WEBPDEC_H_
|
1173
examples/webpinfo.c
Normal file
1173
examples/webpinfo.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -28,7 +28,6 @@
|
||||
webpmux -set xmp image_metadata.xmp in.webp -o out_xmp_container.webp
|
||||
|
||||
Extract relevant data from WebP container file:
|
||||
webpmux -get frgm n in.webp -o out_fragment.webp
|
||||
webpmux -get frame n in.webp -o out_frame.webp
|
||||
webpmux -get icc in.webp -o image_profile.icc
|
||||
webpmux -get exif in.webp -o image_metadata.exif
|
||||
@ -39,6 +38,11 @@
|
||||
webpmux -strip exif in.webp -o out.webp
|
||||
webpmux -strip xmp in.webp -o out.webp
|
||||
|
||||
Change duration of frame intervals:
|
||||
webpmux -duration 150 in.webp -o out.webp
|
||||
webpmux -duration 33,2 in.webp -o out.webp
|
||||
webpmux -duration 200,10,0 -duration 150,6,50 in.webp -o out.webp
|
||||
|
||||
Misc:
|
||||
webpmux -info in.webp
|
||||
webpmux [ -h | -help ]
|
||||
@ -55,7 +59,8 @@
|
||||
#include <string.h>
|
||||
#include "webp/decode.h"
|
||||
#include "webp/mux.h"
|
||||
#include "./example_util.h"
|
||||
#include "../examples/example_util.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Config object to parse command-line arguments.
|
||||
@ -66,7 +71,8 @@ typedef enum {
|
||||
ACTION_SET,
|
||||
ACTION_STRIP,
|
||||
ACTION_INFO,
|
||||
ACTION_HELP
|
||||
ACTION_HELP,
|
||||
ACTION_DURATION
|
||||
} ActionType;
|
||||
|
||||
typedef enum {
|
||||
@ -88,17 +94,17 @@ typedef enum {
|
||||
FEATURE_XMP,
|
||||
FEATURE_ICCP,
|
||||
FEATURE_ANMF,
|
||||
FEATURE_FRGM,
|
||||
FEATURE_DURATION,
|
||||
LAST_FEATURE
|
||||
} FeatureType;
|
||||
|
||||
static const char* const kFourccList[LAST_FEATURE] = {
|
||||
NULL, "EXIF", "XMP ", "ICCP", "ANMF", "FRGM"
|
||||
NULL, "EXIF", "XMP ", "ICCP", "ANMF"
|
||||
};
|
||||
|
||||
static const char* const kDescriptions[LAST_FEATURE] = {
|
||||
NULL, "EXIF metadata", "XMP metadata", "ICC profile",
|
||||
"Animation frame", "Image fragment"
|
||||
"Animation frame"
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -182,7 +188,6 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
printf("Canvas size: %d x %d\n", width, height);
|
||||
|
||||
err = WebPMuxGetFeatures(mux, &flag);
|
||||
if (flag & FRAGMENTS_FLAG) err = WEBP_MUX_INVALID_ARGUMENT;
|
||||
RETURN_IF_ERROR("Failed to retrieve features\n");
|
||||
|
||||
if (flag == 0) {
|
||||
@ -193,26 +198,22 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
// Print the features present.
|
||||
printf("Features present:");
|
||||
if (flag & ANIMATION_FLAG) printf(" animation");
|
||||
if (flag & FRAGMENTS_FLAG) printf(" image fragments");
|
||||
if (flag & ICCP_FLAG) printf(" ICC profile");
|
||||
if (flag & EXIF_FLAG) printf(" EXIF metadata");
|
||||
if (flag & XMP_FLAG) printf(" XMP metadata");
|
||||
if (flag & ALPHA_FLAG) printf(" transparency");
|
||||
printf("\n");
|
||||
|
||||
if ((flag & ANIMATION_FLAG) || (flag & FRAGMENTS_FLAG)) {
|
||||
const int is_anim = !!(flag & ANIMATION_FLAG);
|
||||
const WebPChunkId id = is_anim ? WEBP_CHUNK_ANMF : WEBP_CHUNK_FRGM;
|
||||
const char* const type_str = is_anim ? "frame" : "fragment";
|
||||
if (flag & ANIMATION_FLAG) {
|
||||
const WebPChunkId id = WEBP_CHUNK_ANMF;
|
||||
const char* const type_str = "frame";
|
||||
int nFrames;
|
||||
|
||||
if (is_anim) {
|
||||
WebPMuxAnimParams params;
|
||||
err = WebPMuxGetAnimationParams(mux, ¶ms);
|
||||
assert(err == WEBP_MUX_OK);
|
||||
printf("Background color : 0x%.8X Loop Count : %d\n",
|
||||
params.bgcolor, params.loop_count);
|
||||
}
|
||||
WebPMuxAnimParams params;
|
||||
err = WebPMuxGetAnimationParams(mux, ¶ms);
|
||||
assert(err == WEBP_MUX_OK);
|
||||
printf("Background color : 0x%.8X Loop Count : %d\n",
|
||||
params.bgcolor, params.loop_count);
|
||||
|
||||
err = WebPMuxNumChunks(mux, id, &nFrames);
|
||||
assert(err == WEBP_MUX_OK);
|
||||
@ -221,8 +222,8 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
if (nFrames > 0) {
|
||||
int i;
|
||||
printf("No.: width height alpha x_offset y_offset ");
|
||||
if (is_anim) printf("duration dispose blend ");
|
||||
printf("image_size\n");
|
||||
printf("duration dispose blend ");
|
||||
printf("image_size compression\n");
|
||||
for (i = 1; i <= nFrames; i++) {
|
||||
WebPMuxFrameInfo frame;
|
||||
err = WebPMuxGetFrame(mux, i, &frame);
|
||||
@ -235,7 +236,7 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
printf("%3d: %5d %5d %5s %8d %8d ", i, features.width,
|
||||
features.height, features.has_alpha ? "yes" : "no",
|
||||
frame.x_offset, frame.y_offset);
|
||||
if (is_anim) {
|
||||
{
|
||||
const char* const dispose =
|
||||
(frame.dispose_method == WEBP_MUX_DISPOSE_NONE) ? "none"
|
||||
: "background";
|
||||
@ -243,7 +244,10 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
(frame.blend_method == WEBP_MUX_BLEND) ? "yes" : "no";
|
||||
printf("%8d %10s %5s ", frame.duration, dispose, blend);
|
||||
}
|
||||
printf("%10d\n", (int)frame.bitstream.size);
|
||||
printf("%10d %11s\n", (int)frame.bitstream.size,
|
||||
(features.format == 1) ? "lossy" :
|
||||
(features.format == 2) ? "lossless" :
|
||||
"undefined");
|
||||
}
|
||||
WebPDataClear(&frame.bitstream);
|
||||
RETURN_IF_ERROR3("Failed to retrieve %s#%d\n", type_str, i);
|
||||
@ -272,7 +276,7 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
printf("Size of the XMP metadata: %d\n", (int)xmp.size);
|
||||
}
|
||||
|
||||
if ((flag & ALPHA_FLAG) && !(flag & (ANIMATION_FLAG | FRAGMENTS_FLAG))) {
|
||||
if ((flag & ALPHA_FLAG) && !(flag & ANIMATION_FLAG)) {
|
||||
WebPMuxFrameInfo image;
|
||||
err = WebPMuxGetFrame(mux, 1, &image);
|
||||
if (err == WEBP_MUX_OK) {
|
||||
@ -288,6 +292,8 @@ static WebPMuxError DisplayInfo(const WebPMux* mux) {
|
||||
static void PrintHelp(void) {
|
||||
printf("Usage: webpmux -get GET_OPTIONS INPUT -o OUTPUT\n");
|
||||
printf(" webpmux -set SET_OPTIONS INPUT -o OUTPUT\n");
|
||||
printf(" webpmux -duration DURATION_OPTIONS [-duration ...]\n");
|
||||
printf(" INPUT -o OUTPUT\n");
|
||||
printf(" webpmux -strip STRIP_OPTIONS INPUT -o OUTPUT\n");
|
||||
printf(" webpmux -frame FRAME_OPTIONS [-frame...] [-loop LOOP_COUNT]"
|
||||
"\n");
|
||||
@ -314,6 +320,18 @@ static void PrintHelp(void) {
|
||||
printf(" 'file.exif' contains the EXIF metadata to be set\n");
|
||||
printf(" 'file.xmp' contains the XMP metadata to be set\n");
|
||||
|
||||
printf("\n");
|
||||
printf("DURATION_OPTIONS:\n");
|
||||
printf(" Set duration of selected frames:\n");
|
||||
printf(" duration set duration for each frames\n");
|
||||
printf(" duration,frame set duration of a particular frame\n");
|
||||
printf(" duration,start,end set duration of frames in the\n");
|
||||
printf(" interval [start,end])\n");
|
||||
printf(" where: 'duration' is the duration in milliseconds\n");
|
||||
printf(" 'start' is the start frame index\n");
|
||||
printf(" 'end' is the inclusive end frame index\n");
|
||||
printf(" The special 'end' value '0' means: last frame.\n");
|
||||
|
||||
printf("\n");
|
||||
printf("STRIP_OPTIONS:\n");
|
||||
printf(" Strip color profile/metadata:\n");
|
||||
@ -365,7 +383,7 @@ static int ReadFileToWebPData(const char* const filename,
|
||||
WebPData* const webp_data) {
|
||||
const uint8_t* data;
|
||||
size_t size;
|
||||
if (!ExUtilReadFile(filename, &data, &size)) return 0;
|
||||
if (!ImgIoUtilReadFile(filename, &data, &size)) return 0;
|
||||
webp_data->bytes = data;
|
||||
webp_data->size = size;
|
||||
return 1;
|
||||
@ -385,7 +403,7 @@ static int CreateMux(const char* const filename, WebPMux** mux) {
|
||||
static int WriteData(const char* filename, const WebPData* const webpdata) {
|
||||
int ok = 0;
|
||||
FILE* fout = strcmp(filename, "-") ? fopen(filename, "wb")
|
||||
: ExUtilSetBinaryMode(stdout);
|
||||
: ImgIoUtilSetBinaryMode(stdout);
|
||||
if (fout == NULL) {
|
||||
fprintf(stderr, "Error opening output WebP file %s!\n", filename);
|
||||
return 0;
|
||||
@ -414,6 +432,45 @@ static int WriteWebP(WebPMux* const mux, const char* filename) {
|
||||
return ok;
|
||||
}
|
||||
|
||||
static WebPMux* DuplicateMuxHeader(const WebPMux* const mux) {
|
||||
WebPMux* new_mux = WebPMuxNew();
|
||||
WebPMuxAnimParams p;
|
||||
WebPMuxError err;
|
||||
int i;
|
||||
int ok = 1;
|
||||
|
||||
if (new_mux == NULL) return NULL;
|
||||
|
||||
err = WebPMuxGetAnimationParams(mux, &p);
|
||||
if (err == WEBP_MUX_OK) {
|
||||
err = WebPMuxSetAnimationParams(new_mux, &p);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
ERROR_GOTO2("Error (%s) handling animation params.\n",
|
||||
ErrorString(err), End);
|
||||
}
|
||||
} else {
|
||||
/* it might not be an animation. Just keep moving. */
|
||||
}
|
||||
|
||||
for (i = 1; i <= 3; ++i) {
|
||||
WebPData metadata;
|
||||
err = WebPMuxGetChunk(mux, kFourccList[i], &metadata);
|
||||
if (err == WEBP_MUX_OK && metadata.size > 0) {
|
||||
err = WebPMuxSetChunk(new_mux, kFourccList[i], &metadata, 1);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
ERROR_GOTO1("Error transferring metadata in DuplicateMux().", End);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
End:
|
||||
if (!ok) {
|
||||
WebPMuxDelete(new_mux);
|
||||
new_mux = NULL;
|
||||
}
|
||||
return new_mux;
|
||||
}
|
||||
|
||||
static int ParseFrameArgs(const char* args, WebPMuxFrameInfo* const info) {
|
||||
int dispose_method, dummy;
|
||||
char plus_minus, blend_method;
|
||||
@ -449,13 +506,6 @@ static int ParseFrameArgs(const char* args, WebPMuxFrameInfo* const info) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ParseFragmentArgs(const char* args, WebPMuxFrameInfo* const info) {
|
||||
const int ok =
|
||||
(sscanf(args, "+%d+%d", &info->x_offset, &info->y_offset) == 2);
|
||||
if (ok) WarnAboutOddOffset(info);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int ParseBgcolorArgs(const char* args, uint32_t* const bgcolor) {
|
||||
uint32_t a, r, g, b;
|
||||
if (sscanf(args, "%u,%u,%u,%u", &a, &r, &g, &b) != 4) return 0;
|
||||
@ -484,9 +534,9 @@ static void DeleteConfig(WebPMuxConfig* config) {
|
||||
static int ValidateCommandLine(int argc, const char* argv[],
|
||||
int* num_feature_args) {
|
||||
int num_frame_args;
|
||||
int num_frgm_args;
|
||||
int num_loop_args;
|
||||
int num_bgcolor_args;
|
||||
int num_durations_args;
|
||||
int ok = 1;
|
||||
|
||||
assert(num_feature_args != NULL);
|
||||
@ -511,9 +561,9 @@ static int ValidateCommandLine(int argc, const char* argv[],
|
||||
|
||||
// Compound checks.
|
||||
num_frame_args = CountOccurrences(argv, argc, "-frame");
|
||||
num_frgm_args = CountOccurrences(argv, argc, "-frgm");
|
||||
num_loop_args = CountOccurrences(argv, argc, "-loop");
|
||||
num_bgcolor_args = CountOccurrences(argv, argc, "-bgcolor");
|
||||
num_durations_args = CountOccurrences(argv, argc, "-duration");
|
||||
|
||||
if (num_loop_args > 1) {
|
||||
ERROR_GOTO1("ERROR: Multiple loop counts specified.\n", ErrValidate);
|
||||
@ -526,22 +576,20 @@ static int ValidateCommandLine(int argc, const char* argv[],
|
||||
ERROR_GOTO1("ERROR: Loop count and background color are relevant only in "
|
||||
"case of animation.\n", ErrValidate);
|
||||
}
|
||||
if (num_frame_args > 0 && num_frgm_args > 0) {
|
||||
ERROR_GOTO1("ERROR: Only one of frames & fragments can be specified at a "
|
||||
"time.\n", ErrValidate);
|
||||
if (num_durations_args > 0 && num_frame_args != 0) {
|
||||
ERROR_GOTO1("ERROR: Can not combine -duration and -frame commands.\n",
|
||||
ErrValidate);
|
||||
}
|
||||
|
||||
assert(ok == 1);
|
||||
if (num_frame_args == 0 && num_frgm_args == 0) {
|
||||
if (num_durations_args > 0) {
|
||||
*num_feature_args = num_durations_args;
|
||||
} else if (num_frame_args == 0) {
|
||||
// Single argument ('set' action for ICCP/EXIF/XMP, OR a 'get' action).
|
||||
*num_feature_args = 1;
|
||||
} else {
|
||||
// Multiple arguments ('set' action for animation or fragmented image).
|
||||
if (num_frame_args > 0) {
|
||||
*num_feature_args = num_frame_args + num_loop_args + num_bgcolor_args;
|
||||
} else {
|
||||
*num_feature_args = num_frgm_args;
|
||||
}
|
||||
// Multiple arguments ('set' action for animation)
|
||||
*num_feature_args = num_frame_args + num_loop_args + num_bgcolor_args;
|
||||
}
|
||||
|
||||
ErrValidate:
|
||||
@ -583,6 +631,21 @@ static int ParseCommandLine(int argc, const char* argv[],
|
||||
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
|
||||
}
|
||||
++i;
|
||||
} else if (!strcmp(argv[i], "-duration")) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
if (ACTION_IS_NIL || config->action_type_ == ACTION_DURATION) {
|
||||
config->action_type_ = ACTION_DURATION;
|
||||
} else {
|
||||
ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse);
|
||||
}
|
||||
if (FEATURETYPE_IS_NIL || feature->type_ == FEATURE_DURATION) {
|
||||
feature->type_ = FEATURE_DURATION;
|
||||
} else {
|
||||
ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse);
|
||||
}
|
||||
arg->params_ = argv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
} else if (!strcmp(argv[i], "-get")) {
|
||||
if (ACTION_IS_NIL) {
|
||||
config->action_type_ = ACTION_GET;
|
||||
@ -694,8 +757,7 @@ static int ParseCommandLine(int argc, const char* argv[],
|
||||
} else if (!strcmp(argv[i], "frame") &&
|
||||
(config->action_type_ == ACTION_GET)) {
|
||||
CHECK_NUM_ARGS_LESS(2, ErrParse);
|
||||
feature->type_ = (!strcmp(argv[i], "frame")) ? FEATURE_ANMF :
|
||||
FEATURE_FRGM;
|
||||
feature->type_ = FEATURE_ANMF;
|
||||
arg->params_ = argv[i + 1];
|
||||
++feature_arg_index;
|
||||
i += 2;
|
||||
@ -733,8 +795,7 @@ static int ValidateConfig(WebPMuxConfig* config) {
|
||||
if (config->input_ == NULL) {
|
||||
if (config->action_type_ != ACTION_SET) {
|
||||
ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2);
|
||||
} else if (feature->type_ != FEATURE_ANMF &&
|
||||
feature->type_ != FEATURE_FRGM) {
|
||||
} else if (feature->type_ != FEATURE_ANMF) {
|
||||
ERROR_GOTO1("ERROR: No input file specified.\n", ErrValidate2);
|
||||
}
|
||||
}
|
||||
@ -786,14 +847,13 @@ static int InitializeConfig(int argc, const char* argv[],
|
||||
//------------------------------------------------------------------------------
|
||||
// Processing.
|
||||
|
||||
static int GetFrameFragment(const WebPMux* mux,
|
||||
const WebPMuxConfig* config, int is_frame) {
|
||||
static int GetFrame(const WebPMux* mux, const WebPMuxConfig* config) {
|
||||
WebPMuxError err = WEBP_MUX_OK;
|
||||
WebPMux* mux_single = NULL;
|
||||
int num = 0;
|
||||
int ok = 1;
|
||||
int parse_error = 0;
|
||||
const WebPChunkId id = is_frame ? WEBP_CHUNK_ANMF : WEBP_CHUNK_FRGM;
|
||||
const WebPChunkId id = WEBP_CHUNK_ANMF;
|
||||
WebPMuxFrameInfo info;
|
||||
WebPDataInit(&info.bitstream);
|
||||
|
||||
@ -844,9 +904,7 @@ static int Process(const WebPMuxConfig* config) {
|
||||
if (!ok) goto Err2;
|
||||
switch (feature->type_) {
|
||||
case FEATURE_ANMF:
|
||||
case FEATURE_FRGM:
|
||||
ok = GetFrameFragment(mux, config,
|
||||
(feature->type_ == FEATURE_ANMF) ? 1 : 0);
|
||||
ok = GetFrame(mux, config);
|
||||
break;
|
||||
|
||||
case FEATURE_ICCP:
|
||||
@ -938,35 +996,6 @@ static int Process(const WebPMuxConfig* config) {
|
||||
break;
|
||||
}
|
||||
|
||||
case FEATURE_FRGM: {
|
||||
int i;
|
||||
mux = WebPMuxNew();
|
||||
if (mux == NULL) {
|
||||
ERROR_GOTO2("ERROR (%s): Could not allocate a mux object.\n",
|
||||
ErrorString(WEBP_MUX_MEMORY_ERROR), Err2);
|
||||
}
|
||||
for (i = 0; i < feature->arg_count_; ++i) {
|
||||
WebPMuxFrameInfo frgm;
|
||||
frgm.id = WEBP_CHUNK_FRGM;
|
||||
ok = ReadFileToWebPData(feature->args_[i].filename_,
|
||||
&frgm.bitstream);
|
||||
if (!ok) goto Err2;
|
||||
ok = ParseFragmentArgs(feature->args_[i].params_, &frgm);
|
||||
if (!ok) {
|
||||
WebPDataClear(&frgm.bitstream);
|
||||
ERROR_GOTO1("ERROR: Could not parse fragment properties.\n",
|
||||
Err2);
|
||||
}
|
||||
err = WebPMuxPushFrame(mux, &frgm, 1);
|
||||
WebPDataClear(&frgm.bitstream);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
ERROR_GOTO3("ERROR (%s): Could not add a fragment at index %d.\n",
|
||||
ErrorString(err), i, Err2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FEATURE_ICCP:
|
||||
case FEATURE_EXIF:
|
||||
case FEATURE_XMP: {
|
||||
@ -990,6 +1019,89 @@ static int Process(const WebPMuxConfig* config) {
|
||||
ok = WriteWebP(mux, config->output_);
|
||||
break;
|
||||
}
|
||||
case ACTION_DURATION: {
|
||||
int num_frames;
|
||||
ok = CreateMux(config->input_, &mux);
|
||||
if (!ok) goto Err2;
|
||||
err = WebPMuxNumChunks(mux, WEBP_CHUNK_ANMF, &num_frames);
|
||||
ok = (err == WEBP_MUX_OK);
|
||||
if (!ok) {
|
||||
ERROR_GOTO1("ERROR: can not parse the number of frames.\n", Err2);
|
||||
}
|
||||
if (num_frames == 0) {
|
||||
fprintf(stderr, "Doesn't look like the source is animated. "
|
||||
"Skipping duration setting.\n");
|
||||
ok = WriteWebP(mux, config->output_);
|
||||
if (!ok) goto Err2;
|
||||
} else {
|
||||
int i;
|
||||
int* durations = NULL;
|
||||
WebPMux* new_mux = DuplicateMuxHeader(mux);
|
||||
if (new_mux == NULL) goto Err2;
|
||||
durations = (int*)malloc((size_t)num_frames * sizeof(*durations));
|
||||
if (durations == NULL) goto Err2;
|
||||
for (i = 0; i < num_frames; ++i) durations[i] = -1;
|
||||
|
||||
// Parse intervals to process.
|
||||
for (i = 0; i < feature->arg_count_; ++i) {
|
||||
int k;
|
||||
int args[3];
|
||||
int duration, start, end;
|
||||
const int nb_args = ExUtilGetInts(feature->args_[i].params_,
|
||||
10, 3, args);
|
||||
ok = (nb_args >= 1);
|
||||
if (!ok) goto Err3;
|
||||
duration = args[0];
|
||||
if (duration < 0) {
|
||||
ERROR_GOTO1("ERROR: duration must be strictly positive.\n", Err3);
|
||||
}
|
||||
|
||||
if (nb_args == 1) { // only duration is present -> use full interval
|
||||
start = 1;
|
||||
end = num_frames;
|
||||
} else {
|
||||
start = args[1];
|
||||
if (start <= 0) {
|
||||
start = 1;
|
||||
} else if (start > num_frames) {
|
||||
start = num_frames;
|
||||
}
|
||||
end = (nb_args >= 3) ? args[2] : start;
|
||||
if (end == 0 || end > num_frames) end = num_frames;
|
||||
}
|
||||
|
||||
for (k = start; k <= end; ++k) {
|
||||
assert(k >= 1 && k <= num_frames);
|
||||
durations[k - 1] = duration;
|
||||
}
|
||||
}
|
||||
|
||||
// Apply non-negative durations to their destination frames.
|
||||
for (i = 1; i <= num_frames; ++i) {
|
||||
WebPMuxFrameInfo frame;
|
||||
err = WebPMuxGetFrame(mux, i, &frame);
|
||||
if (err != WEBP_MUX_OK || frame.id != WEBP_CHUNK_ANMF) {
|
||||
ERROR_GOTO2("ERROR: can not retrieve frame #%d.\n", i, Err3);
|
||||
}
|
||||
if (durations[i - 1] >= 0) frame.duration = durations[i - 1];
|
||||
err = WebPMuxPushFrame(new_mux, &frame, 1);
|
||||
if (err != WEBP_MUX_OK) {
|
||||
ERROR_GOTO2("ERROR: error push frame data #%d\n", i, Err3);
|
||||
}
|
||||
WebPDataClear(&frame.bitstream);
|
||||
}
|
||||
WebPMuxDelete(mux);
|
||||
ok = WriteWebP(new_mux, config->output_);
|
||||
mux = new_mux; // transfer for the WebPMuxDelete() call
|
||||
new_mux = NULL;
|
||||
|
||||
Err3:
|
||||
free(durations);
|
||||
WebPMuxDelete(new_mux);
|
||||
if (!ok) goto Err2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ACTION_STRIP: {
|
||||
ok = CreateMux(config->input_, &mux);
|
||||
if (!ok) goto Err2;
|
||||
|
36
extras/Makefile.am
Normal file
36
extras/Makefile.am
Normal file
@ -0,0 +1,36 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
noinst_LTLIBRARIES = libwebpextras.la
|
||||
|
||||
noinst_HEADERS =
|
||||
noinst_HEADERS += ../src/webp/types.h
|
||||
|
||||
libwebpextras_la_SOURCES =
|
||||
libwebpextras_la_SOURCES += extras.c extras.h quality_estimate.c
|
||||
|
||||
libwebpextras_la_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libwebpextras_la_LDFLAGS = -lm
|
||||
libwebpextras_la_LIBADD = ../src/libwebp.la
|
||||
|
||||
noinst_PROGRAMS =
|
||||
noinst_PROGRAMS += get_disto webp_quality
|
||||
if BUILD_VWEBP_SDL
|
||||
noinst_PROGRAMS += vwebp_sdl
|
||||
endif
|
||||
|
||||
get_disto_SOURCES = get_disto.c
|
||||
get_disto_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
get_disto_LDADD = ../imageio/libimageio_util.la ../imageio/libimagedec.la
|
||||
get_disto_LDADD += ../src/libwebp.la
|
||||
get_disto_LDADD += $(PNG_LIBS) $(JPEG_LIBS) $(TIFF_LIBS)
|
||||
|
||||
webp_quality_SOURCES = webp_quality.c
|
||||
webp_quality_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
webp_quality_LDADD = ../imageio/libimageio_util.la
|
||||
webp_quality_LDADD += libwebpextras.la
|
||||
webp_quality_LDADD += ../src/libwebp.la
|
||||
|
||||
vwebp_sdl_SOURCES = vwebp_sdl.c webp_to_sdl.c webp_to_sdl.h
|
||||
vwebp_sdl_CPPFLAGS = $(AM_CPPFLAGS) $(SDL_INCLUDES)
|
||||
vwebp_sdl_LDADD = ../imageio/libimageio_util.la
|
||||
vwebp_sdl_LDADD += ../src/libwebp.la
|
||||
vwebp_sdl_LDADD += $(SDL_LIBS)
|
@ -10,12 +10,14 @@
|
||||
// Additional WebP utilities.
|
||||
//
|
||||
|
||||
#include "../webp/extras.h"
|
||||
#include "./extras.h"
|
||||
#include "webp/format_constants.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#define XTRA_MAJ_VERSION 0
|
||||
#define XTRA_MIN_VERSION 0
|
||||
#define XTRA_MIN_VERSION 1
|
||||
#define XTRA_REV_VERSION 0
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -108,4 +110,33 @@ int WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride,
|
||||
const uint32_t palette[], int palette_size,
|
||||
WebPPicture* pic) {
|
||||
int x, y;
|
||||
uint32_t* dst;
|
||||
// 256 as the input buffer is uint8_t.
|
||||
assert(MAX_PALETTE_SIZE <= 256);
|
||||
if (pic == NULL || indexed == NULL || indexed_stride < pic->width ||
|
||||
palette == NULL || palette_size > MAX_PALETTE_SIZE || palette_size <= 0) {
|
||||
return 0;
|
||||
}
|
||||
pic->use_argb = 1;
|
||||
if (!WebPPictureAlloc(pic)) return 0;
|
||||
dst = pic->argb;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
// Make sure we are within the palette.
|
||||
if (indexed[x] >= palette_size) {
|
||||
WebPPictureFree(pic);
|
||||
return 0;
|
||||
}
|
||||
dst[x] = palette[indexed[x]];
|
||||
}
|
||||
indexed += indexed_stride;
|
||||
dst += pic->argb_stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
@ -8,18 +8,18 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
|
||||
#ifndef WEBP_WEBP_EXTRAS_H_
|
||||
#define WEBP_WEBP_EXTRAS_H_
|
||||
#ifndef WEBP_EXTRAS_EXTRAS_H_
|
||||
#define WEBP_EXTRAS_EXTRAS_H_
|
||||
|
||||
#include "./types.h"
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "./encode.h"
|
||||
#include "webp/encode.h"
|
||||
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0000 // MAJOR(8b) + MINOR(8b)
|
||||
#define WEBP_EXTRAS_ABI_VERSION 0x0001 // MAJOR(8b) + MINOR(8b)
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@ -42,10 +42,29 @@ WEBP_EXTERN(int) WebPImportRGB565(const uint8_t* rgb565, WebPPicture* pic);
|
||||
// width and height must be set prior to calling this function.
|
||||
WEBP_EXTERN(int) WebPImportRGB4444(const uint8_t* rgb4444, WebPPicture* pic);
|
||||
|
||||
// Import a color mapped image. The number of colors is less or equal to
|
||||
// MAX_PALETTE_SIZE. 'pic' must have been initialized. Its content, if any,
|
||||
// will be discarded. Returns 'false' in case of error, or if indexed[] contains
|
||||
// invalid indices.
|
||||
WEBP_EXTERN(int)
|
||||
WebPImportColorMappedARGB(const uint8_t* indexed, int indexed_stride,
|
||||
const uint32_t palette[], int palette_size,
|
||||
WebPPicture* pic);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Parse a bitstream, search for VP8 (lossy) header and report a
|
||||
// rough estimation of the quality factor used for compressing the bitstream.
|
||||
// If the bitstream is in lossless format, the special value '101' is returned.
|
||||
// Otherwise (lossy bitstream), the returned value is in the range [0..100].
|
||||
// Any error (invalid bitstream, animated WebP, incomplete header, etc.)
|
||||
// will return a value of -1.
|
||||
WEBP_EXTERN(int) VP8EstimateQuality(const uint8_t* const data, size_t size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif /* WEBP_WEBP_EXTRAS_H_ */
|
||||
#endif /* WEBP_EXTRAS_EXTRAS_H_ */
|
343
extras/get_disto.c
Normal file
343
extras/get_disto.c
Normal file
@ -0,0 +1,343 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Simple tool to load two webp/png/jpg/tiff files and compute PSNR/SSIM.
|
||||
// This is mostly a wrapper around WebPPictureDistortion().
|
||||
//
|
||||
/*
|
||||
gcc -o get_disto get_disto.c -O3 -I../ -L../examples -L../imageio \
|
||||
-lexample_util -limageio_util -limagedec -lwebp -L/opt/local/lib \
|
||||
-lpng -lz -ljpeg -ltiff -lm -lpthread
|
||||
*/
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "../imageio/image_dec.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
static size_t ReadPicture(const char* const filename, WebPPicture* const pic,
|
||||
int keep_alpha) {
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
WebPImageReader reader = NULL;
|
||||
int ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
if (!ok) goto End;
|
||||
|
||||
pic->use_argb = 1; // force ARGB
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
// Try to decode the file using WIC falling back to the other readers for
|
||||
// e.g., WebP.
|
||||
ok = ReadPictureWithWIC(filename, pic, keep_alpha, NULL);
|
||||
if (ok) goto End;
|
||||
#endif
|
||||
reader = WebPGuessImageReader(data, data_size);
|
||||
ok = reader(data, data_size, pic, keep_alpha, NULL);
|
||||
|
||||
End:
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Error! Could not process file %s\n", filename);
|
||||
}
|
||||
free((void*)data);
|
||||
return ok ? data_size : 0;
|
||||
}
|
||||
|
||||
static void RescalePlane(uint8_t* plane, int width, int height,
|
||||
int x_stride, int y_stride, int max) {
|
||||
const uint32_t factor = (max > 0) ? (255u << 16) / max : 0;
|
||||
int x, y;
|
||||
for (y = 0; y < height; ++y) {
|
||||
uint8_t* const ptr = plane + y * y_stride;
|
||||
for (x = 0; x < width * x_stride; x += x_stride) {
|
||||
const uint32_t diff = (ptr[x] * factor + (1 << 15)) >> 16;
|
||||
ptr[x] = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the max absolute difference.
|
||||
static int DiffScaleChannel(uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int x_stride, int w, int h, int do_scaling) {
|
||||
int x, y;
|
||||
int max = 0;
|
||||
for (y = 0; y < h; ++y) {
|
||||
uint8_t* const ptr1 = src1 + y * stride1;
|
||||
const uint8_t* const ptr2 = src2 + y * stride2;
|
||||
for (x = 0; x < w * x_stride; x += x_stride) {
|
||||
const int diff = abs(ptr1[x] - ptr2[x]);
|
||||
if (diff > max) max = diff;
|
||||
ptr1[x] = diff;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_scaling) RescalePlane(src1, w, h, x_stride, stride1, max);
|
||||
return max;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// SSIM calculation. We re-implement these functions here, out of dsp/, to avoid
|
||||
// breaking the library's hidden visibility. This code duplication avoids the
|
||||
// bigger annoyance of having to open up internal details of libdsp...
|
||||
|
||||
#define SSIM_KERNEL 3 // total size of the kernel: 2 * SSIM_KERNEL + 1
|
||||
|
||||
// struct for accumulating statistical moments
|
||||
typedef struct {
|
||||
uint32_t w; // sum(w_i) : sum of weights
|
||||
uint32_t xm, ym; // sum(w_i * x_i), sum(w_i * y_i)
|
||||
uint32_t xxm, xym, yym; // sum(w_i * x_i * x_i), etc.
|
||||
} DistoStats;
|
||||
|
||||
// hat-shaped filter. Sum of coefficients is equal to 16.
|
||||
static const uint32_t kWeight[2 * SSIM_KERNEL + 1] = { 1, 2, 3, 4, 3, 2, 1 };
|
||||
|
||||
static WEBP_INLINE double SSIMCalculation(const DistoStats* const stats) {
|
||||
const uint32_t N = stats->w;
|
||||
const uint32_t w2 = N * N;
|
||||
const uint32_t C1 = 20 * w2;
|
||||
const uint32_t C2 = 60 * w2;
|
||||
const uint32_t C3 = 8 * 8 * w2; // 'dark' limit ~= 6
|
||||
const uint64_t xmxm = (uint64_t)stats->xm * stats->xm;
|
||||
const uint64_t ymym = (uint64_t)stats->ym * stats->ym;
|
||||
if (xmxm + ymym >= C3) {
|
||||
const int64_t xmym = (int64_t)stats->xm * stats->ym;
|
||||
const int64_t sxy = (int64_t)stats->xym * N - xmym; // can be negative
|
||||
const uint64_t sxx = (uint64_t)stats->xxm * N - xmxm;
|
||||
const uint64_t syy = (uint64_t)stats->yym * N - ymym;
|
||||
// we descale by 8 to prevent overflow during the fnum/fden multiply.
|
||||
const uint64_t num_S = (2 * (uint64_t)(sxy < 0 ? 0 : sxy) + C2) >> 8;
|
||||
const uint64_t den_S = (sxx + syy + C2) >> 8;
|
||||
const uint64_t fnum = (2 * xmym + C1) * num_S;
|
||||
const uint64_t fden = (xmxm + ymym + C1) * den_S;
|
||||
const double r = (double)fnum / fden;
|
||||
assert(r >= 0. && r <= 1.0);
|
||||
return r;
|
||||
}
|
||||
return 1.; // area is too dark to contribute meaningfully
|
||||
}
|
||||
|
||||
static double SSIMGetClipped(const uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int xo, int yo, int W, int H) {
|
||||
DistoStats stats = { 0, 0, 0, 0, 0, 0 };
|
||||
const int ymin = (yo - SSIM_KERNEL < 0) ? 0 : yo - SSIM_KERNEL;
|
||||
const int ymax = (yo + SSIM_KERNEL > H - 1) ? H - 1 : yo + SSIM_KERNEL;
|
||||
const int xmin = (xo - SSIM_KERNEL < 0) ? 0 : xo - SSIM_KERNEL;
|
||||
const int xmax = (xo + SSIM_KERNEL > W - 1) ? W - 1 : xo + SSIM_KERNEL;
|
||||
int x, y;
|
||||
src1 += ymin * stride1;
|
||||
src2 += ymin * stride2;
|
||||
for (y = ymin; y <= ymax; ++y, src1 += stride1, src2 += stride2) {
|
||||
for (x = xmin; x <= xmax; ++x) {
|
||||
const uint32_t w = kWeight[SSIM_KERNEL + x - xo]
|
||||
* kWeight[SSIM_KERNEL + y - yo];
|
||||
const uint32_t s1 = src1[x];
|
||||
const uint32_t s2 = src2[x];
|
||||
stats.w += w;
|
||||
stats.xm += w * s1;
|
||||
stats.ym += w * s2;
|
||||
stats.xxm += w * s1 * s1;
|
||||
stats.xym += w * s1 * s2;
|
||||
stats.yym += w * s2 * s2;
|
||||
}
|
||||
}
|
||||
return SSIMCalculation(&stats);
|
||||
}
|
||||
|
||||
// Compute SSIM-score map. Return -1 in case of error, max diff otherwise.
|
||||
static int SSIMScaleChannel(uint8_t* src1, int stride1,
|
||||
const uint8_t* src2, int stride2,
|
||||
int x_stride, int w, int h, int do_scaling) {
|
||||
int x, y;
|
||||
int max = 0;
|
||||
uint8_t* const plane1 = (uint8_t*)malloc(2 * w * h * sizeof(*plane1));
|
||||
uint8_t* const plane2 = plane1 + w * h;
|
||||
if (plane1 == NULL) return -1;
|
||||
|
||||
// extract plane
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < w; ++x) {
|
||||
plane1[x + y * w] = src1[x * x_stride + y * stride1];
|
||||
plane2[x + y * w] = src2[x * x_stride + y * stride2];
|
||||
}
|
||||
}
|
||||
for (y = 0; y < h; ++y) {
|
||||
for (x = 0; x < w; ++x) {
|
||||
const double ssim = SSIMGetClipped(plane1, w, plane2, w, x, y, w, h);
|
||||
int diff = (int)(255 * (1. - ssim));
|
||||
if (diff < 0) {
|
||||
diff = 0;
|
||||
} else if (diff > max) {
|
||||
max = diff;
|
||||
}
|
||||
src1[x * x_stride + y * stride1] = (diff > 255) ? 255u : (uint8_t)diff;
|
||||
}
|
||||
}
|
||||
free(plane1);
|
||||
|
||||
if (do_scaling) RescalePlane(src1, w, h, x_stride, stride1, max);
|
||||
return max;
|
||||
}
|
||||
|
||||
// Convert an argb picture to luminance.
|
||||
static void ConvertToGray(WebPPicture* const pic) {
|
||||
int x, y;
|
||||
assert(pic != NULL);
|
||||
assert(pic->use_argb);
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
uint32_t* const row = &pic->argb[y * pic->argb_stride];
|
||||
for (x = 0; x < pic->width; ++x) {
|
||||
const uint32_t argb = row[x];
|
||||
const uint32_t r = (argb >> 16) & 0xff;
|
||||
const uint32_t g = (argb >> 8) & 0xff;
|
||||
const uint32_t b = (argb >> 0) & 0xff;
|
||||
// We use BT.709 for converting to luminance.
|
||||
const uint32_t Y = (uint32_t)(0.2126 * r + 0.7152 * g + 0.0722 * b + .5);
|
||||
row[x] = (argb & 0xff000000u) | (Y * 0x010101u);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void Help(void) {
|
||||
fprintf(stderr,
|
||||
"Usage: get_disto [-ssim][-psnr][-alpha] compressed.webp orig.webp\n"
|
||||
" -ssim ..... print SSIM distortion\n"
|
||||
" -psnr ..... print PSNR distortion (default)\n"
|
||||
" -alpha .... preserve alpha plane\n"
|
||||
" -h ........ this message\n"
|
||||
" -o <file> . save the diff map as a WebP lossless file\n"
|
||||
" -scale .... scale the difference map to fit [0..255] range\n"
|
||||
" -gray ..... use grayscale for difference map (-scale)\n"
|
||||
" Also handles PNG, JPG and TIFF files, in addition to WebP.\n");
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
WebPPicture pic1, pic2;
|
||||
size_t size1 = 0, size2 = 0;
|
||||
int ret = 1;
|
||||
float disto[5];
|
||||
int type = 0;
|
||||
int c;
|
||||
int help = 0;
|
||||
int keep_alpha = 0;
|
||||
int scale = 0;
|
||||
int use_gray = 0;
|
||||
const char* name1 = NULL;
|
||||
const char* name2 = NULL;
|
||||
const char* output = NULL;
|
||||
|
||||
if (!WebPPictureInit(&pic1) || !WebPPictureInit(&pic2)) {
|
||||
fprintf(stderr, "Can't init pictures\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (c = 1; c < argc; ++c) {
|
||||
if (!strcmp(argv[c], "-ssim")) {
|
||||
type = 1;
|
||||
} else if (!strcmp(argv[c], "-psnr")) {
|
||||
type = 0;
|
||||
} else if (!strcmp(argv[c], "-alpha")) {
|
||||
keep_alpha = 1;
|
||||
} else if (!strcmp(argv[c], "-scale")) {
|
||||
scale = 1;
|
||||
} else if (!strcmp(argv[c], "-gray")) {
|
||||
use_gray = 1;
|
||||
} else if (!strcmp(argv[c], "-h")) {
|
||||
help = 1;
|
||||
ret = 0;
|
||||
} else if (!strcmp(argv[c], "-o")) {
|
||||
if (++c == argc) {
|
||||
fprintf(stderr, "missing file name after %s option.\n", argv[c - 1]);
|
||||
goto End;
|
||||
}
|
||||
output = argv[c];
|
||||
} else if (name1 == NULL) {
|
||||
name1 = argv[c];
|
||||
} else {
|
||||
name2 = argv[c];
|
||||
}
|
||||
}
|
||||
if (help || name1 == NULL || name2 == NULL) {
|
||||
if (!help) {
|
||||
fprintf(stderr, "Error: missing arguments.\n");
|
||||
}
|
||||
Help();
|
||||
goto End;
|
||||
}
|
||||
size1 = ReadPicture(name1, &pic1, 1);
|
||||
size2 = ReadPicture(name2, &pic2, 1);
|
||||
if (size1 == 0 || size2 == 0) goto End;
|
||||
|
||||
if (!keep_alpha) {
|
||||
WebPBlendAlpha(&pic1, 0x00000000);
|
||||
WebPBlendAlpha(&pic2, 0x00000000);
|
||||
}
|
||||
|
||||
if (!WebPPictureDistortion(&pic1, &pic2, type, disto)) {
|
||||
fprintf(stderr, "Error while computing the distortion.\n");
|
||||
goto End;
|
||||
}
|
||||
printf("%u %.2f %.2f %.2f %.2f %.2f\n",
|
||||
(unsigned int)size1,
|
||||
disto[4], disto[0], disto[1], disto[2], disto[3]);
|
||||
|
||||
if (output != NULL) {
|
||||
uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
if (pic1.use_argb != pic2.use_argb) {
|
||||
fprintf(stderr, "Pictures are not in the same argb format. "
|
||||
"Can't save the difference map.\n");
|
||||
goto End;
|
||||
}
|
||||
if (pic1.use_argb) {
|
||||
int n;
|
||||
fprintf(stderr, "max differences per channel: ");
|
||||
for (n = 0; n < 3; ++n) { // skip the alpha channel
|
||||
const int range = (type == 1) ?
|
||||
SSIMScaleChannel((uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4,
|
||||
4, pic1.width, pic1.height, scale) :
|
||||
DiffScaleChannel((uint8_t*)pic1.argb + n, pic1.argb_stride * 4,
|
||||
(const uint8_t*)pic2.argb + n, pic2.argb_stride * 4,
|
||||
4, pic1.width, pic1.height, scale);
|
||||
if (range < 0) fprintf(stderr, "\nError computing diff map\n");
|
||||
fprintf(stderr, "[%d]", range);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
if (use_gray) ConvertToGray(&pic1);
|
||||
} else {
|
||||
fprintf(stderr, "Can only compute the difference map in ARGB format.\n");
|
||||
goto End;
|
||||
}
|
||||
data_size = WebPEncodeLosslessBGRA((const uint8_t*)pic1.argb,
|
||||
pic1.width, pic1.height,
|
||||
pic1.argb_stride * 4,
|
||||
&data);
|
||||
if (data_size == 0) {
|
||||
fprintf(stderr, "Error during lossless encoding.\n");
|
||||
goto End;
|
||||
}
|
||||
ret = ImgIoUtilWriteFile(output, data, data_size) ? 0 : 1;
|
||||
WebPFree(data);
|
||||
if (ret) goto End;
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
End:
|
||||
WebPPictureFree(&pic1);
|
||||
WebPPictureFree(&pic2);
|
||||
return ret;
|
||||
}
|
129
extras/quality_estimate.c
Normal file
129
extras/quality_estimate.c
Normal file
@ -0,0 +1,129 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// VP8EstimateQuality(): rough encoding quality estimate
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./extras.h"
|
||||
#include "webp/decode.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define INVALID_BIT_POS (1ull << 63)
|
||||
|
||||
// In most cases, we don't need to use a full arithmetic decoder, since
|
||||
// all the header's bits are written using a uniform probability of 128.
|
||||
// We can just parse the header as if it was bits (works in 99.999% cases).
|
||||
static WEBP_INLINE uint32_t GetBit(const uint8_t* const data, size_t nb,
|
||||
uint64_t max_size, uint64_t* const bit_pos) {
|
||||
uint32_t val = 0;
|
||||
if (*bit_pos + nb <= 8 * max_size) {
|
||||
while (nb-- > 0) {
|
||||
const uint64_t p = (*bit_pos)++;
|
||||
const int bit = !!(data[p >> 3] & (128 >> ((p & 7))));
|
||||
val = (val << 1) | bit;
|
||||
}
|
||||
} else {
|
||||
*bit_pos = INVALID_BIT_POS;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
#define GET_BIT(n) GetBit(data, (n), size, &bit_pos)
|
||||
#define CONDITIONAL_SKIP(n) (GET_BIT(1) ? GET_BIT((n)) : 0)
|
||||
|
||||
int VP8EstimateQuality(const uint8_t* const data, size_t size) {
|
||||
size_t pos = 0;
|
||||
uint64_t bit_pos;
|
||||
uint64_t sig = 0x00;
|
||||
int ok = 0;
|
||||
int Q = -1;
|
||||
WebPBitstreamFeatures features;
|
||||
|
||||
if (data == NULL) return -1;
|
||||
|
||||
if (WebPGetFeatures(data, size, &features) != VP8_STATUS_OK) {
|
||||
return -1; // invalid file
|
||||
}
|
||||
if (features.format == 2) return 101; // lossless
|
||||
if (features.format == 0 || features.has_animation) return -1; // mixed
|
||||
|
||||
while (pos < size) {
|
||||
sig = (sig >> 8) | ((uint64_t)data[pos++] << 40);
|
||||
if ((sig >> 24) == 0x2a019dull) {
|
||||
ok = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) return -1;
|
||||
if (pos + 4 > size) return -1;
|
||||
|
||||
// Skip main Header
|
||||
// width = (data[pos + 0] | (data[pos + 1] << 8)) & 0x3fff;
|
||||
// height = (data[pos + 2] | (data[pos + 3] << 8)) & 0x3fff;
|
||||
pos += 4;
|
||||
bit_pos = pos * 8;
|
||||
|
||||
GET_BIT(2); // color_space + clamp type
|
||||
|
||||
// Segment header
|
||||
if (GET_BIT(1)) { // use_segment_
|
||||
int s;
|
||||
const int update_map = GET_BIT(1);
|
||||
if (GET_BIT(1)) { // update data
|
||||
const int absolute_delta = GET_BIT(1);
|
||||
int q[4] = { 0, 0, 0, 0 };
|
||||
for (s = 0; s < 4; ++s) {
|
||||
if (GET_BIT(1)) {
|
||||
q[s] = GET_BIT(7);
|
||||
if (GET_BIT(1)) q[s] = -q[s]; // sign
|
||||
}
|
||||
}
|
||||
if (absolute_delta) Q = q[0]; // just use the first segment's quantizer
|
||||
for (s = 0; s < 4; ++s) CONDITIONAL_SKIP(7); // filter strength
|
||||
}
|
||||
if (update_map) {
|
||||
for (s = 0; s < 3; ++s) CONDITIONAL_SKIP(8);
|
||||
}
|
||||
}
|
||||
// Filter header
|
||||
GET_BIT(1 + 6 + 3); // simple + level + sharpness
|
||||
if (GET_BIT(1)) { // use_lf_delta
|
||||
if (GET_BIT(1)) { // update lf_delta?
|
||||
int n;
|
||||
for (n = 0; n < 4 + 4; ++n) CONDITIONAL_SKIP(6);
|
||||
}
|
||||
}
|
||||
// num partitions
|
||||
GET_BIT(2);
|
||||
|
||||
// ParseQuant
|
||||
{
|
||||
const int base_q = GET_BIT(7);
|
||||
/* dqy1_dc = */ CONDITIONAL_SKIP(5);
|
||||
/* dqy2_dc = */ CONDITIONAL_SKIP(5);
|
||||
/* dqy2_ac = */ CONDITIONAL_SKIP(5);
|
||||
/* dquv_dc = */ CONDITIONAL_SKIP(5);
|
||||
/* dquv_ac = */ CONDITIONAL_SKIP(5);
|
||||
|
||||
if (Q < 0) Q = base_q;
|
||||
}
|
||||
if (bit_pos == INVALID_BIT_POS) return -1;
|
||||
|
||||
// base mapping
|
||||
Q = (127 - Q) * 100 / 127;
|
||||
// correction for power-law behavior in low range
|
||||
if (Q < 80) {
|
||||
Q = (int)(pow(Q / 80., 1. / 0.38) * 80);
|
||||
}
|
||||
return Q;
|
||||
}
|
96
extras/vwebp_sdl.c
Normal file
96
extras/vwebp_sdl.c
Normal file
@ -0,0 +1,96 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Simple SDL-based WebP file viewer.
|
||||
// Does not support animation, just static images.
|
||||
//
|
||||
// Press 'q' to exit.
|
||||
//
|
||||
// Author: James Zern (jzern@google.com)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#if defined(WEBP_HAVE_SDL)
|
||||
|
||||
#include "webp_to_sdl.h"
|
||||
#include "webp/decode.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <SDL/SDL.h>
|
||||
#endif
|
||||
|
||||
static void ProcessEvents(void) {
|
||||
int done = 0;
|
||||
SDL_Event event;
|
||||
while (!done && SDL_WaitEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYUP:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_q: done = 1; break;
|
||||
default: break;
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int c;
|
||||
int ok = 0;
|
||||
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;
|
||||
} else {
|
||||
file = argv[c];
|
||||
}
|
||||
if (file == NULL) continue;
|
||||
if (!ImgIoUtilReadFile(file, &webp, &webp_size)) {
|
||||
fprintf(stderr, "Error opening file: %s\n", file);
|
||||
goto Error;
|
||||
}
|
||||
if (webp_size != (size_t)(int)webp_size) {
|
||||
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);
|
||||
goto Error;
|
||||
}
|
||||
ProcessEvents();
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
SDL_Quit();
|
||||
return ok ? 0 : 1;
|
||||
}
|
||||
|
||||
#else // !WEBP_HAVE_SDL
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
fprintf(stderr, "SDL support not enabled in %s.\n", argv[0]);
|
||||
(void)argc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
50
extras/webp_quality.c
Normal file
50
extras/webp_quality.c
Normal file
@ -0,0 +1,50 @@
|
||||
// Simple tool to roughly evaluate the quality encoding of a webp bitstream
|
||||
//
|
||||
// Result is a *rough* estimation of the quality. You should just consider
|
||||
// the bucket it's in (q > 80? > 50? > 20?) and not take it for face value.
|
||||
/*
|
||||
gcc -o webp_quality webp_quality.c -O3 -I../ -L. -L../imageio \
|
||||
-limageio_util -lwebpextras -lwebp -lm -lpthread
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "./extras.h"
|
||||
#include "../imageio/imageio_util.h"
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
int c;
|
||||
int quiet = 0;
|
||||
int ok = 1;
|
||||
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;
|
||||
} else {
|
||||
const char* const filename = 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 (q < 0) {
|
||||
fprintf(stderr, "Not a WebP file, or not a lossy WebP file.\n");
|
||||
ok = 0;
|
||||
} else {
|
||||
if (!quiet) {
|
||||
printf("Estimated quality factor: %d\n", q);
|
||||
} else {
|
||||
printf("%d\n", q); // just print the number
|
||||
}
|
||||
}
|
||||
free((void*)data);
|
||||
}
|
||||
}
|
||||
return ok ? 0 : 1;
|
||||
}
|
105
extras/webp_to_sdl.c
Executable file
105
extras/webp_to_sdl.c
Executable file
@ -0,0 +1,105 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Simple WebP-to-SDL wrapper. Useful for emscripten.
|
||||
//
|
||||
// Author: James Zern (jzern@google.com)
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#if defined(WEBP_HAVE_SDL)
|
||||
|
||||
#include "webp_to_sdl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "webp/decode.h"
|
||||
|
||||
#if defined(WEBP_HAVE_JUST_SDL_H)
|
||||
#include <SDL.h>
|
||||
#else
|
||||
#include <SDL/SDL.h>
|
||||
#endif
|
||||
|
||||
int WebpToSDL(const char* data, unsigned int data_size) {
|
||||
int ok = 0;
|
||||
VP8StatusCode status;
|
||||
WebPDecoderConfig config;
|
||||
WebPBitstreamFeatures* const input = &config.input;
|
||||
WebPDecBuffer* const output = &config.output;
|
||||
SDL_Surface* screen = NULL;
|
||||
SDL_Surface* surface = NULL;
|
||||
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
status = WebPGetFeatures((uint8_t*)data, (size_t)data_size, &config.input);
|
||||
if (status != VP8_STATUS_OK) goto Error;
|
||||
|
||||
screen = SDL_SetVideoMode(input->width, input->height, 32, SDL_SWSURFACE);
|
||||
if (screen == NULL) {
|
||||
fprintf(stderr, "Unable to set video mode (32bpp %dx%d)!\n",
|
||||
input->width, input->height);
|
||||
goto Error;
|
||||
}
|
||||
|
||||
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
||||
input->width, input->height, 32,
|
||||
0x000000ffu, // R mask
|
||||
0x0000ff00u, // G mask
|
||||
0x00ff0000u, // B mask
|
||||
0xff000000u); // A mask
|
||||
|
||||
if (surface == NULL) {
|
||||
fprintf(stderr, "Unable to create %dx%d RGBA surface!\n",
|
||||
input->width, input->height);
|
||||
goto Error;
|
||||
}
|
||||
if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface);
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
output->colorspace = MODE_BGRA;
|
||||
#else
|
||||
output->colorspace = MODE_RGBA;
|
||||
#endif
|
||||
output->width = surface->w;
|
||||
output->height = surface->h;
|
||||
output->u.RGBA.rgba = surface->pixels;
|
||||
output->u.RGBA.stride = surface->pitch;
|
||||
output->u.RGBA.size = surface->pitch * surface->h;
|
||||
output->is_external_memory = 1;
|
||||
|
||||
status = WebPDecode((const uint8_t*)data, (size_t)data_size, &config);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
fprintf(stderr, "Error decoding image (%d)\n", status);
|
||||
goto Error;
|
||||
}
|
||||
|
||||
if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
|
||||
if (SDL_BlitSurface(surface, NULL, screen, NULL) ||
|
||||
SDL_Flip(screen)) {
|
||||
goto Error;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
SDL_FreeSurface(surface);
|
||||
SDL_FreeSurface(screen);
|
||||
return ok;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif // WEBP_HAVE_SDL
|
22
extras/webp_to_sdl.h
Normal file
22
extras/webp_to_sdl.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Simple WebP-to-SDL wrapper. Useful for emscripten.
|
||||
//
|
||||
// Author: James Zern (jzern@google.com)
|
||||
|
||||
#ifndef WEBP_EXTRAS_WEBP_TO_SDL_H_
|
||||
#define WEBP_EXTRAS_WEBP_TO_SDL_H_
|
||||
|
||||
// Exports the method WebpToSDL(const char* data, int data_size) which decodes
|
||||
// a WebP bitstream into an RGBA SDL surface.
|
||||
// Return false on failure.
|
||||
extern int WebpToSDL(const char* data, unsigned int data_size);
|
||||
|
||||
#endif // WEBP_EXTRAS_WEBP_TO_SDL_H_
|
54
imageio/Android.mk
Normal file
54
imageio/Android.mk
Normal file
@ -0,0 +1,54 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
################################################################################
|
||||
# libimageio_util
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
imageio_util.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
|
||||
LOCAL_MODULE := imageio_util
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
################################################################################
|
||||
# libimagedec
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
image_dec.c \
|
||||
jpegdec.c \
|
||||
metadata.c \
|
||||
pngdec.c \
|
||||
pnmdec.c \
|
||||
tiffdec.c \
|
||||
webpdec.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := imageio_util
|
||||
|
||||
LOCAL_MODULE := imagedec
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
||||
|
||||
################################################################################
|
||||
# libimageenc
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := \
|
||||
image_enc.c \
|
||||
|
||||
LOCAL_CFLAGS := $(WEBP_CFLAGS)
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../src
|
||||
LOCAL_STATIC_LIBRARIES := imageio_util
|
||||
|
||||
LOCAL_MODULE := imageenc
|
||||
|
||||
include $(BUILD_STATIC_LIBRARY)
|
23
imageio/Makefile.am
Normal file
23
imageio/Makefile.am
Normal file
@ -0,0 +1,23 @@
|
||||
AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
|
||||
noinst_LTLIBRARIES = libimageio_util.la libimagedec.la libimageenc.la
|
||||
|
||||
noinst_HEADERS =
|
||||
noinst_HEADERS += ../src/webp/decode.h
|
||||
noinst_HEADERS += ../src/webp/types.h
|
||||
|
||||
libimageio_util_la_SOURCES = imageio_util.c imageio_util.h
|
||||
|
||||
libimagedec_la_SOURCES = image_dec.c image_dec.h
|
||||
libimagedec_la_SOURCES += jpegdec.c jpegdec.h
|
||||
libimagedec_la_SOURCES += metadata.c metadata.h
|
||||
libimagedec_la_SOURCES += pngdec.c pngdec.h
|
||||
libimagedec_la_SOURCES += pnmdec.c pnmdec.h
|
||||
libimagedec_la_SOURCES += tiffdec.c tiffdec.h
|
||||
libimagedec_la_SOURCES += webpdec.c webpdec.h
|
||||
libimagedec_la_SOURCES += wicdec.c wicdec.h
|
||||
libimagedec_la_CPPFLAGS = $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
|
||||
libimagedec_la_CPPFLAGS += $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
||||
|
||||
libimageenc_la_SOURCES = image_enc.c image_enc.h
|
||||
libimageenc_la_CPPFLAGS = $(JPEG_INCLUDES) $(PNG_INCLUDES) $(TIFF_INCLUDES)
|
||||
libimageenc_la_CPPFLAGS += $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
|
@ -29,18 +29,38 @@ WebPInputFileFormat WebPGuessImageType(const uint8_t* const data,
|
||||
format = WEBP_TIFF_FORMAT;
|
||||
} else if (magic1 == 0x52494646 && magic2 == 0x57454250) {
|
||||
format = WEBP_WEBP_FORMAT;
|
||||
} else if (((magic1 >> 24) & 0xff) == 'P') {
|
||||
const int type = (magic1 >> 16) & 0xff;
|
||||
// we only support 'P5 -> P7' for now.
|
||||
if (type >= '5' && type <= '7') format = WEBP_PNM_FORMAT;
|
||||
}
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
||||
WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
size_t data_size) {
|
||||
switch (WebPGuessImageType(data, data_size)) {
|
||||
static int FailReader(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
int keep_alpha, struct Metadata* const metadata) {
|
||||
(void)data;
|
||||
(void)data_size;
|
||||
(void)pic;
|
||||
(void)keep_alpha;
|
||||
(void)metadata;
|
||||
return 0;
|
||||
}
|
||||
|
||||
WebPImageReader WebPGetImageReader(WebPInputFileFormat format) {
|
||||
switch (format) {
|
||||
case WEBP_PNG_FORMAT: return ReadPNG;
|
||||
case WEBP_JPEG_FORMAT: return ReadJPEG;
|
||||
case WEBP_TIFF_FORMAT: return ReadTIFF;
|
||||
case WEBP_WEBP_FORMAT: return ReadWebP;
|
||||
default: return NULL;
|
||||
case WEBP_PNM_FORMAT: return ReadPNM;
|
||||
default: return FailReader;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
size_t data_size) {
|
||||
return WebPGetImageReader(WebPGuessImageType(data, data_size));
|
||||
}
|
@ -11,8 +11,8 @@
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#ifndef WEBP_EXAMPLES_IMAGE_DEC_H_
|
||||
#define WEBP_EXAMPLES_IMAGE_DEC_H_
|
||||
#ifndef WEBP_IMAGEIO_IMAGE_DEC_H_
|
||||
#define WEBP_IMAGEIO_IMAGE_DEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "./metadata.h"
|
||||
#include "./jpegdec.h"
|
||||
#include "./pngdec.h"
|
||||
#include "./pnmdec.h"
|
||||
#include "./tiffdec.h"
|
||||
#include "./webpdec.h"
|
||||
#include "./wicdec.h"
|
||||
@ -36,6 +37,7 @@ typedef enum {
|
||||
WEBP_JPEG_FORMAT,
|
||||
WEBP_TIFF_FORMAT,
|
||||
WEBP_WEBP_FORMAT,
|
||||
WEBP_PNM_FORMAT,
|
||||
WEBP_UNSUPPORTED_FORMAT
|
||||
} WebPInputFileFormat;
|
||||
|
||||
@ -49,8 +51,12 @@ typedef int (*WebPImageReader)(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
int keep_alpha, struct Metadata* const metadata);
|
||||
|
||||
// Return the reader associated to a given file format.
|
||||
WebPImageReader WebPGetImageReader(WebPInputFileFormat format);
|
||||
|
||||
// This function is similar to WebPGuessImageType(), but returns a
|
||||
// suitable reader function. Or NULL if the image can't be guessed.
|
||||
// suitable reader function. The returned reader is never NULL, but
|
||||
// unknown formats will return an always-failing valid reader.
|
||||
WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
size_t data_size);
|
||||
|
||||
@ -58,4 +64,4 @@ WebPImageReader WebPGuessImageReader(const uint8_t* const data,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_IMAGE_DEC_H_
|
||||
#endif // WEBP_IMAGEIO_IMAGE_DEC_H_
|
594
imageio/image_enc.c
Normal file
594
imageio/image_enc.c
Normal file
@ -0,0 +1,594 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Save image
|
||||
|
||||
#include "./image_enc.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef WEBP_HAVE_PNG
|
||||
#include <png.h>
|
||||
#include <setjmp.h> // note: this must be included *after* png.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
#ifdef __MINGW32__
|
||||
#define INITGUID // Without this GUIDs are declared extern and fail to link
|
||||
#endif
|
||||
#define CINTERFACE
|
||||
#define COBJMACROS
|
||||
#define _WIN32_IE 0x500 // Workaround bug in shlwapi.h when compiling C++
|
||||
// code with COBJMACROS.
|
||||
#include <ole2.h> // CreateStreamOnHGlobal()
|
||||
#include <shlwapi.h>
|
||||
#include <windows.h>
|
||||
#include <wincodec.h>
|
||||
#endif
|
||||
|
||||
#include "./imageio_util.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PNG
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
|
||||
#define IFS(fn) \
|
||||
do { \
|
||||
if (SUCCEEDED(hr)) { \
|
||||
hr = (fn); \
|
||||
if (FAILED(hr)) fprintf(stderr, #fn " failed %08lx\n", hr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MAKE_REFGUID(x) (x)
|
||||
#else
|
||||
#define MAKE_REFGUID(x) &(x)
|
||||
#endif
|
||||
|
||||
static HRESULT CreateOutputStream(const char* out_file_name,
|
||||
int write_to_mem, IStream** stream) {
|
||||
HRESULT hr = S_OK;
|
||||
if (write_to_mem) {
|
||||
// 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));
|
||||
}
|
||||
if (FAILED(hr)) {
|
||||
fprintf(stderr, "Error opening output file %s (%08lx)\n",
|
||||
out_file_name, hr);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
static HRESULT WriteUsingWIC(const char* out_file_name, int use_stdout,
|
||||
REFGUID container_guid,
|
||||
uint8_t* rgb, int stride,
|
||||
uint32_t width, uint32_t height, int has_alpha) {
|
||||
HRESULT hr = S_OK;
|
||||
IWICImagingFactory* factory = NULL;
|
||||
IWICBitmapFrameEncode* frame = NULL;
|
||||
IWICBitmapEncoder* encoder = NULL;
|
||||
IStream* stream = NULL;
|
||||
WICPixelFormatGUID pixel_format = has_alpha ? GUID_WICPixelFormat32bppBGRA
|
||||
: GUID_WICPixelFormat24bppBGR;
|
||||
|
||||
if (out_file_name == NULL || rgb == NULL) return E_INVALIDARG;
|
||||
|
||||
IFS(CoInitialize(NULL));
|
||||
IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
MAKE_REFGUID(IID_IWICImagingFactory),
|
||||
(LPVOID*)&factory));
|
||||
if (hr == REGDB_E_CLASSNOTREG) {
|
||||
fprintf(stderr,
|
||||
"Couldn't access Windows Imaging Component (are you running "
|
||||
"Windows XP SP3 or newer?). PNG support not available. "
|
||||
"Use -ppm or -pgm for available PPM and PGM formats.\n");
|
||||
}
|
||||
IFS(CreateOutputStream(out_file_name, use_stdout, &stream));
|
||||
IFS(IWICImagingFactory_CreateEncoder(factory, container_guid, NULL,
|
||||
&encoder));
|
||||
IFS(IWICBitmapEncoder_Initialize(encoder, stream,
|
||||
WICBitmapEncoderNoCache));
|
||||
IFS(IWICBitmapEncoder_CreateNewFrame(encoder, &frame, NULL));
|
||||
IFS(IWICBitmapFrameEncode_Initialize(frame, NULL));
|
||||
IFS(IWICBitmapFrameEncode_SetSize(frame, width, height));
|
||||
IFS(IWICBitmapFrameEncode_SetPixelFormat(frame, &pixel_format));
|
||||
IFS(IWICBitmapFrameEncode_WritePixels(frame, height, stride,
|
||||
height * stride, rgb));
|
||||
IFS(IWICBitmapFrameEncode_Commit(frame));
|
||||
IFS(IWICBitmapEncoder_Commit(encoder));
|
||||
|
||||
if (SUCCEEDED(hr) && use_stdout) {
|
||||
HGLOBAL image;
|
||||
IFS(GetHGlobalFromStream(stream, &image));
|
||||
if (SUCCEEDED(hr)) {
|
||||
HANDLE std_output = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
DWORD mode;
|
||||
const BOOL update_mode = GetConsoleMode(std_output, &mode);
|
||||
const void* const image_mem = GlobalLock(image);
|
||||
DWORD bytes_written = 0;
|
||||
|
||||
// Clear output processing if necessary, then output the image.
|
||||
if (update_mode) SetConsoleMode(std_output, 0);
|
||||
if (!WriteFile(std_output, image_mem, (DWORD)GlobalSize(image),
|
||||
&bytes_written, NULL) ||
|
||||
bytes_written != GlobalSize(image)) {
|
||||
hr = E_FAIL;
|
||||
}
|
||||
if (update_mode) SetConsoleMode(std_output, mode);
|
||||
GlobalUnlock(image);
|
||||
}
|
||||
}
|
||||
|
||||
if (frame != NULL) IUnknown_Release(frame);
|
||||
if (encoder != NULL) IUnknown_Release(encoder);
|
||||
if (factory != NULL) IUnknown_Release(factory);
|
||||
if (stream != NULL) IUnknown_Release(stream);
|
||||
return hr;
|
||||
}
|
||||
|
||||
int WebPWritePNG(const char* out_file_name, int use_stdout,
|
||||
const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
uint8_t* const rgb = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
|
||||
return SUCCEEDED(WriteUsingWIC(out_file_name, use_stdout,
|
||||
MAKE_REFGUID(GUID_ContainerFormatPng),
|
||||
rgb, stride, width, height, has_alpha));
|
||||
}
|
||||
|
||||
#elif defined(WEBP_HAVE_PNG) // !HAVE_WINCODEC_H
|
||||
static void PNGAPI PNGErrorFunction(png_structp png, png_const_charp dummy) {
|
||||
(void)dummy; // remove variable-unused warning
|
||||
longjmp(png_jmpbuf(png), 1);
|
||||
}
|
||||
|
||||
int WebPWritePNG(FILE* out_file, const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
png_bytep row = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
volatile png_structp png;
|
||||
volatile png_infop info;
|
||||
png_uint_32 y;
|
||||
|
||||
if (out_file == NULL || buffer == NULL) return 0;
|
||||
|
||||
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
NULL, PNGErrorFunction, NULL);
|
||||
if (png == NULL) {
|
||||
return 0;
|
||||
}
|
||||
info = png_create_info_struct(png);
|
||||
if (info == NULL) {
|
||||
png_destroy_write_struct((png_structpp)&png, NULL);
|
||||
return 0;
|
||||
}
|
||||
if (setjmp(png_jmpbuf(png))) {
|
||||
png_destroy_write_struct((png_structpp)&png, (png_infopp)&info);
|
||||
return 0;
|
||||
}
|
||||
png_init_io(png, out_file);
|
||||
png_set_IHDR(png, info, width, height, 8,
|
||||
has_alpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
png_write_info(png, info);
|
||||
for (y = 0; y < height; ++y) {
|
||||
png_write_rows(png, &row, 1);
|
||||
row += stride;
|
||||
}
|
||||
png_write_end(png, info);
|
||||
png_destroy_write_struct((png_structpp)&png, (png_infopp)&info);
|
||||
return 1;
|
||||
}
|
||||
#else // !HAVE_WINCODEC_H && !WEBP_HAVE_PNG
|
||||
int WebPWritePNG(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
if (fout == NULL || buffer == NULL) return 0;
|
||||
|
||||
fprintf(stderr, "PNG support not compiled. Please install the libpng "
|
||||
"development package before building.\n");
|
||||
fprintf(stderr, "You can run with -ppm flag to decode in PPM format.\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PPM / PAM
|
||||
|
||||
static int WritePPMPAM(FILE* fout, const WebPDecBuffer* const buffer,
|
||||
int alpha) {
|
||||
if (fout == NULL || buffer == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* row = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const size_t bytes_per_px = alpha ? 4 : 3;
|
||||
uint32_t y;
|
||||
|
||||
if (row == NULL) return 0;
|
||||
|
||||
if (alpha) {
|
||||
fprintf(fout, "P7\nWIDTH %u\nHEIGHT %u\nDEPTH 4\nMAXVAL 255\n"
|
||||
"TUPLTYPE RGB_ALPHA\nENDHDR\n", width, height);
|
||||
} else {
|
||||
fprintf(fout, "P6\n%u %u\n255\n", width, height);
|
||||
}
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(row, width, bytes_per_px, fout) != bytes_per_px) {
|
||||
return 0;
|
||||
}
|
||||
row += stride;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WebPWritePPM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
return WritePPMPAM(fout, buffer, 0);
|
||||
}
|
||||
|
||||
int WebPWritePAM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
return WritePPMPAM(fout, buffer, 1);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Raw PGM
|
||||
|
||||
// Save 16b mode (RGBA4444, RGB565, ...) for debugging purpose.
|
||||
int WebPWrite16bAsPGM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint32_t bytes_per_px = 2;
|
||||
uint32_t y;
|
||||
|
||||
if (fout == NULL || buffer == NULL || rgba == NULL) return 0;
|
||||
|
||||
fprintf(fout, "P5\n%u %u\n255\n", width * bytes_per_px, height);
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba, width, bytes_per_px, fout) != bytes_per_px) {
|
||||
return 0;
|
||||
}
|
||||
rgba += stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// BMP
|
||||
|
||||
static void PutLE16(uint8_t* const dst, uint32_t value) {
|
||||
dst[0] = (value >> 0) & 0xff;
|
||||
dst[1] = (value >> 8) & 0xff;
|
||||
}
|
||||
|
||||
static void PutLE32(uint8_t* const dst, uint32_t value) {
|
||||
PutLE16(dst + 0, (value >> 0) & 0xffff);
|
||||
PutLE16(dst + 2, (value >> 16) & 0xffff);
|
||||
}
|
||||
|
||||
#define BMP_HEADER_SIZE 54
|
||||
int WebPWriteBMP(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint32_t bytes_per_px = has_alpha ? 4 : 3;
|
||||
uint32_t y;
|
||||
const uint32_t line_size = bytes_per_px * width;
|
||||
const uint32_t bmp_stride = (line_size + 3) & ~3; // pad to 4
|
||||
const uint32_t total_size = bmp_stride * height + BMP_HEADER_SIZE;
|
||||
uint8_t bmp_header[BMP_HEADER_SIZE] = { 0 };
|
||||
|
||||
if (fout == NULL || buffer == NULL || rgba == NULL) return 0;
|
||||
|
||||
// bitmap file header
|
||||
PutLE16(bmp_header + 0, 0x4d42); // signature 'BM'
|
||||
PutLE32(bmp_header + 2, total_size); // size including header
|
||||
PutLE32(bmp_header + 6, 0); // reserved
|
||||
PutLE32(bmp_header + 10, BMP_HEADER_SIZE); // offset to pixel array
|
||||
// bitmap info header
|
||||
PutLE32(bmp_header + 14, 40); // DIB header size
|
||||
PutLE32(bmp_header + 18, width); // dimensions
|
||||
PutLE32(bmp_header + 22, -(int)height); // vertical flip!
|
||||
PutLE16(bmp_header + 26, 1); // number of planes
|
||||
PutLE16(bmp_header + 28, bytes_per_px * 8); // bits per pixel
|
||||
PutLE32(bmp_header + 30, 0); // no compression (BI_RGB)
|
||||
PutLE32(bmp_header + 34, 0); // image size (dummy)
|
||||
PutLE32(bmp_header + 38, 2400); // x pixels/meter
|
||||
PutLE32(bmp_header + 42, 2400); // y pixels/meter
|
||||
PutLE32(bmp_header + 46, 0); // number of palette colors
|
||||
PutLE32(bmp_header + 50, 0); // important color count
|
||||
|
||||
// TODO(skal): color profile
|
||||
|
||||
// write header
|
||||
if (fwrite(bmp_header, sizeof(bmp_header), 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// write pixel array
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba, line_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
// write padding zeroes
|
||||
if (bmp_stride != line_size) {
|
||||
const uint8_t zeroes[3] = { 0 };
|
||||
if (fwrite(zeroes, bmp_stride - line_size, 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
rgba += stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#undef BMP_HEADER_SIZE
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// TIFF
|
||||
|
||||
#define NUM_IFD_ENTRIES 15
|
||||
#define EXTRA_DATA_SIZE 16
|
||||
// 10b for signature/header + n * 12b entries + 4b for IFD terminator:
|
||||
#define EXTRA_DATA_OFFSET (10 + 12 * NUM_IFD_ENTRIES + 4)
|
||||
#define TIFF_HEADER_SIZE (EXTRA_DATA_OFFSET + EXTRA_DATA_SIZE)
|
||||
|
||||
int WebPWriteTIFF(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
const int has_alpha = WebPIsAlphaMode(buffer->colorspace);
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* rgba = buffer->u.RGBA.rgba;
|
||||
const int stride = buffer->u.RGBA.stride;
|
||||
const uint8_t bytes_per_px = has_alpha ? 4 : 3;
|
||||
const uint8_t assoc_alpha =
|
||||
WebPIsPremultipliedMode(buffer->colorspace) ? 1 : 2;
|
||||
// For non-alpha case, we omit tag 0x152 (ExtraSamples).
|
||||
const uint8_t num_ifd_entries = has_alpha ? NUM_IFD_ENTRIES
|
||||
: NUM_IFD_ENTRIES - 1;
|
||||
uint8_t tiff_header[TIFF_HEADER_SIZE] = {
|
||||
0x49, 0x49, 0x2a, 0x00, // little endian signature
|
||||
8, 0, 0, 0, // offset to the unique IFD that follows
|
||||
// IFD (offset = 8). Entries must be written in increasing tag order.
|
||||
num_ifd_entries, 0, // Number of entries in the IFD (12 bytes each).
|
||||
0x00, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 10: Width (TBD)
|
||||
0x01, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 22: Height (TBD)
|
||||
0x02, 0x01, 3, 0, bytes_per_px, 0, 0, 0, // 34: BitsPerSample: 8888
|
||||
EXTRA_DATA_OFFSET + 0, 0, 0, 0,
|
||||
0x03, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 46: Compression: none
|
||||
0x06, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 58: Photometric: RGB
|
||||
0x11, 0x01, 4, 0, 1, 0, 0, 0, // 70: Strips offset:
|
||||
TIFF_HEADER_SIZE, 0, 0, 0, // data follows header
|
||||
0x12, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 82: Orientation: topleft
|
||||
0x15, 0x01, 3, 0, 1, 0, 0, 0, // 94: SamplesPerPixels
|
||||
bytes_per_px, 0, 0, 0,
|
||||
0x16, 0x01, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 106: Rows per strip (TBD)
|
||||
0x17, 0x01, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, // 118: StripByteCount (TBD)
|
||||
0x1a, 0x01, 5, 0, 1, 0, 0, 0, // 130: X-resolution
|
||||
EXTRA_DATA_OFFSET + 8, 0, 0, 0,
|
||||
0x1b, 0x01, 5, 0, 1, 0, 0, 0, // 142: Y-resolution
|
||||
EXTRA_DATA_OFFSET + 8, 0, 0, 0,
|
||||
0x1c, 0x01, 3, 0, 1, 0, 0, 0, 1, 0, 0, 0, // 154: PlanarConfiguration
|
||||
0x28, 0x01, 3, 0, 1, 0, 0, 0, 2, 0, 0, 0, // 166: ResolutionUnit (inch)
|
||||
0x52, 0x01, 3, 0, 1, 0, 0, 0,
|
||||
assoc_alpha, 0, 0, 0, // 178: ExtraSamples: rgbA/RGBA
|
||||
0, 0, 0, 0, // 190: IFD terminator
|
||||
// EXTRA_DATA_OFFSET:
|
||||
8, 0, 8, 0, 8, 0, 8, 0, // BitsPerSample
|
||||
72, 0, 0, 0, 1, 0, 0, 0 // 72 pixels/inch, for X/Y-resolution
|
||||
};
|
||||
uint32_t y;
|
||||
|
||||
if (fout == NULL || buffer == NULL || rgba == NULL) return 0;
|
||||
|
||||
// Fill placeholders in IFD:
|
||||
PutLE32(tiff_header + 10 + 8, width);
|
||||
PutLE32(tiff_header + 22 + 8, height);
|
||||
PutLE32(tiff_header + 106 + 8, height);
|
||||
PutLE32(tiff_header + 118 + 8, width * bytes_per_px * height);
|
||||
if (!has_alpha) PutLE32(tiff_header + 178, 0); // IFD terminator
|
||||
|
||||
// write header
|
||||
if (fwrite(tiff_header, sizeof(tiff_header), 1, fout) != 1) {
|
||||
return 0;
|
||||
}
|
||||
// write pixel values
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(rgba, bytes_per_px, width, fout) != width) {
|
||||
return 0;
|
||||
}
|
||||
rgba += stride;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#undef TIFF_HEADER_SIZE
|
||||
#undef EXTRA_DATA_OFFSET
|
||||
#undef EXTRA_DATA_SIZE
|
||||
#undef NUM_IFD_ENTRIES
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Raw Alpha
|
||||
|
||||
int WebPWriteAlphaPlane(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
if (fout == NULL || buffer == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
const uint32_t width = buffer->width;
|
||||
const uint32_t height = buffer->height;
|
||||
const uint8_t* a = buffer->u.YUVA.a;
|
||||
const int a_stride = buffer->u.YUVA.a_stride;
|
||||
uint32_t y;
|
||||
|
||||
if (a == NULL) return 0;
|
||||
|
||||
fprintf(fout, "P5\n%u %u\n255\n", width, height);
|
||||
for (y = 0; y < height; ++y) {
|
||||
if (fwrite(a, width, 1, fout) != 1) return 0;
|
||||
a += a_stride;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// PGM with IMC4 layout
|
||||
|
||||
int WebPWritePGM(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
if (fout == NULL || buffer == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
const int width = buffer->width;
|
||||
const int height = buffer->height;
|
||||
const WebPYUVABuffer* const yuv = &buffer->u.YUVA;
|
||||
const uint8_t* src_y = yuv->y;
|
||||
const uint8_t* src_u = yuv->u;
|
||||
const uint8_t* src_v = yuv->v;
|
||||
const uint8_t* src_a = yuv->a;
|
||||
const int uv_width = (width + 1) / 2;
|
||||
const int uv_height = (height + 1) / 2;
|
||||
const int a_height = (src_a != NULL) ? height : 0;
|
||||
int ok = 1;
|
||||
int y;
|
||||
|
||||
if (src_y == NULL || src_u == NULL || src_v == NULL) return 0;
|
||||
|
||||
fprintf(fout, "P5\n%d %d\n255\n",
|
||||
(width + 1) & ~1, height + uv_height + a_height);
|
||||
for (y = 0; ok && y < height; ++y) {
|
||||
ok &= (fwrite(src_y, width, 1, fout) == 1);
|
||||
if (width & 1) fputc(0, fout); // padding byte
|
||||
src_y += yuv->y_stride;
|
||||
}
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(src_u, uv_width, 1, fout) == 1);
|
||||
ok &= (fwrite(src_v, uv_width, 1, fout) == 1);
|
||||
src_u += yuv->u_stride;
|
||||
src_v += yuv->v_stride;
|
||||
}
|
||||
for (y = 0; ok && y < a_height; ++y) {
|
||||
ok &= (fwrite(src_a, width, 1, fout) == 1);
|
||||
if (width & 1) fputc(0, fout); // padding byte
|
||||
src_a += yuv->a_stride;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Raw YUV(A) planes
|
||||
|
||||
int WebPWriteYUV(FILE* fout, const WebPDecBuffer* const buffer) {
|
||||
if (fout == NULL || buffer == NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
const int width = buffer->width;
|
||||
const int height = buffer->height;
|
||||
const WebPYUVABuffer* const yuv = &buffer->u.YUVA;
|
||||
const uint8_t* src_y = yuv->y;
|
||||
const uint8_t* src_u = yuv->u;
|
||||
const uint8_t* src_v = yuv->v;
|
||||
const uint8_t* src_a = yuv->a;
|
||||
const int uv_width = (width + 1) / 2;
|
||||
const int uv_height = (height + 1) / 2;
|
||||
const int a_height = (src_a != NULL) ? height : 0;
|
||||
int ok = 1;
|
||||
int y;
|
||||
|
||||
if (src_y == NULL || src_u == NULL || src_v == NULL) return 0;
|
||||
|
||||
for (y = 0; ok && y < height; ++y) {
|
||||
ok &= (fwrite(src_y, width, 1, fout) == 1);
|
||||
src_y += yuv->y_stride;
|
||||
}
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(src_u, uv_width, 1, fout) == 1);
|
||||
src_u += yuv->u_stride;
|
||||
}
|
||||
for (y = 0; ok && y < uv_height; ++y) {
|
||||
ok &= (fwrite(src_v, uv_width, 1, fout) == 1);
|
||||
src_v += yuv->v_stride;
|
||||
}
|
||||
for (y = 0; ok && y < a_height; ++y) {
|
||||
ok &= (fwrite(src_a, width, 1, fout) == 1);
|
||||
src_a += yuv->a_stride;
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Generic top-level call
|
||||
|
||||
int WebPSaveImage(const WebPDecBuffer* const buffer,
|
||||
WebPOutputFileFormat format, const char* const out_file) {
|
||||
FILE* fout = NULL;
|
||||
int needs_open_file = 1;
|
||||
const int use_stdout = (out_file != NULL) && !strcmp(out_file, "-");
|
||||
int ok = 1;
|
||||
|
||||
if (buffer == NULL || out_file == NULL) return 0;
|
||||
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
needs_open_file = (format != PNG);
|
||||
#endif
|
||||
|
||||
if (needs_open_file) {
|
||||
fout = use_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(out_file, "wb");
|
||||
if (fout == NULL) {
|
||||
fprintf(stderr, "Error opening output file %s\n", out_file);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (format == PNG ||
|
||||
format == RGBA || format == BGRA || format == ARGB ||
|
||||
format == rgbA || format == bgrA || format == Argb) {
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
ok &= WebPWritePNG(out_file, use_stdout, buffer);
|
||||
#else
|
||||
ok &= WebPWritePNG(fout, buffer);
|
||||
#endif
|
||||
} else if (format == PAM) {
|
||||
ok &= WebPWritePAM(fout, buffer);
|
||||
} else if (format == PPM || format == RGB || format == BGR) {
|
||||
ok &= WebPWritePPM(fout, buffer);
|
||||
} else if (format == RGBA_4444 || format == RGB_565 || format == rgbA_4444) {
|
||||
ok &= WebPWrite16bAsPGM(fout, buffer);
|
||||
} else if (format == BMP) {
|
||||
ok &= WebPWriteBMP(fout, buffer);
|
||||
} else if (format == TIFF) {
|
||||
ok &= WebPWriteTIFF(fout, buffer);
|
||||
} else if (format == RAW_YUV) {
|
||||
ok &= WebPWriteYUV(fout, buffer);
|
||||
} else if (format == PGM || format == YUV || format == YUVA) {
|
||||
ok &= WebPWritePGM(fout, buffer);
|
||||
} else if (format == ALPHA_PLANE_ONLY) {
|
||||
ok &= WebPWriteAlphaPlane(fout, buffer);
|
||||
}
|
||||
if (fout != NULL && fout != stdout) {
|
||||
fclose(fout);
|
||||
}
|
||||
return ok;
|
||||
}
|
96
imageio/image_enc.h
Normal file
96
imageio/image_enc.h
Normal file
@ -0,0 +1,96 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// All-in-one library to save PNG/JPEG/WebP/TIFF/WIC images.
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#ifndef WEBP_IMAGEIO_IMAGE_ENC_H_
|
||||
#define WEBP_IMAGEIO_IMAGE_ENC_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include "webp/types.h"
|
||||
#include "webp/decode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Output types
|
||||
typedef enum {
|
||||
PNG = 0,
|
||||
PAM,
|
||||
PPM,
|
||||
PGM,
|
||||
BMP,
|
||||
TIFF,
|
||||
RAW_YUV,
|
||||
ALPHA_PLANE_ONLY, // this is for experimenting only
|
||||
// forced colorspace output (for testing, mostly)
|
||||
RGB, RGBA, BGR, BGRA, ARGB,
|
||||
RGBA_4444, RGB_565,
|
||||
rgbA, bgrA, Argb, rgbA_4444,
|
||||
YUV, YUVA
|
||||
} WebPOutputFileFormat;
|
||||
|
||||
// General all-purpose call.
|
||||
// Most formats expect a 'buffer' containing RGBA-like samples, except
|
||||
// RAW_YUV, YUV and YUVA formats.
|
||||
// If 'out_file_name' is "-", data is saved to stdout.
|
||||
// Returns false if an error occurred, true otherwise.
|
||||
int WebPSaveImage(const WebPDecBuffer* const buffer,
|
||||
WebPOutputFileFormat format, const char* const out_file_name);
|
||||
|
||||
// Save to PNG.
|
||||
#ifdef HAVE_WINCODEC_H
|
||||
int WebPWritePNG(const char* out_file_name, int use_stdout,
|
||||
const struct WebPDecBuffer* const buffer);
|
||||
#else
|
||||
int WebPWritePNG(FILE* out_file, const WebPDecBuffer* const buffer);
|
||||
#endif
|
||||
|
||||
// Save to PPM format (RGB, no alpha)
|
||||
int WebPWritePPM(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save to PAM format (= PPM + alpha)
|
||||
int WebPWritePAM(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save 16b mode (RGBA4444, RGB565, ...) for debugging purposes.
|
||||
int WebPWrite16bAsPGM(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save as BMP
|
||||
int WebPWriteBMP(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save as TIFF
|
||||
int WebPWriteTIFF(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save the ALPHA plane (only) as a PGM
|
||||
int WebPWriteAlphaPlane(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save as YUV samples as PGM format (using IMC4 layout).
|
||||
// See: http://www.fourcc.org/yuv.php#IMC4.
|
||||
// (very convenient format for viewing the samples, esp. for odd dimensions).
|
||||
int WebPWritePGM(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save YUV(A) planes sequentially (raw dump)
|
||||
int WebPWriteYUV(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
// Save 16b mode (RGBA4444, RGB565, ...) as PGM format, for debugging purposes.
|
||||
int WebPWrite16bAsPGM(FILE* fout, const struct WebPDecBuffer* const buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_IMAGEIO_IMAGE_ENC_H_
|
143
imageio/imageio_util.c
Normal file
143
imageio/imageio_util.c
Normal file
@ -0,0 +1,143 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Utility functions used by the image decoders.
|
||||
//
|
||||
|
||||
#include "./imageio_util.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <fcntl.h> // for _O_BINARY
|
||||
#include <io.h> // for _setmode()
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File I/O
|
||||
|
||||
FILE* ImgIoUtilSetBinaryMode(FILE* file) {
|
||||
#if defined(_WIN32)
|
||||
if (_setmode(_fileno(file), _O_BINARY) == -1) {
|
||||
fprintf(stderr, "Failed to reopen file in O_BINARY mode.\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
return file;
|
||||
}
|
||||
|
||||
int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size) {
|
||||
static const size_t kBlockSize = 16384; // default initial size
|
||||
size_t max_size = 0;
|
||||
size_t size = 0;
|
||||
uint8_t* input = NULL;
|
||||
|
||||
if (data == NULL || data_size == NULL) return 0;
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
|
||||
if (!ImgIoUtilSetBinaryMode(stdin)) return 0;
|
||||
|
||||
while (!feof(stdin)) {
|
||||
// We double the buffer size each time and read as much as possible.
|
||||
const size_t extra_size = (max_size == 0) ? kBlockSize : max_size;
|
||||
void* const new_data = realloc(input, max_size + extra_size);
|
||||
if (new_data == NULL) goto Error;
|
||||
input = (uint8_t*)new_data;
|
||||
max_size += extra_size;
|
||||
size += fread(input + size, 1, extra_size, stdin);
|
||||
if (size < max_size) break;
|
||||
}
|
||||
if (ferror(stdin)) goto Error;
|
||||
*data = input;
|
||||
*data_size = size;
|
||||
return 1;
|
||||
|
||||
Error:
|
||||
free(input);
|
||||
fprintf(stderr, "Could not read from stdin\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ImgIoUtilReadFile(const char* const file_name,
|
||||
const uint8_t** data, size_t* data_size) {
|
||||
int ok;
|
||||
void* file_data;
|
||||
size_t file_size;
|
||||
FILE* in;
|
||||
const int from_stdin = (file_name == NULL) || !strcmp(file_name, "-");
|
||||
|
||||
if (from_stdin) return ImgIoUtilReadFromStdin(data, data_size);
|
||||
|
||||
if (data == NULL || data_size == NULL) return 0;
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
|
||||
in = fopen(file_name, "rb");
|
||||
if (in == NULL) {
|
||||
fprintf(stderr, "cannot open input file '%s'\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
fseek(in, 0, SEEK_END);
|
||||
file_size = ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
file_data = malloc(file_size);
|
||||
if (file_data == NULL) 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);
|
||||
free(file_data);
|
||||
return 0;
|
||||
}
|
||||
*data = (uint8_t*)file_data;
|
||||
*data_size = file_size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
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, "-");
|
||||
|
||||
if (data == NULL) {
|
||||
return 0;
|
||||
}
|
||||
out = to_stdout ? ImgIoUtilSetBinaryMode(stdout) : fopen(file_name, "wb");
|
||||
if (out == NULL) {
|
||||
fprintf(stderr, "Error! Cannot open output file '%s'\n", file_name);
|
||||
return 0;
|
||||
}
|
||||
ok = (fwrite(data, data_size, 1, out) == 1);
|
||||
if (out != stdout) fclose(out);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height) {
|
||||
while (height-- > 0) {
|
||||
memcpy(dst, src, width * sizeof(*dst));
|
||||
src += src_stride;
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size) {
|
||||
const uint64_t total_size = nmemb * size;
|
||||
return (total_size == (size_t)total_size);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
61
imageio/imageio_util.h
Normal file
61
imageio/imageio_util.h
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2016 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Utility functions used by the image decoders.
|
||||
//
|
||||
|
||||
#ifndef WEBP_IMAGEIO_IMAGEIO_UTIL_H_
|
||||
#define WEBP_IMAGEIO_IMAGEIO_UTIL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// File I/O
|
||||
|
||||
// Reopen file in binary (O_BINARY) mode.
|
||||
// Returns 'file' on success, NULL otherwise.
|
||||
FILE* ImgIoUtilSetBinaryMode(FILE* file);
|
||||
|
||||
// Allocates storage for entire file 'file_name' and returns contents and size
|
||||
// in 'data' and 'data_size'. Returns 1 on success, 0 otherwise. '*data' should
|
||||
// be deleted using free().
|
||||
// If 'file_name' is NULL or equal to "-", input is read from stdin by calling
|
||||
// the function ImgIoUtilReadFromStdin().
|
||||
int ImgIoUtilReadFile(const char* const file_name,
|
||||
const uint8_t** data, size_t* data_size);
|
||||
|
||||
// Same as ImgIoUtilReadFile(), but reads until EOF from stdin instead.
|
||||
int ImgIoUtilReadFromStdin(const uint8_t** data, size_t* data_size);
|
||||
|
||||
// Write a data segment into a file named 'file_name'. Returns true if ok.
|
||||
// If 'file_name' is NULL or equal to "-", output is written to stdout.
|
||||
int ImgIoUtilWriteFile(const char* const file_name,
|
||||
const uint8_t* data, size_t data_size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Copy width x height pixels from 'src' to 'dst' honoring the strides.
|
||||
void ImgIoUtilCopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Returns 0 in case of overflow of nmemb * size.
|
||||
int ImgIoUtilCheckSizeArgumentsOverflow(uint64_t nmemb, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_IMAGEIO_IMAGEIO_UTIL_H_
|
@ -25,7 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./example_util.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -266,6 +266,8 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
JSAMPROW buffer[1];
|
||||
JPEGReadContext ctx;
|
||||
|
||||
if (data == NULL || data_size == 0 || pic == NULL) return 0;
|
||||
|
||||
(void)keep_alpha;
|
||||
memset(&ctx, 0, sizeof(ctx));
|
||||
ctx.data = data;
|
@ -9,10 +9,9 @@
|
||||
//
|
||||
// JPEG decode.
|
||||
|
||||
#ifndef WEBP_EXAMPLES_JPEGDEC_H_
|
||||
#define WEBP_EXAMPLES_JPEGDEC_H_
|
||||
#ifndef WEBP_IMAGEIO_JPEGDEC_H_
|
||||
#define WEBP_IMAGEIO_JPEGDEC_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -35,4 +34,4 @@ int ReadJPEG(const uint8_t* const data, size_t data_size,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_JPEGDEC_H_
|
||||
#endif // WEBP_IMAGEIO_JPEGDEC_H_
|
@ -10,8 +10,8 @@
|
||||
// Metadata types and functions.
|
||||
//
|
||||
|
||||
#ifndef WEBP_EXAMPLES_METADATA_H_
|
||||
#define WEBP_EXAMPLES_METADATA_H_
|
||||
#ifndef WEBP_IMAGEIO_METADATA_H_
|
||||
#define WEBP_IMAGEIO_METADATA_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
@ -44,4 +44,4 @@ int MetadataCopy(const char* metadata, size_t metadata_len,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_METADATA_H_
|
||||
#endif // WEBP_IMAGEIO_METADATA_H_
|
@ -24,7 +24,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./example_util.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
static void PNGAPI error_function(png_structp png, png_const_charp error) {
|
||||
@ -220,6 +220,8 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
|
||||
int64_t stride;
|
||||
uint8_t* volatile rgb = NULL;
|
||||
|
||||
if (data == NULL || data_size == 0 || pic == NULL) return 0;
|
||||
|
||||
context.data = data;
|
||||
context.data_size = data_size;
|
||||
|
||||
@ -280,9 +282,10 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
|
||||
rgb = (uint8_t*)malloc((size_t)stride * height);
|
||||
if (rgb == NULL) goto Error;
|
||||
for (p = 0; p < num_passes; ++p) {
|
||||
png_bytep row = rgb;
|
||||
for (y = 0; y < height; ++y) {
|
||||
png_bytep row = (png_bytep)(rgb + y * stride);
|
||||
png_read_rows(png, &row, NULL, 1);
|
||||
row += stride;
|
||||
}
|
||||
}
|
||||
png_read_end(png, end_info);
|
@ -9,8 +9,8 @@
|
||||
//
|
||||
// PNG decode.
|
||||
|
||||
#ifndef WEBP_EXAMPLES_PNGDEC_H_
|
||||
#define WEBP_EXAMPLES_PNGDEC_H_
|
||||
#ifndef WEBP_IMAGEIO_PNGDEC_H_
|
||||
#define WEBP_IMAGEIO_PNGDEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
@ -34,4 +34,4 @@ int ReadPNG(const uint8_t* const data, size_t data_size,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_PNGDEC_H_
|
||||
#endif // WEBP_IMAGEIO_PNGDEC_H_
|
252
imageio/pnmdec.c
Normal file
252
imageio/pnmdec.c
Normal file
@ -0,0 +1,252 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// (limited) PNM decoder
|
||||
|
||||
#include "./pnmdec.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./imageio_util.h"
|
||||
|
||||
typedef enum {
|
||||
WIDTH_FLAG = 1 << 0,
|
||||
HEIGHT_FLAG = 1 << 1,
|
||||
DEPTH_FLAG = 1 << 2,
|
||||
MAXVAL_FLAG = 1 << 3,
|
||||
TUPLE_FLAG = 1 << 4,
|
||||
ALL_NEEDED_FLAGS = 0x1f
|
||||
} PNMFlags;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
size_t data_size;
|
||||
int width, height;
|
||||
int bytes_per_px; // 1, 3, 4
|
||||
int depth;
|
||||
int max_value;
|
||||
int type; // 5, 6 or 7
|
||||
int seen_flags;
|
||||
} PNMInfo;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// PNM decoding
|
||||
|
||||
#define MAX_LINE_SIZE 1024
|
||||
static const size_t kMinPNMHeaderSize = 3;
|
||||
|
||||
static size_t ReadLine(const uint8_t* const data, size_t off, size_t data_size,
|
||||
char out[MAX_LINE_SIZE + 1], size_t* const out_size) {
|
||||
size_t i = 0;
|
||||
*out_size = 0;
|
||||
redo:
|
||||
for (i = 0; i < MAX_LINE_SIZE && off < data_size; ++i) {
|
||||
out[i] = data[off++];
|
||||
if (out[i] == '\n') break;
|
||||
}
|
||||
if (off < data_size) {
|
||||
if (i == 0) goto redo; // empty line
|
||||
if (out[0] == '#') goto redo; // skip comment
|
||||
}
|
||||
out[i] = 0; // safety sentinel
|
||||
*out_size = i;
|
||||
return off;
|
||||
}
|
||||
|
||||
static size_t FlagError(const char flag[]) {
|
||||
fprintf(stderr, "PAM header error: flags '%s' already seen.\n", flag);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// inspired from http://netpbm.sourceforge.net/doc/pam.html
|
||||
static size_t ReadPAMFields(PNMInfo* const info, size_t off) {
|
||||
char out[MAX_LINE_SIZE + 1];
|
||||
size_t out_size;
|
||||
int tmp;
|
||||
assert(info != NULL);
|
||||
while (1) {
|
||||
off = ReadLine(info->data, off, info->data_size, out, &out_size);
|
||||
if (off == 0) return 0;
|
||||
if (sscanf(out, "WIDTH %d", &tmp) == 1) {
|
||||
if (info->seen_flags & WIDTH_FLAG) return FlagError("WIDTH");
|
||||
info->seen_flags |= WIDTH_FLAG;
|
||||
info->width = tmp;
|
||||
} else if (sscanf(out, "HEIGHT %d", &tmp) == 1) {
|
||||
if (info->seen_flags & HEIGHT_FLAG) return FlagError("HEIGHT");
|
||||
info->seen_flags |= HEIGHT_FLAG;
|
||||
info->height = tmp;
|
||||
} else if (sscanf(out, "DEPTH %d", &tmp) == 1) {
|
||||
if (info->seen_flags & DEPTH_FLAG) return FlagError("DEPTH");
|
||||
info->seen_flags |= DEPTH_FLAG;
|
||||
info->depth = tmp;
|
||||
} else if (sscanf(out, "MAXVAL %d", &tmp) == 1) {
|
||||
if (info->seen_flags & MAXVAL_FLAG) return FlagError("MAXVAL");
|
||||
info->seen_flags |= MAXVAL_FLAG;
|
||||
info->max_value = tmp;
|
||||
} else if (!strcmp(out, "TUPLTYPE RGB_ALPHA")) {
|
||||
info->bytes_per_px = 4;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "TUPLTYPE RGB")) {
|
||||
info->bytes_per_px = 3;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "TUPLTYPE GRAYSCALE")) {
|
||||
info->bytes_per_px = 1;
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
} else if (!strcmp(out, "ENDHDR")) {
|
||||
break;
|
||||
} else {
|
||||
static const char kEllipsis[] = " ...";
|
||||
int i;
|
||||
if (out_size > 20) sprintf(out + 20 - strlen(kEllipsis), kEllipsis);
|
||||
for (i = 0; i < (int)strlen(out); ++i) {
|
||||
if (!isprint(out[i])) out[i] = ' ';
|
||||
}
|
||||
fprintf(stderr, "PAM header error: unrecognized entry [%s]\n", out);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (!(info->seen_flags & TUPLE_FLAG)) {
|
||||
info->seen_flags |= TUPLE_FLAG;
|
||||
info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1);
|
||||
}
|
||||
if (info->seen_flags != ALL_NEEDED_FLAGS) {
|
||||
fprintf(stderr, "PAM: incomplete header.\n");
|
||||
return 0;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
static size_t ReadHeader(PNMInfo* const info) {
|
||||
size_t off = 0;
|
||||
char out[MAX_LINE_SIZE + 1];
|
||||
size_t out_size;
|
||||
if (info == NULL) return 0;
|
||||
if (info->data == NULL || info->data_size < kMinPNMHeaderSize) return 0;
|
||||
|
||||
info->width = info->height = 0;
|
||||
info->type = -1;
|
||||
info->seen_flags = 0;
|
||||
info->bytes_per_px = 0;
|
||||
info->depth = 0;
|
||||
info->max_value = 0;
|
||||
|
||||
off = ReadLine(info->data, off, info->data_size, out, &out_size);
|
||||
if (off == 0 || sscanf(out, "P%d", &info->type) != 1) return 0;
|
||||
if (info->type == 7) {
|
||||
off = ReadPAMFields(info, off);
|
||||
} else {
|
||||
off = ReadLine(info->data, off, info->data_size, out, &out_size);
|
||||
if (off == 0 || sscanf(out, "%d %d", &info->width, &info->height) != 2) {
|
||||
return 0;
|
||||
}
|
||||
off = ReadLine(info->data, off, info->data_size, out, &out_size);
|
||||
if (off == 0 || sscanf(out, "%d", &info->max_value) != 1) return 0;
|
||||
|
||||
// finish initializing missing fields
|
||||
info->depth = (info->type == 5) ? 1 : 3;
|
||||
info->bytes_per_px = info->depth * (info->max_value > 255 ? 2 : 1);
|
||||
}
|
||||
// perform some basic numerical validation
|
||||
if (info->width <= 0 || info->height <= 0 ||
|
||||
info->type <= 0 || info->type >= 9 ||
|
||||
info->depth <= 0 || info->depth > 4 ||
|
||||
info->bytes_per_px < info->depth ||
|
||||
info->max_value <= 0 || info->max_value >= 65536) {
|
||||
return 0;
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
int ReadPNM(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic, int keep_alpha,
|
||||
struct Metadata* const metadata) {
|
||||
int ok = 0;
|
||||
int i, j;
|
||||
uint64_t stride, pixel_bytes;
|
||||
uint8_t* rgb = NULL, *tmp_rgb;
|
||||
size_t offset;
|
||||
PNMInfo info;
|
||||
|
||||
info.data = data;
|
||||
info.data_size = data_size;
|
||||
offset = ReadHeader(&info);
|
||||
if (offset == 0) {
|
||||
fprintf(stderr, "Error parsing PNM header.\n");
|
||||
goto End;
|
||||
}
|
||||
|
||||
if (info.type < 5 || info.type > 7) {
|
||||
fprintf(stderr, "Unsupported P%d PNM format.\n", info.type);
|
||||
goto End;
|
||||
}
|
||||
|
||||
// Some basic validations.
|
||||
if (pic == NULL) goto End;
|
||||
if (info.width > WEBP_MAX_DIMENSION || info.height > WEBP_MAX_DIMENSION) {
|
||||
fprintf(stderr, "Invalid %dx%d dimension for PNM\n",
|
||||
info.width, info.height);
|
||||
goto End;
|
||||
}
|
||||
|
||||
pixel_bytes = (uint64_t)info.width * info.height * info.bytes_per_px;
|
||||
if (data_size < offset + pixel_bytes) {
|
||||
fprintf(stderr, "Truncated PNM file (P%d).\n", info.type);
|
||||
goto End;
|
||||
}
|
||||
stride =
|
||||
(uint64_t)(info.bytes_per_px < 3 ? 3 : info.bytes_per_px) * info.width;
|
||||
if (stride != (size_t)stride ||
|
||||
!ImgIoUtilCheckSizeArgumentsOverflow(stride, info.height)) {
|
||||
goto End;
|
||||
}
|
||||
|
||||
rgb = (uint8_t*)malloc((size_t)stride * info.height);
|
||||
if (rgb == NULL) goto End;
|
||||
|
||||
// Convert input
|
||||
tmp_rgb = rgb;
|
||||
for (j = 0; j < info.height; ++j) {
|
||||
assert(offset + info.bytes_per_px * info.width <= data_size);
|
||||
if (info.depth == 1) {
|
||||
// convert grayscale -> RGB
|
||||
for (i = 0; i < info.width; ++i) {
|
||||
const uint8_t v = data[offset + i];
|
||||
tmp_rgb[3 * i + 0] = tmp_rgb[3 * i + 1] = tmp_rgb[3 * i + 2] = v;
|
||||
}
|
||||
} else if (info.depth == 3) { // RGB
|
||||
memcpy(tmp_rgb, data + offset, 3 * info.width * sizeof(*data));
|
||||
} else if (info.depth == 4) { // RGBA
|
||||
memcpy(tmp_rgb, data + offset, 4 * info.width * sizeof(*data));
|
||||
}
|
||||
offset += info.bytes_per_px * info.width;
|
||||
tmp_rgb += stride;
|
||||
}
|
||||
|
||||
// WebP conversion.
|
||||
pic->width = info.width;
|
||||
pic->height = info.height;
|
||||
ok = (info.depth == 4) ? WebPPictureImportRGBA(pic, rgb, (int)stride)
|
||||
: WebPPictureImportRGB(pic, rgb, (int)stride);
|
||||
if (!ok) goto End;
|
||||
|
||||
ok = 1;
|
||||
End:
|
||||
free((void*)rgb);
|
||||
|
||||
(void)metadata;
|
||||
(void)keep_alpha;
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
37
imageio/pnmdec.h
Normal file
37
imageio/pnmdec.h
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// partial PNM format decoder (ppm/pgm)
|
||||
|
||||
#ifndef WEBP_IMAGEIO_PNMDEC_H_
|
||||
#define WEBP_IMAGEIO_PNMDEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Metadata;
|
||||
struct WebPPicture;
|
||||
|
||||
// Reads a PNM file from 'data', returning the decoded output in 'pic'.
|
||||
// The output is RGB or YUV depending on pic->use_argb value.
|
||||
// Returns true on success.
|
||||
// 'metadata' has no effect, but is kept for coherence with other signatures
|
||||
// for image readers.
|
||||
int ReadPNM(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic, int keep_alpha,
|
||||
struct Metadata* const metadata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_IMAGEIO_PNMDEC_H_
|
@ -15,6 +15,7 @@
|
||||
#include "webp/config.h"
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -22,7 +23,7 @@
|
||||
#include <tiffio.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./example_util.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
static const struct {
|
||||
@ -107,7 +108,7 @@ static void MyUnmapFile(thandle_t opaque, void* base, toff_t size) {
|
||||
static tsize_t MyRead(thandle_t opaque, void* dst, tsize_t size) {
|
||||
MyData* const my_data = (MyData*)opaque;
|
||||
if (my_data->pos + size > my_data->size) {
|
||||
size = my_data->size - my_data->pos;
|
||||
size = (tsize_t)(my_data->size - my_data->pos);
|
||||
}
|
||||
if (size > 0) {
|
||||
memcpy(dst, my_data->data + my_data->pos, size);
|
||||
@ -116,19 +117,59 @@ static tsize_t MyRead(thandle_t opaque, void* dst, tsize_t size) {
|
||||
return size;
|
||||
}
|
||||
|
||||
// Unmultiply Argb data. Taken from dsp/alpha_processing
|
||||
// (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;
|
||||
return (v > 255u) ? 255u : v;
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t GetScale(uint32_t a) {
|
||||
return (255u << MFIX) / a;
|
||||
}
|
||||
|
||||
static void MultARGBRow(uint8_t* ptr, int width) {
|
||||
int x;
|
||||
for (x = 0; x < width; ++x, ptr += 4) {
|
||||
const uint32_t alpha = ptr[3];
|
||||
if (alpha < 255) {
|
||||
if (alpha == 0) { // alpha == 0
|
||||
ptr[0] = ptr[1] = ptr[2] = 0;
|
||||
} else {
|
||||
const uint32_t scale = GetScale(alpha);
|
||||
ptr[0] = Unmult(ptr[0], scale);
|
||||
ptr[1] = Unmult(ptr[1], scale);
|
||||
ptr[2] = Unmult(ptr[2], scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic, int keep_alpha,
|
||||
Metadata* const metadata) {
|
||||
MyData my_data = { data, (toff_t)data_size, 0 };
|
||||
TIFF* const tif = TIFFClientOpen("Memory", "r", &my_data,
|
||||
MyRead, MyRead, MySeek, MyClose,
|
||||
MySize, MyMapFile, MyUnmapFile);
|
||||
uint32 width, height;
|
||||
uint32* raster;
|
||||
TIFF* tif;
|
||||
uint32_t width, height;
|
||||
uint16_t samples_per_px = 0;
|
||||
uint16_t extra_samples = 0;
|
||||
uint16_t* extra_samples_ptr = NULL;
|
||||
uint32_t* raster;
|
||||
int64_t alloc_size;
|
||||
int ok = 0;
|
||||
tdir_t dircount;
|
||||
|
||||
if (data == NULL || data_size == 0 || data_size > INT_MAX || pic == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
tif = TIFFClientOpen("Memory", "r", &my_data,
|
||||
MyRead, MyRead, MySeek, MyClose,
|
||||
MySize, MyMapFile, MyUnmapFile);
|
||||
if (tif == NULL) {
|
||||
fprintf(stderr, "Error! Cannot parse TIFF file\n");
|
||||
return 0;
|
||||
@ -140,17 +181,27 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
"Only the first will be used, %d will be ignored.\n",
|
||||
dircount - 1);
|
||||
}
|
||||
if (!TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &samples_per_px)) {
|
||||
fprintf(stderr, "Error! Cannot retrieve TIFF samples-per-pixel info.\n");
|
||||
goto End;
|
||||
}
|
||||
if (samples_per_px < 3 || samples_per_px > 4) goto End; // not supported
|
||||
|
||||
if (!(TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) &&
|
||||
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height))) {
|
||||
fprintf(stderr, "Error! Cannot retrieve TIFF image dimensions.\n");
|
||||
goto End;
|
||||
}
|
||||
|
||||
if (!ImgIoUtilCheckSizeArgumentsOverflow((uint64_t)width * height,
|
||||
sizeof(*raster))) {
|
||||
goto End;
|
||||
}
|
||||
if (samples_per_px > 3 && !TIFFGetField(tif, TIFFTAG_EXTRASAMPLES,
|
||||
&extra_samples, &extra_samples_ptr)) {
|
||||
fprintf(stderr, "Error! Cannot retrieve TIFF ExtraSamples info.\n");
|
||||
goto End;
|
||||
}
|
||||
|
||||
// _Tiffmalloc uses a signed type for size.
|
||||
alloc_size = (int64_t)((uint64_t)width * height * sizeof(*raster));
|
||||
if (alloc_size < 0 || alloc_size != (tsize_t)alloc_size) goto End;
|
||||
@ -166,6 +217,16 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
TIFFSwabArrayOfLong(raster, width * height);
|
||||
#endif
|
||||
// if we have an alpha channel, we must un-multiply from rgbA to RGBA
|
||||
if (extra_samples == 1 && extra_samples_ptr != NULL &&
|
||||
extra_samples_ptr[0] == EXTRASAMPLE_ASSOCALPHA) {
|
||||
uint32_t y;
|
||||
uint8_t* tmp = (uint8_t*)raster;
|
||||
for (y = 0; y < height; ++y) {
|
||||
MultARGBRow(tmp, width);
|
||||
tmp += stride;
|
||||
}
|
||||
}
|
||||
ok = keep_alpha
|
||||
? WebPPictureImportRGBA(pic, (const uint8_t*)raster, stride)
|
||||
: WebPPictureImportRGBX(pic, (const uint8_t*)raster, stride);
|
@ -9,8 +9,8 @@
|
||||
//
|
||||
// TIFF decode.
|
||||
|
||||
#ifndef WEBP_EXAMPLES_TIFFDEC_H_
|
||||
#define WEBP_EXAMPLES_TIFFDEC_H_
|
||||
#ifndef WEBP_IMAGEIO_TIFFDEC_H_
|
||||
#define WEBP_IMAGEIO_TIFFDEC_H_
|
||||
|
||||
#include "webp/types.h"
|
||||
|
||||
@ -34,4 +34,4 @@ int ReadTIFF(const uint8_t* const data, size_t data_size,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_TIFFDEC_H_
|
||||
#endif // WEBP_IMAGEIO_TIFFDEC_H_
|
197
imageio/webpdec.c
Normal file
197
imageio/webpdec.c
Normal file
@ -0,0 +1,197 @@
|
||||
// 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// WebP decode.
|
||||
|
||||
#include "./webpdec.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "webp/decode.h"
|
||||
#include "webp/encode.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WebP decoding
|
||||
|
||||
static const char* const kStatusMessages[VP8_STATUS_NOT_ENOUGH_DATA + 1] = {
|
||||
"OK", "OUT_OF_MEMORY", "INVALID_PARAM", "BITSTREAM_ERROR",
|
||||
"UNSUPPORTED_FEATURE", "SUSPENDED", "USER_ABORT", "NOT_ENOUGH_DATA"
|
||||
};
|
||||
|
||||
static void PrintAnimationWarning(const WebPDecoderConfig* const config) {
|
||||
if (config->input.has_animation) {
|
||||
fprintf(stderr,
|
||||
"Error! Decoding of an animated WebP file is not supported.\n"
|
||||
" Use webpmux to extract the individual frames or\n"
|
||||
" vwebp to view this image.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void PrintWebPError(const char* const in_file, int status) {
|
||||
fprintf(stderr, "Decoding of %s failed.\n", in_file);
|
||||
fprintf(stderr, "Status: %d", status);
|
||||
if (status >= VP8_STATUS_OK && status <= VP8_STATUS_NOT_ENOUGH_DATA) {
|
||||
fprintf(stderr, "(%s)", kStatusMessages[status]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
int LoadWebP(const char* const in_file,
|
||||
const uint8_t** data, size_t* data_size,
|
||||
WebPBitstreamFeatures* bitstream) {
|
||||
VP8StatusCode status;
|
||||
WebPBitstreamFeatures local_features;
|
||||
if (!ImgIoUtilReadFile(in_file, data, data_size)) return 0;
|
||||
|
||||
if (bitstream == NULL) {
|
||||
bitstream = &local_features;
|
||||
}
|
||||
|
||||
status = WebPGetFeatures(*data, *data_size, bitstream);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
free((void*)*data);
|
||||
*data = NULL;
|
||||
*data_size = 0;
|
||||
PrintWebPError(in_file, status);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
VP8StatusCode DecodeWebP(const uint8_t* const data, size_t data_size,
|
||||
WebPDecoderConfig* const config) {
|
||||
if (config == NULL) return VP8_STATUS_INVALID_PARAM;
|
||||
PrintAnimationWarning(config);
|
||||
return WebPDecode(data, data_size, config);
|
||||
}
|
||||
|
||||
VP8StatusCode DecodeWebPIncremental(
|
||||
const uint8_t* const data, size_t data_size,
|
||||
WebPDecoderConfig* const config) {
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
if (config == NULL) return VP8_STATUS_INVALID_PARAM;
|
||||
|
||||
PrintAnimationWarning(config);
|
||||
|
||||
// Decoding call.
|
||||
{
|
||||
WebPIDecoder* const idec = WebPIDecode(data, data_size, config);
|
||||
if (idec == NULL) {
|
||||
fprintf(stderr, "Failed during WebPINewDecoder().\n");
|
||||
return VP8_STATUS_OUT_OF_MEMORY;
|
||||
} else {
|
||||
#ifdef WEBP_EXPERIMENTAL_FEATURES
|
||||
size_t size = 0;
|
||||
const size_t incr = 2 + (data_size / 20);
|
||||
while (size < data_size) {
|
||||
size_t next_size = size + (rand() % incr);
|
||||
if (next_size > data_size) next_size = data_size;
|
||||
status = WebPIUpdate(idec, data, next_size);
|
||||
if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) break;
|
||||
size = next_size;
|
||||
}
|
||||
#else
|
||||
status = WebPIUpdate(idec, data, data_size);
|
||||
#endif
|
||||
WebPIDelete(idec);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int ReadWebP(const uint8_t* const data, size_t data_size,
|
||||
WebPPicture* const pic,
|
||||
int keep_alpha, Metadata* const metadata) {
|
||||
int ok = 0;
|
||||
VP8StatusCode status = VP8_STATUS_OK;
|
||||
WebPDecoderConfig config;
|
||||
WebPDecBuffer* const output_buffer = &config.output;
|
||||
WebPBitstreamFeatures* const bitstream = &config.input;
|
||||
|
||||
if (data == NULL || data_size == 0 || pic == NULL) return 0;
|
||||
|
||||
// TODO(jzern): add Exif/XMP/ICC extraction.
|
||||
if (metadata != NULL) {
|
||||
fprintf(stderr, "Warning: metadata extraction from WebP is unsupported.\n");
|
||||
}
|
||||
|
||||
if (!WebPInitDecoderConfig(&config)) {
|
||||
fprintf(stderr, "Library version mismatch!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
status = WebPGetFeatures(data, data_size, bitstream);
|
||||
if (status != VP8_STATUS_OK) {
|
||||
PrintWebPError("input data", status);
|
||||
return 0;
|
||||
}
|
||||
|
||||
do {
|
||||
const int has_alpha = keep_alpha && bitstream->has_alpha;
|
||||
pic->width = bitstream->width;
|
||||
pic->height = bitstream->height;
|
||||
if (!pic->use_argb) pic->colorspace = has_alpha ? WEBP_YUV420A
|
||||
: WEBP_YUV420;
|
||||
ok = WebPPictureAlloc(pic);
|
||||
if (!ok) {
|
||||
status = VP8_STATUS_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
if (pic->use_argb) {
|
||||
output_buffer->colorspace = MODE_BGRA;
|
||||
output_buffer->u.RGBA.rgba = (uint8_t*)pic->argb;
|
||||
output_buffer->u.RGBA.stride = pic->argb_stride * sizeof(uint32_t);
|
||||
output_buffer->u.RGBA.size = output_buffer->u.RGBA.stride * pic->height;
|
||||
} else {
|
||||
output_buffer->colorspace = has_alpha ? MODE_YUVA : MODE_YUV;
|
||||
output_buffer->u.YUVA.y = pic->y;
|
||||
output_buffer->u.YUVA.u = pic->u;
|
||||
output_buffer->u.YUVA.v = pic->v;
|
||||
output_buffer->u.YUVA.a = has_alpha ? pic->a : NULL;
|
||||
output_buffer->u.YUVA.y_stride = pic->y_stride;
|
||||
output_buffer->u.YUVA.u_stride = pic->uv_stride;
|
||||
output_buffer->u.YUVA.v_stride = pic->uv_stride;
|
||||
output_buffer->u.YUVA.a_stride = has_alpha ? pic->a_stride : 0;
|
||||
output_buffer->u.YUVA.y_size = pic->height * pic->y_stride;
|
||||
output_buffer->u.YUVA.u_size = (pic->height + 1) / 2 * pic->uv_stride;
|
||||
output_buffer->u.YUVA.v_size = (pic->height + 1) / 2 * pic->uv_stride;
|
||||
output_buffer->u.YUVA.a_size = pic->height * pic->a_stride;
|
||||
}
|
||||
output_buffer->is_external_memory = 1;
|
||||
|
||||
status = DecodeWebP(data, data_size, &config);
|
||||
ok = (status == VP8_STATUS_OK);
|
||||
if (!ok) WebPPictureFree(pic);
|
||||
if (ok && !keep_alpha && pic->use_argb) {
|
||||
// Need to wipe out the alpha value, as requested.
|
||||
int x, y;
|
||||
uint32_t* argb = pic->argb;
|
||||
for (y = 0; y < pic->height; ++y) {
|
||||
for (x = 0; x < pic->width; ++x) argb[x] |= 0xff000000u;
|
||||
argb += pic->argb_stride;
|
||||
}
|
||||
}
|
||||
} while (0); // <- so we can 'break' out of the loop
|
||||
|
||||
if (status != VP8_STATUS_OK) {
|
||||
PrintWebPError("input data", status);
|
||||
}
|
||||
|
||||
WebPFreeDecBuffer(output_buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
67
imageio/webpdec.h
Normal file
67
imageio/webpdec.h
Normal file
@ -0,0 +1,67 @@
|
||||
// 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// WebP decode.
|
||||
|
||||
#ifndef WEBP_IMAGEIO_WEBPDEC_H_
|
||||
#define WEBP_IMAGEIO_WEBPDEC_H_
|
||||
|
||||
#include "webp/decode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Metadata;
|
||||
struct WebPPicture;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WebP decoding
|
||||
|
||||
// Prints an informative error message regarding decode failure of 'in_file'.
|
||||
// 'status' is treated as a VP8StatusCode and if valid will be printed as a
|
||||
// text string.
|
||||
void PrintWebPError(const char* const in_file, int status);
|
||||
|
||||
// Reads a WebP from 'in_file', returning the contents and size in 'data' and
|
||||
// 'data_size'. If not NULL, 'bitstream' is populated using WebPGetFeatures().
|
||||
// Returns true on success.
|
||||
int LoadWebP(const char* const in_file,
|
||||
const uint8_t** data, size_t* data_size,
|
||||
WebPBitstreamFeatures* bitstream);
|
||||
|
||||
// Decodes the WebP contained in 'data'.
|
||||
// 'config' is a structure previously initialized by WebPInitDecoderConfig().
|
||||
// 'config->output' should have the desired colorspace selected.
|
||||
// Returns the decoder status. On success 'config->output' will contain the
|
||||
// decoded picture.
|
||||
VP8StatusCode DecodeWebP(const uint8_t* const data, size_t data_size,
|
||||
WebPDecoderConfig* const config);
|
||||
|
||||
// Same as DecodeWebP(), but using the incremental decoder.
|
||||
VP8StatusCode DecodeWebPIncremental(
|
||||
const uint8_t* const data, size_t data_size,
|
||||
WebPDecoderConfig* const config);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Decodes a WebP contained in 'data', returning the decoded output in 'pic'.
|
||||
// Output is RGBA or YUVA, depending on pic->use_argb value.
|
||||
// If 'keep_alpha' is true and the WebP has an alpha channel, the output is RGBA
|
||||
// or YUVA. Otherwise, alpha channel is dropped and output is RGB or YUV.
|
||||
// Returns true on success.
|
||||
int ReadWebP(const uint8_t* const data, size_t data_size,
|
||||
struct WebPPicture* const pic,
|
||||
int keep_alpha, struct Metadata* const metadata);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_IMAGEIO_WEBPDEC_H_
|
@ -33,7 +33,7 @@
|
||||
#include <wincodec.h>
|
||||
|
||||
#include "webp/encode.h"
|
||||
#include "./example_util.h"
|
||||
#include "./imageio_util.h"
|
||||
#include "./metadata.h"
|
||||
|
||||
#define IFS(fn) \
|
||||
@ -88,7 +88,7 @@ static HRESULT OpenInputStream(const char* filename, IStream** stream) {
|
||||
if (!strcmp(filename, "-")) {
|
||||
const uint8_t* data = NULL;
|
||||
size_t data_size = 0;
|
||||
const int ok = ExUtilReadFile(filename, &data, &data_size);
|
||||
const int ok = ImgIoUtilReadFile(filename, &data, &data_size);
|
||||
if (ok) {
|
||||
HGLOBAL image = GlobalAlloc(GMEM_MOVEABLE, data_size);
|
||||
if (image != NULL) {
|
||||
@ -276,6 +276,8 @@ int ReadPictureWithWIC(const char* const filename,
|
||||
int has_alpha = 0;
|
||||
int64_t stride;
|
||||
|
||||
if (filename == NULL || pic == NULL) return 0;
|
||||
|
||||
IFS(CoInitialize(NULL));
|
||||
IFS(CoCreateInstance(MAKE_REFGUID(CLSID_WICImagingFactory), NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
@ -9,8 +9,8 @@
|
||||
//
|
||||
// Windows Imaging Component (WIC) decode.
|
||||
|
||||
#ifndef WEBP_EXAMPLES_WICDEC_H_
|
||||
#define WEBP_EXAMPLES_WICDEC_H_
|
||||
#ifndef WEBP_IMAGEIO_WICDEC_H_
|
||||
#define WEBP_IMAGEIO_WICDEC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -31,4 +31,4 @@ int ReadPictureWithWIC(const char* const filename,
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // WEBP_EXAMPLES_WICDEC_H_
|
||||
#endif // WEBP_IMAGEIO_WICDEC_H_
|
@ -122,8 +122,8 @@ for PLATFORM in ${PLATFORMS}; do
|
||||
export PATH=${OLDPATH}
|
||||
done
|
||||
|
||||
cp -a ${SRCDIR}/src/webp/*.h ${TARGETDIR}/Headers/
|
||||
cp -a ${SRCDIR}/src/webp/{decode,encode,types}.h ${TARGETDIR}/Headers/
|
||||
${LIPO} -create ${LIBLIST} -output ${TARGETDIR}/WebP
|
||||
|
||||
cp -a ${SRCDIR}/src/webp/*.h ${DECTARGETDIR}/Headers/
|
||||
cp -a ${SRCDIR}/src/webp/{decode,types}.h ${DECTARGETDIR}/Headers/
|
||||
${LIPO} -create ${DECLIBLIST} -output ${DECTARGETDIR}/WebPDecoder
|
||||
|
267
makefile.unix
267
makefile.unix
@ -3,7 +3,7 @@
|
||||
# It will not install the libraries system-wide, but just create the 'cwebp'
|
||||
# and 'dwebp' tools in the examples/ directory, along with the static
|
||||
# libraries 'src/libwebp.a', 'src/libwebpdecoder.a', 'src/mux/libwebpmux.a',
|
||||
# 'src/demux/libwebpdemux.a' and 'src/libwebpextras.a'.
|
||||
# 'src/demux/libwebpdemux.a' and 'extras/libwebpextras.a'.
|
||||
#
|
||||
# To build the library and examples, use:
|
||||
# make -f makefile.unix
|
||||
@ -29,6 +29,8 @@ ifeq ($(strip $(shell uname)), Darwin)
|
||||
EXTRA_LIBS += -L/opt/local/lib
|
||||
GL_LIBS = -framework GLUT -framework OpenGL
|
||||
else
|
||||
EXTRA_FLAGS += -I/usr/local/include
|
||||
EXTRA_LIBS += -L/usr/local/lib
|
||||
GL_LIBS = -lglut -lGL
|
||||
endif
|
||||
|
||||
@ -113,16 +115,16 @@ ANIM_UTIL_OBJS = \
|
||||
examples/anim_util.o \
|
||||
|
||||
DEC_OBJS = \
|
||||
src/dec/alpha.o \
|
||||
src/dec/buffer.o \
|
||||
src/dec/frame.o \
|
||||
src/dec/idec.o \
|
||||
src/dec/io.o \
|
||||
src/dec/quant.o \
|
||||
src/dec/tree.o \
|
||||
src/dec/vp8.o \
|
||||
src/dec/vp8l.o \
|
||||
src/dec/webp.o \
|
||||
src/dec/alpha_dec.o \
|
||||
src/dec/buffer_dec.o \
|
||||
src/dec/frame_dec.o \
|
||||
src/dec/idec_dec.o \
|
||||
src/dec/io_dec.o \
|
||||
src/dec/quant_dec.o \
|
||||
src/dec/tree_dec.o \
|
||||
src/dec/vp8_dec.o \
|
||||
src/dec/vp8l_dec.o \
|
||||
src/dec/webp_dec.o \
|
||||
|
||||
DEMUX_OBJS = \
|
||||
src/demux/anim_decode.o \
|
||||
@ -131,6 +133,7 @@ DEMUX_OBJS = \
|
||||
DSP_DEC_OBJS = \
|
||||
src/dsp/alpha_processing.o \
|
||||
src/dsp/alpha_processing_mips_dsp_r2.o \
|
||||
src/dsp/alpha_processing_neon.o \
|
||||
src/dsp/alpha_processing_sse2.o \
|
||||
src/dsp/alpha_processing_sse41.o \
|
||||
src/dsp/cpu.o \
|
||||
@ -144,23 +147,29 @@ DSP_DEC_OBJS = \
|
||||
src/dsp/dec_sse41.o \
|
||||
src/dsp/filters.o \
|
||||
src/dsp/filters_mips_dsp_r2.o \
|
||||
src/dsp/filters_msa.o \
|
||||
src/dsp/filters_neon.o \
|
||||
src/dsp/filters_sse2.o \
|
||||
src/dsp/lossless.o \
|
||||
src/dsp/lossless_mips_dsp_r2.o \
|
||||
src/dsp/lossless_msa.o \
|
||||
src/dsp/lossless_neon.o \
|
||||
src/dsp/lossless_sse2.o \
|
||||
src/dsp/rescaler.o \
|
||||
src/dsp/rescaler_mips32.o \
|
||||
src/dsp/rescaler_mips_dsp_r2.o \
|
||||
src/dsp/rescaler_msa.o \
|
||||
src/dsp/rescaler_neon.o \
|
||||
src/dsp/rescaler_sse2.o \
|
||||
src/dsp/upsampling.o \
|
||||
src/dsp/upsampling_mips_dsp_r2.o \
|
||||
src/dsp/upsampling_msa.o \
|
||||
src/dsp/upsampling_neon.o \
|
||||
src/dsp/upsampling_sse2.o \
|
||||
src/dsp/yuv.o \
|
||||
src/dsp/yuv_mips32.o \
|
||||
src/dsp/yuv_mips_dsp_r2.o \
|
||||
src/dsp/yuv_neon.o \
|
||||
src/dsp/yuv_sse2.o \
|
||||
|
||||
DSP_ENC_OBJS = \
|
||||
@ -175,47 +184,57 @@ DSP_ENC_OBJS = \
|
||||
src/dsp/enc_avx2.o \
|
||||
src/dsp/enc_mips32.o \
|
||||
src/dsp/enc_mips_dsp_r2.o \
|
||||
src/dsp/enc_msa.o \
|
||||
src/dsp/enc_neon.o \
|
||||
src/dsp/enc_sse2.o \
|
||||
src/dsp/enc_sse41.o \
|
||||
src/dsp/lossless_enc.o \
|
||||
src/dsp/lossless_enc_mips32.o \
|
||||
src/dsp/lossless_enc_mips_dsp_r2.o \
|
||||
src/dsp/lossless_enc_msa.o \
|
||||
src/dsp/lossless_enc_neon.o \
|
||||
src/dsp/lossless_enc_sse2.o \
|
||||
src/dsp/lossless_enc_sse41.o \
|
||||
src/dsp/ssim.o \
|
||||
src/dsp/ssim_sse2.o \
|
||||
|
||||
ENC_OBJS = \
|
||||
src/enc/alpha.o \
|
||||
src/enc/analysis.o \
|
||||
src/enc/backward_references.o \
|
||||
src/enc/config.o \
|
||||
src/enc/cost.o \
|
||||
src/enc/delta_palettization.o \
|
||||
src/enc/filter.o \
|
||||
src/enc/frame.o \
|
||||
src/enc/histogram.o \
|
||||
src/enc/iterator.o \
|
||||
src/enc/near_lossless.o \
|
||||
src/enc/picture.o \
|
||||
src/enc/picture_csp.o \
|
||||
src/enc/picture_psnr.o \
|
||||
src/enc/picture_rescale.o \
|
||||
src/enc/picture_tools.o \
|
||||
src/enc/quant.o \
|
||||
src/enc/syntax.o \
|
||||
src/enc/token.o \
|
||||
src/enc/tree.o \
|
||||
src/enc/vp8l.o \
|
||||
src/enc/webpenc.o \
|
||||
src/enc/alpha_enc.o \
|
||||
src/enc/analysis_enc.o \
|
||||
src/enc/backward_references_cost_enc.o \
|
||||
src/enc/backward_references_enc.o \
|
||||
src/enc/config_enc.o \
|
||||
src/enc/cost_enc.o \
|
||||
src/enc/delta_palettization_enc.o \
|
||||
src/enc/filter_enc.o \
|
||||
src/enc/frame_enc.o \
|
||||
src/enc/histogram_enc.o \
|
||||
src/enc/iterator_enc.o \
|
||||
src/enc/near_lossless_enc.o \
|
||||
src/enc/picture_enc.o \
|
||||
src/enc/picture_csp_enc.o \
|
||||
src/enc/picture_psnr_enc.o \
|
||||
src/enc/picture_rescale_enc.o \
|
||||
src/enc/picture_tools_enc.o \
|
||||
src/enc/predictor_enc.o \
|
||||
src/enc/quant_enc.o \
|
||||
src/enc/syntax_enc.o \
|
||||
src/enc/token_enc.o \
|
||||
src/enc/tree_enc.o \
|
||||
src/enc/vp8l_enc.o \
|
||||
src/enc/webp_enc.o \
|
||||
|
||||
EX_FORMAT_DEC_OBJS = \
|
||||
examples/image_dec.o \
|
||||
examples/jpegdec.o \
|
||||
examples/metadata.o \
|
||||
examples/pngdec.o \
|
||||
examples/tiffdec.o \
|
||||
examples/webpdec.o \
|
||||
imageio/image_dec.o \
|
||||
imageio/jpegdec.o \
|
||||
imageio/metadata.o \
|
||||
imageio/pngdec.o \
|
||||
imageio/pnmdec.o \
|
||||
imageio/tiffdec.o \
|
||||
imageio/webpdec.o \
|
||||
|
||||
EX_FORMAT_ENC_OBJS = \
|
||||
imageio/image_enc.o \
|
||||
|
||||
EX_UTIL_OBJS = \
|
||||
examples/example_util.o \
|
||||
@ -223,6 +242,9 @@ EX_UTIL_OBJS = \
|
||||
GIFDEC_OBJS = \
|
||||
examples/gifdec.o \
|
||||
|
||||
IMAGE_UTIL_OBJS = \
|
||||
imageio/imageio_util.o \
|
||||
|
||||
MUX_OBJS = \
|
||||
src/mux/anim_encode.o \
|
||||
src/mux/muxedit.o \
|
||||
@ -230,23 +252,24 @@ MUX_OBJS = \
|
||||
src/mux/muxread.o \
|
||||
|
||||
UTILS_DEC_OBJS = \
|
||||
src/utils/bit_reader.o \
|
||||
src/utils/color_cache.o \
|
||||
src/utils/filters.o \
|
||||
src/utils/huffman.o \
|
||||
src/utils/quant_levels_dec.o \
|
||||
src/utils/random.o \
|
||||
src/utils/rescaler.o \
|
||||
src/utils/thread.o \
|
||||
src/utils/bit_reader_utils.o \
|
||||
src/utils/color_cache_utils.o \
|
||||
src/utils/filters_utils.o \
|
||||
src/utils/huffman_utils.o \
|
||||
src/utils/quant_levels_dec_utils.o \
|
||||
src/utils/random_utils.o \
|
||||
src/utils/rescaler_utils.o \
|
||||
src/utils/thread_utils.o \
|
||||
src/utils/utils.o \
|
||||
|
||||
UTILS_ENC_OBJS = \
|
||||
src/utils/bit_writer.o \
|
||||
src/utils/huffman_encode.o \
|
||||
src/utils/quant_levels.o \
|
||||
src/utils/bit_writer_utils.o \
|
||||
src/utils/huffman_encode_utils.o \
|
||||
src/utils/quant_levels_utils.o \
|
||||
|
||||
EXTRA_OBJS = \
|
||||
src/extras/extras.o \
|
||||
extras/extras.o \
|
||||
extras/quality_estimate.o \
|
||||
|
||||
LIBWEBPDECODER_OBJS = $(DEC_OBJS) $(DSP_DEC_OBJS) $(UTILS_DEC_OBJS)
|
||||
LIBWEBP_OBJS = $(LIBWEBPDECODER_OBJS) $(ENC_OBJS) $(DSP_ENC_OBJS) \
|
||||
@ -264,82 +287,95 @@ HDRS_INSTALLED = \
|
||||
src/webp/types.h \
|
||||
|
||||
HDRS = \
|
||||
src/dec/alphai.h \
|
||||
src/dec/common.h \
|
||||
src/dec/decode_vp8.h \
|
||||
src/dec/vp8i.h \
|
||||
src/dec/vp8li.h \
|
||||
src/dec/webpi.h \
|
||||
src/dec/alphai_dec.h \
|
||||
src/dec/common_dec.h \
|
||||
src/dec/vp8_dec.h \
|
||||
src/dec/vp8i_dec.h \
|
||||
src/dec/vp8li_dec.h \
|
||||
src/dec/webpi_dec.h \
|
||||
src/dsp/common_sse2.h \
|
||||
src/dsp/dsp.h \
|
||||
src/dsp/lossless.h \
|
||||
src/dsp/lossless_common.h \
|
||||
src/dsp/mips_macro.h \
|
||||
src/dsp/msa_macro.h \
|
||||
src/dsp/neon.h \
|
||||
src/dsp/yuv.h \
|
||||
src/enc/backward_references.h \
|
||||
src/enc/cost.h \
|
||||
src/enc/delta_palettization.h \
|
||||
src/enc/histogram.h \
|
||||
src/enc/vp8enci.h \
|
||||
src/enc/vp8li.h \
|
||||
src/enc/backward_references_enc.h \
|
||||
src/enc/cost_enc.h \
|
||||
src/enc/delta_palettization_enc.h \
|
||||
src/enc/histogram_enc.h \
|
||||
src/enc/vp8i_enc.h \
|
||||
src/enc/vp8li_enc.h \
|
||||
src/mux/animi.h \
|
||||
src/mux/muxi.h \
|
||||
src/utils/bit_reader.h \
|
||||
src/utils/bit_reader_inl.h \
|
||||
src/utils/bit_writer.h \
|
||||
src/utils/color_cache.h \
|
||||
src/utils/endian_inl.h \
|
||||
src/utils/filters.h \
|
||||
src/utils/huffman.h \
|
||||
src/utils/huffman_encode.h \
|
||||
src/utils/quant_levels.h \
|
||||
src/utils/quant_levels_dec.h \
|
||||
src/utils/random.h \
|
||||
src/utils/rescaler.h \
|
||||
src/utils/thread.h \
|
||||
src/utils/bit_reader_utils.h \
|
||||
src/utils/bit_reader_inl_utils.h \
|
||||
src/utils/bit_writer_utils.h \
|
||||
src/utils/color_cache_utils.h \
|
||||
src/utils/endian_inl_utils.h \
|
||||
src/utils/filters_utils.h \
|
||||
src/utils/huffman_utils.h \
|
||||
src/utils/huffman_encode_utils.h \
|
||||
src/utils/quant_levels_utils.h \
|
||||
src/utils/quant_levels_dec_utils.h \
|
||||
src/utils/random_utils.h \
|
||||
src/utils/rescaler_utils.h \
|
||||
src/utils/thread_utils.h \
|
||||
src/utils/utils.h \
|
||||
src/webp/format_constants.h \
|
||||
$(HDRS_INSTALLED) \
|
||||
|
||||
OUT_LIBS = examples/libexample_util.a src/libwebpdecoder.a src/libwebp.a
|
||||
EXTRA_LIB = src/libwebpextras.a
|
||||
OUT_LIBS = examples/libexample_util.a
|
||||
OUT_LIBS += imageio/libimageio_util.a
|
||||
OUT_LIBS += imageio/libimagedec.a
|
||||
OUT_LIBS += imageio/libimageenc.a
|
||||
OUT_LIBS += src/libwebpdecoder.a
|
||||
OUT_LIBS += src/libwebp.a
|
||||
EXTRA_LIB = extras/libwebpextras.a
|
||||
OUT_EXAMPLES = examples/cwebp examples/dwebp
|
||||
EXTRA_EXAMPLES = examples/gif2webp examples/vwebp examples/webpmux \
|
||||
examples/anim_diff
|
||||
examples/anim_diff examples/img2webp examples/webpinfo
|
||||
OTHER_EXAMPLES = extras/get_disto extras/webp_quality extras/vwebp_sdl
|
||||
|
||||
OUTPUT = $(OUT_LIBS) $(OUT_EXAMPLES)
|
||||
ifeq ($(MAKECMDGOALS),clean)
|
||||
OUTPUT += $(EXTRA_EXAMPLES)
|
||||
OUTPUT += $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES)
|
||||
OUTPUT += src/demux/libwebpdemux.a src/mux/libwebpmux.a $(EXTRA_LIB)
|
||||
OUTPUT += examples/libgifdec.a examples/libanim_util.a
|
||||
endif
|
||||
|
||||
ex: $(OUT_EXAMPLES)
|
||||
all: ex $(EXTRA_EXAMPLES)
|
||||
all: ex $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES)
|
||||
extras: $(EXTRA_LIB)
|
||||
|
||||
$(EX_FORMAT_DEC_OBJS): %.o: %.h
|
||||
|
||||
# special dependencies:
|
||||
# tree.c/vp8.c/bit_reader.c <-> bit_reader_inl.h, endian_inl.h
|
||||
# bit_writer.c <-> endian_inl.h
|
||||
src/dec/tree.o: src/utils/bit_reader_inl.h src/utils/endian_inl.h
|
||||
src/dec/vp8.o: src/utils/bit_reader_inl.h src/utils/endian_inl.h
|
||||
src/utils/bit_reader.o: src/utils/bit_reader_inl.h src/utils/endian_inl.h
|
||||
src/utils/bit_writer.o: src/utils/endian_inl.h
|
||||
# tree_dec.c/vp8_dec.c/bit_reader_utils.c <->
|
||||
# bit_reader_inl_utils.h, endian_inl_utils.h
|
||||
# bit_writer_utils.c <-> endian_inl_utils.h
|
||||
src/dec/tree_dec.o: src/utils/bit_reader_inl_utils.h
|
||||
src/dec/tree_dec.o: src/utils/endian_inl_utils.h
|
||||
src/dec/vp8_dec.o: src/utils/bit_reader_inl_utils.h src/utils/endian_inl_utils.h
|
||||
src/utils/bit_reader_utils.o: src/utils/bit_reader_inl_utils.h
|
||||
src/utils/bit_reader_utils.o: src/utils/endian_inl_utils.h
|
||||
src/utils/bit_writer_utils.o: src/utils/endian_inl_utils.h
|
||||
|
||||
%.o: %.c $(HDRS)
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
examples/libanim_util.a: $(ANIM_UTIL_OBJS)
|
||||
examples/libexample_dec.a: $(EX_FORMAT_DEC_OBJS)
|
||||
examples/libexample_util.a: $(EX_UTIL_OBJS)
|
||||
examples/libgifdec.a: $(GIFDEC_OBJS)
|
||||
extras/libwebpextras.a: $(LIBWEBPEXTRA_OBJS)
|
||||
imageio/libimagedec.a: $(EX_FORMAT_DEC_OBJS)
|
||||
imageio/libimageenc.a: $(EX_FORMAT_ENC_OBJS)
|
||||
imageio/libimageio_util.a: $(IMAGE_UTIL_OBJS)
|
||||
src/libwebpdecoder.a: $(LIBWEBPDECODER_OBJS)
|
||||
src/libwebp.a: $(LIBWEBP_OBJS)
|
||||
src/mux/libwebpmux.a: $(LIBWEBPMUX_OBJS)
|
||||
src/demux/libwebpdemux.a: $(LIBWEBPDEMUX_OBJS)
|
||||
src/libwebpextras.a: $(LIBWEBPEXTRA_OBJS)
|
||||
|
||||
%.a:
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
@ -350,29 +386,58 @@ examples/dwebp: examples/dwebp.o
|
||||
examples/gif2webp: examples/gif2webp.o $(GIFDEC_OBJS)
|
||||
examples/vwebp: examples/vwebp.o
|
||||
examples/webpmux: examples/webpmux.o
|
||||
examples/img2webp: examples/img2webp.o
|
||||
examples/webpinfo: examples/webpinfo.o
|
||||
|
||||
examples/anim_diff: examples/libanim_util.a examples/libgifdec.a
|
||||
examples/anim_diff: src/demux/libwebpdemux.a examples/libexample_util.a
|
||||
examples/anim_diff: src/libwebp.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/cwebp: examples/libexample_util.a examples/libexample_dec.a
|
||||
examples/cwebp: examples/libexample_util.a
|
||||
examples/cwebp: imageio/libimagedec.a
|
||||
examples/cwebp: imageio/libimageio_util.a
|
||||
examples/cwebp: src/libwebp.a
|
||||
examples/cwebp: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||
examples/dwebp: examples/libexample_util.a src/libwebpdecoder.a
|
||||
examples/dwebp: examples/libexample_util.a
|
||||
examples/dwebp: imageio/libimagedec.a
|
||||
examples/dwebp: imageio/libimageenc.a
|
||||
examples/dwebp: imageio/libimageio_util.a
|
||||
examples/dwebp: src/libwebp.a
|
||||
examples/dwebp: EXTRA_LIBS += $(DWEBP_LIBS)
|
||||
examples/gif2webp: examples/libexample_util.a examples/libgifdec.a
|
||||
examples/gif2webp: src/mux/libwebpmux.a src/libwebp.a
|
||||
examples/gif2webp: examples/libexample_util.a imageio/libimageio_util.a
|
||||
examples/gif2webp: examples/libgifdec.a src/mux/libwebpmux.a src/libwebp.a
|
||||
examples/gif2webp: EXTRA_LIBS += $(GIF_LIBS)
|
||||
examples/gif2webp: EXTRA_FLAGS += -DWEBP_HAVE_GIF
|
||||
examples/vwebp: examples/libexample_util.a src/demux/libwebpdemux.a
|
||||
examples/vwebp: src/libwebp.a
|
||||
examples/vwebp: imageio/libimageio_util.a src/libwebp.a
|
||||
examples/vwebp: EXTRA_LIBS += $(GL_LIBS)
|
||||
examples/vwebp: EXTRA_FLAGS += -DWEBP_HAVE_GL
|
||||
examples/webpmux: examples/libexample_util.a src/mux/libwebpmux.a
|
||||
examples/webpmux: src/libwebpdecoder.a
|
||||
examples/webpmux: examples/libexample_util.a imageio/libimageio_util.a
|
||||
examples/webpmux: src/mux/libwebpmux.a src/libwebpdecoder.a
|
||||
examples/img2webp: examples/libexample_util.a imageio/libimageio_util.a
|
||||
examples/img2webp: imageio/libimagedec.a
|
||||
examples/img2webp: src/mux/libwebpmux.a src/libwebp.a
|
||||
examples/img2webp: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||
examples/webpinfo: examples/libexample_util.a imageio/libimageio_util.a
|
||||
examples/webpinfo: src/libwebpdecoder.a
|
||||
|
||||
$(OUT_EXAMPLES) $(EXTRA_EXAMPLES):
|
||||
extras/get_disto: extras/get_disto.o
|
||||
extras/get_disto: imageio/libimagedec.a imageio/libimageio_util.a src/libwebp.a
|
||||
extras/get_disto: EXTRA_LIBS += $(CWEBP_LIBS)
|
||||
|
||||
extras/webp_quality: extras/webp_quality.o
|
||||
extras/webp_quality: imageio/libimageio_util.a
|
||||
extras/webp_quality: $(EXTRA_LIB) src/libwebp.a
|
||||
|
||||
extras/vwebp_sdl: extras/vwebp_sdl.o
|
||||
extras/vwebp_sdl: extras/webp_to_sdl.o
|
||||
extras/vwebp_sdl: imageio/libimageio_util.a
|
||||
extras/vwebp_sdl: src/libwebp.a
|
||||
extras/vwebp_sdl: EXTRA_FLAGS += -DWEBP_HAVE_SDL
|
||||
extras/vwebp_sdl: EXTRA_LIBS += -lSDL
|
||||
|
||||
$(OUT_EXAMPLES) $(EXTRA_EXAMPLES) $(OTHER_EXAMPLES):
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
dist: DESTDIR := dist
|
||||
@ -386,7 +451,8 @@ dist: all
|
||||
$(INSTALL) -m644 src/demux/libwebpdemux.a $(DESTDIR)/lib
|
||||
$(INSTALL) -m644 src/mux/libwebpmux.a $(DESTDIR)/lib
|
||||
umask 022; \
|
||||
for m in man/[cdv]webp.1 man/gif2webp.1 man/webpmux.1; do \
|
||||
for m in man/[cdv]webp.1 man/gif2webp.1 man/webpmux.1 \
|
||||
man/img2webp.1 man/webpinfo.1; do \
|
||||
basenam=$$(basename $$m .1); \
|
||||
$(GROFF) -t -e -man -T utf8 $$m \
|
||||
| $(COL) -bx >$(DESTDIR)/doc/$${basenam}.txt; \
|
||||
@ -397,11 +463,12 @@ dist: all
|
||||
clean:
|
||||
$(RM) $(OUTPUT) *~ \
|
||||
examples/*.o examples/*~ \
|
||||
extras/*.o extras/*~ \
|
||||
imageio/*.o imageio/*~ \
|
||||
src/dec/*.o src/dec/*~ \
|
||||
src/demux/*.o src/demux/*~ \
|
||||
src/dsp/*.o src/dsp/*~ \
|
||||
src/enc/*.o src/enc/*~ \
|
||||
src/extras/*.o src/extras/*~ \
|
||||
src/mux/*.o src/mux/*~ \
|
||||
src/utils/*.o src/utils/*~ \
|
||||
src/webp/*~ man/*~ doc/*~ swig/*~ \
|
||||
|
@ -8,4 +8,7 @@ endif
|
||||
if BUILD_VWEBP
|
||||
man_MANS += vwebp.1
|
||||
endif
|
||||
if BUILD_WEBPINFO
|
||||
man_MANS += webpinfo.1
|
||||
endif
|
||||
EXTRA_DIST = $(man_MANS)
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH CWEBP 1 "September 02, 2016"
|
||||
.TH CWEBP 1 "January 20, 2017"
|
||||
.SH NAME
|
||||
cwebp \- compress an image file to a WebP file
|
||||
.SH SYNOPSIS
|
||||
@ -98,8 +98,7 @@ Crop the source to a rectangle with top\-left corner at coordinates
|
||||
This cropping area must be fully contained within the source rectangle.
|
||||
.TP
|
||||
.B \-mt
|
||||
Use multi\-threading for encoding, if possible. This option is only effective
|
||||
when using lossy compression on a source with a transparency channel.
|
||||
Use multi\-threading for encoding, if possible.
|
||||
.TP
|
||||
.B \-low_memory
|
||||
Reduce memory usage of lossy encoding by saving four times the compressed
|
||||
@ -166,6 +165,10 @@ Use strong filtering (if filtering is being used thanks to the
|
||||
Disable strong filtering (if filtering is being used thanks to the
|
||||
\fB\-f\fP option) and use simple filtering instead.
|
||||
.TP
|
||||
.B \-sharp_yuv
|
||||
Use more accurate and sharper RGB->YUV conversion if needed. Note that this
|
||||
process is slower than the default 'fast' RGB->YUV conversion.
|
||||
.TP
|
||||
.BI \-sns " int
|
||||
Specify the amplitude of the spatial noise shaping. Spatial noise shaping
|
||||
(or \fBsns\fP for short) refers to a general collection of built\-in algorithms
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH GIF2WEBP 1 "June 23, 2016"
|
||||
.TH GIF2WEBP 1 "January 25, 2017"
|
||||
.SH NAME
|
||||
gif2webp \- Convert a GIF image to WebP
|
||||
.SH SYNOPSIS
|
||||
@ -68,8 +68,9 @@ Specify the minimum and maximum distance between consecutive key frames
|
||||
some key frames into the output animation as needed so that this criteria is
|
||||
satisfied.
|
||||
.br
|
||||
A 'kmin' value of 0 will turn off insertion of key frames. A 'kmax' value of 0
|
||||
will result in all frames being key frames.
|
||||
A 'kmax' value of 0 will turn off insertion of key frames. A 'kmax' value of 1
|
||||
will result in all frames being key frames. 'kmin' value is not taken into
|
||||
account in both these special cases.
|
||||
Typical values are in the range 3 to 30. Default values are kmin = 9,
|
||||
kmax = 17 for lossless compression and kmin = 3, kmax = 5 for lossy compression.
|
||||
.br
|
||||
@ -107,8 +108,7 @@ the value the smoother the picture will appear. Typical values are usually in
|
||||
the range of 20 to 50.
|
||||
.TP
|
||||
.B \-mt
|
||||
Use multi-threading for encoding, if possible. This option is only effective
|
||||
when using lossy compression.
|
||||
Use multi-threading for encoding, if possible.
|
||||
.TP
|
||||
.B \-v
|
||||
Print extra information.
|
||||
|
97
man/img2webp.1
Normal file
97
man/img2webp.1
Normal file
@ -0,0 +1,97 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH IMG2WEBP 1 "January 23, 2017"
|
||||
.SH NAME
|
||||
img2webp \- create animated WebP file from a sequence of input images.
|
||||
.SH SYNOPSIS
|
||||
.B img2webp
|
||||
[file_level_options] [files] [per_frame_options...]
|
||||
.br
|
||||
.SH DESCRIPTION
|
||||
This manual page documents the
|
||||
.B img2webp
|
||||
command.
|
||||
.PP
|
||||
\fBimg2webp\fP compresses a sequence of images using the animated WebP format.
|
||||
Input images can either be PNG, JPEG, TIFF or WebP.
|
||||
.SH FILE-LEVEL OPTIONS
|
||||
The file-level options are applied at the beginning of the compression process,
|
||||
before the input frames are read.
|
||||
.TP
|
||||
.BI \-o " string
|
||||
Specify the name of the output WebP file.
|
||||
.TP
|
||||
.BI \-min_size
|
||||
Encode images to achieve smallest size. This disables key frame insertion and
|
||||
picks the parameters resulting in smallest output for each frame. It uses
|
||||
lossless compression by default, but can be combined with \-q, \-m, \-lossy or
|
||||
\-mixed options.
|
||||
.TP
|
||||
.BI \-kmin " int
|
||||
.TP
|
||||
.BI \-kmax " int
|
||||
Specify the minimum and maximum distance between consecutive key frames
|
||||
(independently decodable frames) in the output animation. The tool will insert
|
||||
some key frames into the output animation as needed so that this criteria is
|
||||
satisfied.
|
||||
.br
|
||||
.B \-mixed
|
||||
Mixed compression mode: optimize compression of the image by picking either
|
||||
lossy or lossless compression for each frame heuristically. This global
|
||||
option disables the local option \fB-lossy\fP and \fB-lossless\fP .
|
||||
.TP
|
||||
.BI \-loop " int
|
||||
Specifies the number of times the animation should loop. Using '0' means
|
||||
'loop indefinitely'.
|
||||
.TP
|
||||
.BI \-v
|
||||
Be more verbose.
|
||||
.TP
|
||||
.B \-h, \-help
|
||||
A short usage summary.
|
||||
|
||||
.SH PER-FRAME OPTIONS
|
||||
The per-frame options are applied for the images following as arguments in the
|
||||
command line. They can be modified any number of times preceding each particular
|
||||
input image.
|
||||
.TP
|
||||
.BI \-d " int
|
||||
Specify the image duration in milliseconds.
|
||||
.TP
|
||||
.B \-lossless, \-lossy
|
||||
Compress the next image(s) using lossless or lossy compression mode. The
|
||||
default mode is lossless.
|
||||
.TP
|
||||
.BI \-q " float
|
||||
Specify the compression factor between 0 and 100. The default is 75.
|
||||
.TP
|
||||
.BI \-m " int
|
||||
Specify the compression method to use. This parameter controls the
|
||||
trade off between encoding speed and the compressed file size and quality.
|
||||
Possible values range from 0 to 6. Default value is 4.
|
||||
|
||||
.SH EXAMPLE
|
||||
img2webp -loop 2 in0.png -lossy in1.jpg -d 80 in2.tiff -o out.webp
|
||||
.br
|
||||
|
||||
.SH BUGS
|
||||
Please report all bugs to the issue tracker:
|
||||
https://bugs.chromium.org/p/webp
|
||||
.br
|
||||
Patches welcome! See this page to get started:
|
||||
http://www.webmproject.org/code/contribute/submitting\-patches/
|
||||
|
||||
.SH AUTHORS
|
||||
\fBimg2webp\fP is a part of libwebp and was written by the WebP team.
|
||||
.br
|
||||
The latest source tree is available at
|
||||
https://chromium.googlesource.com/webm/libwebp
|
||||
.PP
|
||||
This manual page was written by Pascal Massimino <pascal.massimino@gmail.com>,
|
||||
for the Debian project (and may be used by others).
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR webpmux (1),
|
||||
.BR gif2webp (1)
|
||||
.br
|
||||
Please refer to http://developers.google.com/speed/webp/ for additional
|
||||
information.
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH VWEBP 1 "June 23, 2016"
|
||||
.TH VWEBP 1 "November 25, 2016"
|
||||
.SH NAME
|
||||
vwebp \- decompress a WebP file and display it in a window
|
||||
.SH SYNOPSIS
|
||||
@ -59,6 +59,9 @@ Toggle use of color profile.
|
||||
.B 'i'
|
||||
Overlay file information.
|
||||
.TP
|
||||
.B 'd'
|
||||
Disable blending and disposal process, for debugging purposes.
|
||||
.TP
|
||||
.B 'q' / 'Q' / ESC
|
||||
Quit.
|
||||
|
||||
|
77
man/webpinfo.1
Normal file
77
man/webpinfo.1
Normal file
@ -0,0 +1,77 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH WEBPINFO 1 "May 08, 2017"
|
||||
.SH NAME
|
||||
webpinfo \- print out the chunk level structure of WebP files
|
||||
along with basic integrity checks.
|
||||
.SH SYNOPSIS
|
||||
.B webpinfo
|
||||
.I OPTIONS
|
||||
.I INPUT
|
||||
.br
|
||||
.B webpinfo [\-h|\-help|\-H|\-longhelp]
|
||||
.br
|
||||
|
||||
.SH DESCRIPTION
|
||||
This manual page documents the
|
||||
.B webpinfo
|
||||
command.
|
||||
.PP
|
||||
\fBwebpinfo\fP can be used to print out the chunk level structure and bitstream
|
||||
header information of WebP files. It can also check if the files are of valid
|
||||
WebP format.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B -quiet
|
||||
Do not show chunk parsing information.
|
||||
.TP
|
||||
.B -diag
|
||||
Show parsing error diagnosis.
|
||||
.TP
|
||||
.B -summary
|
||||
Show chunk stats summary.
|
||||
.TP
|
||||
.BI -bitstream_info
|
||||
Parse bitstream header.
|
||||
.TP
|
||||
.B \-h, \-help
|
||||
A short usage summary.
|
||||
.TP
|
||||
.B \-H, \-longhelp
|
||||
Detailed usage instructions.
|
||||
|
||||
.SH INPUT
|
||||
Input files in WebP format. Input files must come last, following
|
||||
options (if any). There can be multiple input files.
|
||||
|
||||
.SH BUGS
|
||||
Please report all bugs to the issue tracker:
|
||||
https://bugs.chromium.org/p/webp
|
||||
.br
|
||||
Patches welcome! See this page to get started:
|
||||
http://www.webmproject.org/code/contribute/submitting\-patches/
|
||||
|
||||
.SH EXAMPLES
|
||||
.br
|
||||
webpinfo \-h
|
||||
.br
|
||||
webpinfo \-diag \-summary input_file.webp
|
||||
.br
|
||||
webpinfo \-bitstream_info input_file_1.webp input_file_2.webp
|
||||
.br
|
||||
webpinfo *.webp
|
||||
|
||||
.SH AUTHORS
|
||||
\fBwebpinfo\fP is a part of libwebp and was written by the WebP team.
|
||||
.br
|
||||
The latest source tree is available at
|
||||
https://chromium.googlesource.com/webm/libwebp
|
||||
.PP
|
||||
This manual page was written by Hui Su <huisu@google.com>,
|
||||
for the Debian project (and may be used by others).
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR webpmux (1)
|
||||
.br
|
||||
Please refer to http://developers.google.com/speed/webp/ for additional
|
||||
information.
|
@ -1,5 +1,5 @@
|
||||
.\" Hey, EMACS: -*- nroff -*-
|
||||
.TH WEBPMUX 1 "June 23, 2016"
|
||||
.TH WEBPMUX 1 "November 10, 2016"
|
||||
.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.
|
||||
@ -35,6 +35,13 @@ frames from animated WebP images, and manage XMP/EXIF metadata and ICC profile.
|
||||
.I OUTPUT
|
||||
.RE
|
||||
.br
|
||||
.B webpmux \-duration
|
||||
.I DURATION OPTIONS
|
||||
.B [ \-duration ... ]
|
||||
.I INPUT
|
||||
.B \-o
|
||||
.I OUTPUT
|
||||
.br
|
||||
.B webpmux \-info
|
||||
.I INPUT
|
||||
.br
|
||||
@ -91,6 +98,42 @@ Strip EXIF metadata.
|
||||
.B xmp
|
||||
Strip XMP metadata.
|
||||
|
||||
.SS DURATION_OPTIONS (\-duration)
|
||||
Amend the duration of a specific interval of frames. This option is only
|
||||
effective on animated WebP and has no effect on a single-frame file.
|
||||
.TP
|
||||
.I duration[,start[,end]]
|
||||
Where:
|
||||
.br
|
||||
.B duration
|
||||
is the duration for the interval in milliseconds (mandatory).
|
||||
Must be non-negative.
|
||||
.br
|
||||
.B start
|
||||
is the starting frame index of the interval (optional).
|
||||
.br
|
||||
.B end
|
||||
is the ending frame index (inclusive) of the interval (optional).
|
||||
.TP
|
||||
The three typical usages of this option are:
|
||||
.br
|
||||
.B -duration d
|
||||
set the duration to 'd' for the whole animation.
|
||||
.br
|
||||
.B -duration d,f
|
||||
set the duration of frame 'f' to 'd'.
|
||||
.br
|
||||
.B -duration d,start,end
|
||||
set the duration to 'd' for the whole [start,end] interval.
|
||||
.TP
|
||||
.P
|
||||
Note that the frames outside of the [start, end] interval will remain untouched.
|
||||
The 'end' value '0' has the special meaning 'last frame of the animation'.
|
||||
.TP
|
||||
.I Reminder:
|
||||
frame indexing starts at '1'.
|
||||
.br
|
||||
|
||||
.SS FRAME_OPTIONS (\-frame)
|
||||
Create an animated WebP file from multiple (non\-animated) WebP images.
|
||||
.TP
|
||||
|
@ -1,4 +1,4 @@
|
||||
# The mux, demux and extras libraries depend on libwebp, thus the '.' to force
|
||||
# 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
|
||||
@ -7,9 +7,6 @@ endif
|
||||
if WANT_DEMUX
|
||||
SUBDIRS += demux
|
||||
endif
|
||||
if WANT_EXTRAS
|
||||
SUBDIRS += extras
|
||||
endif
|
||||
|
||||
lib_LTLIBRARIES = libwebp.la
|
||||
|
||||
@ -38,7 +35,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 6:2:0
|
||||
libwebp_la_LDFLAGS = -no-undefined -version-info 7:0:0
|
||||
libwebpincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebp.pc
|
||||
|
||||
@ -50,7 +47,7 @@ if BUILD_LIBWEBPDECODER
|
||||
libwebpdecoder_la_LIBADD += dsp/libwebpdspdecode.la
|
||||
libwebpdecoder_la_LIBADD += utils/libwebputilsdecode.la
|
||||
|
||||
libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 2:2:0
|
||||
libwebpdecoder_la_LDFLAGS = -no-undefined -version-info 3:0:0
|
||||
pkgconfig_DATA += libwebpdecoder.pc
|
||||
endif
|
||||
|
||||
|
@ -1,22 +1,22 @@
|
||||
noinst_LTLIBRARIES = libwebpdecode.la
|
||||
|
||||
libwebpdecode_la_SOURCES =
|
||||
libwebpdecode_la_SOURCES += alpha.c
|
||||
libwebpdecode_la_SOURCES += alphai.h
|
||||
libwebpdecode_la_SOURCES += buffer.c
|
||||
libwebpdecode_la_SOURCES += common.h
|
||||
libwebpdecode_la_SOURCES += decode_vp8.h
|
||||
libwebpdecode_la_SOURCES += frame.c
|
||||
libwebpdecode_la_SOURCES += idec.c
|
||||
libwebpdecode_la_SOURCES += io.c
|
||||
libwebpdecode_la_SOURCES += quant.c
|
||||
libwebpdecode_la_SOURCES += tree.c
|
||||
libwebpdecode_la_SOURCES += vp8.c
|
||||
libwebpdecode_la_SOURCES += vp8i.h
|
||||
libwebpdecode_la_SOURCES += vp8l.c
|
||||
libwebpdecode_la_SOURCES += vp8li.h
|
||||
libwebpdecode_la_SOURCES += webp.c
|
||||
libwebpdecode_la_SOURCES += webpi.h
|
||||
libwebpdecode_la_SOURCES += alpha_dec.c
|
||||
libwebpdecode_la_SOURCES += alphai_dec.h
|
||||
libwebpdecode_la_SOURCES += buffer_dec.c
|
||||
libwebpdecode_la_SOURCES += common_dec.h
|
||||
libwebpdecode_la_SOURCES += vp8_dec.h
|
||||
libwebpdecode_la_SOURCES += frame_dec.c
|
||||
libwebpdecode_la_SOURCES += idec_dec.c
|
||||
libwebpdecode_la_SOURCES += io_dec.c
|
||||
libwebpdecode_la_SOURCES += quant_dec.c
|
||||
libwebpdecode_la_SOURCES += tree_dec.c
|
||||
libwebpdecode_la_SOURCES += vp8_dec.c
|
||||
libwebpdecode_la_SOURCES += vp8i_dec.h
|
||||
libwebpdecode_la_SOURCES += vp8l_dec.c
|
||||
libwebpdecode_la_SOURCES += vp8li_dec.h
|
||||
libwebpdecode_la_SOURCES += webp_dec.c
|
||||
libwebpdecode_la_SOURCES += webpi_dec.h
|
||||
|
||||
libwebpdecodeinclude_HEADERS =
|
||||
libwebpdecodeinclude_HEADERS += ../webp/decode.h
|
||||
|
@ -12,11 +12,11 @@
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "./alphai.h"
|
||||
#include "./vp8i.h"
|
||||
#include "./vp8li.h"
|
||||
#include "./alphai_dec.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "./vp8li_dec.h"
|
||||
#include "../dsp/dsp.h"
|
||||
#include "../utils/quant_levels_dec.h"
|
||||
#include "../utils/quant_levels_dec_utils.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../webp/format_constants.h"
|
||||
|
@ -14,8 +14,8 @@
|
||||
#ifndef WEBP_DEC_ALPHAI_H_
|
||||
#define WEBP_DEC_ALPHAI_H_
|
||||
|
||||
#include "./webpi.h"
|
||||
#include "../utils/filters.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../utils/filters_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
@ -13,8 +13,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "./vp8i.h"
|
||||
#include "./webpi.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
@ -12,7 +12,7 @@
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "./vp8i.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -723,7 +723,7 @@ static int AllocateMemory(VP8Decoder* const dec) {
|
||||
return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
|
||||
"no memory during frame initialization.");
|
||||
}
|
||||
// down-cast is ok, thanks to WebPSafeAlloc() above.
|
||||
// down-cast is ok, thanks to WebPSafeMalloc() above.
|
||||
dec->mem_size_ = (size_t)needed;
|
||||
}
|
||||
|
@ -15,9 +15,9 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "./alphai.h"
|
||||
#include "./webpi.h"
|
||||
#include "./vp8i.h"
|
||||
#include "./alphai_dec.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
// In append mode, buffer allocations increase as multiples of this value.
|
@ -13,8 +13,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include "../dec/vp8i.h"
|
||||
#include "./webpi.h"
|
||||
#include "../dec/vp8i_dec.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../dsp/dsp.h"
|
||||
#include "../dsp/yuv.h"
|
||||
#include "../utils/utils.h"
|
||||
@ -256,7 +256,7 @@ static int Rescale(const uint8_t* src, int src_stride,
|
||||
static int EmitRescaledYUV(const VP8Io* const io, WebPDecParams* const p) {
|
||||
const int mb_h = io->mb_h;
|
||||
const int uv_mb_h = (mb_h + 1) >> 1;
|
||||
WebPRescaler* const scaler = &p->scaler_y;
|
||||
WebPRescaler* const scaler = p->scaler_y;
|
||||
int num_lines_out = 0;
|
||||
if (WebPIsAlphaMode(p->output->colorspace) && io->a != NULL) {
|
||||
// Before rescaling, we premultiply the luma directly into the io->y
|
||||
@ -267,29 +267,28 @@ static int EmitRescaledYUV(const VP8Io* const io, WebPDecParams* const p) {
|
||||
io->a, io->width, io->mb_w, mb_h, 0);
|
||||
}
|
||||
num_lines_out = Rescale(io->y, io->y_stride, mb_h, scaler);
|
||||
Rescale(io->u, io->uv_stride, uv_mb_h, &p->scaler_u);
|
||||
Rescale(io->v, io->uv_stride, uv_mb_h, &p->scaler_v);
|
||||
Rescale(io->u, io->uv_stride, uv_mb_h, p->scaler_u);
|
||||
Rescale(io->v, io->uv_stride, uv_mb_h, p->scaler_v);
|
||||
return num_lines_out;
|
||||
}
|
||||
|
||||
static int EmitRescaledAlphaYUV(const VP8Io* const io, WebPDecParams* const p,
|
||||
int expected_num_lines_out) {
|
||||
const WebPYUVABuffer* const buf = &p->output->u.YUVA;
|
||||
uint8_t* const dst_a = buf->a + p->last_y * buf->a_stride;
|
||||
if (io->a != NULL) {
|
||||
uint8_t* dst_y = buf->y + p->last_y * buf->y_stride;
|
||||
const uint8_t* src_a = buf->a + p->last_y * buf->a_stride;
|
||||
const int num_lines_out = Rescale(io->a, io->width, io->mb_h, &p->scaler_a);
|
||||
(void)expected_num_lines_out;
|
||||
uint8_t* const dst_y = buf->y + p->last_y * buf->y_stride;
|
||||
const int num_lines_out = Rescale(io->a, io->width, io->mb_h, p->scaler_a);
|
||||
assert(expected_num_lines_out == num_lines_out);
|
||||
if (num_lines_out > 0) { // unmultiply the Y
|
||||
WebPMultRows(dst_y, buf->y_stride, src_a, buf->a_stride,
|
||||
p->scaler_a.dst_width, num_lines_out, 1);
|
||||
WebPMultRows(dst_y, buf->y_stride, dst_a, buf->a_stride,
|
||||
p->scaler_a->dst_width, num_lines_out, 1);
|
||||
}
|
||||
} else if (buf->a != NULL) {
|
||||
// the user requested alpha, but there is none, set it to opaque.
|
||||
assert(p->last_y + expected_num_lines_out <= io->scaled_height);
|
||||
FillAlphaPlane(buf->a + p->last_y * buf->a_stride,
|
||||
io->scaled_width, expected_num_lines_out, buf->a_stride);
|
||||
FillAlphaPlane(dst_a, io->scaled_width, expected_num_lines_out,
|
||||
buf->a_stride);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -305,31 +304,42 @@ static int InitYUVRescaler(const VP8Io* const io, WebPDecParams* const p) {
|
||||
const int uv_in_height = (io->mb_h + 1) >> 1;
|
||||
const size_t work_size = 2 * out_width; // scratch memory for luma rescaler
|
||||
const size_t uv_work_size = 2 * uv_out_width; // and for each u/v ones
|
||||
size_t tmp_size;
|
||||
size_t tmp_size, rescaler_size;
|
||||
rescaler_t* work;
|
||||
WebPRescaler* scalers;
|
||||
const int num_rescalers = has_alpha ? 4 : 3;
|
||||
|
||||
tmp_size = (work_size + 2 * uv_work_size) * sizeof(*work);
|
||||
if (has_alpha) {
|
||||
tmp_size += work_size * sizeof(*work);
|
||||
}
|
||||
p->memory = WebPSafeMalloc(1ULL, tmp_size);
|
||||
rescaler_size = num_rescalers * sizeof(*p->scaler_y) + WEBP_ALIGN_CST;
|
||||
|
||||
p->memory = WebPSafeMalloc(1ULL, tmp_size + rescaler_size);
|
||||
if (p->memory == NULL) {
|
||||
return 0; // memory error
|
||||
}
|
||||
work = (rescaler_t*)p->memory;
|
||||
WebPRescalerInit(&p->scaler_y, io->mb_w, io->mb_h,
|
||||
|
||||
scalers = (WebPRescaler*)WEBP_ALIGN((const uint8_t*)work + tmp_size);
|
||||
p->scaler_y = &scalers[0];
|
||||
p->scaler_u = &scalers[1];
|
||||
p->scaler_v = &scalers[2];
|
||||
p->scaler_a = has_alpha ? &scalers[3] : NULL;
|
||||
|
||||
WebPRescalerInit(p->scaler_y, io->mb_w, io->mb_h,
|
||||
buf->y, out_width, out_height, buf->y_stride, 1,
|
||||
work);
|
||||
WebPRescalerInit(&p->scaler_u, uv_in_width, uv_in_height,
|
||||
WebPRescalerInit(p->scaler_u, uv_in_width, uv_in_height,
|
||||
buf->u, uv_out_width, uv_out_height, buf->u_stride, 1,
|
||||
work + work_size);
|
||||
WebPRescalerInit(&p->scaler_v, uv_in_width, uv_in_height,
|
||||
WebPRescalerInit(p->scaler_v, uv_in_width, uv_in_height,
|
||||
buf->v, uv_out_width, uv_out_height, buf->v_stride, 1,
|
||||
work + work_size + uv_work_size);
|
||||
p->emit = EmitRescaledYUV;
|
||||
|
||||
if (has_alpha) {
|
||||
WebPRescalerInit(&p->scaler_a, io->mb_w, io->mb_h,
|
||||
WebPRescalerInit(p->scaler_a, io->mb_w, io->mb_h,
|
||||
buf->a, out_width, out_height, buf->a_stride, 1,
|
||||
work + work_size + 2 * uv_work_size);
|
||||
p->emit_alpha = EmitRescaledAlphaYUV;
|
||||
@ -349,15 +359,15 @@ static int ExportRGB(WebPDecParams* const p, int y_pos) {
|
||||
int num_lines_out = 0;
|
||||
// For RGB rescaling, because of the YUV420, current scan position
|
||||
// U/V can be +1/-1 line from the Y one. Hence the double test.
|
||||
while (WebPRescalerHasPendingOutput(&p->scaler_y) &&
|
||||
WebPRescalerHasPendingOutput(&p->scaler_u)) {
|
||||
while (WebPRescalerHasPendingOutput(p->scaler_y) &&
|
||||
WebPRescalerHasPendingOutput(p->scaler_u)) {
|
||||
assert(y_pos + num_lines_out < p->output->height);
|
||||
assert(p->scaler_u.y_accum == p->scaler_v.y_accum);
|
||||
WebPRescalerExportRow(&p->scaler_y);
|
||||
WebPRescalerExportRow(&p->scaler_u);
|
||||
WebPRescalerExportRow(&p->scaler_v);
|
||||
convert(p->scaler_y.dst, p->scaler_u.dst, p->scaler_v.dst,
|
||||
dst, p->scaler_y.dst_width);
|
||||
assert(p->scaler_u->y_accum == p->scaler_v->y_accum);
|
||||
WebPRescalerExportRow(p->scaler_y);
|
||||
WebPRescalerExportRow(p->scaler_u);
|
||||
WebPRescalerExportRow(p->scaler_v);
|
||||
convert(p->scaler_y->dst, p->scaler_u->dst, p->scaler_v->dst,
|
||||
dst, p->scaler_y->dst_width);
|
||||
dst += buf->stride;
|
||||
++num_lines_out;
|
||||
}
|
||||
@ -371,15 +381,15 @@ static int EmitRescaledRGB(const VP8Io* const io, WebPDecParams* const p) {
|
||||
int num_lines_out = 0;
|
||||
while (j < mb_h) {
|
||||
const int y_lines_in =
|
||||
WebPRescalerImport(&p->scaler_y, mb_h - j,
|
||||
WebPRescalerImport(p->scaler_y, mb_h - j,
|
||||
io->y + j * io->y_stride, io->y_stride);
|
||||
j += y_lines_in;
|
||||
if (WebPRescaleNeededLines(&p->scaler_u, uv_mb_h - uv_j)) {
|
||||
if (WebPRescaleNeededLines(p->scaler_u, uv_mb_h - uv_j)) {
|
||||
const int u_lines_in =
|
||||
WebPRescalerImport(&p->scaler_u, uv_mb_h - uv_j,
|
||||
WebPRescalerImport(p->scaler_u, uv_mb_h - uv_j,
|
||||
io->u + uv_j * io->uv_stride, io->uv_stride);
|
||||
const int v_lines_in =
|
||||
WebPRescalerImport(&p->scaler_v, uv_mb_h - uv_j,
|
||||
WebPRescalerImport(p->scaler_v, uv_mb_h - uv_j,
|
||||
io->v + uv_j * io->uv_stride, io->uv_stride);
|
||||
(void)v_lines_in; // remove a gcc warning
|
||||
assert(u_lines_in == v_lines_in);
|
||||
@ -400,13 +410,13 @@ static int ExportAlpha(WebPDecParams* const p, int y_pos, int max_lines_out) {
|
||||
int num_lines_out = 0;
|
||||
const int is_premult_alpha = WebPIsPremultipliedMode(colorspace);
|
||||
uint32_t non_opaque = 0;
|
||||
const int width = p->scaler_a.dst_width;
|
||||
const int width = p->scaler_a->dst_width;
|
||||
|
||||
while (WebPRescalerHasPendingOutput(&p->scaler_a) &&
|
||||
while (WebPRescalerHasPendingOutput(p->scaler_a) &&
|
||||
num_lines_out < max_lines_out) {
|
||||
assert(y_pos + num_lines_out < p->output->height);
|
||||
WebPRescalerExportRow(&p->scaler_a);
|
||||
non_opaque |= WebPDispatchAlpha(p->scaler_a.dst, 0, width, 1, dst, 0);
|
||||
WebPRescalerExportRow(p->scaler_a);
|
||||
non_opaque |= WebPDispatchAlpha(p->scaler_a->dst, 0, width, 1, dst, 0);
|
||||
dst += buf->stride;
|
||||
++num_lines_out;
|
||||
}
|
||||
@ -428,18 +438,18 @@ static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos,
|
||||
#endif
|
||||
int num_lines_out = 0;
|
||||
const WEBP_CSP_MODE colorspace = p->output->colorspace;
|
||||
const int width = p->scaler_a.dst_width;
|
||||
const int width = p->scaler_a->dst_width;
|
||||
const int is_premult_alpha = WebPIsPremultipliedMode(colorspace);
|
||||
uint32_t alpha_mask = 0x0f;
|
||||
|
||||
while (WebPRescalerHasPendingOutput(&p->scaler_a) &&
|
||||
while (WebPRescalerHasPendingOutput(p->scaler_a) &&
|
||||
num_lines_out < max_lines_out) {
|
||||
int i;
|
||||
assert(y_pos + num_lines_out < p->output->height);
|
||||
WebPRescalerExportRow(&p->scaler_a);
|
||||
WebPRescalerExportRow(p->scaler_a);
|
||||
for (i = 0; i < width; ++i) {
|
||||
// Fill in the alpha value (converted to 4 bits).
|
||||
const uint32_t alpha_value = p->scaler_a.dst[i] >> 4;
|
||||
const uint32_t alpha_value = p->scaler_a->dst[i] >> 4;
|
||||
alpha_dst[2 * i] = (alpha_dst[2 * i] & 0xf0) | alpha_value;
|
||||
alpha_mask &= alpha_value;
|
||||
}
|
||||
@ -455,7 +465,7 @@ static int ExportAlphaRGBA4444(WebPDecParams* const p, int y_pos,
|
||||
static int EmitRescaledAlphaRGB(const VP8Io* const io, WebPDecParams* const p,
|
||||
int expected_num_out_lines) {
|
||||
if (io->a != NULL) {
|
||||
WebPRescaler* const scaler = &p->scaler_a;
|
||||
WebPRescaler* const scaler = p->scaler_a;
|
||||
int lines_left = expected_num_out_lines;
|
||||
const int y_end = p->last_y + lines_left;
|
||||
while (lines_left > 0) {
|
||||
@ -477,7 +487,9 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) {
|
||||
const size_t work_size = 2 * out_width; // scratch memory for one rescaler
|
||||
rescaler_t* work; // rescalers work area
|
||||
uint8_t* tmp; // tmp storage for scaled YUV444 samples before RGB conversion
|
||||
size_t tmp_size1, tmp_size2, total_size;
|
||||
size_t tmp_size1, tmp_size2, total_size, rescaler_size;
|
||||
WebPRescaler* scalers;
|
||||
const int num_rescalers = has_alpha ? 4 : 3;
|
||||
|
||||
tmp_size1 = 3 * work_size;
|
||||
tmp_size2 = 3 * out_width;
|
||||
@ -486,26 +498,35 @@ static int InitRGBRescaler(const VP8Io* const io, WebPDecParams* const p) {
|
||||
tmp_size2 += out_width;
|
||||
}
|
||||
total_size = tmp_size1 * sizeof(*work) + tmp_size2 * sizeof(*tmp);
|
||||
p->memory = WebPSafeMalloc(1ULL, total_size);
|
||||
rescaler_size = num_rescalers * sizeof(*p->scaler_y) + WEBP_ALIGN_CST;
|
||||
|
||||
p->memory = WebPSafeMalloc(1ULL, total_size + rescaler_size);
|
||||
if (p->memory == NULL) {
|
||||
return 0; // memory error
|
||||
}
|
||||
work = (rescaler_t*)p->memory;
|
||||
tmp = (uint8_t*)(work + tmp_size1);
|
||||
WebPRescalerInit(&p->scaler_y, io->mb_w, io->mb_h,
|
||||
|
||||
scalers = (WebPRescaler*)WEBP_ALIGN((const uint8_t*)work + total_size);
|
||||
p->scaler_y = &scalers[0];
|
||||
p->scaler_u = &scalers[1];
|
||||
p->scaler_v = &scalers[2];
|
||||
p->scaler_a = has_alpha ? &scalers[3] : NULL;
|
||||
|
||||
WebPRescalerInit(p->scaler_y, io->mb_w, io->mb_h,
|
||||
tmp + 0 * out_width, out_width, out_height, 0, 1,
|
||||
work + 0 * work_size);
|
||||
WebPRescalerInit(&p->scaler_u, uv_in_width, uv_in_height,
|
||||
WebPRescalerInit(p->scaler_u, uv_in_width, uv_in_height,
|
||||
tmp + 1 * out_width, out_width, out_height, 0, 1,
|
||||
work + 1 * work_size);
|
||||
WebPRescalerInit(&p->scaler_v, uv_in_width, uv_in_height,
|
||||
WebPRescalerInit(p->scaler_v, uv_in_width, uv_in_height,
|
||||
tmp + 2 * out_width, out_width, out_height, 0, 1,
|
||||
work + 2 * work_size);
|
||||
p->emit = EmitRescaledRGB;
|
||||
WebPInitYUV444Converters();
|
||||
|
||||
if (has_alpha) {
|
||||
WebPRescalerInit(&p->scaler_a, io->mb_w, io->mb_h,
|
||||
WebPRescalerInit(p->scaler_a, io->mb_w, io->mb_h,
|
||||
tmp + 3 * out_width, out_width, out_height, 0, 1,
|
||||
work + 3 * work_size);
|
||||
p->emit_alpha = EmitRescaledAlphaRGB;
|
@ -11,7 +11,7 @@
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./vp8i.h"
|
||||
#include "./vp8i_dec.h"
|
||||
|
||||
static WEBP_INLINE int clip(int v, int M) {
|
||||
return v < 0 ? 0 : v > M ? M : v;
|
@ -11,10 +11,13 @@
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./vp8i.h"
|
||||
#include "../utils/bit_reader_inl.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "../utils/bit_reader_inl_utils.h"
|
||||
|
||||
#if !defined(__arm__) && !defined(_M_ARM) && !defined(__aarch64__)
|
||||
// using a table is ~1-2% slower on ARM. Prefer the coded-tree approach then.
|
||||
#define USE_GENERIC_TREE
|
||||
#endif
|
||||
|
||||
#ifdef USE_GENERIC_TREE
|
||||
static const int8_t kYModesIntra4[18] = {
|
@ -13,11 +13,11 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "./alphai.h"
|
||||
#include "./vp8i.h"
|
||||
#include "./vp8li.h"
|
||||
#include "./webpi.h"
|
||||
#include "../utils/bit_reader_inl.h"
|
||||
#include "./alphai_dec.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "./vp8li_dec.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../utils/bit_reader_inl_utils.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -26,6 +26,16 @@ int WebPGetDecoderVersion(void) {
|
||||
return (DEC_MAJ_VERSION << 16) | (DEC_MIN_VERSION << 8) | DEC_REV_VERSION;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Signature and pointer-to-function for GetCoeffs() variants below.
|
||||
|
||||
typedef int (*GetCoeffsFunc)(VP8BitReader* const br,
|
||||
const VP8BandProbas* const prob[],
|
||||
int ctx, const quant_t dq, int n, int16_t* out);
|
||||
static volatile GetCoeffsFunc GetCoeffs = NULL;
|
||||
|
||||
static void InitGetCoeffs(void);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// VP8Decoder
|
||||
|
||||
@ -51,6 +61,7 @@ VP8Decoder* VP8New(void) {
|
||||
WebPGetWorkerInterface()->Init(&dec->worker_);
|
||||
dec->ready_ = 0;
|
||||
dec->num_parts_minus_one_ = 0;
|
||||
InitGetCoeffs();
|
||||
}
|
||||
return dec;
|
||||
}
|
||||
@ -273,12 +284,14 @@ int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io) {
|
||||
frm_hdr->profile_ = (bits >> 1) & 7;
|
||||
frm_hdr->show_ = (bits >> 4) & 1;
|
||||
frm_hdr->partition_length_ = (bits >> 5);
|
||||
if (frm_hdr->profile_ > 3)
|
||||
if (frm_hdr->profile_ > 3) {
|
||||
return VP8SetError(dec, VP8_STATUS_BITSTREAM_ERROR,
|
||||
"Incorrect keyframe parameters.");
|
||||
if (!frm_hdr->show_)
|
||||
}
|
||||
if (!frm_hdr->show_) {
|
||||
return VP8SetError(dec, VP8_STATUS_UNSUPPORTED_FEATURE,
|
||||
"Frame not displayable.");
|
||||
}
|
||||
buf += 3;
|
||||
buf_size -= 3;
|
||||
}
|
||||
@ -420,8 +433,9 @@ static int GetLargeValue(VP8BitReader* const br, const uint8_t* const p) {
|
||||
}
|
||||
|
||||
// Returns the position of the last non-zero coeff plus one
|
||||
static int GetCoeffs(VP8BitReader* const br, const VP8BandProbas* const prob[],
|
||||
int ctx, const quant_t dq, int n, int16_t* out) {
|
||||
static int GetCoeffsFast(VP8BitReader* const br,
|
||||
const VP8BandProbas* const prob[],
|
||||
int ctx, const quant_t dq, int n, int16_t* out) {
|
||||
const uint8_t* p = prob[n]->probas_[ctx];
|
||||
for (; n < 16; ++n) {
|
||||
if (!VP8GetBit(br, p[0])) {
|
||||
@ -447,6 +461,46 @@ static int GetCoeffs(VP8BitReader* const br, const VP8BandProbas* const prob[],
|
||||
return 16;
|
||||
}
|
||||
|
||||
// This version of GetCoeffs() uses VP8GetBitAlt() which is an alternate version
|
||||
// of VP8GetBitAlt() targeting specific platforms.
|
||||
static int GetCoeffsAlt(VP8BitReader* const br,
|
||||
const VP8BandProbas* const prob[],
|
||||
int ctx, const quant_t dq, int n, int16_t* out) {
|
||||
const uint8_t* p = prob[n]->probas_[ctx];
|
||||
for (; n < 16; ++n) {
|
||||
if (!VP8GetBitAlt(br, p[0])) {
|
||||
return n; // previous coeff was last non-zero coeff
|
||||
}
|
||||
while (!VP8GetBitAlt(br, p[1])) { // sequence of zero coeffs
|
||||
p = prob[++n]->probas_[0];
|
||||
if (n == 16) return 16;
|
||||
}
|
||||
{ // non zero coeff
|
||||
const VP8ProbaArray* const p_ctx = &prob[n + 1]->probas_[0];
|
||||
int v;
|
||||
if (!VP8GetBitAlt(br, p[2])) {
|
||||
v = 1;
|
||||
p = p_ctx[1];
|
||||
} else {
|
||||
v = GetLargeValue(br, p);
|
||||
p = p_ctx[2];
|
||||
}
|
||||
out[kZigzag[n]] = VP8GetSigned(br, v) * dq[n > 0];
|
||||
}
|
||||
}
|
||||
return 16;
|
||||
}
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION static void InitGetCoeffs(void) {
|
||||
if (GetCoeffs == NULL) {
|
||||
if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) {
|
||||
GetCoeffs = GetCoeffsAlt;
|
||||
} else {
|
||||
GetCoeffs = GetCoeffsFast;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static WEBP_INLINE uint32_t NzCodeBits(uint32_t nz_coeffs, int nz, int dc_nz) {
|
||||
nz_coeffs <<= 2;
|
||||
nz_coeffs |= (nz > 3) ? 3 : (nz > 1) ? 2 : dc_nz;
|
@ -33,7 +33,7 @@ extern "C" {
|
||||
// /* customize io's functions (setup()/put()/teardown()) if needed. */
|
||||
//
|
||||
// VP8Decoder* dec = VP8New();
|
||||
// bool ok = VP8Decode(dec);
|
||||
// int ok = VP8Decode(dec, &io);
|
||||
// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));
|
||||
// VP8Delete(dec);
|
||||
// return ok;
|
@ -15,11 +15,11 @@
|
||||
#define WEBP_DEC_VP8I_H_
|
||||
|
||||
#include <string.h> // for memcpy()
|
||||
#include "./common.h"
|
||||
#include "./vp8li.h"
|
||||
#include "../utils/bit_reader.h"
|
||||
#include "../utils/random.h"
|
||||
#include "../utils/thread.h"
|
||||
#include "./common_dec.h"
|
||||
#include "./vp8li_dec.h"
|
||||
#include "../utils/bit_reader_utils.h"
|
||||
#include "../utils/random_utils.h"
|
||||
#include "../utils/thread_utils.h"
|
||||
#include "../dsp/dsp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -31,8 +31,8 @@ extern "C" {
|
||||
|
||||
// version numbers
|
||||
#define DEC_MAJ_VERSION 0
|
||||
#define DEC_MIN_VERSION 5
|
||||
#define DEC_REV_VERSION 2
|
||||
#define DEC_MIN_VERSION 6
|
||||
#define DEC_REV_VERSION 0
|
||||
|
||||
// YUV-cache parameters. Cache is 32-bytes wide (= one cacheline).
|
||||
// Constraints are: We need to store one 16x16 block of luma samples (y),
|
@ -14,13 +14,14 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "./alphai.h"
|
||||
#include "./vp8li.h"
|
||||
#include "./alphai_dec.h"
|
||||
#include "./vp8li_dec.h"
|
||||
#include "../dsp/dsp.h"
|
||||
#include "../dsp/lossless.h"
|
||||
#include "../dsp/lossless_common.h"
|
||||
#include "../dsp/yuv.h"
|
||||
#include "../utils/endian_inl.h"
|
||||
#include "../utils/huffman.h"
|
||||
#include "../utils/endian_inl_utils.h"
|
||||
#include "../utils/huffman_utils.h"
|
||||
#include "../utils/utils.h"
|
||||
|
||||
#define NUM_ARGB_CACHE_ROWS 16
|
||||
@ -547,11 +548,14 @@ static int EmitRescaledRowsRGBA(const VP8LDecoder* const dec,
|
||||
uint8_t* const row_out = out + num_lines_out * out_stride;
|
||||
const int lines_left = mb_h - num_lines_in;
|
||||
const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left);
|
||||
int lines_imported;
|
||||
assert(needed_lines > 0 && needed_lines <= lines_left);
|
||||
WebPMultARGBRows(row_in, in_stride,
|
||||
dec->rescaler->src_width, needed_lines, 0);
|
||||
WebPRescalerImport(dec->rescaler, lines_left, row_in, in_stride);
|
||||
num_lines_in += needed_lines;
|
||||
lines_imported =
|
||||
WebPRescalerImport(dec->rescaler, lines_left, row_in, in_stride);
|
||||
assert(lines_imported == needed_lines);
|
||||
num_lines_in += lines_imported;
|
||||
num_lines_out += Export(dec->rescaler, colorspace, out_stride, row_out);
|
||||
}
|
||||
return num_lines_out;
|
||||
@ -623,9 +627,12 @@ static int EmitRescaledRowsYUVA(const VP8LDecoder* const dec,
|
||||
while (num_lines_in < mb_h) {
|
||||
const int lines_left = mb_h - num_lines_in;
|
||||
const int needed_lines = WebPRescaleNeededLines(dec->rescaler, lines_left);
|
||||
int lines_imported;
|
||||
WebPMultARGBRows(in, in_stride, dec->rescaler->src_width, needed_lines, 0);
|
||||
WebPRescalerImport(dec->rescaler, lines_left, in, in_stride);
|
||||
num_lines_in += needed_lines;
|
||||
lines_imported =
|
||||
WebPRescalerImport(dec->rescaler, lines_left, in, in_stride);
|
||||
assert(lines_imported == needed_lines);
|
||||
num_lines_in += lines_imported;
|
||||
in += needed_lines * in_stride;
|
||||
y_pos += ExportYUVA(dec, y_pos);
|
||||
}
|
||||
@ -705,13 +712,15 @@ static void ApplyInverseTransforms(VP8LDecoder* const dec, int num_rows,
|
||||
uint32_t* const rows_out = dec->argb_cache_;
|
||||
|
||||
// Inverse transforms.
|
||||
// TODO: most transforms only need to operate on the cropped region only.
|
||||
memcpy(rows_out, rows_in, cache_pixs * sizeof(*rows_out));
|
||||
while (n-- > 0) {
|
||||
VP8LTransform* const transform = &dec->transforms_[n];
|
||||
VP8LInverseTransform(transform, start_row, end_row, rows_in, rows_out);
|
||||
rows_in = rows_out;
|
||||
}
|
||||
if (rows_in != rows_out) {
|
||||
// No transform called, hence just copy.
|
||||
memcpy(rows_out, rows_in, cache_pixs * sizeof(*rows_out));
|
||||
}
|
||||
}
|
||||
|
||||
// Processes (transforms, scales & color-converts) the rows decoded after the
|
||||
@ -1003,12 +1012,13 @@ static int DecodeAlphaData(VP8LDecoder* const dec, uint8_t* const data,
|
||||
ok = 0;
|
||||
goto End;
|
||||
}
|
||||
assert(br->eos_ == VP8LIsEndOfStream(br));
|
||||
br->eos_ = VP8LIsEndOfStream(br);
|
||||
}
|
||||
// Process the remaining rows corresponding to last row-block.
|
||||
ExtractPalettedAlphaRows(dec, row > last_row ? last_row : row);
|
||||
|
||||
End:
|
||||
br->eos_ = VP8LIsEndOfStream(br);
|
||||
if (!ok || (br->eos_ && pos < end)) {
|
||||
ok = 0;
|
||||
dec->status_ = br->eos_ ? VP8_STATUS_SUSPENDED
|
||||
@ -1081,11 +1091,12 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
|
||||
VP8LFillBitWindow(br);
|
||||
if (htree_group->use_packed_table) {
|
||||
code = ReadPackedSymbols(htree_group, br, src);
|
||||
if (VP8LIsEndOfStream(br)) break;
|
||||
if (code == PACKED_NON_LITERAL_CODE) goto AdvanceByOne;
|
||||
} else {
|
||||
code = ReadSymbol(htree_group->htrees[GREEN], br);
|
||||
}
|
||||
if (br->eos_) break; // early out
|
||||
if (VP8LIsEndOfStream(br)) break;
|
||||
if (code < NUM_LITERAL_CODES) { // Literal
|
||||
if (htree_group->is_trivial_literal) {
|
||||
*src = htree_group->literal_arb | (code << 8);
|
||||
@ -1095,7 +1106,7 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
|
||||
VP8LFillBitWindow(br);
|
||||
blue = ReadSymbol(htree_group->htrees[BLUE], br);
|
||||
alpha = ReadSymbol(htree_group->htrees[ALPHA], br);
|
||||
if (br->eos_) break;
|
||||
if (VP8LIsEndOfStream(br)) break;
|
||||
*src = ((uint32_t)alpha << 24) | (red << 16) | (code << 8) | blue;
|
||||
}
|
||||
AdvanceByOne:
|
||||
@ -1123,7 +1134,7 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
|
||||
VP8LFillBitWindow(br);
|
||||
dist_code = GetCopyDistance(dist_symbol, br);
|
||||
dist = PlaneCodeToDistance(width, dist_code);
|
||||
if (br->eos_) break;
|
||||
if (VP8LIsEndOfStream(br)) break;
|
||||
if (src - data < (ptrdiff_t)dist || src_end - src < (ptrdiff_t)length) {
|
||||
goto Error;
|
||||
} else {
|
||||
@ -1160,9 +1171,9 @@ static int DecodeImageData(VP8LDecoder* const dec, uint32_t* const data,
|
||||
} else { // Not reached
|
||||
goto Error;
|
||||
}
|
||||
assert(br->eos_ == VP8LIsEndOfStream(br));
|
||||
}
|
||||
|
||||
br->eos_ = VP8LIsEndOfStream(br);
|
||||
if (dec->incremental_ && br->eos_ && src < src_end) {
|
||||
RestoreState(dec);
|
||||
} else if (!br->eos_) {
|
||||
@ -1210,8 +1221,9 @@ static int ExpandColorMap(int num_colors, VP8LTransform* const transform) {
|
||||
// Equivalent to AddPixelEq(), on a byte-basis.
|
||||
new_data[i] = (data[i] + new_data[i - 4]) & 0xff;
|
||||
}
|
||||
for (; i < 4 * final_num_colors; ++i)
|
||||
for (; i < 4 * final_num_colors; ++i) {
|
||||
new_data[i] = 0; // black tail.
|
||||
}
|
||||
WebPSafeFree(transform->data_);
|
||||
transform->data_ = new_color_map;
|
||||
}
|
||||
@ -1482,9 +1494,8 @@ static void ExtractAlphaRows(VP8LDecoder* const dec, int last_row) {
|
||||
const int cache_pixs = width * num_rows_to_process;
|
||||
uint8_t* const dst = output + width * cur_row;
|
||||
const uint32_t* const src = dec->argb_cache_;
|
||||
int i;
|
||||
ApplyInverseTransforms(dec, num_rows_to_process, in);
|
||||
for (i = 0; i < cache_pixs; ++i) dst[i] = (src[i] >> 8) & 0xff;
|
||||
WebPExtractGreen(src, dst, cache_pixs);
|
||||
AlphaApplyFilter(alph_dec,
|
||||
cur_row, cur_row + num_rows_to_process, dst, width);
|
||||
num_rows -= num_rows_to_process;
|
||||
@ -1552,6 +1563,8 @@ int VP8LDecodeAlphaImageStream(ALPHDecoder* const alph_dec, int last_row) {
|
||||
return 1; // done
|
||||
}
|
||||
|
||||
if (!alph_dec->use_8b_decode_) WebPInitAlphaProcessing();
|
||||
|
||||
// Decode (with special row processing).
|
||||
return alph_dec->use_8b_decode_ ?
|
||||
DecodeAlphaData(dec, (uint8_t*)dec->pixels_, dec->width_, dec->height_,
|
@ -16,10 +16,10 @@
|
||||
#define WEBP_DEC_VP8LI_H_
|
||||
|
||||
#include <string.h> // for memcpy()
|
||||
#include "./webpi.h"
|
||||
#include "../utils/bit_reader.h"
|
||||
#include "../utils/color_cache.h"
|
||||
#include "../utils/huffman.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../utils/bit_reader_utils.h"
|
||||
#include "../utils/color_cache_utils.h"
|
||||
#include "../utils/huffman_utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
@ -13,9 +13,9 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "./vp8i.h"
|
||||
#include "./vp8li.h"
|
||||
#include "./webpi.h"
|
||||
#include "./vp8i_dec.h"
|
||||
#include "./vp8li_dec.h"
|
||||
#include "./webpi_dec.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "../webp/mux_types.h" // ALPHA_FLAG
|
||||
|
||||
@ -39,8 +39,8 @@
|
||||
// 20..23 VP8X flags bit-map corresponding to the chunk-types present.
|
||||
// 24..26 Width of the Canvas Image.
|
||||
// 27..29 Height of the Canvas Image.
|
||||
// There can be extra chunks after the "VP8X" chunk (ICCP, FRGM, ANMF, VP8,
|
||||
// VP8L, XMP, EXIF ...)
|
||||
// There can be extra chunks after the "VP8X" chunk (ICCP, ANMF, VP8, VP8L,
|
||||
// XMP, EXIF ...)
|
||||
// All sizes are in little-endian order.
|
||||
// Note: chunk data size must be padded to multiple of 2 when written.
|
||||
|
||||
@ -289,7 +289,6 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
||||
int found_riff = 0;
|
||||
int found_vp8x = 0;
|
||||
int animation_present = 0;
|
||||
int fragments_present = 0;
|
||||
const int have_all_data = (headers != NULL) ? headers->have_all_data : 0;
|
||||
|
||||
VP8StatusCode status;
|
||||
@ -318,7 +317,6 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
||||
return status; // Wrong VP8X / insufficient data.
|
||||
}
|
||||
animation_present = !!(flags & ANIMATION_FLAG);
|
||||
fragments_present = !!(flags & FRAGMENTS_FLAG);
|
||||
if (!found_riff && found_vp8x) {
|
||||
// Note: This restriction may be removed in the future, if it becomes
|
||||
// necessary to send VP8X chunk to the decoder.
|
||||
@ -330,8 +328,7 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
||||
|
||||
image_width = canvas_width;
|
||||
image_height = canvas_height;
|
||||
if (found_vp8x && (animation_present || fragments_present) &&
|
||||
headers == NULL) {
|
||||
if (found_vp8x && animation_present && headers == NULL) {
|
||||
status = VP8_STATUS_OK;
|
||||
goto ReturnWidthHeight; // Just return features from VP8X header.
|
||||
}
|
||||
@ -362,7 +359,7 @@ static VP8StatusCode ParseHeadersInternal(const uint8_t* data,
|
||||
return VP8_STATUS_BITSTREAM_ERROR;
|
||||
}
|
||||
|
||||
if (format != NULL && !(animation_present || fragments_present)) {
|
||||
if (format != NULL && !animation_present) {
|
||||
*format = hdrs.is_lossless ? 2 : 1;
|
||||
}
|
||||
|
@ -18,8 +18,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../utils/rescaler.h"
|
||||
#include "./decode_vp8.h"
|
||||
#include "../utils/rescaler_utils.h"
|
||||
#include "./vp8_dec.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// WebPDecParams: Decoding output parameters. Transient internal object.
|
||||
@ -38,27 +38,18 @@ struct WebPDecParams {
|
||||
|
||||
int last_y; // coordinate of the line that was last output
|
||||
const WebPDecoderOptions* options; // if not NULL, use alt decoding features
|
||||
// rescalers
|
||||
WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a;
|
||||
|
||||
WebPRescaler* scaler_y, *scaler_u, *scaler_v, *scaler_a; // rescalers
|
||||
void* memory; // overall scratch memory for the output work.
|
||||
|
||||
OutputFunc emit; // output RGB or YUV samples
|
||||
OutputAlphaFunc emit_alpha; // output alpha channel
|
||||
OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values
|
||||
|
||||
WebPDecBuffer* final_output; // In case the user supplied a slow-memory
|
||||
// output, we decode image in temporary buffer
|
||||
// (this::output) and copy it here.
|
||||
WebPDecBuffer tmp_buffer; // this::output will point to this one in case
|
||||
// of slow memory.
|
||||
};
|
||||
|
||||
// Should be called first, before any use of the WebPDecParams object.
|
||||
void WebPResetDecParams(WebPDecParams* const params);
|
||||
|
||||
// Delete all memory (after an error occurred, for instance)
|
||||
void WebPFreeDecParams(WebPDecParams* const params);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Header parsing helpers
|
||||
|
@ -9,6 +9,6 @@ libwebpdemuxinclude_HEADERS += ../webp/mux_types.h
|
||||
libwebpdemuxinclude_HEADERS += ../webp/types.h
|
||||
|
||||
libwebpdemux_la_LIBADD = ../libwebp.la
|
||||
libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:1:0
|
||||
libwebpdemux_la_LDFLAGS = -no-undefined -version-info 2:2:0
|
||||
libwebpdemuxincludedir = $(includedir)/webp
|
||||
pkgconfig_DATA = libwebpdemux.pc
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
#define DMUX_MAJ_VERSION 0
|
||||
#define DMUX_MIN_VERSION 3
|
||||
#define DMUX_REV_VERSION 1
|
||||
#define DMUX_REV_VERSION 2
|
||||
|
||||
typedef struct {
|
||||
size_t start_; // start location of the data
|
||||
@ -590,7 +590,6 @@ static int CheckFrameBounds(const Frame* const frame, int exact,
|
||||
|
||||
static int IsValidExtendedFormat(const WebPDemuxer* const dmux) {
|
||||
const int is_animation = !!(dmux->feature_flags_ & ANIMATION_FLAG);
|
||||
const int is_fragmented = !!(dmux->feature_flags_ & FRAGMENTS_FLAG);
|
||||
const Frame* f = dmux->frames_;
|
||||
|
||||
if (dmux->state_ == WEBP_DEMUX_PARSING_HEADER) return 1;
|
||||
@ -598,7 +597,7 @@ static int IsValidExtendedFormat(const WebPDemuxer* const dmux) {
|
||||
if (dmux->canvas_width_ <= 0 || dmux->canvas_height_ <= 0) return 0;
|
||||
if (dmux->loop_count_ < 0) return 0;
|
||||
if (dmux->state_ == WEBP_DEMUX_DONE && dmux->frames_ == NULL) return 0;
|
||||
if (is_fragmented) return 0;
|
||||
if (dmux->feature_flags_ & ~ALL_VALID_FLAGS) return 0; // invalid bitstream
|
||||
|
||||
while (f != NULL) {
|
||||
const int cur_frame_set = f->frame_num_;
|
||||
|
41
src/demux/libwebpdemux.rc
Normal file
41
src/demux/libwebpdemux.rc
Normal file
@ -0,0 +1,41 @@
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
#include "winres.h"
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 0,3,0,2
|
||||
PRODUCTVERSION 0,3,0,2
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "Google, Inc."
|
||||
VALUE "FileDescription", "libwebpdemux DLL"
|
||||
VALUE "FileVersion", "0.3.2"
|
||||
VALUE "InternalName", "libwebpdemux.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2017"
|
||||
VALUE "OriginalFilename", "libwebpdemux.dll"
|
||||
VALUE "ProductName", "WebP Image Demuxer"
|
||||
VALUE "ProductVersion", "0.3.2"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
@ -2,7 +2,8 @@ noinst_LTLIBRARIES = libwebpdsp.la libwebpdsp_avx2.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_sse2.la libwebpdspdecode_sse2.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_sse41.la libwebpdspdecode_sse41.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_neon.la libwebpdspdecode_neon.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_msa.la
|
||||
noinst_LTLIBRARIES += libwebpdsp_msa.la libwebpdspdecode_msa.la
|
||||
noinst_LTLIBRARIES += libwebpdspdecode_wasm.la
|
||||
|
||||
if BUILD_LIBWEBPDECODER
|
||||
noinst_LTLIBRARIES += libwebpdspdecode.la
|
||||
@ -25,6 +26,7 @@ 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
|
||||
@ -49,6 +51,7 @@ 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 += ssim.c
|
||||
|
||||
libwebpdsp_avx2_la_SOURCES =
|
||||
libwebpdsp_avx2_la_SOURCES += enc_avx2.c
|
||||
@ -73,25 +76,37 @@ libwebpdspdecode_sse2_la_CPPFLAGS = $(libwebpdsp_sse2_la_CPPFLAGS)
|
||||
libwebpdspdecode_sse2_la_CFLAGS = $(libwebpdsp_sse2_la_CFLAGS)
|
||||
|
||||
libwebpdspdecode_neon_la_SOURCES =
|
||||
libwebpdspdecode_neon_la_SOURCES += alpha_processing_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += dec_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += filters_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += lossless_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += neon.h
|
||||
libwebpdspdecode_neon_la_SOURCES += rescaler_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += upsampling_neon.c
|
||||
libwebpdspdecode_neon_la_SOURCES += yuv_neon.c
|
||||
libwebpdspdecode_neon_la_CPPFLAGS = $(libwebpdsp_neon_la_CPPFLAGS)
|
||||
libwebpdspdecode_neon_la_CFLAGS = $(libwebpdsp_neon_la_CFLAGS)
|
||||
|
||||
libwebpdspdecode_msa_la_SOURCES =
|
||||
libwebpdspdecode_msa_la_SOURCES += dec_msa.c
|
||||
libwebpdspdecode_msa_la_SOURCES += filters_msa.c
|
||||
libwebpdspdecode_msa_la_SOURCES += lossless_msa.c
|
||||
libwebpdspdecode_msa_la_SOURCES += msa_macro.h
|
||||
libwebpdspdecode_msa_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdspdecode_msa_la_CFLAGS = $(AM_CFLAGS)
|
||||
libwebpdspdecode_msa_la_SOURCES += rescaler_msa.c
|
||||
libwebpdspdecode_msa_la_SOURCES += upsampling_msa.c
|
||||
libwebpdspdecode_msa_la_CPPFLAGS = $(libwebpdsp_msa_la_CPPFLAGS)
|
||||
libwebpdspdecode_msa_la_CFLAGS = $(libwebpdsp_msa_la_CFLAGS)
|
||||
|
||||
# WASM is not fully integrated into configure; the addition here keeps source
|
||||
# extraction by cmake simple.
|
||||
libwebpdspdecode_wasm_la_SOURCES = dec_wasm.c
|
||||
|
||||
libwebpdsp_sse2_la_SOURCES =
|
||||
libwebpdsp_sse2_la_SOURCES += argb_sse2.c
|
||||
libwebpdsp_sse2_la_SOURCES += cost_sse2.c
|
||||
libwebpdsp_sse2_la_SOURCES += enc_sse2.c
|
||||
libwebpdsp_sse2_la_SOURCES += lossless_enc_sse2.c
|
||||
libwebpdsp_sse2_la_SOURCES += ssim_sse2.c
|
||||
libwebpdsp_sse2_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_sse2_la_CFLAGS = $(AM_CFLAGS) $(SSE2_FLAGS)
|
||||
libwebpdsp_sse2_la_LIBADD = libwebpdspdecode_sse2.la
|
||||
@ -110,10 +125,17 @@ libwebpdsp_neon_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_FLAGS)
|
||||
libwebpdsp_neon_la_LIBADD = libwebpdspdecode_neon.la
|
||||
|
||||
libwebpdsp_msa_la_SOURCES =
|
||||
libwebpdsp_msa_la_SOURCES += enc_msa.c
|
||||
libwebpdsp_msa_la_SOURCES += lossless_enc_msa.c
|
||||
libwebpdsp_msa_la_CPPFLAGS = $(libwebpdsp_la_CPPFLAGS)
|
||||
libwebpdsp_msa_la_CFLAGS = $(AM_CFLAGS)
|
||||
libwebpdsp_msa_la_LIBADD = libwebpdspdecode_msa.la
|
||||
|
||||
libwebpdsp_la_SOURCES = $(COMMON_SOURCES) $(ENC_SOURCES)
|
||||
|
||||
noinst_HEADERS =
|
||||
noinst_HEADERS += ../dec/decode_vp8.h
|
||||
noinst_HEADERS += ../dec/vp8_dec.h
|
||||
noinst_HEADERS += ../webp/decode.h
|
||||
|
||||
libwebpdsp_la_CPPFLAGS =
|
||||
@ -124,7 +146,7 @@ libwebpdsp_la_LIBADD =
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_avx2.la libwebpdsp_sse2.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_sse41.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_neon.la
|
||||
libwebpdsp_la_LIBADD += libwebpdspdecode_msa.la
|
||||
libwebpdsp_la_LIBADD += libwebpdsp_msa.la
|
||||
|
||||
if BUILD_LIBWEBPDECODER
|
||||
libwebpdspdecode_la_SOURCES = $(COMMON_SOURCES)
|
||||
|
@ -284,9 +284,9 @@ static void ApplyAlphaMultiply_16b(uint8_t* rgba4444,
|
||||
#endif
|
||||
}
|
||||
|
||||
static int DispatchAlpha(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint8_t* dst, int dst_stride) {
|
||||
static int DispatchAlpha_C(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint8_t* dst, int dst_stride) {
|
||||
uint32_t alpha_mask = 0xff;
|
||||
int i, j;
|
||||
|
||||
@ -303,9 +303,9 @@ static int DispatchAlpha(const uint8_t* alpha, int alpha_stride,
|
||||
return (alpha_mask != 0xff);
|
||||
}
|
||||
|
||||
static void DispatchAlphaToGreen(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint32_t* dst, int dst_stride) {
|
||||
static void DispatchAlphaToGreen_C(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint32_t* dst, int dst_stride) {
|
||||
int i, j;
|
||||
for (j = 0; j < height; ++j) {
|
||||
for (i = 0; i < width; ++i) {
|
||||
@ -316,9 +316,9 @@ static void DispatchAlphaToGreen(const uint8_t* alpha, int alpha_stride,
|
||||
}
|
||||
}
|
||||
|
||||
static int ExtractAlpha(const uint8_t* argb, int argb_stride,
|
||||
int width, int height,
|
||||
uint8_t* alpha, int alpha_stride) {
|
||||
static int ExtractAlpha_C(const uint8_t* argb, int argb_stride,
|
||||
int width, int height,
|
||||
uint8_t* alpha, int alpha_stride) {
|
||||
uint8_t alpha_mask = 0xff;
|
||||
int i, j;
|
||||
|
||||
@ -334,11 +334,17 @@ static int ExtractAlpha(const uint8_t* argb, int argb_stride,
|
||||
return (alpha_mask == 0xff);
|
||||
}
|
||||
|
||||
static void ExtractGreen_C(const uint32_t* argb, uint8_t* alpha, int size) {
|
||||
int i;
|
||||
for (i = 0; i < size; ++i) alpha[i] = argb[i] >> 8;
|
||||
}
|
||||
|
||||
void (*WebPApplyAlphaMultiply)(uint8_t*, int, int, int, int);
|
||||
void (*WebPApplyAlphaMultiply4444)(uint8_t*, int, int, int);
|
||||
int (*WebPDispatchAlpha)(const uint8_t*, int, int, int, uint8_t*, int);
|
||||
void (*WebPDispatchAlphaToGreen)(const uint8_t*, int, int, int, uint32_t*, int);
|
||||
int (*WebPExtractAlpha)(const uint8_t*, int, int, int, uint8_t*, int);
|
||||
void (*WebPExtractGreen)(const uint32_t* argb, uint8_t* alpha, int size);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Init function
|
||||
@ -346,6 +352,7 @@ int (*WebPExtractAlpha)(const uint8_t*, int, int, int, uint8_t*, int);
|
||||
extern void WebPInitAlphaProcessingMIPSdspR2(void);
|
||||
extern void WebPInitAlphaProcessingSSE2(void);
|
||||
extern void WebPInitAlphaProcessingSSE41(void);
|
||||
extern void WebPInitAlphaProcessingNEON(void);
|
||||
|
||||
static volatile VP8CPUInfo alpha_processing_last_cpuinfo_used =
|
||||
(VP8CPUInfo)&alpha_processing_last_cpuinfo_used;
|
||||
@ -357,9 +364,11 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) {
|
||||
WebPMultRow = WebPMultRowC;
|
||||
WebPApplyAlphaMultiply = ApplyAlphaMultiply;
|
||||
WebPApplyAlphaMultiply4444 = ApplyAlphaMultiply_16b;
|
||||
WebPDispatchAlpha = DispatchAlpha;
|
||||
WebPDispatchAlphaToGreen = DispatchAlphaToGreen;
|
||||
WebPExtractAlpha = ExtractAlpha;
|
||||
|
||||
WebPDispatchAlpha = DispatchAlpha_C;
|
||||
WebPDispatchAlphaToGreen = DispatchAlphaToGreen_C;
|
||||
WebPExtractAlpha = ExtractAlpha_C;
|
||||
WebPExtractGreen = ExtractGreen_C;
|
||||
|
||||
// If defined, use CPUInfo() to overwrite some pointers with faster versions.
|
||||
if (VP8GetCPUInfo != NULL) {
|
||||
@ -373,6 +382,11 @@ WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessing(void) {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#if defined(WEBP_USE_NEON)
|
||||
if (VP8GetCPUInfo(kNEON)) {
|
||||
WebPInitAlphaProcessingNEON();
|
||||
}
|
||||
#endif
|
||||
#if defined(WEBP_USE_MIPS_DSP_R2)
|
||||
if (VP8GetCPUInfo(kMIPSdspR2)) {
|
||||
WebPInitAlphaProcessingMIPSdspR2();
|
||||
|
191
src/dsp/alpha_processing_neon.c
Normal file
191
src/dsp/alpha_processing_neon.c
Normal file
@ -0,0 +1,191 @@
|
||||
// Copyright 2017 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.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Utilities for processing transparent channel, NEON version.
|
||||
//
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./dsp.h"
|
||||
|
||||
#if defined(WEBP_USE_NEON)
|
||||
|
||||
#include "./neon.h"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#define MULTIPLIER(a) ((a) * 0x8081)
|
||||
#define PREMULTIPLY(x, m) (((x) * (m)) >> 23)
|
||||
|
||||
#define MULTIPLY_BY_ALPHA(V, ALPHA, OTHER) do { \
|
||||
const uint8x8_t alpha = (V).val[(ALPHA)]; \
|
||||
const uint16x8_t r1 = vmull_u8((V).val[1], alpha); \
|
||||
const uint16x8_t g1 = vmull_u8((V).val[2], alpha); \
|
||||
const uint16x8_t b1 = vmull_u8((V).val[(OTHER)], alpha); \
|
||||
/* we use: v / 255 = (v + 1 + (v >> 8)) >> 8 */ \
|
||||
const uint16x8_t r2 = vsraq_n_u16(r1, r1, 8); \
|
||||
const uint16x8_t g2 = vsraq_n_u16(g1, g1, 8); \
|
||||
const uint16x8_t b2 = vsraq_n_u16(b1, b1, 8); \
|
||||
const uint16x8_t r3 = vaddq_u16(r2, kOne); \
|
||||
const uint16x8_t g3 = vaddq_u16(g2, kOne); \
|
||||
const uint16x8_t b3 = vaddq_u16(b2, kOne); \
|
||||
(V).val[1] = vshrn_n_u16(r3, 8); \
|
||||
(V).val[2] = vshrn_n_u16(g3, 8); \
|
||||
(V).val[(OTHER)] = vshrn_n_u16(b3, 8); \
|
||||
} while (0)
|
||||
|
||||
static void ApplyAlphaMultiply_NEON(uint8_t* rgba, int alpha_first,
|
||||
int w, int h, int stride) {
|
||||
const uint16x8_t kOne = vdupq_n_u16(1u);
|
||||
while (h-- > 0) {
|
||||
uint32_t* const rgbx = (uint32_t*)rgba;
|
||||
int i = 0;
|
||||
if (alpha_first) {
|
||||
for (; i + 8 <= w; i += 8) {
|
||||
// load aaaa...|rrrr...|gggg...|bbbb...
|
||||
uint8x8x4_t RGBX = vld4_u8((const uint8_t*)(rgbx + i));
|
||||
MULTIPLY_BY_ALPHA(RGBX, 0, 3);
|
||||
vst4_u8((uint8_t*)(rgbx + i), RGBX);
|
||||
}
|
||||
} else {
|
||||
for (; i + 8 <= w; i += 8) {
|
||||
uint8x8x4_t RGBX = vld4_u8((const uint8_t*)(rgbx + i));
|
||||
MULTIPLY_BY_ALPHA(RGBX, 3, 0);
|
||||
vst4_u8((uint8_t*)(rgbx + i), RGBX);
|
||||
}
|
||||
}
|
||||
// Finish with left-overs.
|
||||
for (; i < w; ++i) {
|
||||
uint8_t* const rgb = rgba + (alpha_first ? 1 : 0);
|
||||
const uint8_t* const alpha = rgba + (alpha_first ? 0 : 3);
|
||||
const uint32_t a = alpha[4 * i];
|
||||
if (a != 0xff) {
|
||||
const uint32_t mult = MULTIPLIER(a);
|
||||
rgb[4 * i + 0] = PREMULTIPLY(rgb[4 * i + 0], mult);
|
||||
rgb[4 * i + 1] = PREMULTIPLY(rgb[4 * i + 1], mult);
|
||||
rgb[4 * i + 2] = PREMULTIPLY(rgb[4 * i + 2], mult);
|
||||
}
|
||||
}
|
||||
rgba += stride;
|
||||
}
|
||||
}
|
||||
#undef MULTIPLY_BY_ALPHA
|
||||
#undef MULTIPLIER
|
||||
#undef PREMULTIPLY
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static int DispatchAlpha_NEON(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint8_t* dst, int dst_stride) {
|
||||
uint32_t alpha_mask = 0xffffffffu;
|
||||
uint8x8_t mask8 = vdup_n_u8(0xff);
|
||||
uint32_t tmp[2];
|
||||
int i, j;
|
||||
for (j = 0; j < height; ++j) {
|
||||
// We don't know if alpha is first or last in dst[] (depending on rgbA/Argb
|
||||
// mode). So we must be sure dst[4*i + 8 - 1] is writable for the store.
|
||||
// Hence the test with 'width - 1' instead of just 'width'.
|
||||
for (i = 0; i + 8 <= width - 1; i += 8) {
|
||||
uint8x8x4_t rgbX = vld4_u8((const uint8_t*)(dst + 4 * i));
|
||||
const uint8x8_t alphas = vld1_u8(alpha + i);
|
||||
rgbX.val[0] = alphas;
|
||||
vst4_u8((uint8_t*)(dst + 4 * i), rgbX);
|
||||
mask8 = vand_u8(mask8, alphas);
|
||||
}
|
||||
for (; i < width; ++i) {
|
||||
const uint32_t alpha_value = alpha[i];
|
||||
dst[4 * i] = alpha_value;
|
||||
alpha_mask &= alpha_value;
|
||||
}
|
||||
alpha += alpha_stride;
|
||||
dst += dst_stride;
|
||||
}
|
||||
vst1_u8((uint8_t*)tmp, mask8);
|
||||
alpha_mask &= tmp[0];
|
||||
alpha_mask &= tmp[1];
|
||||
return (alpha_mask != 0xffffffffu);
|
||||
}
|
||||
|
||||
static void DispatchAlphaToGreen_NEON(const uint8_t* alpha, int alpha_stride,
|
||||
int width, int height,
|
||||
uint32_t* dst, int dst_stride) {
|
||||
int i, j;
|
||||
uint8x8x4_t greens; // leave A/R/B channels zero'd.
|
||||
greens.val[0] = vdup_n_u8(0);
|
||||
greens.val[2] = vdup_n_u8(0);
|
||||
greens.val[3] = vdup_n_u8(0);
|
||||
for (j = 0; j < height; ++j) {
|
||||
for (i = 0; i + 8 <= width; i += 8) {
|
||||
greens.val[1] = vld1_u8(alpha + i);
|
||||
vst4_u8((uint8_t*)(dst + i), greens);
|
||||
}
|
||||
for (; i < width; ++i) dst[i] = alpha[i] << 8;
|
||||
alpha += alpha_stride;
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
|
||||
static int ExtractAlpha_NEON(const uint8_t* argb, int argb_stride,
|
||||
int width, int height,
|
||||
uint8_t* alpha, int alpha_stride) {
|
||||
uint32_t alpha_mask = 0xffffffffu;
|
||||
uint8x8_t mask8 = vdup_n_u8(0xff);
|
||||
uint32_t tmp[2];
|
||||
int i, j;
|
||||
for (j = 0; j < height; ++j) {
|
||||
// We don't know if alpha is first or last in dst[] (depending on rgbA/Argb
|
||||
// mode). So we must be sure dst[4*i + 8 - 1] is writable for the store.
|
||||
// Hence the test with 'width - 1' instead of just 'width'.
|
||||
for (i = 0; i + 8 <= width - 1; i += 8) {
|
||||
const uint8x8x4_t rgbX = vld4_u8((const uint8_t*)(argb + 4 * i));
|
||||
const uint8x8_t alphas = rgbX.val[0];
|
||||
vst1_u8((uint8_t*)(alpha + i), alphas);
|
||||
mask8 = vand_u8(mask8, alphas);
|
||||
}
|
||||
for (; i < width; ++i) {
|
||||
alpha[i] = argb[4 * i];
|
||||
alpha_mask &= alpha[i];
|
||||
}
|
||||
argb += argb_stride;
|
||||
alpha += alpha_stride;
|
||||
}
|
||||
vst1_u8((uint8_t*)tmp, mask8);
|
||||
alpha_mask &= tmp[0];
|
||||
alpha_mask &= tmp[1];
|
||||
return (alpha_mask == 0xffffffffu);
|
||||
}
|
||||
|
||||
static void ExtractGreen_NEON(const uint32_t* argb,
|
||||
uint8_t* alpha, int size) {
|
||||
int i;
|
||||
for (i = 0; i + 16 <= size; i += 16) {
|
||||
const uint8x16x4_t rgbX = vld4q_u8((const uint8_t*)(argb + i));
|
||||
const uint8x16_t greens = rgbX.val[1];
|
||||
vst1q_u8(alpha + i, greens);
|
||||
}
|
||||
for (; i < size; ++i) alpha[i] = (argb[i] >> 8) & 0xff;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern void WebPInitAlphaProcessingNEON(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingNEON(void) {
|
||||
WebPApplyAlphaMultiply = ApplyAlphaMultiply_NEON;
|
||||
WebPDispatchAlpha = DispatchAlpha_NEON;
|
||||
WebPDispatchAlphaToGreen = DispatchAlphaToGreen_NEON;
|
||||
WebPExtractAlpha = ExtractAlpha_NEON;
|
||||
WebPExtractGreen = ExtractGreen_NEON;
|
||||
}
|
||||
|
||||
#else // !WEBP_USE_NEON
|
||||
|
||||
WEBP_DSP_INIT_STUB(WebPInitAlphaProcessingNEON)
|
||||
|
||||
#endif // WEBP_USE_NEON
|
@ -150,46 +150,46 @@ static int ExtractAlpha(const uint8_t* argb, int argb_stride,
|
||||
#define PREMULTIPLY(x, m) (((x) * (m)) >> 23)
|
||||
|
||||
// We can't use a 'const int' for the SHUFFLE value, because it has to be an
|
||||
// immediate in the _mm_shufflexx_epi16() instruction. We really a macro here.
|
||||
#define APPLY_ALPHA(RGBX, SHUFFLE, MASK, MULT) do { \
|
||||
const __m128i argb0 = _mm_loadl_epi64((__m128i*)&(RGBX)); \
|
||||
const __m128i argb1 = _mm_unpacklo_epi8(argb0, zero); \
|
||||
const __m128i alpha0 = _mm_and_si128(argb1, MASK); \
|
||||
const __m128i alpha1 = _mm_shufflelo_epi16(alpha0, SHUFFLE); \
|
||||
const __m128i alpha2 = _mm_shufflehi_epi16(alpha1, SHUFFLE); \
|
||||
/* alpha2 = [0 a0 a0 a0][0 a1 a1 a1] */ \
|
||||
const __m128i scale0 = _mm_mullo_epi16(alpha2, MULT); \
|
||||
const __m128i scale1 = _mm_mulhi_epu16(alpha2, MULT); \
|
||||
const __m128i argb2 = _mm_mulhi_epu16(argb1, scale0); \
|
||||
const __m128i argb3 = _mm_mullo_epi16(argb1, scale1); \
|
||||
const __m128i argb4 = _mm_adds_epu16(argb2, argb3); \
|
||||
const __m128i argb5 = _mm_srli_epi16(argb4, 7); \
|
||||
const __m128i argb6 = _mm_or_si128(argb5, alpha0); \
|
||||
const __m128i argb7 = _mm_packus_epi16(argb6, zero); \
|
||||
_mm_storel_epi64((__m128i*)&(RGBX), argb7); \
|
||||
// immediate in the _mm_shufflexx_epi16() instruction. We really need a macro.
|
||||
// We use: v / 255 = (v * 0x8081) >> 23, where v = alpha * {r,g,b} is a 16bit
|
||||
// value.
|
||||
#define APPLY_ALPHA(RGBX, SHUFFLE) do { \
|
||||
const __m128i argb0 = _mm_loadu_si128((const __m128i*)&(RGBX)); \
|
||||
const __m128i argb1_lo = _mm_unpacklo_epi8(argb0, zero); \
|
||||
const __m128i argb1_hi = _mm_unpackhi_epi8(argb0, zero); \
|
||||
const __m128i alpha0_lo = _mm_or_si128(argb1_lo, kMask); \
|
||||
const __m128i alpha0_hi = _mm_or_si128(argb1_hi, kMask); \
|
||||
const __m128i alpha1_lo = _mm_shufflelo_epi16(alpha0_lo, SHUFFLE); \
|
||||
const __m128i alpha1_hi = _mm_shufflelo_epi16(alpha0_hi, SHUFFLE); \
|
||||
const __m128i alpha2_lo = _mm_shufflehi_epi16(alpha1_lo, SHUFFLE); \
|
||||
const __m128i alpha2_hi = _mm_shufflehi_epi16(alpha1_hi, SHUFFLE); \
|
||||
/* alpha2 = [ff a0 a0 a0][ff a1 a1 a1] */ \
|
||||
const __m128i A0_lo = _mm_mullo_epi16(alpha2_lo, argb1_lo); \
|
||||
const __m128i A0_hi = _mm_mullo_epi16(alpha2_hi, argb1_hi); \
|
||||
const __m128i A1_lo = _mm_mulhi_epu16(A0_lo, kMult); \
|
||||
const __m128i A1_hi = _mm_mulhi_epu16(A0_hi, kMult); \
|
||||
const __m128i A2_lo = _mm_srli_epi16(A1_lo, 7); \
|
||||
const __m128i A2_hi = _mm_srli_epi16(A1_hi, 7); \
|
||||
const __m128i A3 = _mm_packus_epi16(A2_lo, A2_hi); \
|
||||
_mm_storeu_si128((__m128i*)&(RGBX), A3); \
|
||||
} while (0)
|
||||
|
||||
static void ApplyAlphaMultiply(uint8_t* rgba, int alpha_first,
|
||||
int w, int h, int stride) {
|
||||
static void ApplyAlphaMultiply_SSE2(uint8_t* rgba, int alpha_first,
|
||||
int w, int h, int stride) {
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
const int kSpan = 2;
|
||||
const int w2 = w & ~(kSpan - 1);
|
||||
const __m128i kMult = _mm_set1_epi16(0x8081u);
|
||||
const __m128i kMask = _mm_set_epi16(0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0);
|
||||
const int kSpan = 4;
|
||||
while (h-- > 0) {
|
||||
uint32_t* const rgbx = (uint32_t*)rgba;
|
||||
int i;
|
||||
if (!alpha_first) {
|
||||
const __m128i kMask = _mm_set_epi16(0xff, 0, 0, 0, 0xff, 0, 0, 0);
|
||||
const __m128i kMult =
|
||||
_mm_set_epi16(0, 0x8081, 0x8081, 0x8081, 0, 0x8081, 0x8081, 0x8081);
|
||||
for (i = 0; i < w2; i += kSpan) {
|
||||
APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(0, 3, 3, 3), kMask, kMult);
|
||||
for (i = 0; i + kSpan <= w; i += kSpan) {
|
||||
APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(2, 3, 3, 3));
|
||||
}
|
||||
} else {
|
||||
const __m128i kMask = _mm_set_epi16(0, 0, 0, 0xff, 0, 0, 0, 0xff);
|
||||
const __m128i kMult =
|
||||
_mm_set_epi16(0x8081, 0x8081, 0x8081, 0, 0x8081, 0x8081, 0x8081, 0);
|
||||
for (i = 0; i < w2; i += kSpan) {
|
||||
APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(0, 0, 0, 3), kMask, kMult);
|
||||
for (i = 0; i + kSpan <= w; i += kSpan) {
|
||||
APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(0, 0, 0, 1));
|
||||
}
|
||||
}
|
||||
// Finish with left-overs.
|
||||
@ -213,64 +213,51 @@ static void ApplyAlphaMultiply(uint8_t* rgba, int alpha_first,
|
||||
// -----------------------------------------------------------------------------
|
||||
// Apply alpha value to rows
|
||||
|
||||
// We use: kINV255 = (1 << 24) / 255 = 0x010101
|
||||
// So: a * kINV255 = (a << 16) | [(a << 8) | a]
|
||||
// -> _mm_mulhi_epu16() takes care of the (a<<16) part,
|
||||
// and _mm_mullo_epu16(a * 0x0101,...) takes care of the "(a << 8) | a" one.
|
||||
|
||||
static void MultARGBRow(uint32_t* const ptr, int width, int inverse) {
|
||||
static void MultARGBRow_SSE2(uint32_t* const ptr, int width, int inverse) {
|
||||
int x = 0;
|
||||
if (!inverse) {
|
||||
const int kSpan = 2;
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
const __m128i kRound =
|
||||
_mm_set_epi16(0, 1 << 7, 1 << 7, 1 << 7, 0, 1 << 7, 1 << 7, 1 << 7);
|
||||
const __m128i kMult =
|
||||
_mm_set_epi16(0, 0x0101, 0x0101, 0x0101, 0, 0x0101, 0x0101, 0x0101);
|
||||
const __m128i kOne64 = _mm_set_epi16(1u << 8, 0, 0, 0, 1u << 8, 0, 0, 0);
|
||||
const int w2 = width & ~(kSpan - 1);
|
||||
for (x = 0; x < w2; x += kSpan) {
|
||||
const __m128i argb0 = _mm_loadl_epi64((__m128i*)&ptr[x]);
|
||||
const __m128i argb1 = _mm_unpacklo_epi8(argb0, zero);
|
||||
const __m128i tmp0 = _mm_shufflelo_epi16(argb1, _MM_SHUFFLE(3, 3, 3, 3));
|
||||
const __m128i tmp1 = _mm_shufflehi_epi16(tmp0, _MM_SHUFFLE(3, 3, 3, 3));
|
||||
const __m128i tmp2 = _mm_srli_epi64(tmp1, 16);
|
||||
const __m128i scale0 = _mm_mullo_epi16(tmp1, kMult);
|
||||
const __m128i scale1 = _mm_or_si128(tmp2, kOne64);
|
||||
const __m128i argb2 = _mm_mulhi_epu16(argb1, scale0);
|
||||
const __m128i argb3 = _mm_mullo_epi16(argb1, scale1);
|
||||
const __m128i argb4 = _mm_adds_epu16(argb2, argb3);
|
||||
const __m128i argb5 = _mm_adds_epu16(argb4, kRound);
|
||||
const __m128i argb6 = _mm_srli_epi16(argb5, 8);
|
||||
const __m128i argb7 = _mm_packus_epi16(argb6, zero);
|
||||
_mm_storel_epi64((__m128i*)&ptr[x], argb7);
|
||||
const __m128i k128 = _mm_set1_epi16(128);
|
||||
const __m128i kMult = _mm_set1_epi16(0x0101);
|
||||
const __m128i kMask = _mm_set_epi16(0, 0xff, 0, 0, 0, 0xff, 0, 0);
|
||||
for (x = 0; x + kSpan <= width; x += kSpan) {
|
||||
// To compute 'result = (int)(a * x / 255. + .5)', we use:
|
||||
// tmp = a * v + 128, result = (tmp * 0x0101u) >> 16
|
||||
const __m128i A0 = _mm_loadl_epi64((const __m128i*)&ptr[x]);
|
||||
const __m128i A1 = _mm_unpacklo_epi8(A0, zero);
|
||||
const __m128i A2 = _mm_or_si128(A1, kMask);
|
||||
const __m128i A3 = _mm_shufflelo_epi16(A2, _MM_SHUFFLE(2, 3, 3, 3));
|
||||
const __m128i A4 = _mm_shufflehi_epi16(A3, _MM_SHUFFLE(2, 3, 3, 3));
|
||||
// here, A4 = [ff a0 a0 a0][ff a1 a1 a1]
|
||||
const __m128i A5 = _mm_mullo_epi16(A4, A1);
|
||||
const __m128i A6 = _mm_add_epi16(A5, k128);
|
||||
const __m128i A7 = _mm_mulhi_epu16(A6, kMult);
|
||||
const __m128i A10 = _mm_packus_epi16(A7, zero);
|
||||
_mm_storel_epi64((__m128i*)&ptr[x], A10);
|
||||
}
|
||||
}
|
||||
width -= x;
|
||||
if (width > 0) WebPMultARGBRowC(ptr + x, width, inverse);
|
||||
}
|
||||
|
||||
static void MultRow(uint8_t* const ptr, const uint8_t* const alpha,
|
||||
int width, int inverse) {
|
||||
static void MultRow_SSE2(uint8_t* const ptr, const uint8_t* const alpha,
|
||||
int width, int inverse) {
|
||||
int x = 0;
|
||||
if (!inverse) {
|
||||
const int kSpan = 8;
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
const __m128i kRound = _mm_set1_epi16(1 << 7);
|
||||
const int w2 = width & ~(kSpan - 1);
|
||||
for (x = 0; x < w2; x += kSpan) {
|
||||
const __m128i k128 = _mm_set1_epi16(128);
|
||||
const __m128i kMult = _mm_set1_epi16(0x0101);
|
||||
for (x = 0; x + 8 <= width; x += 8) {
|
||||
const __m128i v0 = _mm_loadl_epi64((__m128i*)&ptr[x]);
|
||||
const __m128i a0 = _mm_loadl_epi64((const __m128i*)&alpha[x]);
|
||||
const __m128i v1 = _mm_unpacklo_epi8(v0, zero);
|
||||
const __m128i alpha0 = _mm_loadl_epi64((const __m128i*)&alpha[x]);
|
||||
const __m128i alpha1 = _mm_unpacklo_epi8(alpha0, zero);
|
||||
const __m128i alpha2 = _mm_unpacklo_epi8(alpha0, alpha0);
|
||||
const __m128i v2 = _mm_mulhi_epu16(v1, alpha2);
|
||||
const __m128i v3 = _mm_mullo_epi16(v1, alpha1);
|
||||
const __m128i v4 = _mm_adds_epu16(v2, v3);
|
||||
const __m128i v5 = _mm_adds_epu16(v4, kRound);
|
||||
const __m128i v6 = _mm_srli_epi16(v5, 8);
|
||||
const __m128i v7 = _mm_packus_epi16(v6, zero);
|
||||
_mm_storel_epi64((__m128i*)&ptr[x], v7);
|
||||
const __m128i a1 = _mm_unpacklo_epi8(a0, zero);
|
||||
const __m128i v2 = _mm_mullo_epi16(v1, a1);
|
||||
const __m128i v3 = _mm_add_epi16(v2, k128);
|
||||
const __m128i v4 = _mm_mulhi_epu16(v3, kMult);
|
||||
const __m128i v5 = _mm_packus_epi16(v4, zero);
|
||||
_mm_storel_epi64((__m128i*)&ptr[x], v5);
|
||||
}
|
||||
}
|
||||
width -= x;
|
||||
@ -283,9 +270,9 @@ static void MultRow(uint8_t* const ptr, const uint8_t* const alpha,
|
||||
extern void WebPInitAlphaProcessingSSE2(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE2(void) {
|
||||
WebPMultARGBRow = MultARGBRow;
|
||||
WebPMultRow = MultRow;
|
||||
WebPApplyAlphaMultiply = ApplyAlphaMultiply;
|
||||
WebPMultARGBRow = MultARGBRow_SSE2;
|
||||
WebPMultRow = MultRow_SSE2;
|
||||
WebPApplyAlphaMultiply = ApplyAlphaMultiply_SSE2;
|
||||
WebPDispatchAlpha = DispatchAlpha;
|
||||
WebPDispatchAlphaToGreen = DispatchAlphaToGreen;
|
||||
WebPExtractAlpha = ExtractAlpha;
|
||||
|
@ -12,6 +12,7 @@
|
||||
// Author: Skal (pascal.massimino@gmail.com)
|
||||
|
||||
#include "./dsp.h"
|
||||
#include "./lossless.h"
|
||||
|
||||
#if defined(WEBP_USE_SSE2)
|
||||
|
||||
@ -19,30 +20,13 @@
|
||||
#include <emmintrin.h>
|
||||
#include <string.h>
|
||||
|
||||
static WEBP_INLINE uint32_t MakeARGB32(int a, int r, int g, int b) {
|
||||
return (((uint32_t)a << 24) | (r << 16) | (g << 8) | b);
|
||||
}
|
||||
|
||||
static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
|
||||
const uint8_t* b, int len, uint32_t* out) {
|
||||
(void)a;
|
||||
if (g == r + 1) { // RGBA input order. Need to swap R and B.
|
||||
int i = 0;
|
||||
const int len_max = len & ~3; // max length processed in main loop
|
||||
const __m128i red_blue_mask = _mm_set1_epi32(0x00ff00ffu);
|
||||
assert(b == r + 2);
|
||||
assert(a == r + 3);
|
||||
for (; i < len_max; i += 4) {
|
||||
const __m128i A = _mm_loadu_si128((const __m128i*)(r + 4 * i));
|
||||
const __m128i B = _mm_and_si128(A, red_blue_mask); // R 0 B 0
|
||||
const __m128i C = _mm_andnot_si128(red_blue_mask, A); // 0 G 0 A
|
||||
const __m128i D = _mm_shufflelo_epi16(B, _MM_SHUFFLE(2, 3, 0, 1));
|
||||
const __m128i E = _mm_shufflehi_epi16(D, _MM_SHUFFLE(2, 3, 0, 1));
|
||||
const __m128i F = _mm_or_si128(E, C);
|
||||
_mm_storeu_si128((__m128i*)(out + i), F);
|
||||
}
|
||||
for (; i < len; ++i) {
|
||||
out[i] = MakeARGB32(a[4 * i], r[4 * i], g[4 * i], b[4 * i]);
|
||||
}
|
||||
VP8LConvertBGRAToRGBA((const uint32_t*)r, len, (uint8_t*)out);
|
||||
} else {
|
||||
assert(g == b + 1);
|
||||
assert(r == b + 2);
|
||||
@ -55,8 +39,10 @@ static void PackARGB(const uint8_t* a, const uint8_t* r, const uint8_t* g,
|
||||
// Entry point
|
||||
|
||||
extern void VP8EncDspARGBInitSSE2(void);
|
||||
extern void VP8LDspInitSSE2(void);
|
||||
|
||||
WEBP_TSAN_IGNORE_FUNCTION void VP8EncDspARGBInitSSE2(void) {
|
||||
VP8LDspInitSSE2();
|
||||
VP8PackARGB = PackARGB;
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,91 @@ static WEBP_INLINE void VP8Transpose_2_4x4_16b(
|
||||
// a03 a13 a23 a33 b03 b13 b23 b33
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Channel mixing.
|
||||
|
||||
// Function used several times in VP8PlanarTo24b.
|
||||
// It samples the in buffer as follows: one every two unsigned char is stored
|
||||
// at the beginning of the buffer, while the other half is stored at the end.
|
||||
#define VP8PlanarTo24bHelper(IN, OUT) \
|
||||
do { \
|
||||
const __m128i v_mask = _mm_set1_epi16(0x00ff); \
|
||||
/* Take one every two upper 8b values.*/ \
|
||||
(OUT##0) = _mm_packus_epi16(_mm_and_si128((IN##0), v_mask), \
|
||||
_mm_and_si128((IN##1), v_mask)); \
|
||||
(OUT##1) = _mm_packus_epi16(_mm_and_si128((IN##2), v_mask), \
|
||||
_mm_and_si128((IN##3), v_mask)); \
|
||||
(OUT##2) = _mm_packus_epi16(_mm_and_si128((IN##4), v_mask), \
|
||||
_mm_and_si128((IN##5), v_mask)); \
|
||||
/* Take one every two lower 8b values.*/ \
|
||||
(OUT##3) = _mm_packus_epi16(_mm_srli_epi16((IN##0), 8), \
|
||||
_mm_srli_epi16((IN##1), 8)); \
|
||||
(OUT##4) = _mm_packus_epi16(_mm_srli_epi16((IN##2), 8), \
|
||||
_mm_srli_epi16((IN##3), 8)); \
|
||||
(OUT##5) = _mm_packus_epi16(_mm_srli_epi16((IN##4), 8), \
|
||||
_mm_srli_epi16((IN##5), 8)); \
|
||||
} while (0)
|
||||
|
||||
// Pack the planar buffers
|
||||
// rrrr... rrrr... gggg... gggg... bbbb... bbbb....
|
||||
// triplet by triplet in the output buffer rgb as rgbrgbrgbrgb ...
|
||||
static WEBP_INLINE void VP8PlanarTo24b(__m128i* const in0, __m128i* const in1,
|
||||
__m128i* const in2, __m128i* const in3,
|
||||
__m128i* const in4, __m128i* const in5) {
|
||||
// The input is 6 registers of sixteen 8b but for the sake of explanation,
|
||||
// let's take 6 registers of four 8b values.
|
||||
// To pack, we will keep taking one every two 8b integer and move it
|
||||
// around as follows:
|
||||
// Input:
|
||||
// r0r1r2r3 | r4r5r6r7 | g0g1g2g3 | g4g5g6g7 | b0b1b2b3 | b4b5b6b7
|
||||
// Split the 6 registers in two sets of 3 registers: the first set as the even
|
||||
// 8b bytes, the second the odd ones:
|
||||
// r0r2r4r6 | g0g2g4g6 | b0b2b4b6 | r1r3r5r7 | g1g3g5g7 | b1b3b5b7
|
||||
// Repeat the same permutations twice more:
|
||||
// r0r4g0g4 | b0b4r1r5 | g1g5b1b5 | r2r6g2g6 | b2b6r3r7 | g3g7b3b7
|
||||
// r0g0b0r1 | g1b1r2g2 | b2r3g3b3 | r4g4b4r5 | g5b5r6g6 | b6r7g7b7
|
||||
__m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
|
||||
VP8PlanarTo24bHelper(*in, tmp);
|
||||
VP8PlanarTo24bHelper(tmp, *in);
|
||||
VP8PlanarTo24bHelper(*in, tmp);
|
||||
// We need to do it two more times than the example as we have sixteen bytes.
|
||||
{
|
||||
__m128i out0, out1, out2, out3, out4, out5;
|
||||
VP8PlanarTo24bHelper(tmp, out);
|
||||
VP8PlanarTo24bHelper(out, *in);
|
||||
}
|
||||
}
|
||||
|
||||
#undef VP8PlanarTo24bHelper
|
||||
|
||||
// Convert four packed four-channel buffers like argbargbargbargb... into the
|
||||
// split channels aaaaa ... rrrr ... gggg .... bbbbb ......
|
||||
static WEBP_INLINE void VP8L32bToPlanar(__m128i* const in0,
|
||||
__m128i* const in1,
|
||||
__m128i* const in2,
|
||||
__m128i* const in3) {
|
||||
// Column-wise transpose.
|
||||
const __m128i A0 = _mm_unpacklo_epi8(*in0, *in1);
|
||||
const __m128i A1 = _mm_unpackhi_epi8(*in0, *in1);
|
||||
const __m128i A2 = _mm_unpacklo_epi8(*in2, *in3);
|
||||
const __m128i A3 = _mm_unpackhi_epi8(*in2, *in3);
|
||||
const __m128i B0 = _mm_unpacklo_epi8(A0, A1);
|
||||
const __m128i B1 = _mm_unpackhi_epi8(A0, A1);
|
||||
const __m128i B2 = _mm_unpacklo_epi8(A2, A3);
|
||||
const __m128i B3 = _mm_unpackhi_epi8(A2, A3);
|
||||
// C0 = g7 g6 ... g1 g0 | b7 b6 ... b1 b0
|
||||
// C1 = a7 a6 ... a1 a0 | r7 r6 ... r1 r0
|
||||
const __m128i C0 = _mm_unpacklo_epi8(B0, B1);
|
||||
const __m128i C1 = _mm_unpackhi_epi8(B0, B1);
|
||||
const __m128i C2 = _mm_unpacklo_epi8(B2, B3);
|
||||
const __m128i C3 = _mm_unpackhi_epi8(B2, B3);
|
||||
// Gather the channels.
|
||||
*in0 = _mm_unpackhi_epi64(C1, C3);
|
||||
*in1 = _mm_unpacklo_epi64(C1, C3);
|
||||
*in2 = _mm_unpackhi_epi64(C0, C2);
|
||||
*in3 = _mm_unpacklo_epi64(C0, C2);
|
||||
}
|
||||
|
||||
#endif // WEBP_USE_SSE2
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user