mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Compare commits
483 Commits
21895b05ab
...
v1.7.0beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfc7affa0d | ||
|
|
dba870122c | ||
|
|
35abfe72d6 | ||
|
|
497ff3400c | ||
|
|
bb4e79c947 | ||
|
|
b00bb570f8 | ||
|
|
c68de14844 | ||
|
|
cc7fa5e23f | ||
|
|
ec99b373dd | ||
|
|
3184947a25 | ||
|
|
c5ead5d2cd | ||
|
|
76c5c11168 | ||
|
|
ddcca52933 | ||
|
|
3bd90db79f | ||
|
|
1fc5345bff | ||
|
|
81b1cff052 | ||
|
|
bc1d2b7d23 | ||
|
|
a16d1ef27a | ||
|
|
4b9fe200db | ||
|
|
223aed9f90 | ||
|
|
064ededa0f | ||
|
|
92d7dd1ede | ||
|
|
1b3d312513 | ||
|
|
47b6a93924 | ||
|
|
e1ff1cc930 | ||
|
|
9acee8b4b2 | ||
|
|
8ffa92dc25 | ||
|
|
24382d838c | ||
|
|
9307eef199 | ||
|
|
3d1fec50e8 | ||
|
|
0781bc4905 | ||
|
|
188962a93b | ||
|
|
e55c190818 | ||
|
|
1a9eb510eb | ||
|
|
77476d3c37 | ||
|
|
a671f8baea | ||
|
|
f32c657fc7 | ||
|
|
381283fb5f | ||
|
|
3dd43ae670 | ||
|
|
13d83c6948 | ||
|
|
f19f7a6c95 | ||
|
|
e0fea61cd8 | ||
|
|
689b9c58fe | ||
|
|
dc6cddd798 | ||
|
|
5d2841d272 | ||
|
|
9012e3d108 | ||
|
|
81d58f913e | ||
|
|
0ee7a07a85 | ||
|
|
6acc280403 | ||
|
|
01358ecec2 | ||
|
|
7a35bcac1a | ||
|
|
673ae608ab | ||
|
|
73ea393ab2 | ||
|
|
dff4a834ce | ||
|
|
ad817b9b2b | ||
|
|
218b2d7c70 | ||
|
|
67890a19f3 | ||
|
|
53097f5bbb | ||
|
|
36562c1032 | ||
|
|
82fa6aed0e | ||
|
|
382de60042 | ||
|
|
06963c7841 | ||
|
|
9f2fb72c67 | ||
|
|
10ea5caef2 | ||
|
|
2460d9494d | ||
|
|
e8e7b6681e | ||
|
|
033dd3f20a | ||
|
|
341e23c009 | ||
|
|
e4521a073c | ||
|
|
5ff2d472e8 | ||
|
|
f8eeac2b11 | ||
|
|
e57ab4311b | ||
|
|
9015c44736 | ||
|
|
1d7f037627 | ||
|
|
c4c28d7251 | ||
|
|
0fba15c567 | ||
|
|
c062330846 | ||
|
|
0448d90f01 | ||
|
|
127bede89c | ||
|
|
3e4bd8c261 | ||
|
|
cc085343ec | ||
|
|
ea0197a3e3 | ||
|
|
c2f0c9683f | ||
|
|
79a332afd0 | ||
|
|
352e2fe4c7 | ||
|
|
3077b5e049 | ||
|
|
98043c79a2 | ||
|
|
2bf96d75ec | ||
|
|
678020ae18 | ||
|
|
58e69e45ff | ||
|
|
7b51b8c13b | ||
|
|
5f7e71fa78 | ||
|
|
0cd3d25ae8 | ||
|
|
83a2959908 | ||
|
|
ab2ef2ceb1 | ||
|
|
f0341bae80 | ||
|
|
ed3543679a | ||
|
|
9c7aee825c | ||
|
|
d8055d7123 | ||
|
|
92ef42d5e1 | ||
|
|
1d3a1e36a7 | ||
|
|
d368235da4 | ||
|
|
06b0c83920 | ||
|
|
2130a3cd20 | ||
|
|
f1e4acb5b1 | ||
|
|
7e56f5858d | ||
|
|
82fca45d27 | ||
|
|
f55ee011a2 | ||
|
|
9c9009ec7d | ||
|
|
01d91b4370 | ||
|
|
1fd10de101 | ||
|
|
9149259041 | ||
|
|
8bc832389a | ||
|
|
ba22b208ed | ||
|
|
0f6d60e672 | ||
|
|
6ce2d220b4 | ||
|
|
d7312be749 | ||
|
|
125eac0ee4 | ||
|
|
ab95226db8 | ||
|
|
3043819fb2 | ||
|
|
565e1bc1ae | ||
|
|
5bdcb914a4 | ||
|
|
e8213aa68f | ||
|
|
d4ac328617 | ||
|
|
56e6741b25 | ||
|
|
3e04e189d8 | ||
|
|
eb67f8bcb1 | ||
|
|
9c078fb7d2 | ||
|
|
ae31a1ebdb | ||
|
|
b1d49de5bc | ||
|
|
d7e9c1c584 | ||
|
|
28451a8797 | ||
|
|
e6eb1d6fda | ||
|
|
82dd5d3575 | ||
|
|
a5b6764cea | ||
|
|
56850aba35 | ||
|
|
13f025c29a | ||
|
|
d92b0f23e6 | ||
|
|
eeab1cfefc | ||
|
|
38d22ef928 | ||
|
|
ab1ad88ecc | ||
|
|
caa59e0007 | ||
|
|
310ffb25f8 | ||
|
|
c026b07529 | ||
|
|
6988b31244 | ||
|
|
b23a10f565 | ||
|
|
201e9144a6 | ||
|
|
ba8495bba9 | ||
|
|
3393042627 | ||
|
|
a072dfee8e | ||
|
|
e39e182357 | ||
|
|
ab71e135e7 | ||
|
|
1b577e9bc6 | ||
|
|
238fdc197d | ||
|
|
8cfee5fa78 | ||
|
|
44a9af81b0 | ||
|
|
755f92fc41 | ||
|
|
d9d1c997d8 | ||
|
|
aeb4a22975 | ||
|
|
9c0b5ab848 | ||
|
|
05dcaffd38 | ||
|
|
cca25b182f | ||
|
|
f87df31c8c | ||
|
|
41547820e8 | ||
|
|
e5d462d829 | ||
|
|
6f46730cb7 | ||
|
|
67b88b8ee0 | ||
|
|
7a4bfbdec1 | ||
|
|
859254054a | ||
|
|
515659d638 | ||
|
|
fd409c8019 | ||
|
|
9ee6678e1f | ||
|
|
9b36280e31 | ||
|
|
eaad9f9177 | ||
|
|
70cd1a10f2 | ||
|
|
7974d60f54 | ||
|
|
c7e743d385 | ||
|
|
b2e89f1af6 | ||
|
|
ad30a1262b | ||
|
|
35f88c1341 | ||
|
|
4f8050416f | ||
|
|
776d1768aa | ||
|
|
d7078c52e2 | ||
|
|
4a67ac3f1e | ||
|
|
2799bf9a4f | ||
|
|
34e49ae1bc | ||
|
|
cea01951da | ||
|
|
1a9c06b11a | ||
|
|
f3b1eb68a6 | ||
|
|
12845bc947 | ||
|
|
3ac960f128 | ||
|
|
eb2b0248e2 | ||
|
|
e529698d38 | ||
|
|
1a9e897289 | ||
|
|
3a81956ffe | ||
|
|
0acf4f9770 | ||
|
|
b407af6503 | ||
|
|
0fb41f05df | ||
|
|
8ebdaa0700 | ||
|
|
4e61b58980 | ||
|
|
88e7d62fbc | ||
|
|
43cd0a0bb5 | ||
|
|
1345c5bff8 | ||
|
|
39c420834f | ||
|
|
f898f69f46 | ||
|
|
352f43cdc6 | ||
|
|
f99393490d | ||
|
|
deb920b4a7 | ||
|
|
148cdac18f | ||
|
|
51ecc14a8a | ||
|
|
713a20c57d | ||
|
|
4526f546ba | ||
|
|
0c5acfa19e | ||
|
|
848eeacb41 | ||
|
|
2ced844b0e | ||
|
|
e2c5ed8d1d | ||
|
|
76004ce6ed | ||
|
|
258b986917 | ||
|
|
50a09830b8 | ||
|
|
9a3f244085 | ||
|
|
fb1305faeb | ||
|
|
3d7f3bbab7 | ||
|
|
2d032e966d | ||
|
|
8dd3784f7c | ||
|
|
98b9371115 | ||
|
|
d29413a2a9 | ||
|
|
dc63b03da1 | ||
|
|
cf354c2c82 | ||
|
|
484dad1a19 | ||
|
|
1695471118 | ||
|
|
ae14dcd404 | ||
|
|
302c58b8cf | ||
|
|
39fee3cee1 | ||
|
|
b7362c6738 | ||
|
|
f2d8561fdc | ||
|
|
1bd81ffa21 | ||
|
|
6d2b1a7dbc | ||
|
|
5daa97c2eb | ||
|
|
9e441e96b9 | ||
|
|
a0d314ce84 | ||
|
|
b871b25997 | ||
|
|
d38ebc9ded | ||
|
|
995402ca6e | ||
|
|
1982968dad | ||
|
|
32cd66d619 | ||
|
|
03a53fa429 | ||
|
|
441de8f4fd | ||
|
|
4e5c80034e | ||
|
|
879d63156a | ||
|
|
eb021245d0 | ||
|
|
6607a3b905 | ||
|
|
28711dff2a | ||
|
|
4413d5dcd2 | ||
|
|
206d1eed42 | ||
|
|
114fa16ab3 | ||
|
|
eb2af04bd3 | ||
|
|
200fc68f52 | ||
|
|
4cfd01a288 | ||
|
|
e98229ceb0 | ||
|
|
ad1a4c8cc3 | ||
|
|
8df7c46e5b | ||
|
|
99078ec8bd | ||
|
|
a2c5f56e77 | ||
|
|
9e168ea2c9 | ||
|
|
06be739941 | ||
|
|
448092b8eb | ||
|
|
1faa6ff32c | ||
|
|
3adf438f39 | ||
|
|
d45a632529 | ||
|
|
5a1b8d106d | ||
|
|
05f896004f | ||
|
|
a4f1de9109 | ||
|
|
7ebb353944 | ||
|
|
b1f0c7d0e5 | ||
|
|
55df049962 | ||
|
|
219ba1370e | ||
|
|
4dc4471bb5 | ||
|
|
a199a15b28 | ||
|
|
e9446f2f95 | ||
|
|
f70f2fcf48 | ||
|
|
158c947ce2 | ||
|
|
7e2707e2af | ||
|
|
81824079b5 | ||
|
|
e8e1add0a8 | ||
|
|
a549223f91 | ||
|
|
ebe7945b96 | ||
|
|
e3e35aa980 | ||
|
|
9f2fbcf5d8 | ||
|
|
264ba68afe | ||
|
|
3ef99c9316 | ||
|
|
4b29f97f9b | ||
|
|
fe6e6cf130 | ||
|
|
547df4b9ca | ||
|
|
a0d4a0b971 | ||
|
|
72c2577302 | ||
|
|
091fab713c | ||
|
|
32aeb2cd4e | ||
|
|
c1bcdc3a86 | ||
|
|
553b8f85d3 | ||
|
|
30666a6097 | ||
|
|
0bfa63cd0d | ||
|
|
b37a7c6674 | ||
|
|
7657ac14f2 | ||
|
|
d9f60caf72 | ||
|
|
88c20ada06 | ||
|
|
f3bfc4a142 | ||
|
|
3fdef04d55 | ||
|
|
eae431e514 | ||
|
|
003590c361 | ||
|
|
8e23262b2b | ||
|
|
157e0649e0 | ||
|
|
83f1287c02 | ||
|
|
a1124a574a | ||
|
|
6f27254a7e | ||
|
|
79fc8fa0d9 | ||
|
|
394bc6cdee | ||
|
|
bb06552075 | ||
|
|
a14071d814 | ||
|
|
23f3e46518 | ||
|
|
f97b2a6cde | ||
|
|
23f4320775 | ||
|
|
fb411867b0 | ||
|
|
5aa2ca454d | ||
|
|
7905286ffa | ||
|
|
2edcb6ad0f | ||
|
|
0f1599e6e5 | ||
|
|
cbf22f30b4 | ||
|
|
9bf3c70730 | ||
|
|
1bc5747713 | ||
|
|
4a7796faca | ||
|
|
34081a0e2f | ||
|
|
b88c94208a | ||
|
|
30662f5e92 | ||
|
|
46ad4c5bd4 | ||
|
|
5c32606ec0 | ||
|
|
a08ac031fc | ||
|
|
c233ec8743 | ||
|
|
d594be641a | ||
|
|
4c9168875b | ||
|
|
3c051ee282 | ||
|
|
e1ded944f0 | ||
|
|
c09dddc0cd | ||
|
|
bd56d76417 | ||
|
|
0cc23ac171 | ||
|
|
cb10e19725 | ||
|
|
9dba7219a0 | ||
|
|
17c6af8c40 | ||
|
|
6a02eb6d2c | ||
|
|
40d41fe6f8 | ||
|
|
7073d26e51 | ||
|
|
cf76fe8654 | ||
|
|
b780b64fbf | ||
|
|
b1876ab6e2 | ||
|
|
28a95d125f | ||
|
|
993f68c006 | ||
|
|
8d23524359 | ||
|
|
e0f4aaa668 | ||
|
|
3de174cd2f | ||
|
|
eaf2f1dcbe | ||
|
|
ea0b4c602e | ||
|
|
371c3d4dfd | ||
|
|
0bcf5fb451 | ||
|
|
57d6907d89 | ||
|
|
6cf97e37af | ||
|
|
8ef61c4693 | ||
|
|
25a116f97d | ||
|
|
d6d41c847a | ||
|
|
9e0297546f | ||
|
|
d529363d13 | ||
|
|
55e93d7090 | ||
|
|
23674b75be | ||
|
|
0ddf350360 | ||
|
|
066f9862f0 | ||
|
|
ae1a5c811c | ||
|
|
5a1ce92c0c | ||
|
|
7a498039c5 | ||
|
|
40a93652aa | ||
|
|
a1362f38de | ||
|
|
30bc0333fe | ||
|
|
55794013d4 | ||
|
|
2e92b4dfa0 | ||
|
|
f46106fa04 | ||
|
|
0dcd32f39c | ||
|
|
808ea281a4 | ||
|
|
ec89aefb44 | ||
|
|
6152dbd424 | ||
|
|
fe18c0d9ea | ||
|
|
1b0358302d | ||
|
|
d20f9d5030 | ||
|
|
fc447311aa | ||
|
|
8e30e43587 | ||
|
|
0403ccf1de | ||
|
|
1a321cc088 | ||
|
|
c9f99f487b | ||
|
|
8360e60abc | ||
|
|
2799f74489 | ||
|
|
7363babe4f | ||
|
|
e3a526f789 | ||
|
|
8f0935b8dc | ||
|
|
ae6503fe0e | ||
|
|
851a6265a8 | ||
|
|
ffa24d4108 | ||
|
|
206f4d2678 | ||
|
|
bb040784c2 | ||
|
|
70e1af50ed | ||
|
|
eb4a645eda | ||
|
|
9f7f03a3c4 | ||
|
|
395ddbd318 | ||
|
|
9f0d36c85f | ||
|
|
e9760e5e95 | ||
|
|
b96b2b7e90 | ||
|
|
9bb705e0a8 | ||
|
|
e860f77393 | ||
|
|
b5a7565908 | ||
|
|
e88e221d91 | ||
|
|
b10867cdc2 | ||
|
|
bf7084b80d | ||
|
|
6afcee826f | ||
|
|
f15a5006c8 | ||
|
|
cdbd5174bd | ||
|
|
7a9b6203ef | ||
|
|
803493e19c | ||
|
|
4245e6b1b2 | ||
|
|
81892f6b90 | ||
|
|
862993827d | ||
|
|
d304125332 | ||
|
|
9124f3e29a | ||
|
|
2969375aa6 | ||
|
|
5e8ba1cbbf | ||
|
|
8aee43d10a | ||
|
|
e355657bbe | ||
|
|
fb6ba9acf4 | ||
|
|
815173a0b5 | ||
|
|
7f489a77bb | ||
|
|
8ec8e8fcd5 | ||
|
|
a4e606dd5f | ||
|
|
646de7962b | ||
|
|
4accd423c2 | ||
|
|
f62caaf4dc | ||
|
|
b789bb84bb | ||
|
|
ce60ad642b | ||
|
|
ab097b1168 | ||
|
|
3a737d86c7 | ||
|
|
a1337e57a8 | ||
|
|
247b3fcf49 | ||
|
|
f01273b25c | ||
|
|
8cb1a2ac6d | ||
|
|
e6e5ac8cb7 | ||
|
|
a4798fb83e | ||
|
|
46369f35c5 | ||
|
|
e699993d70 | ||
|
|
5a0afcfa63 | ||
|
|
3fc9cbf126 | ||
|
|
36b628b19e | ||
|
|
2c31365fd4 | ||
|
|
e1e3c1a2a2 | ||
|
|
b940e5dc5d | ||
|
|
fbbbc620b8 | ||
|
|
9b99600c4d | ||
|
|
3129d7426e | ||
|
|
325ceea971 | ||
|
|
ac39fc3024 | ||
|
|
99343407e6 | ||
|
|
3e23f45ba9 | ||
|
|
72389dec42 | ||
|
|
1f0853f47e | ||
|
|
32a60a4885 | ||
|
|
5e07dc6970 | ||
|
|
4b90a8d416 | ||
|
|
d59c19b64c | ||
|
|
bbabd977d1 | ||
|
|
0cf9c7d63d | ||
|
|
b4e241559e | ||
|
|
1e15aee6be | ||
|
|
d59e60d0fb | ||
|
|
ec1d13a1d4 | ||
|
|
d9002f94cb | ||
|
|
1fa858db48 | ||
|
|
0f2a5bac64 | ||
|
|
eac85878bf | ||
|
|
240ac287eb | ||
|
|
3e42c81193 | ||
|
|
ac3b4d9b69 |
125
CMakeLists.txt
125
CMakeLists.txt
@@ -1,6 +1,6 @@
|
||||
# CMakeLists.txt
|
||||
|
||||
# Copyright (C) 2007-2011 Glenn Randers-Pehrson
|
||||
# Copyright (C) 2007-2015 Glenn Randers-Pehrson
|
||||
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -9,32 +9,13 @@
|
||||
cmake_minimum_required(VERSION 2.4.4)
|
||||
set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
|
||||
|
||||
if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
|
||||
if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
|
||||
# workaround CMake 2.4.x bug
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
||||
"Choose the type of build, options are:
|
||||
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
|
||||
Debug
|
||||
Release
|
||||
RelWithDebInfo
|
||||
MinSizeRel.")
|
||||
else()
|
||||
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
|
||||
"Choose the type of build, options are:
|
||||
None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
|
||||
Debug
|
||||
Release
|
||||
RelWithDebInfo
|
||||
MinSizeRel.")
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
|
||||
|
||||
project(libpng C)
|
||||
enable_testing()
|
||||
|
||||
set(PNGLIB_MAJOR 1)
|
||||
set(PNGLIB_MINOR 6)
|
||||
set(PNGLIB_MINOR 7)
|
||||
set(PNGLIB_RELEASE 0)
|
||||
set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
||||
set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
|
||||
@@ -49,8 +30,7 @@ if(NOT WIN32)
|
||||
PATHS /usr/lib /usr/local/lib
|
||||
)
|
||||
if(NOT M_LIBRARY)
|
||||
message(STATUS
|
||||
"math library 'libm' not found - floating point support disabled")
|
||||
message(STATUS "math lib 'libm' not found; floating point support disabled")
|
||||
endif()
|
||||
else()
|
||||
# not needed on windows
|
||||
@@ -58,22 +38,14 @@ else()
|
||||
endif()
|
||||
|
||||
# COMMAND LINE OPTIONS
|
||||
if(DEFINED PNG_SHARED)
|
||||
option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
|
||||
else()
|
||||
option(PNG_SHARED "Build shared lib" ON)
|
||||
endif()
|
||||
if(DEFINED PNG_STATIC)
|
||||
option(PNG_STATIC "Build static lib" ${PNG_STATIC})
|
||||
else()
|
||||
option(PNG_STATIC "Build static lib" ON)
|
||||
endif()
|
||||
|
||||
option(PNG_TESTS "Build libpng tests" YES)
|
||||
option(PNG_SHARED "Build shared lib" ON)
|
||||
option(PNG_STATIC "Build static lib" ON)
|
||||
option(PNG_TESTS "Build libpng tests" ON)
|
||||
|
||||
# Many more configuration options could be added here
|
||||
option(PNG_DEBUG "Build with debug output" NO)
|
||||
option(PNGARG "Disable ANSI-C prototypes" NO)
|
||||
option(PNG_FRAMEWORK "Build OS X framework" OFF)
|
||||
option(PNG_DEBUG "Build with debug output" OFF)
|
||||
option(PNGARG "Disable ANSI-C prototypes" OFF)
|
||||
|
||||
# SET LIBNAME
|
||||
set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
|
||||
@@ -139,8 +111,11 @@ endif()
|
||||
# NOW BUILD OUR TARGET
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
|
||||
|
||||
unset(PNG_LIB_TARGETS)
|
||||
|
||||
if(PNG_SHARED)
|
||||
add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
|
||||
set(PNG_LIB_TARGETS ${PNG_LIB_NAME})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
|
||||
@@ -150,9 +125,10 @@ if(PNG_SHARED)
|
||||
endif()
|
||||
|
||||
if(PNG_STATIC)
|
||||
# does not work without changing name
|
||||
# does not work without changing name
|
||||
set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
|
||||
add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
|
||||
list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_STATIC})
|
||||
if(MSVC)
|
||||
# msvc does not append 'lib' - do it here to have consistent name
|
||||
set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
|
||||
@@ -160,6 +136,29 @@ if(PNG_STATIC)
|
||||
target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(PNG_FRAMEWORK)
|
||||
set(PNG_LIB_NAME_FRAMEWORK ${PNG_LIB_NAME}_framework)
|
||||
add_library(${PNG_LIB_NAME_FRAMEWORK} SHARED ${libpng_sources})
|
||||
list(APPEND PNG_LIB_TARGETS ${PNG_LIB_NAME_FRAMEWORK})
|
||||
set_target_properties(${PNG_LIB_NAME_FRAMEWORK} PROPERTIES
|
||||
FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION ${PNGLIB_VERSION}
|
||||
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}
|
||||
MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}
|
||||
MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng
|
||||
XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
|
||||
PUBLIC_HEADER "${libpng_public_hdrs}"
|
||||
OUTPUT_NAME png)
|
||||
target_link_libraries(${PNG_LIB_NAME_FRAMEWORK} ${ZLIB_LIBRARY} ${M_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(NOT PNG_LIB_TARGETS)
|
||||
message(SEND_ERROR
|
||||
"No library variant selected to build. "
|
||||
"Please enable at least one of the following options: "
|
||||
" PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK")
|
||||
endif()
|
||||
|
||||
if(PNG_SHARED AND WIN32)
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
|
||||
endif()
|
||||
@@ -222,14 +221,16 @@ macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
|
||||
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
ADD_CUSTOM_COMMAND(
|
||||
OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${SRC_FILE}" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
|
||||
DEPENDS ${PNG_LIB_TARGETS}
|
||||
)
|
||||
ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
|
||||
else(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
get_filename_component(LINK_TARGET "${SRC_FILE}" NAME)
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${LINK_TARGET}" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endif(WIN32 AND NOT CYGWIN AND NOT MSYS)
|
||||
endmacro()
|
||||
|
||||
@@ -260,9 +261,9 @@ endif(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
# SET UP LINKS
|
||||
if(PNG_SHARED)
|
||||
set_target_properties(${PNG_LIB_NAME} PROPERTIES
|
||||
# VERSION 16.${PNGLIB_RELEASE}.1.6.0beta33
|
||||
VERSION 16.${PNGLIB_RELEASE}.0
|
||||
SOVERSION 16
|
||||
# VERSION 17.${PNGLIB_RELEASE}.1.7.0beta65
|
||||
VERSION 17.${PNGLIB_RELEASE}.0
|
||||
SOVERSION 17
|
||||
CLEAN_DIRECT_OUTPUT 1)
|
||||
endif()
|
||||
if(PNG_STATIC)
|
||||
@@ -287,40 +288,34 @@ endif()
|
||||
|
||||
# INSTALL
|
||||
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
|
||||
if(PNG_SHARED)
|
||||
install(TARGETS ${PNG_LIB_NAME}
|
||||
${PNG_EXPORT_RULE}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(TARGETS ${PNG_LIB_TARGETS}
|
||||
${PNG_EXPORT_RULE}
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin
|
||||
if(PNG_SHARED)
|
||||
# Create a symlink for libpng.dll.a => libpng17.dll.a on Cygwin
|
||||
if(CYGWIN OR MINGW)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(CYGWIN OR MINGW)
|
||||
|
||||
if(NOT WIN32)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(NOT WIN32)
|
||||
endif(PNG_SHARED)
|
||||
|
||||
if(PNG_STATIC)
|
||||
install(TARGETS ${PNG_LIB_NAME_STATIC}
|
||||
${PNG_EXPORT_RULE}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
if(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
|
||||
get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
|
||||
CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif(NOT WIN32 OR CYGWIN OR MINGW)
|
||||
@@ -365,7 +360,7 @@ if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
|
||||
install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
|
||||
endif()
|
||||
|
||||
# what's with libpng-$VER%.txt and all the extra files?
|
||||
# what's with libpng-manual.txt and all the extra files?
|
||||
|
||||
# UNINSTALL
|
||||
# do we need this?
|
||||
|
||||
302
INSTALL
302
INSTALL
@@ -1,13 +1,47 @@
|
||||
|
||||
Installing libpng
|
||||
|
||||
Contents
|
||||
|
||||
I. Simple installation
|
||||
II. Rebuilding the configure scripts
|
||||
III. Using scripts/makefile*
|
||||
IV. Using cmake
|
||||
V. Directory structure
|
||||
VI. Building with project files
|
||||
VII. Building with makefiles
|
||||
VIII. Configuring libpng for 16-bit platforms
|
||||
IX. Configuring for DOS
|
||||
X. Configuring for Medium Model
|
||||
XI. Prepending a prefix to exported symbols
|
||||
XII. Configuring for compiler xxx:
|
||||
XIII. Removing unwanted object code
|
||||
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
|
||||
XV. Setjmp/longjmp issues
|
||||
XVI. Other sources of information about libpng
|
||||
|
||||
I. Simple installation
|
||||
|
||||
On Unix/Linux and similar systems, you can simply type
|
||||
|
||||
./configure [--prefix=/path]
|
||||
make check
|
||||
make install
|
||||
|
||||
and ignore the rest of this document.
|
||||
and ignore the rest of this document. "/path" is the path to the directory
|
||||
where you want to install the libpng "lib", "include", and "bin"
|
||||
subdirectories.
|
||||
|
||||
If you downloaded a GIT clone, you will need to run ./autogen.sh before
|
||||
running ./configure, to create "configure" and "Makefile.in" which are
|
||||
not included in the GIT repository.
|
||||
|
||||
Note that "configure" is only included in the "*.tar" distributions and not
|
||||
in the "*.zip" or "*.7z" distributions. If you downloaded one of those
|
||||
distributions, see "Building with project files" or "Building with makefiles",
|
||||
below.
|
||||
|
||||
II. Rebuilding the configure scripts
|
||||
|
||||
If configure does not work on your system, or if you have a need to
|
||||
change configure.ac or Makefile.am, and you have a reasonably
|
||||
@@ -24,9 +58,12 @@ aren't using any of the included pre-built scripts, you can do this:
|
||||
make install
|
||||
make check
|
||||
|
||||
III. Using scripts/makefile*
|
||||
|
||||
Instead, you can use one of the custom-built makefiles in the
|
||||
"scripts" directory
|
||||
|
||||
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
|
||||
cp scripts/makefile.system makefile
|
||||
make test
|
||||
make install
|
||||
@@ -38,8 +75,28 @@ Or you can use one of the "projects" in the "projects" directory.
|
||||
|
||||
Before installing libpng, you must first install zlib, if it
|
||||
is not already on your system. zlib can usually be found
|
||||
wherever you got libpng. zlib can be placed in another directory,
|
||||
at the same level as libpng.
|
||||
wherever you got libpng; otherwise go to http://zlib.net. You can place
|
||||
zlib in in the same directory as libpng or in another directory.
|
||||
|
||||
If your system already has a preinstalled zlib you will still need
|
||||
to have access to the zlib.h and zconf.h include files that
|
||||
correspond to the version of zlib that's installed.
|
||||
|
||||
If you wish to test with a particular zlib that is not first in the
|
||||
standard library search path, put ZLIBLIB, ZLIBINC, CPPFLAGS, LDFLAGS,
|
||||
and LD_LIBRARY_PATH in your environment before running "make test"
|
||||
or "make distcheck":
|
||||
|
||||
ZLIBLIB=/path/to/lib export ZLIBLIB
|
||||
ZLIBINC=/path/to/include export ZLIBINC
|
||||
CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
|
||||
LDFLAGS="-L$ZLIBLIB" export LDFLAGS
|
||||
LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
|
||||
|
||||
If you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC
|
||||
in your environment and type "make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test".
|
||||
|
||||
IV. Using cmake
|
||||
|
||||
If you want to use "cmake" (see www.cmake.org), type
|
||||
|
||||
@@ -47,13 +104,15 @@ If you want to use "cmake" (see www.cmake.org), type
|
||||
make
|
||||
make install
|
||||
|
||||
If your system already has a preinstalled zlib you will still need
|
||||
to have access to the zlib.h and zconf.h include files that
|
||||
correspond to the version of zlib that's installed.
|
||||
As when using the simple configure method described above, "/path" points to
|
||||
the installation directory where you want to put the libpng "lib", "include",
|
||||
and "bin" subdirectories.
|
||||
|
||||
V. Directory structure
|
||||
|
||||
You can rename the directories that you downloaded (they
|
||||
might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.5"
|
||||
or "zlib125") so that you have directories called "zlib" and "libpng".
|
||||
might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.8"
|
||||
or "zlib128") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
|
||||
@@ -61,8 +120,7 @@ Your directory structure should look like this:
|
||||
libpng (this directory)
|
||||
INSTALL (this file)
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
*.h, *.c => libpng source files
|
||||
CMakeLists.txt => "cmake" script
|
||||
configuration files:
|
||||
configure.ac, configure, Makefile.am, Makefile.in,
|
||||
@@ -70,14 +128,10 @@ Your directory structure should look like this:
|
||||
libpng-config.in, aclocal.m4, config.h.in, config.sub,
|
||||
depcomp, install-sh, mkinstalldirs, test-pngtest.sh
|
||||
contrib
|
||||
gregbook
|
||||
pngminim
|
||||
pngminus
|
||||
pngsuite
|
||||
visupng
|
||||
arm-neon, conftest, examples, gregbook, libtests, pngminim,
|
||||
pngminus, pngsuite, tools, visupng
|
||||
projects
|
||||
visualc71
|
||||
vstudio
|
||||
cbuilder5, owatcom, visualc71, vstudio, xcode
|
||||
scripts
|
||||
makefile.*
|
||||
*.def (module definition files)
|
||||
@@ -85,29 +139,31 @@ Your directory structure should look like this:
|
||||
pngtest.png
|
||||
etc.
|
||||
zlib
|
||||
README
|
||||
*.h
|
||||
*.c
|
||||
contrib
|
||||
etc.
|
||||
README, *.h, *.c contrib, etc.
|
||||
|
||||
If the line endings in the files look funny, you may wish to get the other
|
||||
distribution of libpng. It is available in both tar.gz (UNIX style line
|
||||
endings) and zip (DOS style line endings) formats.
|
||||
|
||||
VI. Building with project files
|
||||
|
||||
If you are building libpng with MSVC, you can enter the
|
||||
libpng projects\visualc6 or visualc71 directory and follow the instructions
|
||||
libpng projects\visualc71 or vstudio directory and follow the instructions
|
||||
in README.txt.
|
||||
|
||||
Otherwise enter the zlib directory and follow the instructions in zlib/README,
|
||||
then come back here and run "configure" or choose the appropriate
|
||||
makefile.sys in the scripts directory.
|
||||
|
||||
VII. Building with makefiles
|
||||
|
||||
Copy the file (or files) that you need from the
|
||||
scripts directory into this directory, for example
|
||||
|
||||
MSDOS example: copy scripts\makefile.msc makefile
|
||||
UNIX example: cp scripts/makefile.std makefile
|
||||
copy scripts\pnglibconf.h.prebuilt pnglibconf.h
|
||||
UNIX example: cp scripts/makefile.std makefile
|
||||
cp scripts/pnglibconf.h.prebuilt pnglibconf.h
|
||||
|
||||
Read the makefile to see if you need to change any source or
|
||||
target directories to match your preferences.
|
||||
@@ -130,6 +186,202 @@ do that, run "make install" in the zlib directory first if necessary).
|
||||
Some also allow you to run "make test-installed" after you have
|
||||
run "make install".
|
||||
|
||||
VIII. Configuring libpng for 16-bit platforms
|
||||
|
||||
You will want to look into zconf.h to tell zlib (and thus libpng) that
|
||||
it cannot allocate more than 64K at a time. Even if you can, the memory
|
||||
won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
|
||||
|
||||
IX. Configuring for DOS
|
||||
|
||||
For DOS users who only have access to the lower 640K, you will
|
||||
have to limit zlib's memory usage via a png_set_compression_mem_level()
|
||||
call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
|
||||
X. Configuring for Medium Model
|
||||
|
||||
Libpng's support for medium model has been tested on most of the popular
|
||||
compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
|
||||
defined, and FAR gets defined to far in pngconf.h, and you should be
|
||||
all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
the end for pointers (or at least look at them and be careful). Make
|
||||
note that the rows of data are defined as png_bytepp, which is
|
||||
an "unsigned char far * far *".
|
||||
|
||||
XI. Prepending a prefix to exported symbols
|
||||
|
||||
Starting with libpng-1.6.0, you can configure libpng (when using the
|
||||
"configure" script) to prefix all exported symbols by means of the
|
||||
configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
|
||||
string beginning with a letter and containing only uppercase
|
||||
and lowercase letters, digits, and the underscore (i.e., a C language
|
||||
identifier). This creates a set of macros in pnglibconf.h, so this is
|
||||
transparent to applications; their function calls get transformed by
|
||||
the macros to use the modified names.
|
||||
|
||||
XII. Configuring for compiler xxx:
|
||||
|
||||
All includes for libpng are in pngconf.h. If you need to add, change
|
||||
or delete an include, this is the place to do it.
|
||||
The includes that are not needed outside libpng are placed in pngpriv.h,
|
||||
which is only used by the routines inside libpng itself.
|
||||
The files in libpng proper only include pngpriv.h and png.h, which
|
||||
in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
|
||||
As of libpng-1.5.0, pngpriv.h also includes three other private header
|
||||
files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
|
||||
that previously appeared in the public headers.
|
||||
|
||||
XIII. Removing unwanted object code
|
||||
|
||||
There are a bunch of #define's in pngconf.h that control what parts of
|
||||
libpng are compiled. All the defines end in _SUPPORTED. If you are
|
||||
never going to use a capability, you can change the #define to #undef
|
||||
before recompiling libpng and save yourself code and data space, or
|
||||
you can turn off individual capabilities with defines that begin with
|
||||
PNG_NO_.
|
||||
|
||||
In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
|
||||
|
||||
You can also turn all of the transforms and ancillary chunk capabilities
|
||||
off en masse with compiler directives that define
|
||||
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
|
||||
or all four, along with directives to turn on any of the capabilities that
|
||||
you do want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the
|
||||
extra transformations but still leave the library fully capable of reading
|
||||
and writing PNG files with all known public chunks. Use of the
|
||||
PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
|
||||
that is incapable of reading or writing ancillary chunks. If you are
|
||||
not using the progressive reading capability, you can turn that off
|
||||
with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
|
||||
capability, which you'll still have).
|
||||
|
||||
All the reading and writing specific code are in separate files, so the
|
||||
linker should only grab the files it needs. However, if you want to
|
||||
make sure, or if you are building a stand alone library, all the
|
||||
reading files start with "pngr" and all the writing files start with "pngw".
|
||||
The files that don't match either (like png.c, pngtrans.c, etc.)
|
||||
are used for both reading and writing, and always need to be included.
|
||||
The progressive reader is in pngpread.c
|
||||
|
||||
If you are creating or distributing a dynamically linked library (a .so
|
||||
or DLL file), you should not remove or disable any parts of the library,
|
||||
as this will cause applications linked with different versions of the
|
||||
library to fail if they call functions not available in your library.
|
||||
The size of the library itself should not be an issue, because only
|
||||
those sections that are actually used will be loaded into memory.
|
||||
|
||||
XIV. Changes to the build and configuration of libpng in libpng-1.5.x
|
||||
|
||||
Details of internal changes to the library code can be found in the CHANGES
|
||||
file and in the GIT repository logs. These will be of no concern to the vast
|
||||
majority of library users or builders; however, the few who configure libpng
|
||||
to a non-default feature set may need to change how this is done.
|
||||
|
||||
There should be no need for library builders to alter build scripts if
|
||||
these use the distributed build support - configure or the makefiles -
|
||||
however, users of the makefiles may care to update their build scripts
|
||||
to build pnglibconf.h where the corresponding makefile does not do so.
|
||||
|
||||
Building libpng with a non-default configuration has changed completely.
|
||||
The old method using pngusr.h should still work correctly even though the
|
||||
way pngusr.h is used in the build has been changed; however, library
|
||||
builders will probably want to examine the changes to take advantage of
|
||||
new capabilities and to simplify their build system.
|
||||
|
||||
A. Specific changes to library configuration capabilities
|
||||
|
||||
The exact mechanism used to control attributes of API functions has
|
||||
changed. A single set of operating system independent macro definitions
|
||||
is used and operating system specific directives are defined in
|
||||
pnglibconf.h
|
||||
|
||||
As part of this the mechanism used to choose procedure call standards on
|
||||
those systems that allow a choice has been changed. At present this only
|
||||
affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
|
||||
running on Intel processors. As before, PNGAPI is defined where required
|
||||
to control the exported API functions; however, two new macros, PNGCBAPI
|
||||
and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
|
||||
(PNGCAPI) for functions that must match a C library prototype (currently
|
||||
only png_longjmp_ptr, which must match the C longjmp function.) The new
|
||||
approach is documented in pngconf.h
|
||||
|
||||
Despite these changes, libpng 1.5.0 only supports the native C function
|
||||
calling standard on those platforms tested so far (__cdecl on Microsoft
|
||||
Windows). This is because the support requirements for alternative
|
||||
calling conventions seem to no longer exist. Developers who find it
|
||||
necessary to set PNG_API_RULE to 1 should advise the mailing list
|
||||
(png-mng-implement) of this and library builders who use Openwatcom and
|
||||
therefore set PNG_API_RULE to 2 should also contact the mailing list.
|
||||
|
||||
B. Changes to the configuration mechanism
|
||||
|
||||
Prior to libpng-1.5.0 library builders who needed to configure libpng
|
||||
had either to modify the exported pngconf.h header file to add system
|
||||
specific configuration or had to write feature selection macros into
|
||||
pngusr.h and cause this to be included into pngconf.h by defining
|
||||
PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
|
||||
application built without PNG_USER_CONFIG defined would see the
|
||||
unmodified, default, libpng API and thus would probably fail to link.
|
||||
|
||||
These mechanisms still work in the configure build and in any makefile
|
||||
build that builds pnglibconf.h, although the feature selection macros
|
||||
have changed somewhat as described above. In 1.5.0, however, pngusr.h is
|
||||
processed only once, at the time the exported header file pnglibconf.h is
|
||||
built. pngconf.h no longer includes pngusr.h; therefore, pngusr.h is ignored
|
||||
after the build of pnglibconf.h and it is never included in an application
|
||||
build.
|
||||
|
||||
The formerly used alternative of adding a list of feature macros to the
|
||||
CPPFLAGS setting in the build also still works; however, the macros will be
|
||||
copied to pnglibconf.h and this may produce macro redefinition warnings
|
||||
when the individual C files are compiled.
|
||||
|
||||
All configuration now only works if pnglibconf.h is built from
|
||||
scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
|
||||
(the original author of awk) maintains C source code of that awk and this
|
||||
and all known later implementations (often called by subtly different
|
||||
names - nawk and gawk for example) are adequate to build pnglibconf.h.
|
||||
The Sun Microsystems (now Oracle) program 'awk' is an earlier version
|
||||
and does not work; this may also apply to other systems that have a
|
||||
functioning awk called 'nawk'.
|
||||
|
||||
Configuration options are now documented in scripts/pnglibconf.dfa. This
|
||||
file also includes dependency information that ensures a configuration is
|
||||
consistent; that is, if a feature is switched off, dependent features are
|
||||
also switched off. As a recommended alternative to using feature macros in
|
||||
pngusr.h a system builder may also define equivalent options in pngusr.dfa
|
||||
(or, indeed, any file) and add that to the configuration by setting
|
||||
DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
|
||||
how to do this, and also illustrate a case where pngusr.h is still required.
|
||||
|
||||
After you have built libpng, the definitions that were recorded in
|
||||
pnglibconf.h are available to your application (pnglibconf.h is included
|
||||
in png.h and gets installed alongside png.h and pngconf.h in your
|
||||
$PREFIX/include directory). Do not edit pnglibconf.h after you have built
|
||||
libpng, because than the settings would not accurately reflect the settings
|
||||
that were used to build libpng.
|
||||
|
||||
XV. Setjmp/longjmp issues
|
||||
|
||||
Libpng uses setjmp()/longjmp() for error handling. Unfortunately setjmp()
|
||||
is known to be not thread-safe on some platforms and we don't know of
|
||||
any platform where it is guaranteed to be thread-safe. Therefore, if
|
||||
your application is going to be using multiple threads, you should
|
||||
configure libpng with PNG_NO_SETJMP in your pngusr.dfa file, with
|
||||
-DPNG_NO_SETJMP on your compile line, or with
|
||||
|
||||
#undef PNG_SETJMP_SUPPORTED
|
||||
|
||||
in your pnglibconf.h or pngusr.h.
|
||||
|
||||
Starting with libpng-1.6.0, the library included a "simplified API".
|
||||
This requires setjmp/longjmp, so you must either build the library
|
||||
with PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
and PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.
|
||||
|
||||
XVI. Other sources of information about libpng:
|
||||
|
||||
Further information can be found in the README and libpng-manual.txt
|
||||
files, in the individual makefiles, in png.h, and the manual pages
|
||||
libpng.3 and png.5.
|
||||
@@ -147,7 +399,7 @@ CFLAGS="-Wall -O -funroll-loops \
|
||||
--with-pkgconfigdir=/usr/lib/pkgconfig --includedir=/usr/include
|
||||
|
||||
You can alternatively specify --includedir=/usr/include, /usr/local/include,
|
||||
/usr/include/libpng%NN%, or whatever.
|
||||
/usr/include/libpng17, or whatever.
|
||||
|
||||
If you find that the configure script is out-of-date or is not supporting
|
||||
your platform properly, try running autogen.sh to regenerate "configure",
|
||||
|
||||
48
LICENSE
48
LICENSE
@@ -10,21 +10,17 @@ this sentence.
|
||||
|
||||
This code is released under the libpng license.
|
||||
|
||||
libpng versions 1.2.6, August 15, 2004, through 1.6.0beta33, December 10, 2012, are
|
||||
Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are
|
||||
distributed according to the same disclaimer and license as libpng-1.2.5
|
||||
with the following individual added to the list of Contributing Authors
|
||||
|
||||
Cosmin Truta
|
||||
|
||||
libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
|
||||
Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
|
||||
libpng versions 1.0.7, July 1, 2000, through 1.7.0beta65, September 16, 2015, are
|
||||
Copyright (c) 2000-2002, 2004, 2006-2015 Glenn Randers-Pehrson, and are
|
||||
distributed according to the same disclaimer and license as libpng-1.0.6
|
||||
with the following individuals added to the list of Contributing Authors
|
||||
with the following individuals added to the list of Contributing Authors:
|
||||
|
||||
Simon-Pierre Cadieux
|
||||
Eric S. Raymond
|
||||
Mans Rullgard
|
||||
Cosmin Truta
|
||||
Gilles Vollant
|
||||
James Yu
|
||||
|
||||
and with the following additions to the disclaimer:
|
||||
|
||||
@@ -36,17 +32,17 @@ and with the following additions to the disclaimer:
|
||||
the user.
|
||||
|
||||
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
|
||||
distributed according to the same disclaimer and license as libpng-0.96,
|
||||
with the following individuals added to the list of Contributing Authors:
|
||||
Copyright (c) 1998-2000 Glenn Randers-Pehrson, and are distributed according
|
||||
to the same disclaimer and license as libpng-0.96, with the following
|
||||
individuals added to the list of Contributing Authors:
|
||||
|
||||
Tom Lane
|
||||
Glenn Randers-Pehrson
|
||||
Willem van Schaik
|
||||
|
||||
libpng versions 0.89, June 1996, through 0.96, May 1997, are
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
Distributed according to the same disclaimer and license as libpng-0.88,
|
||||
Copyright (c) 1996-1997 Andreas Dilger, and are
|
||||
distributed according to the same disclaimer and license as libpng-0.88,
|
||||
with the following individuals added to the list of Contributing Authors:
|
||||
|
||||
John Bowler
|
||||
@@ -57,7 +53,7 @@ with the following individuals added to the list of Contributing Authors:
|
||||
Tom Tanner
|
||||
|
||||
libpng versions 0.5, May 1995, through 0.88, January 1996, are
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
|
||||
For the purposes of this copyright and license, "Contributing Authors"
|
||||
is defined as the following set of individuals:
|
||||
@@ -80,13 +76,13 @@ Permission is hereby granted to use, copy, modify, and distribute this
|
||||
source code, or portions hereof, for any purpose, without fee, subject
|
||||
to the following restrictions:
|
||||
|
||||
1. The origin of this source code must not be misrepresented.
|
||||
1. The origin of this source code must not be misrepresented.
|
||||
|
||||
2. Altered versions must be plainly marked as such and must not
|
||||
be misrepresented as being the original source.
|
||||
2. Altered versions must be plainly marked as such and must not
|
||||
be misrepresented as being the original source.
|
||||
|
||||
3. This Copyright notice may not be removed or altered from any
|
||||
source or altered source distribution.
|
||||
3. This Copyright notice may not be removed or altered from any
|
||||
source or altered source distribution.
|
||||
|
||||
The Contributing Authors and Group 42, Inc. specifically permit, without
|
||||
fee, and encourage the use of this source code as a component to
|
||||
@@ -94,18 +90,18 @@ supporting the PNG file format in commercial products. If you use this
|
||||
source code in a product, acknowledgment is not required but would be
|
||||
appreciated.
|
||||
|
||||
|
||||
A "png_get_copyright" function is available, for convenient use in "about"
|
||||
boxes and the like:
|
||||
|
||||
printf("%s",png_get_copyright(NULL));
|
||||
printf("%s", png_get_copyright(NULL));
|
||||
|
||||
Also, the PNG logo (in PNG format, of course) is supplied in the
|
||||
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
|
||||
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
|
||||
certification mark of the Open Source Initiative.
|
||||
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
|
||||
a certification mark of the Open Source Initiative. OSI has not addressed
|
||||
the additional disclaimers inserted at version 1.0.7.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
glennrp at users.sourceforge.net
|
||||
December 10, 2012
|
||||
September 16, 2015
|
||||
|
||||
246
Makefile.am
246
Makefile.am
@@ -7,24 +7,66 @@ PNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
|
||||
ACLOCAL_AMFLAGS = -I scripts
|
||||
|
||||
# test programs - run on make check, make distcheck
|
||||
TESTS_ENVIRONMENT= srcdir=$(srcdir)
|
||||
check_PROGRAMS= pngtest
|
||||
check_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage
|
||||
|
||||
# Utilities - installed
|
||||
bin_PROGRAMS= pngfix png-fix-itxt
|
||||
|
||||
# This ensures that pnglibconf.h gets built at the start of 'make all' or
|
||||
# 'make check', but it does not add dependencies to the individual programs,
|
||||
# this is done below.
|
||||
#
|
||||
# IMPORTANT: always add the object modules of new programs to the list below
|
||||
# because otherwise the sequence 'configure; make new-program' will *sometimes*
|
||||
# result in the installed (system) pnglibconf.h being used and the result is
|
||||
# always wrong and always very confusing.
|
||||
BUILT_SOURCES = pnglibconf.h
|
||||
|
||||
pngtest_SOURCES = pngtest.c
|
||||
pngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
TESTS = test-pngtest.sh
|
||||
|
||||
# Only do the following if the contrib directory is present.
|
||||
check_PROGRAMS+= pngvalid pngstest pngunknown
|
||||
pngvalid_SOURCES = contrib/libtests/pngvalid.c
|
||||
pngstest_SOURCES = contrib/libtests/pngstest.c
|
||||
pngunknown_SOURCES = contrib/libtests/pngunknown.c
|
||||
pngvalid_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngstest_SOURCES = contrib/libtests/pngstest.c
|
||||
pngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngunknown_SOURCES = contrib/libtests/pngunknown.c
|
||||
pngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
TESTS += contrib/libtests/test-pngunknown.sh\
|
||||
contrib/libtests/test-pngvalid-simple.sh\
|
||||
contrib/libtests/test-pngvalid-full.sh\
|
||||
contrib/libtests/test-pngstest.sh
|
||||
|
||||
pngimage_SOURCES = contrib/libtests/pngimage.c
|
||||
pngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
pngfix_SOURCES = contrib/tools/pngfix.c
|
||||
pngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
|
||||
png_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c
|
||||
|
||||
# Generally these are single line shell scripts to run a test with a particular
|
||||
# set of parameters:
|
||||
TESTS =\
|
||||
tests/pngtest\
|
||||
tests/pngvalid-gamma-16-to-8 tests/pngvalid-gamma-alpha-mode\
|
||||
tests/pngvalid-gamma-background tests/pngvalid-gamma-expand16-alpha-mode\
|
||||
tests/pngvalid-gamma-expand16-background\
|
||||
tests/pngvalid-gamma-expand16-transform tests/pngvalid-gamma-sbit\
|
||||
tests/pngvalid-gamma-threshold tests/pngvalid-gamma-transform\
|
||||
tests/pngvalid-progressive-interlace-size\
|
||||
tests/pngvalid-progressive-interlace-standard\
|
||||
tests/pngvalid-progressive-interlace-transform\
|
||||
tests/pngvalid-progressive-standard tests/pngvalid-standard\
|
||||
tests/pngstest-0g01 tests/pngstest-0g02 tests/pngstest-0g04\
|
||||
tests/pngstest-0g08 tests/pngstest-0g16 tests/pngstest-2c08\
|
||||
tests/pngstest-2c16 tests/pngstest-3p01 tests/pngstest-3p02\
|
||||
tests/pngstest-3p04 tests/pngstest-3p08 tests/pngstest-4a08\
|
||||
tests/pngstest-4a16 tests/pngstest-6a08 tests/pngstest-6a16\
|
||||
tests/pngstest-error tests/pngunknown-IDAT\
|
||||
tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\
|
||||
tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\
|
||||
tests/pngimage-quick tests/pngimage-full
|
||||
|
||||
# These tests are expected, and required, to fail:
|
||||
XFAIL_TESTS = tests/pngstest-error
|
||||
|
||||
# man pages
|
||||
dist_man_MANS= libpng.3 libpngpf.3 png.5
|
||||
@@ -40,10 +82,15 @@ lib_LTLIBRARIES=libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c\
|
||||
pngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c\
|
||||
pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\
|
||||
png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa
|
||||
png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngchunk.h \
|
||||
pngusr.dfa
|
||||
|
||||
if PNG_ARM_NEON
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/filter_neon.S
|
||||
# Include libpng extensions, if appropriate. This uses a Makefile.am fragment,
|
||||
# pre-set things that might be changed by addition:
|
||||
AM_CPPFLAGS =
|
||||
DFA_EXTENSION =
|
||||
if LIBPNG_EXTENSIONS
|
||||
include $(top_srcdir)/contrib/extensions.am
|
||||
endif
|
||||
|
||||
nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h
|
||||
@@ -76,19 +123,22 @@ nodist_pkginclude_HEADERS= pnglibconf.h
|
||||
pkgconfigdir = @pkgconfigdir@
|
||||
pkgconfig_DATA = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc
|
||||
|
||||
#extra source distribution files.
|
||||
# Extra source distribution files, '${srcdir}' is used below to stop build files
|
||||
# from those directories being included. This only works if the configure is
|
||||
# not done in the source directory!
|
||||
EXTRA_DIST= \
|
||||
ANNOUNCE CHANGES INSTALL LICENSE README TODO \
|
||||
pngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \
|
||||
${srcdir}/contrib ${srcdir}/projects ${srcdir}/scripts \
|
||||
$(TESTS) \
|
||||
$(TESTS) $(XFAIL_TESTS) tests/pngstest \
|
||||
CMakeLists.txt example.c libpng-manual.txt
|
||||
|
||||
SCRIPT_CLEANFILES=scripts/*.out scripts/*.chk scripts/pnglibconf.dfn
|
||||
SCRIPT_CLEANFILES=scripts/*.out scripts/*.chk scripts/pnglibconf.c
|
||||
|
||||
CLEANFILES= *.tf? pngout.png libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc \
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config libpng.vers libpng.sym \
|
||||
check.new pnglibconf.* pngprefix.h symbols.new pngtest-log.txt \
|
||||
check.new pnglibconf.h pngprefix.h symbols.new pngtest-log.txt \
|
||||
pnglibconf.out pnglibconf.c pnglibconf.dfn pnglibconf.pre \
|
||||
$(SCRIPT_CLEANFILES)
|
||||
|
||||
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \
|
||||
@@ -100,14 +150,14 @@ config.sub configure depcomp install-sh ltmain.sh missing
|
||||
PNG_COPTS = @PNG_COPTS@
|
||||
AM_CFLAGS = ${PNG_COPTS}
|
||||
|
||||
# DFNCPP is normally just CPP - the C preprocessor - but on Solaris and maybe
|
||||
# other operating systems (NeXT?) the C preprocessor selected by configure
|
||||
# DFNCPP is normally just "CPP -E" - the C preprocessor - but on Solaris and
|
||||
# maybe other operating systems (NeXT?) the C preprocessor selected by configure
|
||||
# checks input tokens for validity - effectively it performs part of the ANSI-C
|
||||
# parsing - and therefore fails with the .df files. configure.ac has special
|
||||
# checks for this and sets DFNCPP appropriately.
|
||||
DFNCPP = @DFNCPP@
|
||||
|
||||
SUFFIXES = .chk .dfn .out
|
||||
SUFFIXES = .chk .out
|
||||
|
||||
$(PNGLIB_BASENAME).pc: libpng.pc
|
||||
cp libpng.pc $@
|
||||
@@ -118,6 +168,9 @@ $(PNGLIB_BASENAME)-config: libpng-config
|
||||
scripts/sym.out scripts/vers.out: png.h pngconf.h pnglibconf.h
|
||||
scripts/prefix.out: png.h pngconf.h pnglibconf.out
|
||||
scripts/symbols.out: png.h pngconf.h $(srcdir)/scripts/pnglibconf.h.prebuilt
|
||||
scripts/intprefix.out: pnglibconf.h
|
||||
|
||||
pnglibconf.out: config.h
|
||||
|
||||
libpng.sym: scripts/sym.out
|
||||
rm -f $@
|
||||
@@ -130,7 +183,7 @@ if DO_PNG_PREFIX
|
||||
# Rename functions in scripts/prefix.out with a PNG_PREFIX prefix.
|
||||
# Rename macros in scripts/macro.lst from PNG_PREFIXpng_ to PNG_ (the actual
|
||||
# implementation of the macro).
|
||||
pnglibconf.h: pnglibconf.out scripts/prefix.out scripts/macro.lst
|
||||
pnglibconf.h: pnglibconf.out scripts/prefix.out scripts/macro.lst config.h
|
||||
rm -f $@
|
||||
$(AWK) 's==0 && NR>1{print prev}\
|
||||
s==0{prev=$$0}\
|
||||
@@ -156,14 +209,28 @@ endif
|
||||
$(srcdir)/scripts/pnglibconf.h.prebuilt:
|
||||
@echo "Attempting to build $@" >&2
|
||||
@echo "This is a machine generated file, but if you want to make" >&2
|
||||
@echo "a new one simply make 'scripts/pnglibconf.out' and copy that" >&2
|
||||
@echo "a new one simply make 'scripts/pnglibconf.out', copy that" >&2
|
||||
@echo "AND set PNG_ZLIB_VERNUM to 0 (you MUST do this)" >&2
|
||||
@exit 1
|
||||
|
||||
# The following is necessary to ensure that the local pnglibconf.h is used, not
|
||||
# an installed one (this can happen immediately after on a clean system if
|
||||
# 'make test' is the first thing the user does.)
|
||||
contrib/libtests/pngstest.o contrib/libtests/pngvalid.o pngtest.o: pnglibconf.h
|
||||
# 'make test' is the first thing the user does.) Only files which include
|
||||
# one of the png source files (typically png.h or pngpriv.h) need to be listed
|
||||
# here:
|
||||
pngtest.o: pnglibconf.h
|
||||
|
||||
contrib/libtests/makepng.o: pnglibconf.h
|
||||
contrib/libtests/pngstest.o: pnglibconf.h
|
||||
contrib/libtests/pngunknown.o: pnglibconf.h
|
||||
contrib/libtests/pngimage.o: pnglibconf.h
|
||||
contrib/libtests/pngvalid.o: pnglibconf.h
|
||||
contrib/libtests/readpng.o: pnglibconf.h
|
||||
contrib/libtests/tarith.o: pnglibconf.h
|
||||
contrib/libtests/timepng.o: pnglibconf.h
|
||||
|
||||
contrib/tools/makesRGB.o: pnglibconf.h
|
||||
contrib/tools/pngfix.o: pnglibconf.h
|
||||
|
||||
# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually
|
||||
# be built with PNG_USE_READ_MACROS; this prevents the read macros from
|
||||
@@ -177,24 +244,21 @@ if DO_PNG_PREFIX
|
||||
SYMBOL_CFLAGS += -DPNG_PREFIX='@PNG_PREFIX@'
|
||||
endif
|
||||
|
||||
.dfn.out:
|
||||
rm -f $@ $*.c $*.tf[123]
|
||||
test -d scripts || mkdir scripts
|
||||
echo '#include "$<"' >$*.c
|
||||
.c.out:
|
||||
rm -f $@ $*.tf[12]
|
||||
test -d scripts || mkdir scripts || test -d scripts
|
||||
$(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)\
|
||||
$(CPPFLAGS) $(SYMBOL_CFLAGS) $*.c > $*.tf1
|
||||
$(SED) -n -e 's|^.*PNG_DEFN_MAGIC *-\(.*\)- *PNG_DEFN_END.*$$|\1|p'\
|
||||
$*.tf1 >$*.tf2
|
||||
$(SED) -e 's| *PNG_JOIN *||g' -e 's| *$$||' $*.tf2 >$*.tf3
|
||||
rm -f $*.c $*.tf[12]
|
||||
mv $*.tf3 $@
|
||||
$(AM_CPPFLAGS) $(CPPFLAGS) $(SYMBOL_CFLAGS) $< > $*.tf1
|
||||
$(AWK) -f "${srcdir}/scripts/dfn.awk" out="$*.tf2" $*.tf1 1>&2
|
||||
rm -f $*.tf1
|
||||
mv $*.tf2 $@
|
||||
|
||||
# The .dfn file for pnglibconf.h is machine generated
|
||||
pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_XTRA)
|
||||
# The .c file for pnglibconf.h is machine generated
|
||||
pnglibconf.c: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_EXTENSION) $(DFA_XTRA)
|
||||
rm -f $@ $*.tf[45]
|
||||
$(AWK) -f ${srcdir}/scripts/options.awk out=$*.tf4 version=search\
|
||||
${srcdir}/pngconf.h ${srcdir}/scripts/pnglibconf.dfa\
|
||||
${srcdir}/pngusr.dfa $(DFA_XTRA) 1>&2
|
||||
$(DFA_EXTENSION) ${srcdir}/pngusr.dfa $(DFA_XTRA) 1>&2
|
||||
$(AWK) -f ${srcdir}/scripts/options.awk out=$*.tf5 $*.tf4 1>&2
|
||||
rm $*.tf4
|
||||
mv $*.tf5 $@
|
||||
@@ -210,10 +274,10 @@ scripts/symbols.chk: scripts/checksym.awk scripts/symbols.def scripts/symbols.ou
|
||||
|
||||
# used on demand to regenerate the standard header, CPPFLAGS should
|
||||
# be empty - no non-standard defines
|
||||
scripts/pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h
|
||||
scripts/pnglibconf.c: scripts/pnglibconf.dfa scripts/options.awk pngconf.h
|
||||
rm -f $@ pnglibconf.tf[67]
|
||||
test -z "$(CPPFLAGS)"
|
||||
echo "com @PNGLIB_VERSION@ STANDARD API DEFINITION" |\
|
||||
test -z "$(CPPFLAGS)" -a -z "$(AM_CPPFLAGS)"
|
||||
echo "com libpng @PNGLIB_VERSION@ STANDARD API DEFINITION" |\
|
||||
$(AWK) -f ${srcdir}/scripts/options.awk out=pnglibconf.tf6\
|
||||
logunsupported=1 version=search ${srcdir}/pngconf.h -\
|
||||
${srcdir}/scripts/pnglibconf.dfa 1>&2
|
||||
@@ -222,7 +286,7 @@ scripts/pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h
|
||||
rm pnglibconf.tf6
|
||||
mv pnglibconf.tf7 $@
|
||||
|
||||
$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS): png.h pngconf.h \
|
||||
$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS): png.h pngconf.h pngchunk.h \
|
||||
pnglibconf.h pngpriv.h pngdebug.h pnginfo.h pngstruct.h pngprefix.h
|
||||
|
||||
test: check-am
|
||||
@@ -234,34 +298,76 @@ check: scripts/symbols.chk
|
||||
dist-hook:
|
||||
cd '$(top_distdir)'; rm -f $(SCRIPT_CLEANFILES)
|
||||
|
||||
# install the .../include headers as links to the new ones
|
||||
install-data-hook:
|
||||
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h pnglibconf.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/png.h png.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pngconf.h \
|
||||
pngconf.h
|
||||
cd $(DESTDIR)$(includedir); $(LN_S) $(PNGLIB_BASENAME)/pnglibconf.h \
|
||||
pnglibconf.h
|
||||
cd $(DESTDIR)$(pkgconfigdir); rm -f libpng.pc
|
||||
cd $(DESTDIR)$(pkgconfigdir); $(LN_S) $(PNGLIB_BASENAME).pc libpng.pc
|
||||
# Make links between installed files with release-specific names and the generic
|
||||
# file names. If this install rule is run the generic names will be deleted and
|
||||
# recreated - this has obvious issues for systems with multiple installations.
|
||||
|
||||
# do evil things to libpng to cause libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ to be used
|
||||
install-exec-hook:
|
||||
cd $(DESTDIR)$(bindir); rm -f libpng-config
|
||||
cd $(DESTDIR)$(bindir); $(LN_S) $(PNGLIB_BASENAME)-config libpng-config
|
||||
@set -x;\
|
||||
cd $(DESTDIR)$(libdir);\
|
||||
for ext in a la so so.@PNGLIB_MAJOR@@PNGLIB_MINOR@.@PNGLIB_RELEASE@ sl dylib dll.a; do\
|
||||
rm -f libpng.$$ext;\
|
||||
if test -f $(PNGLIB_BASENAME).$$ext; then\
|
||||
$(LN_S) $(PNGLIB_BASENAME).$$ext libpng.$$ext;\
|
||||
fi;\
|
||||
install-header-links:
|
||||
@set -ex; cd '$(DESTDIR)$(includedir)'; for f in $(HEADERS); do \
|
||||
rm -f "$$f"; $(LN_S) "$(PNGLIB_BASENAME)/$$f" "$$f"; done
|
||||
|
||||
uninstall-header-links:
|
||||
cd '$(DESTDIR)$(includedir)'; rm -f $(HEADERS)
|
||||
|
||||
install-libpng-pc:
|
||||
@set -ex; cd '$(DESTDIR)$(pkgconfigdir)'; rm -f libpng.pc; \
|
||||
$(LN_S) '$(PNGLIB_BASENAME).pc' libpng.pc
|
||||
|
||||
uninstall-libpng-pc:
|
||||
rm -f '$(DESTDIR)$(pkgconfigdir)/libpng.pc'
|
||||
|
||||
# EXT_LIST is a list of the possibly library directory extensions, this exists
|
||||
# because we can't find a good way of discovering the file extensions that are
|
||||
# actually installed on a given system, so instead we check for every extension
|
||||
# we have seen.
|
||||
|
||||
EXT_LIST = a dll.a so so.@PNGLIB_MAJOR@@PNGLIB_MINOR@.@PNGLIB_RELEASE@ la sl dylib
|
||||
|
||||
install-library-links:
|
||||
@set -x; cd '$(DESTDIR)$(libdir)';\
|
||||
for ext in $(EXT_LIST); do\
|
||||
rm -f "libpng.$$ext";\
|
||||
if test -f "$(PNGLIB_BASENAME).$$ext"; then\
|
||||
$(LN_S) "$(PNGLIB_BASENAME).$$ext" "libpng.$$ext" || exit 1;\
|
||||
fi;\
|
||||
done
|
||||
|
||||
uninstall-hook:
|
||||
cd $(DESTDIR)$(includedir); rm -f png.h pngconf.h pnglibconf.h
|
||||
rm -f $(DESTDIR)$(pkgconfigdir)/libpng.pc
|
||||
rm -f $(DESTDIR)$(bindir)/libpng-config
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.a
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.la
|
||||
rm -f $(DESTDIR)$(libdir)/libpng.dll.a
|
||||
uninstall-library-links:
|
||||
@set -x; cd '$(DESTDIR)$(libdir)'; for ext in $(EXT_LIST); do\
|
||||
rm -f "libpng.$$ext"; done
|
||||
|
||||
install-libpng-config:
|
||||
@set -ex; cd '$(DESTDIR)$(bindir)'; rm -f libpng-config; \
|
||||
$(LN_S) '$(PNGLIB_BASENAME)-config' libpng-config
|
||||
|
||||
uninstall-libpng-config:
|
||||
rm -f '$(DESTDIR)$(bindir)/libpng-config'
|
||||
|
||||
if DO_INSTALL_LINKS
|
||||
# If --enable-unversioned-links is specified the header and lib file links
|
||||
# will be automatically made on a 'make install':
|
||||
|
||||
install-data-hook: install-header-links
|
||||
uninstall-hook: uninstall-header-links
|
||||
install-exec-hook: install-library-links
|
||||
uninstall-hook: uninstall-library-links
|
||||
endif
|
||||
|
||||
if DO_INSTALL_LIBPNG_PC
|
||||
# Likewise, --install-pc causes libpng.pc to be constructed:
|
||||
|
||||
install-data-hook: install-libpng-pc
|
||||
uninstall-hook: uninstall-libpng-pc
|
||||
endif
|
||||
|
||||
if DO_INSTALL_LIBPNG_CONFIG
|
||||
# And --install-config:
|
||||
|
||||
install-exec-hook: install-libpng-config
|
||||
uninstall-hook: uninstall-libpng-config
|
||||
endif
|
||||
|
||||
# The following addition ensures that 'make all' always builds the test programs
|
||||
# too. It used to, but some change either in libpng or configure stopped this
|
||||
# working.
|
||||
all-am: $(check_PROGRAMS)
|
||||
|
||||
61
README
61
README
@@ -1,11 +1,11 @@
|
||||
README for libpng version 1.6.0beta33 - December 10, 2012 (shared library 16.0)
|
||||
README for libpng version 1.7.0beta65 - September 16, 2015 (shared library 17.0)
|
||||
See the note about version numbers near the top of png.h
|
||||
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz,
|
||||
libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings
|
||||
in the text files, or lpng*.zip if you want DOS-style line endings.
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz or
|
||||
libpng-*.tar.xz or if you want UNIX-style line endings in the text files,
|
||||
or lpng*.7z or lpng*.zip if you want DOS-style line endings.
|
||||
|
||||
Version 0.89 was the first official release of libpng. Don't let the
|
||||
fact that it's the first release fool you. The libpng library has been in
|
||||
@@ -23,18 +23,25 @@ earlier versions if you are using a shared library. The type of the
|
||||
png_uint_32, which will affect shared-library applications that use
|
||||
this function.
|
||||
|
||||
To avoid problems with changes to the internals of png_info_struct,
|
||||
To avoid problems with changes to the internals of png info_struct,
|
||||
new APIs have been made available in 0.95 to avoid direct application
|
||||
access to info_ptr. These functions are the png_set_<chunk> and
|
||||
png_get_<chunk> functions. These functions should be used when
|
||||
accessing/storing the info_struct data, rather than manipulating it
|
||||
directly, to avoid such problems in the future.
|
||||
|
||||
It is important to note that the APIs do not make current programs
|
||||
It is important to note that the APIs did not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||
be converted to the new format, to facilitate upgrades in the future.
|
||||
library, through libpng-1.2.x. In libpng-1.4.x, which was meant to
|
||||
be a transitional release, members of the png_struct and the
|
||||
info_struct can still be accessed, but the compiler will issue a
|
||||
warning about deprecated usage. Since libpng-1.5.0, direct access
|
||||
to these structs is not allowed, and the definitions of the structs
|
||||
reside in private pngstruct.h and pnginfo.h header files that are not
|
||||
accessible to applications. It is strongly suggested that new
|
||||
programs use the new APIs (as shown in example.c and pngtest.c), and
|
||||
older programs be converted to the new format, to facilitate upgrades
|
||||
in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@@ -77,17 +84,21 @@ compression library that is useful for more things than just PNG files.
|
||||
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
||||
you are so inclined.
|
||||
|
||||
zlib should be available at the same place that libpng is, or at.
|
||||
ftp://ftp.info-zip.org/pub/infozip/zlib
|
||||
zlib should be available at the same place that libpng is, or at zlib.net.
|
||||
|
||||
You may also want a copy of the PNG specification. It is available
|
||||
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
|
||||
these at http://www.libpng.org/pub/png/documents/
|
||||
|
||||
This code is currently being archived at libpng.sf.net in the
|
||||
[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||
e-mail me, and I'll help you find it.
|
||||
[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it
|
||||
in any of those places, e-mail me, and I'll help you find it.
|
||||
|
||||
I am not a lawyer, but I believe that the Export Control Classification
|
||||
Number (ECCN) for libpng is EAR99, which means not subject to export
|
||||
controls or International Traffic in Arms Regulations (ITAR) because it
|
||||
is open source, publicly available software, that does not contain any
|
||||
encryption software. See the EAR, paragraphs 734.3(b)(3) and 734.7(b).
|
||||
|
||||
If you have any code changes, requests, problems, etc., please e-mail
|
||||
them to me. Also, I'd appreciate any make files or project files,
|
||||
@@ -123,7 +134,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
|
||||
to others, if necessary.
|
||||
|
||||
Please do not send suggestions on how to change PNG. We have
|
||||
been discussing PNG for sixteen years now, and it is official and
|
||||
been discussing PNG for twenty years now, and it is official and
|
||||
finished. If you have suggestions for libpng, however, I'll
|
||||
gladly listen. Even if your suggestion is not used immediately,
|
||||
it may be used later.
|
||||
@@ -167,23 +178,25 @@ Files in this distribution:
|
||||
pngwrite.c => High-level write functions
|
||||
pngwtran.c => Write data transformations
|
||||
pngwutil.c => Write utility functions
|
||||
arm => Contains optimized code for the ARM platform
|
||||
contrib => Contributions
|
||||
examples => Example programs
|
||||
gregbook => source code for PNG reading and writing, from
|
||||
Greg Roelofs' "PNG: The Definitive Guide",
|
||||
O'Reilly, 1999
|
||||
msvctest => Builds and runs pngtest using a MSVC workspace
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
libtests => Test programs
|
||||
pngminim => Minimal decoder, encoder, and progressive decoder
|
||||
programs demonstrating use of pngusr.dfa
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
tools => Various tools
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
projects => Contains project files and workspaces for
|
||||
building a DLL
|
||||
cbuilder5 => Contains a Borland workspace for building
|
||||
libpng and zlib
|
||||
visualc6 => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
owatcom => Contains a WATCOM project for building libpng
|
||||
visualc71 => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
xcode => Contains an Apple xcode
|
||||
vstudio => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
scripts => Directory containing scripts for building libpng:
|
||||
(see scripts/README.txt for the list of scripts)
|
||||
|
||||
2
TODO
2
TODO
@@ -6,10 +6,12 @@ Better C++ wrapper/full C++ implementation?
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
cHRM transformation.
|
||||
Remove setjmp/longjmp usage in favor of returning error codes.
|
||||
Palette creation.
|
||||
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
||||
Improved dithering.
|
||||
Multi-lingual error and warning message support.
|
||||
Complete sRGB transformation (presently it simply uses gamma=0.45455).
|
||||
Make profile checking optional via a png_set_something() call.
|
||||
Man pages for function calls.
|
||||
Better documentation.
|
||||
Better filter selection
|
||||
|
||||
18
autogen.sh
18
autogen.sh
@@ -9,15 +9,15 @@
|
||||
#
|
||||
# For regular ("tarball") distributions all the files should exist. We do not
|
||||
# want them to be updated *under any circumstances*. It should never be
|
||||
# necessary to rune autogen.sh because ./configure --enable-maintainer-mode says
|
||||
# what to do if Makeile.am or configure.ac are changed.
|
||||
# necessary to run autogen.sh because ./configure --enable-maintainer-mode says
|
||||
# what to do if Makefile.am or configure.ac are changed.
|
||||
#
|
||||
# It is *probably* OK to update the files on a GIT checkout, because they have
|
||||
# come from the local tools, but leave that to the user who is assumed to know
|
||||
# whether it is ok or required.
|
||||
#
|
||||
# This script is intended to work without arguments, there are, however, hidden
|
||||
# arguments for (a) use while testing the script and (b) to fix up systems that
|
||||
# arguments (a) for use while testing the script and (b) to fix up systems that
|
||||
# have been broken. If (b) is required the script prompts for the correct
|
||||
# options. For this reason the options are *NOT* documented in the help; this
|
||||
# is deliberate; UTSL.
|
||||
@@ -73,8 +73,13 @@ done
|
||||
# present bad things are happening.
|
||||
#
|
||||
# The autotools generated files:
|
||||
libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in\
|
||||
config.sub configure depcomp install-sh ltmain.sh missing"
|
||||
libpng_autotools_files="Makefile.in aclocal.m4 config.guess config.h.in
|
||||
config.sub configure depcomp install-sh ltmain.sh missing\
|
||||
test-driver"
|
||||
#
|
||||
# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later
|
||||
# versions than those required by configure.ac):
|
||||
libpng_autotools_extra="compile config.h.in~"
|
||||
#
|
||||
# These are separate because 'maintainer-clean' does not remove them.
|
||||
libpng_libtool_files="scripts/libtool.m4 scripts/ltoptions.m4\
|
||||
@@ -94,6 +99,7 @@ libpng_configure_dirs=".deps"
|
||||
# of Makefile. These functions do the two bits of cleaning.
|
||||
clean_autotools(){
|
||||
rm -rf $libpng_autotools_files $libpng_libtool_files $libpng_autotools_dirs
|
||||
rm -rf $libpng_autotools_extra
|
||||
}
|
||||
|
||||
clean_configure(){
|
||||
@@ -198,7 +204,7 @@ case "$mode" in
|
||||
echo " You can run autoreconf yourself if you don't like maintainer"
|
||||
echo " mode and you can also just run autoreconf -f -i to initialize"
|
||||
echo " everything in the first place; this script is only for"
|
||||
echo " compatiblity with prior releases."
|
||||
echo " compatibility with prior releases."
|
||||
exit 1
|
||||
else
|
||||
exec >&2
|
||||
|
||||
267
configure.ac
267
configure.ac
@@ -18,7 +18,7 @@ AC_PREREQ([2.68])
|
||||
|
||||
dnl Version number stuff here:
|
||||
|
||||
AC_INIT([libpng],[1.6.0beta33],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_INIT([libpng],[1.7.0beta65],[png-mng-implement@lists.sourceforge.net])
|
||||
AC_CONFIG_MACRO_DIR([scripts])
|
||||
|
||||
# libpng does not follow GNU file name conventions (hence 'foreign')
|
||||
@@ -26,9 +26,12 @@ AC_CONFIG_MACRO_DIR([scripts])
|
||||
# silent-rules requires automake 1.11 or later
|
||||
# dist-xz requires automake 1.11 or later
|
||||
# 1.12.2 fixes a security issue in 1.11.2 and 1.12.1
|
||||
AM_INIT_AUTOMAKE([1.12.2 foreign dist-xz dist-bzip2 color-tests silent-rules])
|
||||
# was:
|
||||
# AM_INIT_AUTOMAKE
|
||||
# 1.13 is required for parallel tests
|
||||
# 1.14.1 is required for %reldir% support
|
||||
AM_INIT_AUTOMAKE([1.15 foreign dist-xz color-tests silent-rules subdir-objects])
|
||||
# The following line causes --disable-maintainer-mode to be the default to
|
||||
# configure, this is necessary because libpng distributions cannot rely on the
|
||||
# time stamps of the autotools generated files being correct
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
dnl configure.ac and Makefile.am expect automake 1.11.2 or a compatible later
|
||||
@@ -37,9 +40,9 @@ dnl automake, so the following is not necessary (and is not defined anyway):
|
||||
dnl AM_PREREQ([1.11.2])
|
||||
dnl stop configure from automagically running automake
|
||||
|
||||
PNGLIB_VERSION=1.6.0beta33
|
||||
PNGLIB_VERSION=1.7.0beta65
|
||||
PNGLIB_MAJOR=1
|
||||
PNGLIB_MINOR=6
|
||||
PNGLIB_MINOR=7
|
||||
PNGLIB_RELEASE=0
|
||||
|
||||
dnl End of version number stuff
|
||||
@@ -53,41 +56,33 @@ AC_PROG_CC
|
||||
AM_PROG_AS
|
||||
LT_PATH_LD
|
||||
AC_PROG_CPP
|
||||
AC_CHECK_TOOL(SED, sed, :)
|
||||
AC_CHECK_TOOL(AWK, awk, :)
|
||||
AC_PROG_AWK
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_PROG_MAKE_SET
|
||||
|
||||
dnl libtool/libtoolize; version 2.4.2 is the tested version, this or any
|
||||
dnl libtool/libtoolize; version 2.4.4 is the tested version, this or any
|
||||
dnl compatible later version may be used
|
||||
LT_INIT([win32-dll])
|
||||
LT_PREREQ([2.4.2])
|
||||
LT_PREREQ([2.4.4])
|
||||
|
||||
# On Solaris 10 and 12 CPP gets set to cc -E, however this still
|
||||
# does some input parsing. We need strict ANSI-C style tokenization,
|
||||
# check this:
|
||||
AC_REQUIRE_CPP
|
||||
AC_MSG_CHECKING([for a C preprocessor that does not parse its input])
|
||||
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[1.1.1 16BIT]])],
|
||||
[DFNCPP="$CPP"],
|
||||
[ DFNCPP=""
|
||||
sav_CPP="$CPP"
|
||||
for CPP in "${CC-cc} -E" "${CC-cc} -E -traditional-cpp" "/lib/cpp" "cpp"
|
||||
do
|
||||
AC_PREPROC_IFELSE([AC_LANG_SOURCE([[1.1.1 16BIT]])],
|
||||
[DFNCPP="$CPP"]
|
||||
[break],,)
|
||||
done
|
||||
CPP="$sav_CPP"
|
||||
])
|
||||
if test -n "$DFNCPP"; then
|
||||
AC_MSG_RESULT([$DFNCPP])
|
||||
AC_SUBST(DFNCPP)
|
||||
# Some awks crash when confronted with pnglibconf.dfa, do a test run now
|
||||
# to make sure this doesn't happen
|
||||
AC_MSG_CHECKING([that AWK works])
|
||||
if ${AWK} -f ${srcdir}/scripts/options.awk out="/dev/null" version=search\
|
||||
${srcdir}/pngconf.h ${srcdir}/scripts/pnglibconf.dfa\
|
||||
${srcdir}/pngusr.dfa 1>&2
|
||||
then
|
||||
AC_MSG_RESULT([ok])
|
||||
else
|
||||
AC_MSG_FAILURE([not found], 1)
|
||||
AC_MSG_FAILURE([failed], 1)
|
||||
fi
|
||||
|
||||
# This is a remnant of the old cc -E validation, where it may have been
|
||||
# necessary to use a different preprocessor for .dfn files
|
||||
DFNCPP="$CPP -E"
|
||||
AC_SUBST(DFNCPP)
|
||||
|
||||
# -Werror cannot be passed to GCC in CFLAGS because configure will fail (it
|
||||
# checks the compiler with a program that generates a warning), add the
|
||||
# following option to deal with this
|
||||
@@ -115,31 +110,146 @@ AC_ARG_ENABLE(werror,
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS([malloc.h stdlib.h string.h strings.h])
|
||||
# Headers used in pngpriv.h:
|
||||
AC_CHECK_HEADERS([assert.h stdlib.h string.h float.h fp.h math.h m68881.h])
|
||||
# Additional headers used in pngconf.h:
|
||||
AC_CHECK_HEADERS([limits.h stddef.h stdio.h setjmp.h time.h])
|
||||
# Used by pngread.c (for the simplified API):
|
||||
AC_CHECK_HEADERS([errno.h])
|
||||
# The following are not required for the standard 'make' build of libpng:
|
||||
# Additional requirements of contrib/libtests/makepng.c:
|
||||
AC_CHECK_HEADERS([ctype.h])
|
||||
# Additional requirements of contrib/libtests/pngvalid.c:
|
||||
AC_CHECK_HEADERS([fenv.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
AC_TYPE_SIZE_T
|
||||
AC_STRUCT_TM
|
||||
# Most of these have been removed from 1.7.0 because they checked for non-ANSI-C
|
||||
# behaviors and the result were, anyway, not used by earlier versions of libpng.
|
||||
AC_C_RESTRICT
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_STRTOD
|
||||
AC_CHECK_FUNCS([memset], , AC_MSG_ERROR(memset not found in libc))
|
||||
AC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_MSG_ERROR(cannot find pow)) )
|
||||
AC_ARG_WITH(zlib-prefix,
|
||||
AS_HELP_STRING([[[--with-zlib-prefix]]],
|
||||
[prefix that may have been used in installed zlib]),
|
||||
[ZPREFIX=${withval}],
|
||||
[ZPREFIX='z_'])
|
||||
AC_CHECK_LIB(z, zlibVersion, ,
|
||||
AC_CHECK_LIB(z, ${ZPREFIX}zlibVersion, , AC_MSG_ERROR(zlib not installed)))
|
||||
# Checks for library functions; these need to be in order, least demanding to
|
||||
# most because the -l directives are added to the head of the list at each
|
||||
# check.
|
||||
# ANSI-C functions: all are required but they don't have to be implemented in
|
||||
# libc, it is perfectly ok to configure with an extra, wrapper, library preset
|
||||
# in LIBS. NOTE: this list may not be complete
|
||||
AC_CHECK_FUNCS([memset memcpy strncpy],,
|
||||
AC_MSG_FAILURE([missing ANSI-C functions]))
|
||||
|
||||
# floor and ceil are required for FLOATING_POINT, but they can be turned off on
|
||||
# the configure command line (and they are independent.) Default is to 'on'
|
||||
AC_ARG_ENABLE([floating-point],
|
||||
AS_HELP_STRING([[[--enabled-floating-point]]],
|
||||
[Enable floating point APIs (default: yes)]),,
|
||||
[enable_floating_point=yes])
|
||||
|
||||
AC_ARG_ENABLE([fixed-point],
|
||||
AS_HELP_STRING([[[--enable-fixed-point]]],
|
||||
[Enable fixed point APIs (default: yes)]),,
|
||||
[enable_fixed_point=yes])
|
||||
|
||||
AC_ARG_ENABLE([floating-arithmetic],
|
||||
AS_HELP_STRING([[[--enable-floating-arithmetic]]],
|
||||
[Use floating point arithmetic internally (default: yes)]),,
|
||||
[enable_floating_arithmetic=yes])
|
||||
|
||||
# Check for a requirement for math library support
|
||||
if test "$enable_floating_arithmetic" = yes
|
||||
then
|
||||
AC_SEARCH_LIBS([floor],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([frexp],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([modf],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([atof],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
AC_SEARCH_LIBS([pow],[m],,
|
||||
[AC_MSG_WARN([not found])
|
||||
enable_floating_arithmetic=no])
|
||||
fi
|
||||
|
||||
# Set the relevant defines if required (only if required), this will override
|
||||
# anything on the command line.
|
||||
if test "$enable_floating_point" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Floating point APIs disabled])
|
||||
AC_DEFINE([PNG_NO_FLOATING_POINT],[1],
|
||||
[No support for floating point APIs])
|
||||
fi
|
||||
if test "$enable_fixed_point" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Fixed point APIs disabled])
|
||||
AC_DEFINE([PNG_NO_FIXED_POINT],[1],
|
||||
[No support for fixed point APIs])
|
||||
fi
|
||||
if test "$enable_floating_arithmetic" != yes
|
||||
then
|
||||
AC_MSG_NOTICE([Fixed point arithmetic will be used])
|
||||
AC_DEFINE([PNG_NO_FLOATING_ARITHMETIC],[1],
|
||||
[No support for floating point arithmetic])
|
||||
fi
|
||||
|
||||
# The following is for pngvalid, to ensure it catches FP errors even on
|
||||
# platforms that don't enable FP exceptions, the function appears in the math
|
||||
# library (typically), it's not an error if it is not found.
|
||||
AC_CHECK_LIB([m], [feenableexcept])
|
||||
AC_CHECK_FUNCS([feenableexcept])
|
||||
AC_SEARCH_LIBS([feenableexcept],[m],AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],
|
||||
[Define to 1 if the feenableexcept function is available]))
|
||||
# Required by pngvalid:
|
||||
AC_SEARCH_LIBS([ceil],[m])
|
||||
|
||||
# zlib checks and arguments;
|
||||
# package zlib: argument is the name of the library
|
||||
# zlib-header: the name of the header file
|
||||
# zlib-prefix: the prefix for library functions, if any
|
||||
AC_ARG_WITH([zlib],
|
||||
AS_HELP_STRING([[[--with-zlib=<name>]]],
|
||||
[base name of the zlib implementation (e.g. 'z')]),,
|
||||
[with_zlib='z'])
|
||||
|
||||
z_prefix=
|
||||
AC_ARG_WITH([zlib-prefix],
|
||||
AS_HELP_STRING([[[--with-zlib-prefix=<prefix>]]],
|
||||
[prefix for zlib API functions]),
|
||||
[if test "$withval" = "" -o "$withval" = yes; then
|
||||
with_zlib_prefix='z_'
|
||||
AC_DEFINE([PNG_ZLIB_PREFIX],[z_],[Standard zlib prefix])
|
||||
elif test "${withval}" != "no"; then
|
||||
AC_DEFINE_UNQUOTED([PNG_ZLIB_PREFIX],[${withval}],
|
||||
[User defined zlib prefix])
|
||||
else
|
||||
with_zlib_prefix=
|
||||
fi
|
||||
if test "$with_zlib_prefix" != ""; then
|
||||
AC_DEFINE([Z_PREFIX],[1],[Tell zlib.h to prefix function names])
|
||||
z_prefix="#define Z_PREFIX 1"
|
||||
fi])
|
||||
|
||||
AC_ARG_WITH([zlib-header],
|
||||
AS_HELP_STRING([[[--with-zlib-header='<file>' or '"file"']]],
|
||||
[C include argument to locate zlib header file, e.g. <zlib.h>, take
|
||||
care to put single quotes round this on the command line]),
|
||||
[AC_DEFINE_UNQUOTED([PNG_ZLIB_HEADER],[${withval}],[Zlib header file])],
|
||||
with_zlib_header='<zlib.h>')
|
||||
|
||||
# AC_CHECK_LIB isn't quite enough for this because we need the special header
|
||||
# file too.
|
||||
LIBS="-l${with_zlib} $LIBS"
|
||||
AC_MSG_CHECKING(
|
||||
[[Library '${with_zlib}' and #include ${with_zlib_header} for symbol '${with_zlib_prefix}zlibVersion']])
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[[
|
||||
${z_prefix}
|
||||
#include ${with_zlib_header}
|
||||
]],
|
||||
[[(void)${with_zlib_prefix}zlibVersion();]])],
|
||||
AC_MSG_RESULT([ok]),
|
||||
AC_MSG_FAILURE([not found]))
|
||||
|
||||
AC_MSG_CHECKING([if using Solaris linker])
|
||||
SLD=`$LD --version 2>&1 | grep Solaris`
|
||||
@@ -185,7 +295,7 @@ AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
|
||||
if test "$have_ld_version_script" = "yes"; then
|
||||
AC_MSG_CHECKING([for symbol prefix])
|
||||
SYMBOL_PREFIX=`echo "PREFIX=__USER_LABEL_PREFIX__" \
|
||||
| ${CPP-${CC-gcc} -E} - 2>&1 \
|
||||
| ${DFNCPP-${CC-gcc -E}} - 2>&1 \
|
||||
| ${EGREP-grep} "^PREFIX=" \
|
||||
| ${SED-sed} -e "s:^PREFIX=::" -e "s:__USER_LABEL_PREFIX__::"`
|
||||
AC_SUBST(SYMBOL_PREFIX)
|
||||
@@ -233,24 +343,55 @@ AC_ARG_WITH(libpng-prefix,
|
||||
fi])
|
||||
AM_CONDITIONAL([DO_PNG_PREFIX], [test "${with_libpng_prefix:-no}" != "no"])
|
||||
|
||||
# Because GCC by default assembles code with an executable stack, even though it
|
||||
# compiles C code with a non-executable stack, it is necessary to do a fixup
|
||||
# here (this may by GCC specific)
|
||||
AC_SUBST([AM_CCASFLAGS], [-Wa,--noexecstack])
|
||||
# Control over what links are made for installed files. Versioned files are
|
||||
# always installed, when the following options are turned on corresponding
|
||||
# unversioned links are also created (normally as symbolic links):
|
||||
AC_ARG_ENABLE([unversioned-links],
|
||||
AS_HELP_STRING([[[--enable-unversioned-links]]],
|
||||
[Installed libpng header files are placed in a versioned subdirectory]
|
||||
[and installed libpng library (including DLL) files are versioned.]
|
||||
[If this option is enabled unversioned links will be created pointing to]
|
||||
[the corresponding installed files. If you use libpng.pc or]
|
||||
[libpng-config for all builds you do not need these links, but if you]
|
||||
[compile programs directly they will typically #include <png.h> and]
|
||||
[link with -lpng; in that case you need the links.]
|
||||
[The links can be installed manually using 'make install-header-links']
|
||||
[and 'make install-library-links' and can be removed using the]
|
||||
[corresponding uninstall- targets. If you do enable this option every]
|
||||
[libpng 'make install' will recreate the links to point to the just]
|
||||
[installed version of libpng. The default is to create the links;]
|
||||
[use --disable-unversioned-links to change this]))
|
||||
|
||||
AC_ARG_ENABLE([arm-neon],
|
||||
AS_HELP_STRING([[[--enable-arm-neon]]], [Enable ARM NEON optimizations]),
|
||||
[if test "${enableval}" = "yes"; then
|
||||
AC_DEFINE([PNG_ARM_NEON], [1], [Enable ARM NEON optimizations])
|
||||
AC_DEFINE([PNG_ALIGNED_MEMORY_SUPPORTED], [1], [Align row buffers])
|
||||
fi])
|
||||
AM_CONDITIONAL([PNG_ARM_NEON], [test "${enable_arm_neon:-no}" = yes])
|
||||
# The AM_CONDITIONAL test is written so that the default is enabled;
|
||||
# --disable-unversioned-links must be given to turn the option off.
|
||||
AM_CONDITIONAL([DO_INSTALL_LINKS],[test "$enable_unversioned_links" != "no"])
|
||||
|
||||
AC_ARG_ENABLE([unversioned-libpng-pc],
|
||||
AS_HELP_STRING([[[--enable-unversioned-libpng-pc]]],
|
||||
[Install the configuration file 'libpng.pc' as a link to the versioned]
|
||||
[version. This is done by default - use --disable-unversioned-libpng-pc]
|
||||
[to change this.]))
|
||||
AM_CONDITIONAL([DO_INSTALL_LIBPNG_PC],
|
||||
[test "$enable_unversioned_libpng_pc" != "no"])
|
||||
|
||||
AC_ARG_ENABLE([unversioned-libpng-config],
|
||||
AS_HELP_STRING([[[--enable-unversioned-libpng-config]]],
|
||||
[Install the configuration file 'libpng-config' as a link to the]
|
||||
[versioned version. This is done by default - use]
|
||||
[--disable-unversioned-libpng-config to change this.]))
|
||||
AM_CONDITIONAL([DO_INSTALL_LIBPNG_CONFIG],
|
||||
[test "$enable_unversioned_libpng_config" != "no"])
|
||||
|
||||
# EXTENSIONS
|
||||
# Configure (and all other) support for extensions is included when autoconf is
|
||||
# run by virtue of the existence (or not) of the following file:
|
||||
sinclude([contrib/extensions.ac])
|
||||
AM_CONDITIONAL([LIBPNG_EXTENSIONS],[test -n "$libpng_automake_extensions"])
|
||||
|
||||
AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])
|
||||
|
||||
# Config files, substituting as above
|
||||
AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in])
|
||||
AC_CONFIG_FILES([libpng-config:libpng-config.in],
|
||||
[chmod +x libpng-config])
|
||||
AC_CONFIG_FILES([Makefile libpng.pc])
|
||||
AC_CONFIG_FILES([libpng-config], [chmod +x libpng-config])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
83
contrib/arm-neon/README
Normal file
83
contrib/arm-neon/README
Normal file
@@ -0,0 +1,83 @@
|
||||
OPERATING SYSTEM SPECIFIC ARM NEON DETECTION
|
||||
--------------------------------------------
|
||||
|
||||
Detection of the ability to execute ARM NEON on an ARM processor requires
|
||||
operating system support. (The information is not available in user mode.)
|
||||
|
||||
HOW TO USE THIS
|
||||
---------------
|
||||
|
||||
This directory contains C code fragments that can be included in arm/arm_init.c
|
||||
by setting the macro PNG_ARM_NEON_FILE to the file name in "" or <> at build
|
||||
time. This setting is not recorded in pnglibconf.h and can be changed simply by
|
||||
rebuilding arm/arm_init.o with the required macro definition.
|
||||
|
||||
For any of this code to be used the ARM NEON code must be enabled and run time
|
||||
checks must be supported. I.e.:
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED
|
||||
|
||||
This is done in a 'configure' build by passing configure the argument:
|
||||
|
||||
--enable-arm-neon=check
|
||||
|
||||
Apart from the basic Linux implementation in contrib/arm-neon/linux.c this code
|
||||
is unsupported. That means that it is not even compiled on a regular basis and
|
||||
may be broken in any given minor release.
|
||||
|
||||
FILE FORMAT
|
||||
-----------
|
||||
|
||||
Each file documents its testing status as of the last time it was tested (which
|
||||
may have been a long time ago):
|
||||
|
||||
STATUS: one of:
|
||||
SUPPORTED: This indicates that the file is included in the regularly
|
||||
performed test builds and bugs are fixed when discovered.
|
||||
COMPILED: This indicates that the code did compile at least once. See the
|
||||
more detailed description for the extent to which the result was
|
||||
successful.
|
||||
TESTED: This means the code was fully compiled into the libpng test programs
|
||||
and these were run at least once.
|
||||
|
||||
BUG REPORTS: an email address to which to send reports of problems
|
||||
|
||||
The file is a fragment of C code. It should not define any 'extern' symbols;
|
||||
everything should be static. It must define the function:
|
||||
|
||||
static int png_have_neon(png_structp png_ptr);
|
||||
|
||||
That function must return 1 if ARM NEON instructions are supported, 0 if not.
|
||||
It must not execute png_error unless it detects a bug. A png_error will prevent
|
||||
the reading of the PNG and in the future, writing too.
|
||||
|
||||
BUG REPORTS
|
||||
-----------
|
||||
|
||||
If you mail a bug report for any file that is not SUPPORTED there may only be
|
||||
limited response. Consider fixing it and sending a patch to fix the problem -
|
||||
this is more likely to result in action.
|
||||
|
||||
CONTRIBUTIONS
|
||||
-------------
|
||||
|
||||
You may send contributions of new implementations to
|
||||
png-mng-implement@sourceforge.net. Please write code in strict C90 C where
|
||||
possible. Obviously OS dependencies are to be expected. If you submit code you
|
||||
must have the authors permission and it must have a license that is acceptable
|
||||
to the current maintainer; in particular that license must permit modification
|
||||
and redistribution.
|
||||
|
||||
Please try to make the contribution a single file and give the file a clear and
|
||||
unambiguous name that identifies the target OS. If multiple files really are
|
||||
required put them all in a sub-directory.
|
||||
|
||||
You must also be prepared to handle bug reports from users of the code, either
|
||||
by joining the png-mng-implement mailing list or by providing an email for the
|
||||
"BUG REPORTS" entry or both. Please make sure that the header of the file
|
||||
contains the STATUS and BUG REPORTS fields as above.
|
||||
|
||||
Please list the OS requirements as precisely as possible. Ideally you should
|
||||
also list the environment in which the code has been tested and certainly list
|
||||
any environments where you suspect it might not work.
|
||||
39
contrib/arm-neon/android-ndk.c
Normal file
39
contrib/arm-neon/android-ndk.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* contrib/arm-neon/android-ndk.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Bowler, 2014.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: COMPILED, UNTESTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for the Android NDK, see:
|
||||
*
|
||||
* Documentation:
|
||||
* http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html
|
||||
* http://code.google.com/p/android/issues/detail?id=49065
|
||||
*
|
||||
* NOTE: this requires that libpng is built against the Android NDK and linked
|
||||
* with an implementation of the Android ARM 'cpu-features' library. The code
|
||||
* has been compiled only, not linked: no version of the library has been found,
|
||||
* only the header files exist in the NDK.
|
||||
*/
|
||||
#include <cpu-features.h>
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
/* This is a whole lot easier than the linux code, however it is probably
|
||||
* implemented as below, therefore it is better to cache the result (these
|
||||
* function calls may be slow!)
|
||||
*/
|
||||
PNG_UNUSED(png_ptr)
|
||||
return android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM &&
|
||||
(android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
|
||||
}
|
||||
120
contrib/arm-neon/linux-auxv.c
Normal file
120
contrib/arm-neon/linux-auxv.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/* contrib/arm-neon/linux-auxv.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: COMPILED, TESTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for Linux versions which allow access to
|
||||
* /proc/self/auxv. This is probably faster, cleaner and safer than the code to
|
||||
* read /proc/cpuinfo in contrib/arm-neon/linux, however it is yet another piece
|
||||
* of potentially untested code and has more complex dependencies than the code
|
||||
* to read cpuinfo.
|
||||
*
|
||||
* This generic __linux__ implementation requires reading /proc/self/auxv and
|
||||
* looking at each element for one that records NEON capabilities.
|
||||
*/
|
||||
#include <unistd.h> /* for POSIX 1003.1 */
|
||||
#include <errno.h> /* for EINTR */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <elf.h>
|
||||
#include <asm/hwcap.h>
|
||||
|
||||
/* A read call may be interrupted, in which case it returns -1 and sets errno to
|
||||
* EINTR if nothing was done, otherwise (if something was done) a partial read
|
||||
* may result.
|
||||
*/
|
||||
static size_t
|
||||
safe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)
|
||||
{
|
||||
size_t ntotal = 0;
|
||||
char *buffer = png_voidcast(char*, buffer_in);
|
||||
|
||||
while (nbytes > 0)
|
||||
{
|
||||
unsigned int nread;
|
||||
int iread;
|
||||
|
||||
/* Passing nread > INT_MAX to read is implementation defined in POSIX
|
||||
* 1003.1, therefore despite the unsigned argument portable code must
|
||||
* limit the value to INT_MAX!
|
||||
*/
|
||||
if (nbytes > INT_MAX)
|
||||
nread = INT_MAX;
|
||||
|
||||
else
|
||||
nread = (unsigned int)/*SAFE*/nbytes;
|
||||
|
||||
iread = read(fd, buffer, nread);
|
||||
|
||||
if (iread == -1)
|
||||
{
|
||||
/* This is the devil in the details, a read can terminate early with 0
|
||||
* bytes read because of EINTR, yet it still returns -1 otherwise end
|
||||
* of file cannot be distinguished.
|
||||
*/
|
||||
if (errno != EINTR)
|
||||
{
|
||||
png_warning(png_ptr, "/proc read failed");
|
||||
return 0; /* I.e., a permanent failure */
|
||||
}
|
||||
}
|
||||
|
||||
else if (iread < 0)
|
||||
{
|
||||
/* Not a valid 'read' result: */
|
||||
png_warning(png_ptr, "OS /proc read bug");
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (iread > 0)
|
||||
{
|
||||
/* Continue reading until a permanent failure, or EOF */
|
||||
buffer += iread;
|
||||
nbytes -= (unsigned int)/*SAFE*/iread;
|
||||
ntotal += (unsigned int)/*SAFE*/iread;
|
||||
}
|
||||
|
||||
else
|
||||
return ntotal;
|
||||
}
|
||||
|
||||
return ntotal; /* nbytes == 0 */
|
||||
}
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
int fd = open("/proc/self/auxv", O_RDONLY);
|
||||
Elf32_auxv_t aux;
|
||||
|
||||
/* Failsafe: failure to open means no NEON */
|
||||
if (fd == -1)
|
||||
{
|
||||
png_warning(png_ptr, "/proc/self/auxv open failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (safe_read(png_ptr, fd, &aux, sizeof aux) == sizeof aux)
|
||||
{
|
||||
if (aux.a_type == AT_HWCAP && (aux.a_un.a_val & HWCAP_NEON) != 0)
|
||||
{
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
161
contrib/arm-neon/linux.c
Normal file
161
contrib/arm-neon/linux.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/* contrib/arm-neon/linux.c
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Bowler, 2014.
|
||||
* Last changed in libpng 1.6.16 [December 22, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* SEE contrib/arm-neon/README before reporting bugs
|
||||
*
|
||||
* STATUS: SUPPORTED
|
||||
* BUG REPORTS: png-mng-implement@sourceforge.net
|
||||
*
|
||||
* png_have_neon implemented for Linux by reading the widely available
|
||||
* pseudo-file /proc/cpuinfo.
|
||||
*
|
||||
* This code is strict ANSI-C and is probably moderately portable; it does
|
||||
* however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
static int
|
||||
png_have_neon(png_structp png_ptr)
|
||||
{
|
||||
FILE *f = fopen("/proc/cpuinfo", "rb");
|
||||
|
||||
if (f != NULL)
|
||||
{
|
||||
/* This is a simple state machine which reads the input byte-by-byte until
|
||||
* it gets a match on the 'neon' feature or reaches the end of the stream.
|
||||
*/
|
||||
static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };
|
||||
static const char ch_neon[] = { 78, 69, 79, 78 };
|
||||
|
||||
enum
|
||||
{
|
||||
StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine
|
||||
} state;
|
||||
int counter;
|
||||
|
||||
for (state=StartLine, counter=0;;)
|
||||
{
|
||||
int ch = fgetc(f);
|
||||
|
||||
if (ch == EOF)
|
||||
{
|
||||
/* EOF means error or end-of-file, return false; neon at EOF is
|
||||
* assumed to be a mistake.
|
||||
*/
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case StartLine:
|
||||
/* Match spaces at the start of line */
|
||||
if (ch <= 32) /* skip control characters and space */
|
||||
break;
|
||||
|
||||
counter=0;
|
||||
state = Feature;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case Feature:
|
||||
/* Match 'FEATURE', ASCII case insensitive. */
|
||||
if ((ch & ~0x20) == ch_feature[counter])
|
||||
{
|
||||
if (++counter == (sizeof ch_feature))
|
||||
state = Colon;
|
||||
break;
|
||||
}
|
||||
|
||||
/* did not match 'feature' */
|
||||
state = SkipLine;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case SkipLine:
|
||||
skipLine:
|
||||
/* Skip everything until we see linefeed or carriage return */
|
||||
if (ch != 10 && ch != 13)
|
||||
break;
|
||||
|
||||
state = StartLine;
|
||||
break;
|
||||
|
||||
case Colon:
|
||||
/* Match any number of space or tab followed by ':' */
|
||||
if (ch == 32 || ch == 9)
|
||||
break;
|
||||
|
||||
if (ch == 58) /* i.e. ':' */
|
||||
{
|
||||
state = StartTag;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Either a bad line format or a 'feature' prefix followed by
|
||||
* other characters.
|
||||
*/
|
||||
state = SkipLine;
|
||||
goto skipLine;
|
||||
|
||||
case StartTag:
|
||||
/* Skip space characters before a tag */
|
||||
if (ch == 32 || ch == 9)
|
||||
break;
|
||||
|
||||
state = Neon;
|
||||
counter = 0;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case Neon:
|
||||
/* Look for 'neon' tag */
|
||||
if ((ch & ~0x20) == ch_neon[counter])
|
||||
{
|
||||
if (++counter == (sizeof ch_neon))
|
||||
state = HaveNeon;
|
||||
break;
|
||||
}
|
||||
|
||||
state = SkipTag;
|
||||
/* FALL THROUGH */
|
||||
|
||||
case SkipTag:
|
||||
/* Skip non-space characters */
|
||||
if (ch == 10 || ch == 13)
|
||||
state = StartLine;
|
||||
|
||||
else if (ch == 32 || ch == 9)
|
||||
state = StartTag;
|
||||
break;
|
||||
|
||||
case HaveNeon:
|
||||
/* Have seen a 'neon' prefix, but there must be a space or new
|
||||
* line character to terminate it.
|
||||
*/
|
||||
if (ch == 10 || ch == 13 || ch == 32 || ch == 9)
|
||||
{
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
state = SkipTag;
|
||||
break;
|
||||
|
||||
default:
|
||||
png_error(png_ptr, "png_have_neon: internal error (bug)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
else
|
||||
png_warning(png_ptr, "/proc/cpuinfo open failed");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
49
contrib/conftest/README
Normal file
49
contrib/conftest/README
Normal file
@@ -0,0 +1,49 @@
|
||||
This directory contains test configuration files, currently always '.dfa' files
|
||||
intended to be used in the build by setting the make macro DFA_XTRA to the name
|
||||
of the file.
|
||||
|
||||
These files are used in release validation of the 'configure' builds of libpng
|
||||
by building 'make check', or 'make all-am' for cross-builds, with each .dfa
|
||||
file.
|
||||
|
||||
The files in this directory may change between minor releases, however
|
||||
contributions describing specific builds of libpng are welcomed. There is no
|
||||
guarantee that libpng will continue to build with such configurations; support
|
||||
for given configurations can be, and has been, dropped between successive minor
|
||||
releases. However if a .dfa file describing a configuration is not in this
|
||||
directory it is very unlikely that it will be tested before a minor release!
|
||||
|
||||
You can use these .dfa files as the basis of new configurations. Files in this
|
||||
directory should not have any use restrictions or restrictive licenses.
|
||||
|
||||
This directory is not included in the .zip and .7z distributions, which do
|
||||
not contain 'configure' scripts.
|
||||
|
||||
DOCUMENTATION
|
||||
=============
|
||||
|
||||
Examples:
|
||||
${srcdir}/pngusr.dfa
|
||||
${srcdir}/contrib/pngminim/*/pngusr.dfa
|
||||
|
||||
Documentation of the options:
|
||||
${srcdir}/scripts/pnglibconf.dfa
|
||||
|
||||
Documentation of the file format:
|
||||
${srcdir}/scripts/options.awk
|
||||
|
||||
FILE NAMING
|
||||
===========
|
||||
|
||||
File names in this directory may NOT contain any of the five characters:
|
||||
|
||||
- , + * ?
|
||||
|
||||
Neither may they contain any space character.
|
||||
|
||||
While other characters may be used it is strongly suggested that file names be
|
||||
limited to lower case Latiin alphabetic characters (a-z), digits (0-9) and, if
|
||||
necessary the underscore (_) character. File names should be about 8 characters
|
||||
long (excluding the .dfa extension). Submitted .dfa files should have names
|
||||
between 7 and 16 characters long, shorter names (6 characters or less) are
|
||||
reserved for standard tests.
|
||||
58
contrib/conftest/read.dfa
Normal file
58
contrib/conftest/read.dfa
Normal file
@@ -0,0 +1,58 @@
|
||||
# read.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# Usage rights:
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
#
|
||||
# Build libpng with basic read support. This enables the lowest level libpng
|
||||
# read API - the one where the calling code has to use a loop to read each row.
|
||||
# At present this is the API used by most programs.
|
||||
#
|
||||
# Support is enabled only for those chunks and transformations that are
|
||||
# typically required - others can be added easily.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
# The sequential read code is enabled here; the progressive code can be used
|
||||
# instead but there is no point enabling both.
|
||||
|
||||
option SEQUENTIAL_READ on
|
||||
|
||||
# Likewise it is pointless enabling both fixed and floating point APIs. Choose
|
||||
# one or the other for both the API and the internal math.
|
||||
|
||||
#Fixed point:
|
||||
#option FIXED_POINT on
|
||||
#option FLOATING_ARITHMETIC off
|
||||
|
||||
#Floating point:
|
||||
option FLOATING_POINT on
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# Basic error handling, IO and user memory support. The latter allows the
|
||||
# application program to provide its own implementations of 'malloc' and 'free'.
|
||||
option SETJMP on
|
||||
option STDIO on
|
||||
option USER_MEM on
|
||||
|
||||
# To read the full set of PNG images correctly interlace, transparency and
|
||||
# 16-bit support is required. The application can implement interlace itself,
|
||||
# but very few do and it's no longer possible to disable it when READ is
|
||||
# enabled.
|
||||
option READ_tRNS on
|
||||
option READ_16BIT on
|
||||
|
||||
# Everything else is application dependent. This file assumes the app handles
|
||||
# all the native PNG bit layouts, so it doesn't need any of layout change
|
||||
# transforms, but needs libpng to perform gamma correction. It doesn't do any
|
||||
# colorspace stuff and ignores the 'significant bit' information.
|
||||
#
|
||||
# If your app always expands the image to a limited set of bit layouts you
|
||||
# probably want to consider using the simplified API instead of the low level
|
||||
# one - see png.h and s_read.dfa.
|
||||
option READ_GAMMA on
|
||||
35
contrib/conftest/s_read.dfa
Normal file
35
contrib/conftest/s_read.dfa
Normal file
@@ -0,0 +1,35 @@
|
||||
# s_read.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# Usage rights:
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
#
|
||||
# Build libpng with simplified read support (only). This builds a minimal
|
||||
# libpng able to read all PNG formats and convert them into a small number of
|
||||
# well understood memory formats.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_READ on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_READ_AFIRST on
|
||||
option SIMPLIFIED_READ_BGR on
|
||||
33
contrib/conftest/s_write.dfa
Normal file
33
contrib/conftest/s_write.dfa
Normal file
@@ -0,0 +1,33 @@
|
||||
# s_write.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# Usage rights:
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
#
|
||||
# Build libpng with (just) simplified write support
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_WRITE on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_WRITE_AFIRST on
|
||||
option SIMPLIFIED_WRITE_BGR on
|
||||
36
contrib/conftest/simple.dfa
Normal file
36
contrib/conftest/simple.dfa
Normal file
@@ -0,0 +1,36 @@
|
||||
# simple.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# Usage rights:
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
#
|
||||
# Build libpng with just the simplified APIs (read and write).
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
option SIMPLIFIED_WRITE on
|
||||
option SIMPLIFIED_READ on
|
||||
|
||||
# It isn't necessary to chose fixed or floating point for the APIs because the
|
||||
# simplified API doesn't need fixed or floating point numbers. It is necessary
|
||||
# to chose an internal math implementation. The default (because of 'everything
|
||||
# = off') is fixed point - turn the floating point implementation on if you have
|
||||
# hardware floating point or prefer your software floating point implementation.
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# This is not strictly necessary, but without it the message strings in the API
|
||||
# will not be filled in
|
||||
option ERROR_TEXT on
|
||||
|
||||
# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't
|
||||
# need this if you don't use them, they just allow the in-memory layout to be
|
||||
# changed to match common hardware formats.
|
||||
option SIMPLIFIED_READ_AFIRST on
|
||||
option SIMPLIFIED_READ_BGR on
|
||||
option SIMPLIFIED_WRITE_AFIRST on
|
||||
option SIMPLIFIED_WRITE_BGR on
|
||||
45
contrib/conftest/write.dfa
Normal file
45
contrib/conftest/write.dfa
Normal file
@@ -0,0 +1,45 @@
|
||||
# write.dfa
|
||||
# Build time configuration of libpng
|
||||
#
|
||||
# Author: John Bowler
|
||||
# Copyright: (c) John Bowler, 2013
|
||||
# Usage rights:
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
#
|
||||
# Build libpng with no read support and minimal write support.
|
||||
#
|
||||
|
||||
everything = off
|
||||
|
||||
# Switch on the write code - this makes a minimalist encoder
|
||||
|
||||
option WRITE on
|
||||
|
||||
# Choose fixed or floating point APIs and arithmetic. The choices are
|
||||
# independent but normally they will match. It is typically better to use the
|
||||
# floating point if you have floating point hardware. If you don't know, or
|
||||
# (perhaps) to make libpng smaller used fixed point throughout.
|
||||
|
||||
#Fixed point:
|
||||
#option FIXED_POINT on
|
||||
#option FLOATING_ARITHMETIC off
|
||||
|
||||
#Floating point:
|
||||
option FLOATING_POINT on
|
||||
option FLOATING_ARITHMETIC on
|
||||
|
||||
# Basic error handling, IO and user memory support. The latter allows the
|
||||
# application program to provide its own implementations of 'malloc' and 'free'.
|
||||
option SETJMP on
|
||||
option STDIO on
|
||||
option USER_MEM on
|
||||
|
||||
# Everything else is optional. Unlike the read code in libpng the write code
|
||||
# does not need to deal with arbitrary formats, so only add support for things
|
||||
# you really do write! For example you might only write sRGB images, sometimes
|
||||
# with transparency and never write 16 bit images, so:
|
||||
option WRITE_sRGB on
|
||||
option WRITE_tRNS on
|
||||
#option WRITE_16BIT off (this is the default with 'everything = off')
|
||||
@@ -6,9 +6,9 @@
|
||||
* United States.
|
||||
*
|
||||
* Extract any icc profiles found in the given PNG files. This is a simple
|
||||
* example of a program which extracts information from the header of a PNG file
|
||||
* example of a program that extracts information from the header of a PNG file
|
||||
* without processing the image. Notice that some header information may occur
|
||||
* after the image data, textual data and comments are an example; the approach
|
||||
* after the image data. Textual data and comments are an example; the approach
|
||||
* in this file won't work reliably for such data because it only looks for the
|
||||
* information in the section of the file that preceeds the image data.
|
||||
*
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) && \
|
||||
defined (PNG_iCCP_SUPPORTED)
|
||||
|
||||
|
||||
static int verbose = 1;
|
||||
static png_byte no_profile[] = "no profile";
|
||||
|
||||
@@ -178,3 +182,4 @@ main(int argc, char **argv)
|
||||
/* Exit code is true if any extract succeeds */
|
||||
return extracted == 0;
|
||||
}
|
||||
#endif /* READ && STDIO && iCCP */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Read a single pixel value from a PNG file.
|
||||
*
|
||||
* This code illustrates basic 'by-row' reading of a PNG file using libpng.
|
||||
* Rows are read until a particular pixel is found, the value of this pixel is
|
||||
* Rows are read until a particular pixel is found; the value of this pixel is
|
||||
* then printed on stdout.
|
||||
*
|
||||
* The code illustrates how to do this on interlaced as well as non-interlaced
|
||||
@@ -27,6 +27,8 @@
|
||||
*/
|
||||
#include "../../png.h"
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)
|
||||
|
||||
/* Return component 'c' of pixel 'x' from the given row. */
|
||||
static unsigned int
|
||||
component(png_const_bytep row, png_uint_32 x, unsigned int c,
|
||||
@@ -37,7 +39,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
|
||||
* bytes wide. Since the row fitted into memory, however, the following must
|
||||
* work:
|
||||
*/
|
||||
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels + c);
|
||||
png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);
|
||||
png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);
|
||||
|
||||
row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);
|
||||
@@ -56,7 +58,7 @@ component(png_const_bytep row, png_uint_32 x, unsigned int c,
|
||||
case 8: return row[0];
|
||||
case 16: return (row[0] << 8) + row[1];
|
||||
default:
|
||||
/* This should never happen, it indicates a bug in this program or in
|
||||
/* This should never happen; it indicates a bug in this program or in
|
||||
* libpng itself:
|
||||
*/
|
||||
fprintf(stderr, "pngpixel: invalid bit depth %u\n", bit_depth);
|
||||
@@ -85,7 +87,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
|
||||
*/
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
{
|
||||
PNG_CONST unsigned int index = component(row, x, 0, bit_depth, 1);
|
||||
PNG_CONST int index = component(row, x, 0, bit_depth, 1);
|
||||
png_colorp palette = NULL;
|
||||
int num_palette = 0;
|
||||
|
||||
@@ -132,7 +134,7 @@ print_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,
|
||||
return;
|
||||
|
||||
default:
|
||||
png_error(png_ptr, "invalid color type");
|
||||
png_error(png_ptr, "pngpixel: invalid color type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,3 +368,4 @@ int main(int argc, const char **argv)
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* READ && SEQUENTIAL_READ */
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
* ensure the code picks up the local libpng implementation:
|
||||
*/
|
||||
#include "../../png.h"
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && \
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
@@ -90,3 +92,4 @@ int main(int argc, const char **argv)
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* READ && WRITE */
|
||||
|
||||
648
contrib/examples/simpleover.c
Normal file
648
contrib/examples/simpleover.c
Normal file
@@ -0,0 +1,648 @@
|
||||
/*- simpleover
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2015.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
*
|
||||
* Read several PNG files, which should have an alpha channel or transparency
|
||||
* information, and composite them together to produce one or more 16-bit linear
|
||||
* RGBA intermediates. This involves doing the correct 'over' composition to
|
||||
* combine the alpha channels and corresponding data.
|
||||
*
|
||||
* Finally read an output (background) PNG using the 24-bit RGB format (the
|
||||
* PNG will be composited on green (#00ff00) by default if it has an alpha
|
||||
* channel), and apply the intermediate image generated above to specified
|
||||
* locations in the image.
|
||||
*
|
||||
* The command line has the general format:
|
||||
*
|
||||
* simpleover <background.png> [output.png]
|
||||
* {--sprite=width,height,name {[--at=x,y] {sprite.png}}}
|
||||
* {--add=name {x,y}}
|
||||
*
|
||||
* The --sprite and --add options may occur multiple times. They are executed
|
||||
* in order. --add may refer to any sprite already read.
|
||||
*
|
||||
* This code is intended to show how to composite multiple images together
|
||||
* correctly. Apart from the libpng Simplified API the only work done in here
|
||||
* is to combine multiple input PNG images into a single sprite; this involves
|
||||
* a Porter-Duff 'over' operation and the input PNG images may, as a result,
|
||||
* be regarded as being layered one on top of the other with the first (leftmost
|
||||
* on the command line) being at the bottom and the last on the top.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* Normally use <png.h> here to get the installed libpng, but this is done to
|
||||
* ensure the code picks up the local libpng implementation, so long as this
|
||||
* file is linked against a sufficiently recent libpng (1.6+) it is ok to
|
||||
* change this to <png.h>:
|
||||
*/
|
||||
#include "../../png.h"
|
||||
|
||||
#ifdef PNG_SIMPLIFIED_READ_SUPPORTED
|
||||
|
||||
#define sprite_name_chars 15
|
||||
struct sprite {
|
||||
FILE *file;
|
||||
png_uint_16p buffer;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
char name[sprite_name_chars+1];
|
||||
};
|
||||
|
||||
#if 0 /* div by 65535 test program */
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
double err = 0;
|
||||
unsigned int xerr = 0;
|
||||
unsigned int r = 32769;
|
||||
{
|
||||
unsigned int x = 0;
|
||||
|
||||
do {
|
||||
unsigned int t = x + (x >> 16) /*+ (x >> 31)*/ + r;
|
||||
double v = x, errtest;
|
||||
|
||||
if (t < x) {
|
||||
fprintf(stderr, "overflow: %u+%u -> %u\n", x, r, t);
|
||||
return 1;
|
||||
}
|
||||
|
||||
v /= 65535;
|
||||
errtest = v;
|
||||
t >>= 16;
|
||||
errtest -= t;
|
||||
|
||||
if (errtest > err) {
|
||||
err = errtest;
|
||||
xerr = x;
|
||||
|
||||
if (errtest >= .5) {
|
||||
fprintf(stderr, "error: %u/65535 = %f, not %u, error %f\n",
|
||||
x, v, t, errtest);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} while (++x <= 65535U*65535U);
|
||||
}
|
||||
|
||||
printf("error %f @ %u\n", err, xerr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* div by 65535 test program */
|
||||
|
||||
static void
|
||||
sprite_op(const struct sprite *sprite, int x_offset, int y_offset,
|
||||
png_imagep image, const png_uint_16 *buffer)
|
||||
{
|
||||
/* This is where the Porter-Duff 'Over' operator is evaluated; change this
|
||||
* code to change the operator (this could be parameterized). Any other
|
||||
* image processing operation could be used here.
|
||||
*/
|
||||
|
||||
|
||||
/* Check for an x or y offset that pushes any part of the image beyond the
|
||||
* right or bottom of the sprite:
|
||||
*/
|
||||
if ((y_offset < 0 || (unsigned)/*SAFE*/y_offset < sprite->height) &&
|
||||
(x_offset < 0 || (unsigned)/*SAFE*/x_offset < sprite->width))
|
||||
{
|
||||
unsigned int y = 0;
|
||||
|
||||
if (y_offset < 0)
|
||||
y = -y_offset; /* Skip to first visible row */
|
||||
|
||||
do
|
||||
{
|
||||
unsigned int x = 0;
|
||||
|
||||
if (x_offset < 0)
|
||||
x = -x_offset;
|
||||
|
||||
do
|
||||
{
|
||||
/* In and out are RGBA values, so: */
|
||||
const png_uint_16 *in_pixel = buffer + (y * image->width + x)*4;
|
||||
png_uint_32 in_alpha = in_pixel[3];
|
||||
|
||||
/* This is the optimized Porter-Duff 'Over' operation, when the
|
||||
* input alpha is 0 the output is not changed.
|
||||
*/
|
||||
if (in_alpha > 0)
|
||||
{
|
||||
png_uint_16 *out_pixel = sprite->buffer +
|
||||
((y+y_offset) * sprite->width + (x+x_offset))*4;
|
||||
|
||||
/* This is the weight to apply to the output: */
|
||||
in_alpha = 65535-in_alpha;
|
||||
|
||||
if (in_alpha > 0)
|
||||
{
|
||||
/* The input must be composed onto the output. This means
|
||||
* multiplying the current output pixel value by the inverse
|
||||
* of the input alpha (1-alpha). A division is required but
|
||||
* it is by the constant 65535. Approximate this as:
|
||||
*
|
||||
* (x + (x >> 16) + 32769) >> 16;
|
||||
*
|
||||
* This is exact (and does not overflow) for all values of
|
||||
* x in the range 0..65535*65535. (Note that the calculation
|
||||
* produces the closest integer; the maximum error is <0.5).
|
||||
*/
|
||||
png_uint_32 tmp;
|
||||
|
||||
# define compose(c)\
|
||||
tmp = out_pixel[c] * in_alpha;\
|
||||
tmp = (tmp + (tmp >> 16) + 32769) >> 16;\
|
||||
out_pixel[c] = tmp + in_pixel[c]
|
||||
|
||||
/* The following is very vectorizable... */
|
||||
compose(0);
|
||||
compose(1);
|
||||
compose(2);
|
||||
compose(3);
|
||||
}
|
||||
|
||||
else
|
||||
out_pixel[0] = in_pixel[0],
|
||||
out_pixel[1] = in_pixel[1],
|
||||
out_pixel[2] = in_pixel[2],
|
||||
out_pixel[3] = in_pixel[3];
|
||||
}
|
||||
}
|
||||
while (++x < image->width);
|
||||
}
|
||||
while (++y < image->height);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
create_sprite(struct sprite *sprite, int *argc, const char ***argv)
|
||||
{
|
||||
/* Read the arguments and create this sprite. The sprite buffer has already
|
||||
* been allocated. This reads the input PNGs one by one in linear format,
|
||||
* composes them onto the sprite buffer (the code in the function above)
|
||||
* then saves the result, converting it on the fly to PNG RGBA 8-bit format.
|
||||
*/
|
||||
while (*argc > 0)
|
||||
{
|
||||
char tombstone;
|
||||
int x = 0, y = 0;
|
||||
|
||||
if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')
|
||||
{
|
||||
/* The only supported option is --at. */
|
||||
if (sscanf((*argv)[0], "--at=%d,%d%c", &x, &y, &tombstone) != 2)
|
||||
break; /* success; caller will parse this option */
|
||||
|
||||
++*argv, --*argc;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* The argument has to be a file name */
|
||||
png_image image;
|
||||
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
image.opaque = NULL;
|
||||
|
||||
if (png_image_begin_read_from_file(&image, (*argv)[0]))
|
||||
{
|
||||
png_uint_16p buffer;
|
||||
|
||||
image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
|
||||
|
||||
buffer = malloc(PNG_IMAGE_SIZE(image));
|
||||
|
||||
if (buffer != NULL)
|
||||
{
|
||||
if (png_image_finish_read(&image, NULL/*background*/, buffer,
|
||||
0/*row_stride*/,
|
||||
NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))
|
||||
{
|
||||
/* This is the place where the Porter-Duff 'Over' operator
|
||||
* needs to be done by this code. In fact, any image
|
||||
* processing required can be done here; the data is in
|
||||
* the correct format (linear, 16-bit) and source and
|
||||
* destination are in memory.
|
||||
*/
|
||||
sprite_op(sprite, x, y, &image, buffer);
|
||||
free(buffer);
|
||||
++*argv, --*argc;
|
||||
/* And continue to the next argument */
|
||||
continue;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
free(buffer);
|
||||
fprintf(stderr, "simpleover: read %s: %s\n", (*argv)[0],
|
||||
image.message);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: out of memory: %lu bytes\n",
|
||||
(unsigned long)PNG_IMAGE_SIZE(image));
|
||||
|
||||
/* png_image_free must be called if we abort the Simplified API
|
||||
* read because of a problem detected in this code. If problems
|
||||
* are detected in the Simplified API it cleans up itself.
|
||||
*/
|
||||
png_image_free(&image);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Failed to read the first argument: */
|
||||
fprintf(stderr, "simpleover: %s: %s\n", (*argv)[0], image.message);
|
||||
}
|
||||
|
||||
return 0; /* failure */
|
||||
}
|
||||
}
|
||||
|
||||
/* All the sprite operations have completed successfully. Save the RGBA
|
||||
* buffer as a PNG using the simplified write API.
|
||||
*/
|
||||
sprite->file = tmpfile();
|
||||
|
||||
if (sprite->file != NULL)
|
||||
{
|
||||
png_image save;
|
||||
|
||||
memset(&save, 0, sizeof save);
|
||||
save.version = PNG_IMAGE_VERSION;
|
||||
save.opaque = NULL;
|
||||
save.width = sprite->width;
|
||||
save.height = sprite->height;
|
||||
save.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
|
||||
save.flags = PNG_IMAGE_FLAG_FAST;
|
||||
save.colormap_entries = 0;
|
||||
|
||||
if (png_image_write_to_stdio(&save, sprite->file, 1/*convert_to_8_bit*/,
|
||||
sprite->buffer, 0/*row_stride*/, NULL/*colormap*/))
|
||||
{
|
||||
/* Success; the buffer is no longer needed: */
|
||||
free(sprite->buffer);
|
||||
sprite->buffer = NULL;
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "simpleover: write sprite %s: %s\n", sprite->name,
|
||||
save.message);
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "simpleover: sprite %s: could not allocate tmpfile: %s\n",
|
||||
sprite->name, strerror(errno));
|
||||
|
||||
return 0; /* fail */
|
||||
}
|
||||
|
||||
static int
|
||||
add_sprite(png_imagep output, png_bytep out_buf, struct sprite *sprite,
|
||||
int *argc, const char ***argv)
|
||||
{
|
||||
/* Given a --add argument naming this sprite, perform the operations listed
|
||||
* in the following arguments. The arguments are expected to have the form
|
||||
* (x,y), which is just an offset at which to add the sprite to the
|
||||
* output.
|
||||
*/
|
||||
while (*argc > 0)
|
||||
{
|
||||
char tombstone;
|
||||
int x, y;
|
||||
|
||||
if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')
|
||||
return 1; /* success */
|
||||
|
||||
if (sscanf((*argv)[0], "%d,%d%c", &x, &y, &tombstone) == 2)
|
||||
{
|
||||
/* Now add the new image into the sprite data, but only if it
|
||||
* will fit.
|
||||
*/
|
||||
if (x < 0 || y < 0 ||
|
||||
(unsigned)/*SAFE*/x >= output->width ||
|
||||
(unsigned)/*SAFE*/y >= output->height ||
|
||||
sprite->width > output->width-x ||
|
||||
sprite->height > output->height-y)
|
||||
{
|
||||
fprintf(stderr, "simpleover: sprite %s @ (%d,%d) outside image\n",
|
||||
sprite->name, x, y);
|
||||
/* Could just skip this, but for the moment it is an error */
|
||||
return 0; /* error */
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Since we know the sprite fits we can just read it into the
|
||||
* output using the simplified API.
|
||||
*/
|
||||
png_image in;
|
||||
|
||||
in.version = PNG_IMAGE_VERSION;
|
||||
rewind(sprite->file);
|
||||
|
||||
if (png_image_begin_read_from_stdio(&in, sprite->file))
|
||||
{
|
||||
in.format = PNG_FORMAT_RGB; /* force compose */
|
||||
|
||||
if (png_image_finish_read(&in, NULL/*background*/,
|
||||
out_buf + (y*output->width + x)*3/*RGB*/,
|
||||
output->width*3/*row_stride*/,
|
||||
NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))
|
||||
{
|
||||
++*argv, --*argc;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/* The read failed: */
|
||||
fprintf(stderr, "simpleover: add sprite %s: %s\n", sprite->name,
|
||||
in.message);
|
||||
return 0; /* error */
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: --add='%s': invalid position %s\n",
|
||||
sprite->name, (*argv)[0]);
|
||||
return 0; /* error */
|
||||
}
|
||||
}
|
||||
|
||||
return 1; /* ok */
|
||||
}
|
||||
|
||||
static int
|
||||
simpleover_process(png_imagep output, png_bytep out_buf, int argc,
|
||||
const char **argv)
|
||||
{
|
||||
int result = 1; /* success */
|
||||
# define csprites 10/*limit*/
|
||||
# define str(a) #a
|
||||
int nsprites = 0;
|
||||
struct sprite sprites[csprites];
|
||||
|
||||
while (argc > 0)
|
||||
{
|
||||
result = 0; /* fail */
|
||||
|
||||
if (strncmp(argv[0], "--sprite=", 9) == 0)
|
||||
{
|
||||
char tombstone;
|
||||
|
||||
if (nsprites < csprites)
|
||||
{
|
||||
int n;
|
||||
|
||||
sprites[nsprites].width = sprites[nsprites].height = 0;
|
||||
sprites[nsprites].name[0] = 0;
|
||||
|
||||
n = sscanf(argv[0], "--sprite=%u,%u,%" str(sprite_name_chars) "s%c",
|
||||
&sprites[nsprites].width, &sprites[nsprites].height,
|
||||
sprites[nsprites].name, &tombstone);
|
||||
|
||||
if ((n == 2 || n == 3) &&
|
||||
sprites[nsprites].width > 0 && sprites[nsprites].height > 0)
|
||||
{
|
||||
size_t buf_size, tmp;
|
||||
|
||||
/* Default a name if not given. */
|
||||
if (sprites[nsprites].name[0] == 0)
|
||||
sprintf(sprites[nsprites].name, "sprite-%d", nsprites+1);
|
||||
|
||||
/* Allocate a buffer for the sprite and calculate the buffer
|
||||
* size:
|
||||
*/
|
||||
buf_size = sizeof (png_uint_16 [4]);
|
||||
buf_size *= sprites[nsprites].width;
|
||||
buf_size *= sprites[nsprites].height;
|
||||
|
||||
/* This can overflow a (size_t); check for this: */
|
||||
tmp = buf_size;
|
||||
tmp /= sprites[nsprites].width;
|
||||
tmp /= sprites[nsprites].height;
|
||||
|
||||
if (tmp == sizeof (png_uint_16 [4]))
|
||||
{
|
||||
sprites[nsprites].buffer = malloc(buf_size);
|
||||
/* This buffer must be initialized to transparent: */
|
||||
memset(sprites[nsprites].buffer, 0, buf_size);
|
||||
|
||||
if (sprites[nsprites].buffer != NULL)
|
||||
{
|
||||
sprites[nsprites].file = NULL;
|
||||
++argv, --argc;
|
||||
|
||||
if (create_sprite(sprites+nsprites++, &argc, &argv))
|
||||
{
|
||||
result = 1; /* still ok */
|
||||
continue;
|
||||
}
|
||||
|
||||
break; /* error */
|
||||
}
|
||||
}
|
||||
|
||||
/* Overflow, or OOM */
|
||||
fprintf(stderr, "simpleover: %s: sprite too large\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: %s: invalid sprite (%u,%u)\n",
|
||||
argv[0], sprites[nsprites].width, sprites[nsprites].height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: %s: too many sprites\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (strncmp(argv[0], "--add=", 6) == 0)
|
||||
{
|
||||
const char *name = argv[0]+6;
|
||||
int isprite = nsprites;
|
||||
|
||||
++argv, --argc;
|
||||
|
||||
while (--isprite >= 0)
|
||||
{
|
||||
if (strcmp(sprites[isprite].name, name) == 0)
|
||||
{
|
||||
if (!add_sprite(output, out_buf, sprites+isprite, &argc, &argv))
|
||||
goto out; /* error in add_sprite */
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isprite < 0) /* sprite not found */
|
||||
{
|
||||
fprintf(stderr, "simpleover: --add='%s': sprite not found\n", name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: %s: unrecognized operation\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
result = 1; /* ok */
|
||||
}
|
||||
|
||||
/* Clean up the cache of sprites: */
|
||||
out:
|
||||
while (--nsprites >= 0)
|
||||
{
|
||||
if (sprites[nsprites].buffer != NULL)
|
||||
free(sprites[nsprites].buffer);
|
||||
|
||||
if (sprites[nsprites].file != NULL)
|
||||
(void)fclose(sprites[nsprites].file);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
int result = 1; /* default to fail */
|
||||
|
||||
if (argc >= 2)
|
||||
{
|
||||
int argi = 2;
|
||||
const char *output = NULL;
|
||||
png_image image;
|
||||
|
||||
if (argc > 2 && argv[2][0] != '-'/*an operation*/)
|
||||
{
|
||||
output = argv[2];
|
||||
argi = 3;
|
||||
}
|
||||
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
image.opaque = NULL;
|
||||
|
||||
if (png_image_begin_read_from_file(&image, argv[1]))
|
||||
{
|
||||
png_bytep buffer;
|
||||
|
||||
image.format = PNG_FORMAT_RGB; /* 24-bit RGB */
|
||||
|
||||
buffer = malloc(PNG_IMAGE_SIZE(image));
|
||||
|
||||
if (buffer != NULL)
|
||||
{
|
||||
png_color background = {0, 0xff, 0}; /* fully saturated green */
|
||||
|
||||
if (png_image_finish_read(&image, &background, buffer,
|
||||
0/*row_stride*/, NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP */))
|
||||
{
|
||||
/* At this point png_image_finish_read has cleaned up the
|
||||
* allocated data in png_image, and only the buffer needs to be
|
||||
* freed.
|
||||
*
|
||||
* Perform the remaining operations:
|
||||
*/
|
||||
if (simpleover_process(&image, buffer, argc-argi, argv+argi))
|
||||
{
|
||||
/* Write the output: */
|
||||
if ((output != NULL &&
|
||||
png_image_write_to_file(&image, output,
|
||||
0/*convert_to_8bit*/, buffer, 0/*row_stride*/,
|
||||
NULL/*colormap*/)) ||
|
||||
(output == NULL &&
|
||||
png_image_write_to_stdio(&image, stdout,
|
||||
0/*convert_to_8bit*/, buffer, 0/*row_stride*/,
|
||||
NULL/*colormap*/)))
|
||||
result = 0;
|
||||
|
||||
else
|
||||
fprintf(stderr, "simpleover: write %s: %s\n",
|
||||
output == NULL ? "stdout" : output, image.message);
|
||||
}
|
||||
|
||||
/* else simpleover_process writes an error message */
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "simpleover: read %s: %s\n", argv[1],
|
||||
image.message);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "simpleover: out of memory: %lu bytes\n",
|
||||
(unsigned long)PNG_IMAGE_SIZE(image));
|
||||
|
||||
/* This is the only place where a 'free' is required; libpng does
|
||||
* the cleanup on error and success, but in this case we couldn't
|
||||
* complete the read because of running out of memory.
|
||||
*/
|
||||
png_image_free(&image);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Failed to read the first argument: */
|
||||
fprintf(stderr, "simpleover: %s: %s\n", argv[1], image.message);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Usage message */
|
||||
fprintf(stderr,
|
||||
"simpleover: usage: simpleover background.png [output.png]\n"
|
||||
" Output 'background.png' as a 24-bit RGB PNG file in 'output.png'\n"
|
||||
" or, if not given, stdout. 'background.png' will be composited\n"
|
||||
" on fully saturated green.\n"
|
||||
"\n"
|
||||
" Optionally, before output, process additional PNG files:\n"
|
||||
"\n"
|
||||
" --sprite=width,height,name {[--at=x,y] {sprite.png}}\n"
|
||||
" Produce a transparent sprite of size (width,height) and with\n"
|
||||
" name 'name'.\n"
|
||||
" For each sprite.png composite it using a Porter-Duff 'Over'\n"
|
||||
" operation at offset (x,y) in the sprite (defaulting to (0,0)).\n"
|
||||
" Input PNGs will be truncated to the area of the sprite.\n"
|
||||
"\n"
|
||||
" --add='name' {x,y}\n"
|
||||
" Optionally, before output, composite a sprite, 'name', which\n"
|
||||
" must have been previously produced using --sprite, at each\n"
|
||||
" offset (x,y) in the output image. Each sprite must fit\n"
|
||||
" completely within the output image.\n"
|
||||
"\n"
|
||||
" PNG files are processed in the order they occur on the command\n"
|
||||
" line and thus the first PNG processed appears as the bottommost\n"
|
||||
" in the output image.\n");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* SIMPLIFIED_READ */
|
||||
16
contrib/extensions.ac
Normal file
16
contrib/extensions.ac
Normal file
@@ -0,0 +1,16 @@
|
||||
# CONTRIBUTED EXTENSIONS
|
||||
#
|
||||
# The following extensions are part of a standard libpng distribution. They are
|
||||
# not supported parts of libpng and they are not necessarily released under the
|
||||
# same license as libpng. Please consult the relevant directory for copyright
|
||||
# and support information before uncommenting any of the lines below.
|
||||
#
|
||||
# After you change this file you MUST re-run "autoreconf" to regenerate the
|
||||
# configure script, otherwise the change may have no effect.
|
||||
#
|
||||
# Include the ARM NEON extension:
|
||||
#sinclude([contrib/neon/neon.ac])
|
||||
#
|
||||
# If any of the extensions require automake support (this is likely) automake
|
||||
# must include the file contrib/extensions.am
|
||||
#libpng_automake_extensions="yes"
|
||||
7
contrib/extensions.am
Normal file
7
contrib/extensions.am
Normal file
@@ -0,0 +1,7 @@
|
||||
# CONTRIBUTED EXTENSIONS
|
||||
#
|
||||
# Please read the file "contrib/extensions.ac" before making changes to this
|
||||
# file.
|
||||
#
|
||||
# Include the ARM NEON extension:
|
||||
#include %reldir%/neon/neon.am
|
||||
@@ -47,7 +47,8 @@ CC = gcc
|
||||
#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation
|
||||
LD = $(CC)
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS)
|
||||
CPPFLAGS = $(INCS)
|
||||
CFLAGS = -O -Wall $(MINGW_CCFLAGS)
|
||||
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||
# [-ansi, -pedantic and -W can also be used]
|
||||
LDFLAGS = $(MINGW_LDFLAGS)
|
||||
@@ -85,10 +86,10 @@ EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
%.pic$(O): %.c
|
||||
$(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
PNGINC = -I/usr/local/include/libpng16
|
||||
PNGLIB = -L/usr/local/lib -lpng16 # dynamically linked against libpng
|
||||
#PNGLIB = /usr/local/lib/libpng16.a # statically linked against libpng
|
||||
PNGINC = -I/usr/local/include/libpng17
|
||||
PNGLIB = -L/usr/local/lib -lpng17 # dynamically linked against libpng
|
||||
#PNGLIB = /usr/local/lib/libpng17.a # statically linked against libpng
|
||||
# or:
|
||||
#PNGINC = -I../..
|
||||
#PNGLIB = -L../.. -lpng
|
||||
@@ -53,7 +53,8 @@ CC = cc
|
||||
LD = cc
|
||||
RM = rm -f
|
||||
# ABI must be the same as that used to build libpng.
|
||||
ABI=
|
||||
ABI =
|
||||
CPPFLAGS =
|
||||
CFLAGS = $(ABI) -O -fullwarn $(INCS)
|
||||
LDFLAGS = $(ABI)
|
||||
O = .o
|
||||
@@ -73,7 +74,7 @@ EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -26,14 +26,14 @@
|
||||
# macros --------------------------------------------------------------------
|
||||
|
||||
#PNGDIR = /usr/local/lib
|
||||
#PNGINC = -I/usr/local/include/libpng16
|
||||
#PNGLIBd = -L$(PNGDIR) -lpng16 # dynamically linked, installed libpng
|
||||
#PNGLIBs = $(PNGDIR)/libpng16.a # statically linked, installed libpng
|
||||
#PNGINC = -I/usr/local/include/libpng17
|
||||
#PNGLIBd = -L$(PNGDIR) -lpng17 # dynamically linked, installed libpng
|
||||
#PNGLIBs = $(PNGDIR)/libpng17.a # statically linked, installed libpng
|
||||
# or:
|
||||
PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds
|
||||
#PNGDIR = ../libpng
|
||||
PNGINC = -I$(PNGDIR)
|
||||
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng16 # dynamically linked
|
||||
PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng17 # dynamically linked
|
||||
PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
|
||||
|
||||
ZDIR = /usr/local/lib
|
||||
@@ -64,7 +64,8 @@ WLIBSs = $(PNGLIBs) $(ZLIBs)
|
||||
CC = gcc
|
||||
LD = gcc
|
||||
RM = rm -f
|
||||
CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP
|
||||
CPPFLAGS = $(INCS) -DFEATURE_LOOP
|
||||
CFLAGS = -O -Wall
|
||||
# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
|
||||
# [-ansi, -pedantic and -W can also be used]
|
||||
LDFLAGS =
|
||||
@@ -92,7 +93,7 @@ EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -53,7 +53,8 @@ WLIBS = $(PNGLIB) $(ZLIB)
|
||||
CC = cl
|
||||
LD = link
|
||||
RM = del
|
||||
CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
|
||||
CPPFLAGS = $(INCS)
|
||||
CFLAGS = -nologo -O -W3 $(cvars)
|
||||
# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")]
|
||||
# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
|
||||
O = .obj
|
||||
@@ -76,7 +77,7 @@ EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
|
||||
# dependencies --------------------------------------------------------------
|
||||
|
||||
@@ -215,6 +215,10 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||
* libpng function */
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
free(image_data);
|
||||
image_data = NULL;
|
||||
free(row_pointers);
|
||||
row_pointers = NULL;
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass);
|
||||
static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
|
||||
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg);
|
||||
|
||||
|
||||
|
||||
@@ -104,7 +105,7 @@ int readpng2_init(mainprog_info *mainprog_ptr)
|
||||
/* could also replace libpng warning-handler (final NULL), but no need: */
|
||||
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
|
||||
readpng2_error_handler, NULL);
|
||||
readpng2_error_handler, readpng2_warning_handler);
|
||||
if (!png_ptr)
|
||||
return 4; /* out of memory */
|
||||
|
||||
@@ -447,6 +448,8 @@ static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
/* all done */
|
||||
|
||||
(void)info_ptr; /* Unused */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +470,12 @@ void readpng2_cleanup(mainprog_info *mainprog_ptr)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
fprintf(stderr, "readpng2 libpng warning: %s\n", msg);
|
||||
fflush(stderr);
|
||||
(void)png_ptr; /* Unused */
|
||||
}
|
||||
|
||||
|
||||
static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||
|
||||
@@ -163,8 +163,12 @@ uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
|
||||
|
||||
/* now we can go ahead and just read the whole image */
|
||||
|
||||
fread(image_data, 1L, rowbytes*height, saved_infile);
|
||||
|
||||
if (fread(image_data, 1L, rowbytes*height, saved_infile) <
|
||||
rowbytes*height) {
|
||||
free (image_data);
|
||||
image_data = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return image_data;
|
||||
}
|
||||
|
||||
@@ -41,10 +41,12 @@
|
||||
unexpected-EOF and file-read-error cases; fixed Trace() cut-and-
|
||||
paste bugs
|
||||
- 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options
|
||||
|
||||
- 2.04: Added "void(foo);" statements to quiet pedantic compiler warnings
|
||||
about unused variables (GR-P)
|
||||
- 2.05: Use nanosleep() instead of usleep(), which is deprecated (GR-P).
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
|
||||
Copyright (c) 1998-2010, 2014-2015 Greg Roelofs. All rights reserved.
|
||||
|
||||
This software is provided "as is," without warranty of any kind,
|
||||
express or implied. In no event shall the author or contributors
|
||||
@@ -95,7 +97,7 @@
|
||||
|
||||
#define PROGNAME "rpng2-x"
|
||||
#define LONGNAME "Progressive PNG Viewer for X"
|
||||
#define VERSION "2.03 of 25 February 2010"
|
||||
#define VERSION "2.04 of 15 June 2014"
|
||||
#define RESNAME "rpng2" /* our X resource application name */
|
||||
#define RESCLASS "Rpng" /* our X resource class name */
|
||||
|
||||
@@ -111,6 +113,19 @@
|
||||
#include <X11/Xos.h>
|
||||
#include <X11/keysym.h> /* defines XK_* macros */
|
||||
|
||||
#if _POSIX_C_SOURCE >= 199309L /* have nanosleep() */
|
||||
# undef usleep
|
||||
# define usleep(usec) { \
|
||||
struct timespec ts; \
|
||||
ts.tv_sec = 0; \
|
||||
ts.tv_nsec = (usec) * 1000; \
|
||||
nanosleep(&ts, NULL); }
|
||||
# endif
|
||||
|
||||
#ifndef usleep /* have neither nanosleep() nor usleep() */
|
||||
# define usleep(x) sleep(((x)+499999)/1000000)
|
||||
#endif
|
||||
|
||||
#ifdef VMS
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
@@ -456,40 +471,47 @@ int main(int argc, char **argv)
|
||||
fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
|
||||
readpng2_version_info();
|
||||
fprintf(stderr, "\n"
|
||||
"Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n"
|
||||
"Usage: ");
|
||||
fprintf(stderr,
|
||||
"%s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n"
|
||||
" %*s [-usleep dur | -timing] [-pause]\n",
|
||||
PROGNAME, (int)strlen(PROGNAME), " ");
|
||||
fprintf(stderr,
|
||||
#ifdef FEATURE_LOOP
|
||||
" %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n"
|
||||
#else
|
||||
" %*s [-usleep dur | -timing] [-pause] file.png\n\n"
|
||||
" [-loop [sec]]"
|
||||
#endif
|
||||
" file.png\n\n");
|
||||
fprintf(stderr,
|
||||
" xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
|
||||
" exp \ttransfer-function exponent (``gamma'') of the display\n"
|
||||
"\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
|
||||
"\t\t to the product of the lookup-table exponent (varies)\n"
|
||||
"\t\t to the product of the lookup-table exponent (varies)\n",
|
||||
default_display_exponent);
|
||||
fprintf(stderr,
|
||||
"\t\t and the CRT exponent (usually 2.2); must be positive\n"
|
||||
" bg \tdesired background color in 7-character hex RGB format\n"
|
||||
"\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
|
||||
"\t\t used with transparent images; overrides -bgpat\n"
|
||||
" pat \tdesired background pattern number (0-%d); used with\n"
|
||||
"\t\t transparent images; overrides -bgcolor\n"
|
||||
"\t\t transparent images; overrides -bgcolor\n",
|
||||
num_bgpat-1);
|
||||
#ifdef FEATURE_LOOP
|
||||
fprintf(stderr,
|
||||
" -loop\tloops through background images after initial display\n"
|
||||
"\t\t is complete (depends on -bgpat)\n"
|
||||
" sec \tseconds to display each background image (default = 2)\n"
|
||||
" sec \tseconds to display each background image (default = 2)\n");
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
" dur \tduration in microseconds to wait after displaying each\n"
|
||||
"\t\t row (for demo purposes)\n"
|
||||
" -timing\tenables delay for every block read, to simulate modem\n"
|
||||
"\t\t download of image (~36 Kbps)\n"
|
||||
" -pause\tpauses after displaying each pass until mouse clicked\n"
|
||||
"\nPress Q, Esc or mouse button 1 (within image window, after image\n"
|
||||
"is displayed) to quit.\n"
|
||||
"\n", PROGNAME,
|
||||
(int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1);
|
||||
"is displayed) to quit.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
if (!(infile = fopen(filename, "rb"))) {
|
||||
fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
|
||||
++error;
|
||||
@@ -735,6 +757,8 @@ int main(int argc, char **argv)
|
||||
Trace((stderr, "about to call rpng2_x_cleanup()\n"))
|
||||
rpng2_x_cleanup();
|
||||
|
||||
(void)argc; /* Unused */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1826,6 +1850,9 @@ static void rpng2_x_redisplay_image(ulg startcol, ulg startrow,
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
(void)startcol;
|
||||
(void)width;
|
||||
|
||||
} /* end function rpng2_x_redisplay_image() */
|
||||
|
||||
|
||||
|
||||
65
contrib/libtests/fakepng.c
Normal file
65
contrib/libtests/fakepng.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* Fake a PNG - just write it out directly.
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2014.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zlib.h> /* for crc32 */
|
||||
|
||||
void
|
||||
put_uLong(uLong val)
|
||||
{
|
||||
putchar(val >> 24);
|
||||
putchar(val >> 16);
|
||||
putchar(val >> 8);
|
||||
putchar(val >> 0);
|
||||
}
|
||||
|
||||
void
|
||||
put_chunk(const unsigned char *chunk, uInt length)
|
||||
{
|
||||
uLong crc;
|
||||
|
||||
put_uLong(length-4); /* Exclude the tag */
|
||||
|
||||
fwrite(chunk, length, 1, stdout);
|
||||
|
||||
crc = crc32(0, Z_NULL, 0);
|
||||
put_uLong(crc32(crc, chunk, length));
|
||||
}
|
||||
|
||||
const unsigned char signature[] =
|
||||
{
|
||||
137, 80, 78, 71, 13, 10, 26, 10
|
||||
};
|
||||
|
||||
const unsigned char IHDR[] =
|
||||
{
|
||||
73, 72, 68, 82, /* IHDR */
|
||||
0, 0, 0, 1, /* width */
|
||||
0, 0, 0, 1, /* height */
|
||||
1, /* bit depth */
|
||||
0, /* color type: greyscale */
|
||||
0, /* compression method */
|
||||
0, /* filter method */
|
||||
0 /* interlace method: none */
|
||||
};
|
||||
|
||||
const unsigned char unknown[] =
|
||||
{
|
||||
'u', 'n', 'K', 'n' /* "unKn" - private safe to copy */
|
||||
};
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fwrite(signature, sizeof signature, 1, stdout);
|
||||
put_chunk(IHDR, sizeof IHDR);
|
||||
|
||||
for (;;)
|
||||
put_chunk(unknown, sizeof unknown);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2012 John Cunningham Bowler
|
||||
# Copyright (c) 2013 John Cunningham Bowler
|
||||
#
|
||||
# Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
# Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* makepng.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -83,7 +83,7 @@
|
||||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -107,7 +107,7 @@ typedef struct chunk_insert
|
||||
png_charp parameters[1];
|
||||
} chunk_insert;
|
||||
|
||||
static int
|
||||
static unsigned int
|
||||
channels_of_type(int color_type)
|
||||
{
|
||||
if (color_type & PNG_COLOR_MASK_PALETTE)
|
||||
@@ -128,7 +128,7 @@ channels_of_type(int color_type)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
static unsigned int
|
||||
pixel_depth_of_type(int color_type, int bit_depth)
|
||||
{
|
||||
return channels_of_type(color_type) * bit_depth;
|
||||
@@ -440,7 +440,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
|
||||
/* Palette with fixed color: the image rows are all 0 and the image width
|
||||
* is 16.
|
||||
*/
|
||||
memset(row, rowbytes, 0);
|
||||
memset(row, 0, rowbytes);
|
||||
}
|
||||
|
||||
else if (colors[0] == channels_of_type(color_type))
|
||||
@@ -624,8 +624,8 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
|
||||
|
||||
gamma_table[0] = 0;
|
||||
|
||||
for (i=0; i<255; ++i)
|
||||
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + 127.5);
|
||||
for (i=1; i<255; ++i)
|
||||
gamma_table[i] = (png_byte)floor(pow(i/255.,conv) * 255 + .5);
|
||||
|
||||
gamma_table[255] = 255;
|
||||
}
|
||||
@@ -682,7 +682,11 @@ write_png(const char **name, FILE *fp, int color_type, int bit_depth,
|
||||
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);
|
||||
|
||||
{
|
||||
int passes = png_set_interlace_handling(png_ptr);
|
||||
# ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
int passes = png_set_interlace_handling(png_ptr);
|
||||
# else /* !WRITE_INTERLACING */
|
||||
int passes = 1;
|
||||
# endif /* !WRITE_INTERLACING */
|
||||
int pass;
|
||||
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
|
||||
1686
contrib/libtests/pngimage.c
Normal file
1686
contrib/libtests/pngimage.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* pngstest.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013-2015 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -62,6 +62,12 @@
|
||||
# define aligncastconst(type, value) ((const void*)(value))
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* During parallel runs of pngstest each temporary file needs a unique name,
|
||||
* this is used to permit uniqueness using a command line argument which can be
|
||||
* up to 22 characters long.
|
||||
*/
|
||||
static char tmpf[23] = "TMP";
|
||||
|
||||
/* Generate random bytes. This uses a boring repeatable algorithm and it
|
||||
* is implemented here so that it gives the same set of numbers on every
|
||||
* architecture. It's a linear congruential generator (Knuth or Sedgewick
|
||||
@@ -309,6 +315,7 @@ compare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)
|
||||
#define KEEP_GOING 32
|
||||
#define ACCUMULATE 64
|
||||
#define FAST_WRITE 128
|
||||
#define sRGB_16BIT 256
|
||||
|
||||
static void
|
||||
print_opts(png_uint_32 opts)
|
||||
@@ -329,6 +336,8 @@ print_opts(png_uint_32 opts)
|
||||
printf(" --accumulate");
|
||||
if (!(opts & FAST_WRITE)) /* --fast is currently the default */
|
||||
printf(" --slow");
|
||||
if (opts & sRGB_16BIT)
|
||||
printf(" --sRGB-16bit");
|
||||
}
|
||||
|
||||
#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */
|
||||
@@ -508,14 +517,23 @@ static void format_default(format_list *pf, int redundant)
|
||||
|
||||
for (f=0; f<FORMAT_COUNT; ++f)
|
||||
{
|
||||
/* Eliminate redundant settings. */
|
||||
/* BGR is meaningless if no color: */
|
||||
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 && (f & PNG_FORMAT_FLAG_BGR) != 0)
|
||||
/* Eliminate redundant and unsupported settings. */
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
/* BGR is meaningless if no color: */
|
||||
if ((f & PNG_FORMAT_FLAG_COLOR) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_BGR) != 0)
|
||||
# else
|
||||
if ((f & 0x10U/*HACK: fixed value*/) != 0)
|
||||
# endif
|
||||
continue;
|
||||
|
||||
/* AFIRST is meaningless if no alpha: */
|
||||
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&
|
||||
(f & PNG_FORMAT_FLAG_AFIRST) != 0)
|
||||
# else
|
||||
if ((f & 0x20U/*HACK: fixed value*/) != 0)
|
||||
# endif
|
||||
continue;
|
||||
|
||||
format_set(pf, f);
|
||||
@@ -597,7 +615,7 @@ freeimage(Image *image)
|
||||
|
||||
if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)
|
||||
{
|
||||
remove(image->tmpfile_name);
|
||||
(void)remove(image->tmpfile_name);
|
||||
image->tmpfile_name[0] = 0;
|
||||
}
|
||||
}
|
||||
@@ -777,6 +795,7 @@ gp_ga8(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[1];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_ag8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -785,6 +804,7 @@ gp_ag8(Pixel *p, png_const_voidp pb)
|
||||
p->r = p->g = p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgb8(Pixel *p, png_const_voidp pb)
|
||||
@@ -797,6 +817,7 @@ gp_rgb8(Pixel *p, png_const_voidp pb)
|
||||
p->a = 255;
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgr8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -807,6 +828,7 @@ gp_bgr8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = 255;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgba8(Pixel *p, png_const_voidp pb)
|
||||
@@ -819,6 +841,7 @@ gp_rgba8(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[3];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgra8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -829,7 +852,9 @@ gp_bgra8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = pp[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_argb8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -840,7 +865,9 @@ gp_argb8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[3];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
|
||||
static void
|
||||
gp_abgr8(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -851,6 +878,7 @@ gp_abgr8(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_g16(Pixel *p, png_const_voidp pb)
|
||||
@@ -870,6 +898,7 @@ gp_ga16(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[1];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_ag16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -878,6 +907,7 @@ gp_ag16(Pixel *p, png_const_voidp pb)
|
||||
p->r = p->g = p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgb16(Pixel *p, png_const_voidp pb)
|
||||
@@ -890,6 +920,7 @@ gp_rgb16(Pixel *p, png_const_voidp pb)
|
||||
p->a = 65535;
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgr16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -900,6 +931,7 @@ gp_bgr16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = 65535;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
gp_rgba16(Pixel *p, png_const_voidp pb)
|
||||
@@ -912,6 +944,7 @@ gp_rgba16(Pixel *p, png_const_voidp pb)
|
||||
p->a = pp[3];
|
||||
}
|
||||
|
||||
#ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
static void
|
||||
gp_bgra16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -922,7 +955,9 @@ gp_bgra16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[0];
|
||||
p->a = pp[3];
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
static void
|
||||
gp_argb16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -933,7 +968,9 @@ gp_argb16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[3];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)
|
||||
static void
|
||||
gp_abgr16(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
@@ -944,6 +981,7 @@ gp_abgr16(Pixel *p, png_const_voidp pb)
|
||||
p->b = pp[1];
|
||||
p->a = pp[0];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Given a format, return the correct one of the above functions. */
|
||||
static void (*
|
||||
@@ -957,29 +995,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_COLOR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr16;
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr16;
|
||||
|
||||
else
|
||||
# endif
|
||||
return gp_bgra16;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgra16;
|
||||
return gp_bgr16;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgr16;
|
||||
}
|
||||
|
||||
else
|
||||
# endif
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb16;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb16;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_rgba16;
|
||||
}
|
||||
|
||||
@@ -992,10 +1036,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag16;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag16;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_ga16;
|
||||
}
|
||||
|
||||
@@ -1008,29 +1054,35 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_COLOR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr8;
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_abgr8;
|
||||
|
||||
else
|
||||
# endif
|
||||
return gp_bgra8;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgra8;
|
||||
return gp_bgr8;
|
||||
}
|
||||
|
||||
else
|
||||
return gp_bgr8;
|
||||
}
|
||||
|
||||
else
|
||||
# endif
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb8;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_argb8;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_rgba8;
|
||||
}
|
||||
|
||||
@@ -1043,10 +1095,12 @@ get_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag8;
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
return gp_ag8;
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
return gp_ga8;
|
||||
}
|
||||
|
||||
@@ -2100,7 +2154,7 @@ typedef struct
|
||||
int in_opaque; /* Value of input alpha that is opaque */
|
||||
int is_palette; /* Sample values come from the palette */
|
||||
int accumulate; /* Accumlate component errors (don't log) */
|
||||
int output_8bit; /* Output is 8 bit (else 16 bit) */
|
||||
int output_8bit; /* Output is 8-bit (else 16-bit) */
|
||||
|
||||
void (*in_gp)(Pixel*, png_const_voidp);
|
||||
void (*out_gp)(Pixel*, png_const_voidp);
|
||||
@@ -2609,13 +2663,15 @@ component_loc(png_byte loc[4], png_uint_32 format)
|
||||
|
||||
loc[2] = 1;
|
||||
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
loc[1] = 2;
|
||||
loc[3] = 0;
|
||||
}
|
||||
# ifdef PNG_FORMAT_BGR_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_BGR)
|
||||
{
|
||||
loc[1] = 2;
|
||||
loc[3] = 0;
|
||||
}
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
{
|
||||
loc[1] = 0;
|
||||
loc[3] = 2;
|
||||
@@ -2630,15 +2686,17 @@ component_loc(png_byte loc[4], png_uint_32 format)
|
||||
|
||||
if (format & PNG_FORMAT_FLAG_ALPHA)
|
||||
{
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
{
|
||||
loc[0] = 0;
|
||||
++loc[1];
|
||||
++loc[2];
|
||||
++loc[3];
|
||||
}
|
||||
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
|
||||
if (format & PNG_FORMAT_FLAG_AFIRST)
|
||||
{
|
||||
loc[0] = 0;
|
||||
++loc[1];
|
||||
++loc[2];
|
||||
++loc[3];
|
||||
}
|
||||
|
||||
else
|
||||
else
|
||||
# endif
|
||||
loc[0] = channels;
|
||||
|
||||
++channels;
|
||||
@@ -2770,7 +2828,7 @@ compare_two_images(Image *a, Image *b, int via_linear,
|
||||
|
||||
else if (y >= b->image.colormap_entries)
|
||||
{
|
||||
if ((a->opts & ACCUMULATE) == 0)
|
||||
if ((b->opts & ACCUMULATE) == 0)
|
||||
{
|
||||
char pindex[9];
|
||||
sprintf(pindex, "%lu[%lu]", (unsigned long)y,
|
||||
@@ -3008,17 +3066,29 @@ read_file(Image *image, png_uint_32 format, png_const_colorp background)
|
||||
return logerror(image, "memory init: ", image->file_name, "");
|
||||
}
|
||||
|
||||
else if (image->input_file != NULL)
|
||||
{
|
||||
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
|
||||
return logerror(image, "stdio init: ", image->file_name, "");
|
||||
}
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
else if (image->input_file != NULL)
|
||||
{
|
||||
if (!png_image_begin_read_from_stdio(&image->image, image->input_file))
|
||||
return logerror(image, "stdio init: ", image->file_name, "");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (!png_image_begin_read_from_file(&image->image, image->file_name))
|
||||
return logerror(image, "file init: ", image->file_name, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!png_image_begin_read_from_file(&image->image, image->file_name))
|
||||
return logerror(image, "file init: ", image->file_name, "");
|
||||
}
|
||||
# else
|
||||
else
|
||||
{
|
||||
return logerror(image, "unsupported file/stdio init: ",
|
||||
image->file_name, "");
|
||||
}
|
||||
# endif
|
||||
|
||||
/* This must be set after the begin_read call: */
|
||||
if (image->opts & sRGB_16BIT)
|
||||
image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;
|
||||
|
||||
/* Have an initialized image with all the data we need plus, maybe, an
|
||||
* allocated file (myfile) or buffer (mybuffer) that need to be freed.
|
||||
@@ -3103,32 +3173,45 @@ read_one_file(Image *image)
|
||||
{
|
||||
long int cb = ftell(f);
|
||||
|
||||
if (cb > 0 && (unsigned long int)cb < (size_t)~(size_t)0)
|
||||
if (cb > 0)
|
||||
{
|
||||
png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
|
||||
|
||||
if (b != NULL)
|
||||
#ifndef __COVERITY__
|
||||
if ((unsigned long int)cb <= (size_t)~(size_t)0)
|
||||
#endif
|
||||
{
|
||||
rewind(f);
|
||||
png_bytep b = voidcast(png_bytep, malloc((size_t)cb));
|
||||
|
||||
if (fread(b, (size_t)cb, 1, f) == 1)
|
||||
if (b != NULL)
|
||||
{
|
||||
fclose(f);
|
||||
image->input_memory_size = cb;
|
||||
image->input_memory = b;
|
||||
rewind(f);
|
||||
|
||||
if (fread(b, (size_t)cb, 1, f) == 1)
|
||||
{
|
||||
fclose(f);
|
||||
image->input_memory_size = cb;
|
||||
image->input_memory = b;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
free(b);
|
||||
return logclose(image, f, image->file_name,
|
||||
": read failed: ");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
free(b);
|
||||
return logclose(image, f, image->file_name,
|
||||
": read failed: ");
|
||||
}
|
||||
": out of memory: ");
|
||||
}
|
||||
|
||||
else
|
||||
return logclose(image, f, image->file_name,
|
||||
": out of memory: ");
|
||||
": file too big for this architecture: ");
|
||||
/* cb is the length of the file as a (long) and
|
||||
* this is greater than the maximum amount of
|
||||
* memory that can be requested from malloc.
|
||||
*/
|
||||
}
|
||||
|
||||
else if (cb == 0)
|
||||
@@ -3162,8 +3245,41 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
|
||||
|
||||
if (image->opts & USE_STDIO)
|
||||
{
|
||||
#ifndef PNG_USE_MKSTEMP
|
||||
FILE *f = tmpfile();
|
||||
|
||||
#else
|
||||
/* Experimental. Coverity says tmpfile() is insecure because it
|
||||
* generates predictable names.
|
||||
*
|
||||
* It is possible to satisfy Coverity by using mkstemp(); however,
|
||||
* any platform supporting mkstemp() undoubtedly has a secure tmpfile()
|
||||
* implementation as well, and doesn't need the fix. Note that
|
||||
* the fix won't work on platforms that don't support mkstemp().
|
||||
*
|
||||
* https://www.securecoding.cert.org/confluence/display/c/
|
||||
* FIO21-C.+Do+not+create+temporary+files+in+shared+directories
|
||||
* says that most historic implementations of tmpfile() provide
|
||||
* only a limited number of possible temporary file names
|
||||
* (usually 26) before file names are recycled. That article also
|
||||
* provides a secure solution that unfortunately depends upon mkstemp().
|
||||
*/
|
||||
char tmpfile[] = "pngstest-XXXXXX";
|
||||
int filedes;
|
||||
FILE *f;
|
||||
umask(0177);
|
||||
filedes = mkstemp(tmpfile);
|
||||
if (filedes < 0)
|
||||
f = NULL;
|
||||
else
|
||||
{
|
||||
f = fdopen(filedes,"w+");
|
||||
/* Hide the filename immediately and ensure that the file does
|
||||
* not exist after the program ends
|
||||
*/
|
||||
(void) unlink(tmpfile);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (f != NULL)
|
||||
{
|
||||
if (png_image_write_to_stdio(&image->image, f, convert_to_8bit,
|
||||
@@ -3198,7 +3314,7 @@ write_one_file(Image *output, Image *image, int convert_to_8bit)
|
||||
static int counter = 0;
|
||||
char name[32];
|
||||
|
||||
sprintf(name, "TMP%d.png", ++counter);
|
||||
sprintf(name, "%s%d.png", tmpf, ++counter);
|
||||
|
||||
if (png_image_write_to_file(&image->image, name, convert_to_8bit,
|
||||
image->buffer+16, (png_int_32)image->stride, image->colormap))
|
||||
@@ -3453,11 +3569,19 @@ main(int argc, char **argv)
|
||||
memset(gpc_error_via_linear, 0, sizeof gpc_error_via_linear);
|
||||
}
|
||||
else if (strcmp(arg, "--file") == 0)
|
||||
opts |= READ_FILE;
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
opts |= READ_FILE;
|
||||
# else
|
||||
return 77; /* skipped: no support */
|
||||
# endif
|
||||
else if (strcmp(arg, "--memory") == 0)
|
||||
opts &= ~READ_FILE;
|
||||
else if (strcmp(arg, "--stdio") == 0)
|
||||
opts |= USE_STDIO;
|
||||
# ifdef PNG_STDIO_SUPPORTED
|
||||
opts |= USE_STDIO;
|
||||
# else
|
||||
return 77; /* skipped: no support */
|
||||
# endif
|
||||
else if (strcmp(arg, "--name") == 0)
|
||||
opts &= ~USE_STDIO;
|
||||
else if (strcmp(arg, "--verbose") == 0)
|
||||
@@ -3482,6 +3606,34 @@ main(int argc, char **argv)
|
||||
opts &= ~KEEP_GOING;
|
||||
else if (strcmp(arg, "--strict") == 0)
|
||||
opts |= STRICT;
|
||||
else if (strcmp(arg, "--sRGB-16bit") == 0)
|
||||
opts |= sRGB_16BIT;
|
||||
else if (strcmp(arg, "--linear-16bit") == 0)
|
||||
opts &= ~sRGB_16BIT;
|
||||
else if (strcmp(arg, "--tmpfile") == 0)
|
||||
{
|
||||
if (c+1 < argc)
|
||||
{
|
||||
if (strlen(argv[++c]) >= sizeof tmpf)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s is too long for a temp file prefix\n",
|
||||
argv[0], argv[c]);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* Safe: checked above */
|
||||
strncpy(tmpf, argv[c], sizeof (tmpf)-1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s requires a temporary file prefix\n",
|
||||
argv[0], arg);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
else if (strcmp(arg, "--touch") == 0)
|
||||
{
|
||||
if (c+1 < argc)
|
||||
@@ -3492,7 +3644,7 @@ main(int argc, char **argv)
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: %s requires a file name argument\n",
|
||||
argv[0], arg);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
else if (arg[0] == '+')
|
||||
@@ -3500,7 +3652,7 @@ main(int argc, char **argv)
|
||||
png_uint_32 format = formatof(arg+1);
|
||||
|
||||
if (format > FORMAT_COUNT)
|
||||
exit(1);
|
||||
exit(99);
|
||||
|
||||
format_set(&formats, format);
|
||||
}
|
||||
@@ -3508,7 +3660,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: unknown option: %s\n", argv[0], arg);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3557,7 +3709,7 @@ main(int argc, char **argv)
|
||||
buffer[4095] = 0;
|
||||
fprintf(stderr, "%s...%s: file name too long\n", buffer,
|
||||
buffer+(4096-32));
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3676,7 +3828,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: write failed\n", touch);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3684,7 +3836,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: open failed\n", touch);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3695,6 +3847,7 @@ main(int argc, char **argv)
|
||||
int main(void)
|
||||
{
|
||||
fprintf(stderr, "pngstest: no read support in libpng, test skipped\n");
|
||||
return 0;
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngunknown.c - test the read side unknown chunk handling
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.10 [March 6, 2014]
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by John Cunningham Bowler
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
@@ -30,7 +30,19 @@
|
||||
# include "../../png.h"
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* Since this program tests the ability to change the unknown chunk handling
|
||||
* these must be defined:
|
||||
*/
|
||||
#if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\
|
||||
defined(PNG_READ_SUPPORTED)
|
||||
|
||||
/* One of these must be defined to allow us to find out what happened. It is
|
||||
* still useful to set unknown chunk handling without either of these in order
|
||||
* to cause *known* chunks to be discarded. This can be a significant
|
||||
* efficiency gain, but it can't really be tested here.
|
||||
*/
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\
|
||||
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
|
||||
#if PNG_LIBPNG_VER < 10500
|
||||
/* This deliberately lacks the PNG_CONST. */
|
||||
@@ -75,43 +87,74 @@ typedef png_byte *png_const_bytep;
|
||||
# define png_const_structp png_structp
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
/* Copied from libpng 1.7.0 png.h */
|
||||
#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
|
||||
|
||||
/* Copied from pngpriv.h */
|
||||
#define PNG_32b(b,s) ((png_uint_32)(b) << (s))
|
||||
#define PNG_CHUNK(b1,b2,b3,b4) \
|
||||
(PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
|
||||
#define PNG_U16(b1, b2) ((png_uint_16)PNG_u2(b1, b2))
|
||||
#define PNG_U32(b1, b2, b3, b4)\
|
||||
(((png_uint_32)PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
|
||||
|
||||
#define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
|
||||
#define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
|
||||
#define png_IEND PNG_CHUNK( 73, 69, 78, 68)
|
||||
#define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
|
||||
#define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
|
||||
#define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
|
||||
#define png_gAMA PNG_CHUNK(103, 65, 77, 65)
|
||||
#define png_hIST PNG_CHUNK(104, 73, 83, 84)
|
||||
#define png_iCCP PNG_CHUNK(105, 67, 67, 80)
|
||||
#define png_iTXt PNG_CHUNK(105, 84, 88, 116)
|
||||
#define png_oFFs PNG_CHUNK(111, 70, 70, 115)
|
||||
#define png_pCAL PNG_CHUNK(112, 67, 65, 76)
|
||||
#define png_sCAL PNG_CHUNK(115, 67, 65, 76)
|
||||
#define png_pHYs PNG_CHUNK(112, 72, 89, 115)
|
||||
#define png_sBIT PNG_CHUNK(115, 66, 73, 84)
|
||||
#define png_sPLT PNG_CHUNK(115, 80, 76, 84)
|
||||
#define png_sRGB PNG_CHUNK(115, 82, 71, 66)
|
||||
#define png_sTER PNG_CHUNK(115, 84, 69, 82)
|
||||
#define png_tEXt PNG_CHUNK(116, 69, 88, 116)
|
||||
#define png_tIME PNG_CHUNK(116, 73, 77, 69)
|
||||
#define png_tRNS PNG_CHUNK(116, 82, 78, 83)
|
||||
#define png_zTXt PNG_CHUNK(122, 84, 88, 116)
|
||||
#define png_vpAg PNG_CHUNK('v', 'p', 'A', 'g')
|
||||
/* Constants for known chunk types.
|
||||
*/
|
||||
#define png_IDAT PNG_U32( 73, 68, 65, 84)
|
||||
#define png_IEND PNG_U32( 73, 69, 78, 68)
|
||||
#define png_IHDR PNG_U32( 73, 72, 68, 82)
|
||||
#define png_PLTE PNG_U32( 80, 76, 84, 69)
|
||||
#define png_bKGD PNG_U32( 98, 75, 71, 68)
|
||||
#define png_cHRM PNG_U32( 99, 72, 82, 77)
|
||||
#define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
|
||||
#define png_gAMA PNG_U32(103, 65, 77, 65)
|
||||
#define png_gIFg PNG_U32(103, 73, 70, 103)
|
||||
#define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */
|
||||
#define png_gIFx PNG_U32(103, 73, 70, 120)
|
||||
#define png_hIST PNG_U32(104, 73, 83, 84)
|
||||
#define png_iCCP PNG_U32(105, 67, 67, 80)
|
||||
#define png_iTXt PNG_U32(105, 84, 88, 116)
|
||||
#define png_oFFs PNG_U32(111, 70, 70, 115)
|
||||
#define png_pCAL PNG_U32(112, 67, 65, 76)
|
||||
#define png_pHYs PNG_U32(112, 72, 89, 115)
|
||||
#define png_sBIT PNG_U32(115, 66, 73, 84)
|
||||
#define png_sCAL PNG_U32(115, 67, 65, 76)
|
||||
#define png_sPLT PNG_U32(115, 80, 76, 84)
|
||||
#define png_sRGB PNG_U32(115, 82, 71, 66)
|
||||
#define png_sTER PNG_U32(115, 84, 69, 82)
|
||||
#define png_tEXt PNG_U32(116, 69, 88, 116)
|
||||
#define png_tIME PNG_U32(116, 73, 77, 69)
|
||||
#define png_tRNS PNG_U32(116, 82, 78, 83)
|
||||
#define png_zTXt PNG_U32(122, 84, 88, 116)
|
||||
|
||||
/* Test on flag values as defined in the spec (section 5.4): */
|
||||
#define PNG_CHUNK_ANCILLARY(c ) (1 & ((c) >> 29))
|
||||
#define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29))
|
||||
#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))
|
||||
#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
|
||||
#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
|
||||
#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
|
||||
|
||||
#endif /* PNG_LIBPNG_VER < 10700 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define this not_the_cpp_this
|
||||
# define new not_the_cpp_new
|
||||
# define voidcast(type, value) static_cast<type>(value)
|
||||
#else
|
||||
# define voidcast(type, value) (value)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Unused formal parameter errors are removed using the following macro which is
|
||||
* expected to have no bad effects on performance.
|
||||
*/
|
||||
#ifndef UNUSED
|
||||
# if defined(__GNUC__) || defined(_MSC_VER)
|
||||
# define UNUSED(param) (void)param;
|
||||
# else
|
||||
# define UNUSED(param)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Types of chunks not known to libpng */
|
||||
#define png_vpAg PNG_U32(118, 112, 65, 103)
|
||||
|
||||
/* Chunk information */
|
||||
#define PNG_INFO_tEXt 0x10000000U
|
||||
#define PNG_INFO_iTXt 0x20000000U
|
||||
@@ -139,23 +182,128 @@ static struct
|
||||
{ "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },
|
||||
|
||||
/* Non-critical chunks that libpng handles */
|
||||
{ "bKGD", PNG_INFO_bKGD, png_bKGD, 0, 1, START, 0 },
|
||||
{ "cHRM", PNG_INFO_cHRM, png_cHRM, 0, 1, START, 0 },
|
||||
{ "gAMA", PNG_INFO_gAMA, png_gAMA, 0, 1, START, 0 },
|
||||
{ "hIST", PNG_INFO_hIST, png_hIST, 0, 1, ABSENT, 0 },
|
||||
{ "iCCP", PNG_INFO_iCCP, png_iCCP, 0, 1, ABSENT, 0 },
|
||||
{ "iTXt", PNG_INFO_iTXt, png_iTXt, 0, 1, ABSENT, 0 },
|
||||
{ "oFFs", PNG_INFO_oFFs, png_oFFs, 0, 1, START, 0 },
|
||||
{ "pCAL", PNG_INFO_pCAL, png_pCAL, 0, 1, START, 0 },
|
||||
{ "pHYs", PNG_INFO_pHYs, png_pHYs, 0, 1, START, 0 },
|
||||
{ "sBIT", PNG_INFO_sBIT, png_sBIT, 0, 1, START, 0 },
|
||||
{ "sCAL", PNG_INFO_sCAL, png_sCAL, 0, 1, START, 0 },
|
||||
{ "sPLT", PNG_INFO_sPLT, png_sPLT, 0, 1, ABSENT, 0 },
|
||||
{ "sRGB", PNG_INFO_sRGB, png_sRGB, 0, 1, START, 0 },
|
||||
{ "tEXt", PNG_INFO_tEXt, png_tEXt, 0, 1, START, 0 },
|
||||
{ "tIME", PNG_INFO_tIME, png_tIME, 0, 1, START, 0 },
|
||||
{ "tRNS", PNG_INFO_tRNS, png_tRNS, 0, 0, ABSENT, 0 },
|
||||
{ "zTXt", PNG_INFO_zTXt, png_zTXt, 0, 1, END, 0 },
|
||||
/* This is a mess but it seems to be the only way to do it - there is no way
|
||||
* to check for a definition outside a #if.
|
||||
*/
|
||||
{ "bKGD", PNG_INFO_bKGD, png_bKGD,
|
||||
# ifdef PNG_READ_bKGD_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "cHRM", PNG_INFO_cHRM, png_cHRM,
|
||||
# ifdef PNG_READ_cHRM_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "gAMA", PNG_INFO_gAMA, png_gAMA,
|
||||
# ifdef PNG_READ_gAMA_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "hIST", PNG_INFO_hIST, png_hIST,
|
||||
# ifdef PNG_READ_hIST_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "iCCP", PNG_INFO_iCCP, png_iCCP,
|
||||
# ifdef PNG_READ_iCCP_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "iTXt", PNG_INFO_iTXt, png_iTXt,
|
||||
# ifdef PNG_READ_iTXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "oFFs", PNG_INFO_oFFs, png_oFFs,
|
||||
# ifdef PNG_READ_oFFs_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "pCAL", PNG_INFO_pCAL, png_pCAL,
|
||||
# ifdef PNG_READ_pCAL_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "pHYs", PNG_INFO_pHYs, png_pHYs,
|
||||
# ifdef PNG_READ_pHYs_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sBIT", PNG_INFO_sBIT, png_sBIT,
|
||||
# ifdef PNG_READ_sBIT_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sCAL", PNG_INFO_sCAL, png_sCAL,
|
||||
# ifdef PNG_READ_sCAL_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "sPLT", PNG_INFO_sPLT, png_sPLT,
|
||||
# ifdef PNG_READ_sPLT_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, ABSENT, 0 },
|
||||
{ "sRGB", PNG_INFO_sRGB, png_sRGB,
|
||||
# ifdef PNG_READ_sRGB_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tEXt", PNG_INFO_tEXt, png_tEXt,
|
||||
# ifdef PNG_READ_tEXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tIME", PNG_INFO_tIME, png_tIME,
|
||||
# ifdef PNG_READ_tIME_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, START, 0 },
|
||||
{ "tRNS", PNG_INFO_tRNS, png_tRNS,
|
||||
# ifdef PNG_READ_tRNS_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
0, ABSENT, 0 },
|
||||
{ "zTXt", PNG_INFO_zTXt, png_zTXt,
|
||||
# ifdef PNG_READ_zTXt_SUPPORTED
|
||||
0,
|
||||
# else
|
||||
1,
|
||||
# endif
|
||||
1, END, 0 },
|
||||
|
||||
/* No libpng handling */
|
||||
{ "sTER", PNG_INFO_sTER, png_sTER, 1, 1, START, 0 },
|
||||
@@ -212,14 +360,16 @@ find_by_flag(png_uint_32 flag)
|
||||
static int
|
||||
ancillary(const char *name)
|
||||
{
|
||||
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
|
||||
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
|
||||
}
|
||||
|
||||
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static int
|
||||
ancillaryb(const png_byte *name)
|
||||
{
|
||||
return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
|
||||
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Type of an error_ptr */
|
||||
typedef struct
|
||||
@@ -227,8 +377,11 @@ typedef struct
|
||||
jmp_buf error_return;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr, end_ptr;
|
||||
png_uint_32 before_IDAT;
|
||||
png_uint_32 after_IDAT;
|
||||
int error_count;
|
||||
int warning_count;
|
||||
int keep; /* the default value */
|
||||
const char *program;
|
||||
const char *file;
|
||||
const char *test;
|
||||
@@ -261,9 +414,6 @@ clean_display(display *d)
|
||||
d->test);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Invalidate the test */
|
||||
d->test = init;
|
||||
}
|
||||
|
||||
PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
|
||||
@@ -289,7 +439,7 @@ display_rc(const display *d, int strict)
|
||||
}
|
||||
|
||||
/* libpng error and warning callbacks */
|
||||
PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
|
||||
PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
|
||||
static PNG_NORETURN)
|
||||
{
|
||||
display *d = (display*)png_get_error_ptr(png_ptr);
|
||||
@@ -298,7 +448,7 @@ PNG_FUNCTION(void, error, (png_structp png_ptr, const char *message),
|
||||
display_exit(d);
|
||||
}
|
||||
|
||||
static void
|
||||
static void PNGCBAPI
|
||||
warning(png_structp png_ptr, const char *message)
|
||||
{
|
||||
display *d = (display*)png_get_error_ptr(png_ptr);
|
||||
@@ -308,7 +458,7 @@ warning(png_structp png_ptr, const char *message)
|
||||
}
|
||||
|
||||
static png_uint_32
|
||||
get_valid(display *d, png_const_infop info_ptr)
|
||||
get_valid(display *d, png_infop info_ptr)
|
||||
{
|
||||
png_uint_32 flags = png_get_valid(d->png_ptr, info_ptr, (png_uint_32)~0);
|
||||
|
||||
@@ -339,11 +489,88 @@ get_valid(display *d, png_const_infop info_ptr)
|
||||
return flags;
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
static int PNGCBAPI
|
||||
read_callback(png_structp pp, png_unknown_chunkp pc)
|
||||
{
|
||||
/* This function mimics the behavior of png_set_keep_unknown_chunks by
|
||||
* returning '0' to keep the chunk and '1' to discard it.
|
||||
*/
|
||||
display *d = voidcast(display*, png_get_user_chunk_ptr(pp));
|
||||
int chunk = findb(pc->name);
|
||||
int keep, discard;
|
||||
|
||||
if (chunk < 0) /* not one in our list, so not a known chunk */
|
||||
keep = d->keep;
|
||||
|
||||
else
|
||||
{
|
||||
keep = chunk_info[chunk].keep;
|
||||
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
|
||||
{
|
||||
/* See the comments in png.h - use the default for unknown chunks,
|
||||
* do not keep known chunks.
|
||||
*/
|
||||
if (chunk_info[chunk].unknown)
|
||||
keep = d->keep;
|
||||
|
||||
else
|
||||
keep = PNG_HANDLE_CHUNK_NEVER;
|
||||
}
|
||||
}
|
||||
|
||||
switch (keep)
|
||||
{
|
||||
default:
|
||||
fprintf(stderr, "%s(%s): %d: unrecognized chunk option\n", d->file,
|
||||
d->test, chunk_info[chunk].keep);
|
||||
display_exit(d);
|
||||
|
||||
case PNG_HANDLE_CHUNK_AS_DEFAULT:
|
||||
case PNG_HANDLE_CHUNK_NEVER:
|
||||
discard = 1/*handled; discard*/;
|
||||
break;
|
||||
|
||||
case PNG_HANDLE_CHUNK_IF_SAFE:
|
||||
case PNG_HANDLE_CHUNK_ALWAYS:
|
||||
discard = 0/*not handled; keep*/;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Also store information about this chunk in the display, the relevant flag
|
||||
* is set if the chunk is to be kept ('not handled'.)
|
||||
*/
|
||||
if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
|
||||
{
|
||||
png_uint_32 flag = chunk_info[chunk].flag;
|
||||
|
||||
if (pc->location & PNG_AFTER_IDAT)
|
||||
d->after_IDAT |= flag;
|
||||
|
||||
else
|
||||
d->before_IDAT |= flag;
|
||||
}
|
||||
|
||||
/* However if there is no support to store unknown chunks don't ask libpng to
|
||||
* do it; there will be an png_error.
|
||||
*/
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
return discard;
|
||||
# else
|
||||
return 1; /*handled; discard*/
|
||||
# endif
|
||||
}
|
||||
#endif /* READ_USER_CHUNKS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
static png_uint_32
|
||||
get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
|
||||
{
|
||||
/* Create corresponding 'unknown' flags */
|
||||
png_uint_32 flags = 0;
|
||||
|
||||
UNUSED(after_IDAT)
|
||||
|
||||
{
|
||||
png_unknown_chunkp unknown;
|
||||
int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);
|
||||
@@ -353,16 +580,16 @@ get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
int chunk = findb(unknown[num_unknown].name);
|
||||
|
||||
/* Chunks not known to pngunknown must be validated here; since they
|
||||
* must also be unknown to libpng the 'def' behavior should have been
|
||||
* used.
|
||||
* must also be unknown to libpng the 'display->keep' behavior should
|
||||
* have been used.
|
||||
*/
|
||||
if (chunk < 0) switch (def)
|
||||
if (chunk < 0) switch (d->keep)
|
||||
{
|
||||
default: /* impossible */
|
||||
case PNG_HANDLE_CHUNK_AS_DEFAULT:
|
||||
case PNG_HANDLE_CHUNK_NEVER:
|
||||
fprintf(stderr, "%s(%s): %s: %s: unknown chunk saved\n",
|
||||
d->file, d->test, def ? "discard" : "default",
|
||||
d->file, d->test, d->keep ? "discard" : "default",
|
||||
unknown[num_unknown].name);
|
||||
++(d->error_count);
|
||||
break;
|
||||
@@ -388,14 +615,39 @@ get_unknown(display *d, int def, png_const_infop info_ptr)
|
||||
|
||||
return flags;
|
||||
}
|
||||
#else
|
||||
static png_uint_32
|
||||
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
|
||||
/* Otherwise this will return the cached values set by any user callback */
|
||||
{
|
||||
UNUSED(info_ptr);
|
||||
|
||||
if (after_IDAT)
|
||||
return d->after_IDAT;
|
||||
|
||||
else
|
||||
return d->before_IDAT;
|
||||
}
|
||||
|
||||
# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
/* The #defines above should mean this is never reached, it's just here as
|
||||
* a check to ensure the logic is correct.
|
||||
*/
|
||||
# error No store support and no user chunk support, this will not work
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static int
|
||||
check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
display *d)
|
||||
display *d, int set_callback)
|
||||
{
|
||||
int i, def = PNG_HANDLE_CHUNK_AS_DEFAULT, npasses, ipass;
|
||||
int i, npasses, ipass;
|
||||
png_uint_32 height;
|
||||
|
||||
d->keep = PNG_HANDLE_CHUNK_AS_DEFAULT;
|
||||
d->before_IDAT = 0;
|
||||
d->after_IDAT = 0;
|
||||
|
||||
/* Some of these errors are permanently fatal and cause an exit here, others
|
||||
* are per-test and cause an error return.
|
||||
*/
|
||||
@@ -421,6 +673,16 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
|
||||
png_init_io(d->png_ptr, fp);
|
||||
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
/* This is only done if requested by the caller; it interferes with the
|
||||
* standard store/save mechanism.
|
||||
*/
|
||||
if (set_callback)
|
||||
png_set_read_user_chunk_fn(d->png_ptr, d, read_callback);
|
||||
# else
|
||||
UNUSED(set_callback)
|
||||
# endif
|
||||
|
||||
/* Handle each argument in turn; multiple settings are possible for the same
|
||||
* chunk and multiple calls will occur (the last one should override all
|
||||
* preceding ones).
|
||||
@@ -460,13 +722,17 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
* in this case, so we just check the arguments! This could
|
||||
* be improved in the future by using the read callback.
|
||||
*/
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# if PNG_LIBPNG_VER >= 10700 &&\
|
||||
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
|
||||
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
|
||||
{
|
||||
png_byte name[5];
|
||||
|
||||
memcpy(name, chunk_info[chunk].name, 5);
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
|
||||
chunk_info[chunk].keep = option;
|
||||
# endif
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -475,10 +741,13 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
case 7: /* default */
|
||||
if (memcmp(argv[i], "default", 7) == 0)
|
||||
{
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# if PNG_LIBPNG_VER >= 10700 &&\
|
||||
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
|
||||
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
|
||||
# endif
|
||||
def = option;
|
||||
|
||||
d->keep = option;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -487,14 +756,17 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
case 3: /* all */
|
||||
if (memcmp(argv[i], "all", 3) == 0)
|
||||
{
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
# if PNG_LIBPNG_VER >= 10700 &&\
|
||||
!defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (option < PNG_HANDLE_CHUNK_IF_SAFE)
|
||||
# endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
|
||||
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
|
||||
def = option;
|
||||
|
||||
for (chunk = 0; chunk < NINFO; ++chunk)
|
||||
if (chunk_info[chunk].all)
|
||||
chunk_info[chunk].keep = option;
|
||||
# endif
|
||||
d->keep = option;
|
||||
|
||||
for (chunk = 0; chunk < NINFO; ++chunk)
|
||||
if (chunk_info[chunk].all)
|
||||
chunk_info[chunk].keep = option;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -568,18 +840,18 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
|
||||
png_read_end(d->png_ptr, d->end_ptr);
|
||||
|
||||
flags[0] = get_valid(d, d->info_ptr);
|
||||
flags[1] = get_unknown(d, def, d->info_ptr);
|
||||
flags[1] = get_unknown(d, d->info_ptr, 0/*before IDAT*/);
|
||||
|
||||
/* Only png_read_png sets PNG_INFO_IDAT! */
|
||||
flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |=
|
||||
PNG_INFO_IDAT;
|
||||
|
||||
flags[2] = get_valid(d, d->end_ptr);
|
||||
flags[3] = get_unknown(d, def, d->end_ptr);
|
||||
flags[3] = get_unknown(d, d->end_ptr, 1/*after IDAT*/);
|
||||
|
||||
clean_display(d);
|
||||
|
||||
return def;
|
||||
return d->keep;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -600,7 +872,7 @@ check_error(display *d, png_uint_32 flags, const char *message)
|
||||
|
||||
static void
|
||||
check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
png_uint_32 unknown, const char *position)
|
||||
png_uint_32 unknown, const char *position, int set_callback)
|
||||
{
|
||||
while (chunks)
|
||||
{
|
||||
@@ -707,8 +979,9 @@ check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
if (errorx != NULL)
|
||||
{
|
||||
++(d->error_count);
|
||||
fprintf(stderr, "%s(%s): %s %s %s: %s\n",
|
||||
d->file, d->test, type, chunk_info[i].name, position, errorx);
|
||||
fprintf(stderr, "%s(%s%s): %s %s %s: %s\n", d->file, d->test,
|
||||
set_callback ? ",callback" : "",
|
||||
type, chunk_info[i].name, position, errorx);
|
||||
}
|
||||
|
||||
chunks &= ~flag;
|
||||
@@ -717,7 +990,7 @@ check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
|
||||
|
||||
static void
|
||||
perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
png_uint_32 *default_flags, display *d)
|
||||
png_uint_32 *default_flags, display *d, int set_callback)
|
||||
{
|
||||
int def;
|
||||
png_uint_32 flags[2][4];
|
||||
@@ -726,7 +999,7 @@ perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
clear_keep();
|
||||
memcpy(flags[0], default_flags, sizeof flags[0]);
|
||||
|
||||
def = check(fp, argc, argv, flags[1], d);
|
||||
def = check(fp, argc, argv, flags[1], d, set_callback);
|
||||
|
||||
/* Chunks should either be known or unknown, never both and this should apply
|
||||
* whether the chunk is before or after the IDAT (actually, the app can
|
||||
@@ -761,9 +1034,9 @@ perform_one_test(FILE *fp, int argc, const char **argv,
|
||||
* it or not.
|
||||
*/
|
||||
check_handling(d, def, flags[0][0] | flags[0][1], flags[1][0], flags[1][1],
|
||||
"before IDAT");
|
||||
"before IDAT", set_callback);
|
||||
check_handling(d, def, flags[0][2] | flags[0][3], flags[1][2], flags[1][3],
|
||||
"after IDAT");
|
||||
"after IDAT", set_callback);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -773,7 +1046,12 @@ perform_one_test_safe(FILE *fp, int argc, const char **argv,
|
||||
if (setjmp(d->error_return) == 0)
|
||||
{
|
||||
d->test = test; /* allow use of d->error_return */
|
||||
perform_one_test(fp, argc, argv, default_flags, d);
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, d, 0);
|
||||
# endif
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, d, 1);
|
||||
# endif
|
||||
d->test = init; /* prevent use of d->error_return */
|
||||
}
|
||||
}
|
||||
@@ -797,7 +1075,7 @@ usage(const char *program, const char *reason)
|
||||
fprintf(stderr, "pngunknown: %s: usage:\n %s [--strict] "
|
||||
"--default|{(CHNK|default|all)=(default|discard|if-safe|save)} "
|
||||
"testfile.png\n", reason, program);
|
||||
exit(2);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -845,11 +1123,6 @@ main(int argc, const char **argv)
|
||||
else if (default_tests) if (argc != 1)
|
||||
usage(d.program, "extra arguments");
|
||||
|
||||
# ifndef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
fprintf(stderr, "%s: warning: no 'save' support so arguments ignored\n",
|
||||
d.program);
|
||||
# endif
|
||||
|
||||
/* The name of the test file is the last argument; remove it. */
|
||||
d.file = argv[--argc];
|
||||
|
||||
@@ -857,24 +1130,40 @@ main(int argc, const char **argv)
|
||||
if (fp == NULL)
|
||||
{
|
||||
perror(d.file);
|
||||
exit(2);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* First find all the chunks, known and unknown, in the test file, a failure
|
||||
* here aborts the whole test.
|
||||
*
|
||||
* If 'save' is supported then the normal saving method should happen,
|
||||
* otherwise if 'read' is supported then the read callback will do the
|
||||
* same thing. If both are supported the 'read' callback won't be
|
||||
* instantiated by default. If 'save' is *not* supported then a user
|
||||
* callback is required even though we can call png_get_unknown_chunks.
|
||||
*/
|
||||
if (check(fp, 1, &count_argv, default_flags, &d) !=
|
||||
PNG_HANDLE_CHUNK_ALWAYS)
|
||||
if (check(fp, 1, &count_argv, default_flags, &d,
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
0
|
||||
# else
|
||||
1
|
||||
# endif
|
||||
) != PNG_HANDLE_CHUNK_ALWAYS)
|
||||
{
|
||||
fprintf(stderr, "%s: %s: internal error\n", d.program, d.file);
|
||||
exit(3);
|
||||
exit(99);
|
||||
}
|
||||
|
||||
/* Now find what the various supplied options cause to change: */
|
||||
if (!default_tests)
|
||||
{
|
||||
d.test = cmd; /* acts as a flag to say exit, do not longjmp */
|
||||
perform_one_test(fp, argc, argv, default_flags, &d);
|
||||
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, &d, 0);
|
||||
# endif
|
||||
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
perform_one_test(fp, argc, argv, default_flags, &d, 1);
|
||||
# endif
|
||||
d.test = init;
|
||||
}
|
||||
|
||||
@@ -932,14 +1221,14 @@ main(int argc, const char **argv)
|
||||
if (fclose(fsuccess) || err)
|
||||
{
|
||||
fprintf(stderr, "%s: write failed\n", touch_file);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "%s: open failed\n", touch_file);
|
||||
exit(1);
|
||||
exit(99);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,12 +1238,24 @@ main(int argc, const char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#else
|
||||
#else /* !(READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS) */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" test ignored because libpng was not built with unknown chunk support\n");
|
||||
return 0;
|
||||
" test ignored: no support to find out about unknown chunks\n");
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif
|
||||
#endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
|
||||
|
||||
#else /* !(SET_UNKNOWN_CHUNKS && READ) */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" test ignored: no support to modify unknown chunk handling\n");
|
||||
/* So the test is skipped: */
|
||||
return 77;
|
||||
}
|
||||
#endif /* SET_UNKNOWN_CHUNKS && READ*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
121
contrib/libtests/readpng.c
Normal file
121
contrib/libtests/readpng.c
Normal file
@@ -0,0 +1,121 @@
|
||||
/* readpng.c
|
||||
*
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* Load an arbitrary number of PNG files (from the command line, or, if there
|
||||
* are no arguments on the command line, from stdin) then run a time test by
|
||||
* reading each file by row. The test does nothing with the read result and
|
||||
* does no transforms. The only output is a time as a floating point number of
|
||||
* seconds with 9 decimal digits.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
/* Define the following to use this test against your installed libpng, rather
|
||||
* than the one being built here:
|
||||
*/
|
||||
#ifdef PNG_FREESTANDING_TESTS
|
||||
# include <png.h>
|
||||
#else
|
||||
# include "../../png.h"
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
/* READ_INTERLACING was used instead of READ_DEINTERLACE. */
|
||||
# ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
# define PNG_READ_DEINTERLACE_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
static int
|
||||
read_png(FILE *fp)
|
||||
{
|
||||
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
|
||||
png_infop info_ptr = NULL;
|
||||
png_bytep row = NULL, display = NULL;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
|
||||
if (setjmp(png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
if (row != NULL) free(row);
|
||||
if (display != NULL) free(display);
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
png_error(png_ptr, "OOM allocating info structure");
|
||||
|
||||
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);
|
||||
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
{
|
||||
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
||||
row = malloc(rowbytes);
|
||||
display = malloc(rowbytes);
|
||||
|
||||
if (row == NULL || display == NULL)
|
||||
png_error(png_ptr, "OOM allocating row buffers");
|
||||
|
||||
{
|
||||
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
|
||||
# ifdef PNG_READ_DEINTERLACE_SUPPORTED
|
||||
int passes = png_set_interlace_handling(png_ptr);
|
||||
# else
|
||||
int passes = png_get_interlace_type(png_ptr, info_ptr) ==
|
||||
PNG_INTERLACE_ADAM7 ? PNG_INTERLACE_ADAM7_PASSES : 1;
|
||||
# endif
|
||||
int pass;
|
||||
|
||||
png_start_read_image(png_ptr);
|
||||
|
||||
for (pass = 0; pass < passes; ++pass)
|
||||
{
|
||||
png_uint_32 y = height;
|
||||
|
||||
# ifndef PNG_READ_DEINTERLACE_SUPPORTED
|
||||
if (passes == PNG_INTERLACE_ADAM7_PASSES)
|
||||
y = PNG_PASS_ROWS(y, pass);
|
||||
# endif
|
||||
|
||||
/* NOTE: this trashes the row each time; interlace handling won't
|
||||
* work, but this avoids memory thrashing for speed testing.
|
||||
*/
|
||||
while (y-- > 0)
|
||||
png_read_row(png_ptr, row, display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure to read to the end of the file: */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
free(row);
|
||||
free(display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Exit code 0 on success. */
|
||||
return !read_png(stdin);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
/* tarith.c
|
||||
*
|
||||
* Copyright (c) 2011,2012 John Cunningham Bowler
|
||||
* Copyright (c) 2011-2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -634,7 +634,7 @@ int validation_muldiv(int count, int argc, char **argv)
|
||||
{
|
||||
png_fixed_point result;
|
||||
/* NOTE: your mileage may vary, a type is required below that can
|
||||
* hold 64 bits or more, if floating point is used a 64 bit or
|
||||
* hold 64 bits or more, if floating point is used a 64-bit or
|
||||
* better mantissa is required.
|
||||
*/
|
||||
long long int fp, fpround;
|
||||
@@ -721,7 +721,7 @@ int validation_muldiv(int count, int argc, char **argv)
|
||||
}
|
||||
while (--count > 0);
|
||||
|
||||
printf("%d tests including %d overflows, %d passed, %d failed (%d 64 bit "
|
||||
printf("%d tests including %d overflows, %d passed, %d failed (%d 64-bit "
|
||||
"errors)\n", tested, overflow, passed, error, error64);
|
||||
return 0;
|
||||
}
|
||||
@@ -799,13 +799,13 @@ int validation_gamma(int argc, char **argv)
|
||||
if (i == 0 && png_log8bit(i) != 0xffffffff ||
|
||||
i != 0 && png_log8bit(i) != floor(correct+.5))
|
||||
{
|
||||
fprintf(stderr, "8 bit log error: %d: got %u, expected %f\n",
|
||||
fprintf(stderr, "8-bit log error: %d: got %u, expected %f\n",
|
||||
i, png_log8bit(i), correct);
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("maximum 8 bit log error = %f\n", maxerr);
|
||||
printf("maximum 8-bit log error = %f\n", maxerr);
|
||||
|
||||
maxerr = 0;
|
||||
for (i=0; i<65536; ++i)
|
||||
@@ -821,14 +821,14 @@ int validation_gamma(int argc, char **argv)
|
||||
{
|
||||
if (error > .68) /* By experiment error is less than .68 */
|
||||
{
|
||||
fprintf(stderr, "16 bit log error: %d: got %u, expected %f"
|
||||
fprintf(stderr, "16-bit log error: %d: got %u, expected %f"
|
||||
" error: %f\n", i, png_log16bit(i), correct, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("maximum 16 bit log error = %f\n", maxerr);
|
||||
printf("maximum 16-bit log error = %f\n", maxerr);
|
||||
|
||||
/* Now exponentiations. */
|
||||
maxerr = 0;
|
||||
@@ -841,13 +841,13 @@ int validation_gamma(int argc, char **argv)
|
||||
maxerr = fabs(error);
|
||||
if (fabs(error) > 1883) /* By experiment. */
|
||||
{
|
||||
fprintf(stderr, "32 bit exp error: %d: got %u, expected %f"
|
||||
fprintf(stderr, "32-bit exp error: %d: got %u, expected %f"
|
||||
" error: %f\n", i, png_exp(i), correct, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("maximum 32 bit exp error = %f\n", maxerr);
|
||||
printf("maximum 32-bit exp error = %f\n", maxerr);
|
||||
|
||||
maxerr = 0;
|
||||
for (i=0; i<=0xfffff; ++i)
|
||||
@@ -859,13 +859,13 @@ int validation_gamma(int argc, char **argv)
|
||||
maxerr = fabs(error);
|
||||
if (fabs(error) > .50002) /* By experiment */
|
||||
{
|
||||
fprintf(stderr, "8 bit exp error: %d: got %u, expected %f"
|
||||
fprintf(stderr, "8-bit exp error: %d: got %u, expected %f"
|
||||
" error: %f\n", i, png_exp8bit(i), correct, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("maximum 8 bit exp error = %f\n", maxerr);
|
||||
printf("maximum 8-bit exp error = %f\n", maxerr);
|
||||
|
||||
maxerr = 0;
|
||||
for (i=0; i<=0xfffff; ++i)
|
||||
@@ -877,13 +877,13 @@ int validation_gamma(int argc, char **argv)
|
||||
maxerr = fabs(error);
|
||||
if (fabs(error) > .524) /* By experiment */
|
||||
{
|
||||
fprintf(stderr, "16 bit exp error: %d: got %u, expected %f"
|
||||
fprintf(stderr, "16-bit exp error: %d: got %u, expected %f"
|
||||
" error: %f\n", i, png_exp16bit(i), correct, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("maximum 16 bit exp error = %f\n", maxerr);
|
||||
printf("maximum 16-bit exp error = %f\n", maxerr);
|
||||
} /* !onlygamma */
|
||||
|
||||
/* Test the overall gamma correction. */
|
||||
@@ -913,7 +913,7 @@ int validation_gamma(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("gamma %f: maximum 8 bit error %f\n", g, maxerr);
|
||||
printf("gamma %f: maximum 8-bit error %f\n", g, maxerr);
|
||||
|
||||
maxerr = 0;
|
||||
for (j=0; j<65536; ++j)
|
||||
@@ -932,7 +932,7 @@ int validation_gamma(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
printf("gamma %f: maximum 16 bit error %f\n", g, maxerr);
|
||||
printf("gamma %f: maximum 16-bit error %f\n", g, maxerr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run the simplified API tests
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngstest.sh ==============" >> pngtest-log.txt
|
||||
|
||||
echo "Running test-pngstest.sh"
|
||||
for image in ${srcdir}/contrib/pngsuite/*.png
|
||||
do
|
||||
for opts in ""
|
||||
do
|
||||
if ./pngstest --strict --log "$@" $opts $image >>pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngstest $opts $image"
|
||||
else
|
||||
echo " FAIL: pngstest $opts $image"
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run the unknown API tests
|
||||
err=0
|
||||
image="${srcdir}/pngtest.png"
|
||||
#
|
||||
# stream 4 is used for the output of the shell, pngtest-log.txt gets all the
|
||||
# normal program output.
|
||||
exec 4>&1 1>>pngtest-log.txt 2>&1
|
||||
|
||||
echo
|
||||
echo "============ test-pngunknown.sh =============="
|
||||
|
||||
echo "Running test-pngunknown.sh" >&4
|
||||
|
||||
for tests in \
|
||||
"discard default=discard"\
|
||||
"save default=save"\
|
||||
"if-safe default=if-safe"\
|
||||
"vpAg vpAg=if-safe"\
|
||||
"sTER sTER=if-safe"\
|
||||
"IDAT default=discard IDAT=save"\
|
||||
"sAPI bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save"
|
||||
do
|
||||
set $tests
|
||||
test="$1"
|
||||
shift
|
||||
|
||||
if ./pngunknown "$@" "$image" 4>&-
|
||||
then
|
||||
echo " PASS: test-pngunknown $test" >&4
|
||||
else
|
||||
echo " FAIL: test-pngunknown $test" >&4
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run a sequence of gamma tests quietly
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngvalid-full.sh ==============" >> pngtest-log.txt
|
||||
|
||||
echo "Running test-pngvalid-full.sh"
|
||||
for gamma in threshold transform sbit 16-to-8 background alpha-mode "transform --expand16" "background --expand16" "alpha-mode --expand16"
|
||||
do
|
||||
if ./pngvalid "$@" --gamma-$gamma >> pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngvalid" "$@" "--gamma-$gamma"
|
||||
else
|
||||
echo " FAIL: pngvalid" "$@" "--gamma-$gamma"
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Run a sequence of tests quietly, without the slow
|
||||
# gamma tests
|
||||
err=0
|
||||
|
||||
echo >> pngtest-log.txt
|
||||
echo "============ pngvalid-simple.sh ==============" >> pngtest-log.txt
|
||||
echo "Running test-pngvalid-simple.sh"
|
||||
# The options to test are:
|
||||
#
|
||||
# standard tests with and without progressive reading and interlace
|
||||
# size images with and without progressive reading
|
||||
# transform tests (standard, non-interlaced only)
|
||||
#
|
||||
for opts in "--standard" "--standard --progressive-read" \
|
||||
"--standard --interlace" "--standard --progressive-read --interlace" \
|
||||
"--size" "--size --progressive-read" \
|
||||
"--transform"
|
||||
do
|
||||
if ./pngvalid "$@" $opts >> pngtest-log.txt 2>&1
|
||||
then
|
||||
echo " PASS: pngvalid" "$@" $opts
|
||||
else
|
||||
echo " FAIL: pngvalid" "$@" $opts
|
||||
err=1
|
||||
fi
|
||||
done
|
||||
|
||||
exit $err
|
||||
@@ -1,8 +1,8 @@
|
||||
/* timepng.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#if (defined HAVE_CONFIG_H) && !(defined PNG_NO_CONFIG_H)
|
||||
#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
@@ -252,7 +252,7 @@ int main(int argc, char **argv)
|
||||
|
||||
while (fgets(filename, FILENAME_MAX+1, stdin))
|
||||
{
|
||||
int len = strlen(filename);
|
||||
size_t len = strlen(filename);
|
||||
|
||||
if (filename[len-1] == '\n')
|
||||
{
|
||||
|
||||
135
contrib/neon/arm_init.c
Normal file
135
contrib/neon/arm_init.c
Normal file
@@ -0,0 +1,135 @@
|
||||
|
||||
/* arm_init.c - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.16 [December 22, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
|
||||
* called.
|
||||
*/
|
||||
#define _POSIX_SOURCE 1
|
||||
|
||||
#include "../../pngpriv.h"
|
||||
#define PNG_SRC_FILE PNG_SRC_FILE_arm_arm_init
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */
|
||||
/* WARNING: it is strongly recommended that you do not build libpng with
|
||||
* run-time checks for CPU features if at all possible. In the case of the ARM
|
||||
* NEON instructions there is no processor-specific way of detecting the
|
||||
* presence of the required support, therefore run-time detection is extremely
|
||||
* OS specific.
|
||||
*
|
||||
* You may set the macro PNG_ARM_NEON_FILE to the file name of file containing
|
||||
* a fragment of C source code which defines the png_have_neon function. There
|
||||
* are a number of implementations in contrib/arm-neon, but the only one that
|
||||
* has partial support is contrib/arm-neon/linux.c - a generic Linux
|
||||
* implementation which reads /proc/cpufino.
|
||||
*/
|
||||
#ifndef PNG_ARM_NEON_FILE
|
||||
# ifdef __linux__
|
||||
# define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_ARM_NEON_FILE
|
||||
|
||||
#include <signal.h> /* for sig_atomic_t */
|
||||
static int png_have_neon(png_structp png_ptr);
|
||||
#include PNG_ARM_NEON_FILE
|
||||
|
||||
#else /* PNG_ARM_NEON_FILE */
|
||||
# error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
|
||||
#endif /* PNG_ARM_NEON_FILE */
|
||||
#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
|
||||
|
||||
#ifndef PNG_ALIGNED_MEMORY_SUPPORTED
|
||||
# error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED"
|
||||
#endif
|
||||
|
||||
void
|
||||
png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
|
||||
{
|
||||
/* The switch statement is compiled in for ARM_NEON_API, the call to
|
||||
* png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined
|
||||
* the check is only performed if the API has not set the NEON option on
|
||||
* or off explicitly. In this case the check controls what happens.
|
||||
*
|
||||
* If the CHECK is not compiled in and the option is UNSET the behavior prior
|
||||
* to 1.6.7 was to use the NEON code - this was a bug caused by having the
|
||||
* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
|
||||
* as documented in png.h
|
||||
*/
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
switch ((pp->options >> PNG_ARM_NEON) & 3)
|
||||
{
|
||||
case PNG_OPTION_UNSET:
|
||||
/* Allow the run-time check to execute if it has been enabled -
|
||||
* thus both API and CHECK can be turned on. If it isn't supported
|
||||
* this case will fall through to the 'default' below, which just
|
||||
* returns.
|
||||
*/
|
||||
#endif /* PNG_ARM_NEON_API_SUPPORTED */
|
||||
#ifdef PNG_ARM_NEON_CHECK_SUPPORTED
|
||||
{
|
||||
static volatile sig_atomic_t no_neon = -1; /* not checked */
|
||||
|
||||
if (no_neon < 0)
|
||||
no_neon = !png_have_neon(pp);
|
||||
|
||||
if (no_neon)
|
||||
return;
|
||||
}
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
break;
|
||||
#endif
|
||||
#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
|
||||
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
default: /* OFF or INVALID */
|
||||
return;
|
||||
|
||||
case PNG_OPTION_ON:
|
||||
/* Option turned on */
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* IMPORTANT: any new external functions used here must be declared using
|
||||
* PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
|
||||
* 'prefix' option to configure works:
|
||||
*
|
||||
* ./configure --with-libpng-prefix=foobar_
|
||||
*
|
||||
* Verify you have got this right by running the above command, doing a build
|
||||
* and examining pngprefix.h; it must contain a #define for every external
|
||||
* function you add. (Notice that this happens automatically for the
|
||||
* initialization function.)
|
||||
*/
|
||||
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
|
||||
|
||||
if (bpp == 3)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth3_neon;
|
||||
}
|
||||
|
||||
else if (bpp == 4)
|
||||
{
|
||||
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
|
||||
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
||||
png_read_filter_row_paeth4_neon;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* READ */
|
||||
10
contrib/neon/extensions.ac
Normal file
10
contrib/neon/extensions.ac
Normal file
@@ -0,0 +1,10 @@
|
||||
# To just this extension either copy the 'sinclude' line and the setting of
|
||||
# libpng_automake_extensions into contrib/extensions.am or link/copy the whole
|
||||
# file there. Do the same with the associated file extensions.am
|
||||
#
|
||||
# Include the ARM NEON extension:
|
||||
sinclude([contrib/neon/neon.ac])
|
||||
#
|
||||
# If any of the extensions require automake support (this is likely) automake
|
||||
# must include the file contrib/extensions.am
|
||||
libpng_automake_extensions="yes"
|
||||
5
contrib/neon/extensions.am
Normal file
5
contrib/neon/extensions.am
Normal file
@@ -0,0 +1,5 @@
|
||||
# To just this extension either copy the 'include' line into
|
||||
# contrib/extensions.am or link/copy the whole file there. Do the same with the
|
||||
# associated file extensions.ac
|
||||
# Include the ARM NEON extension:
|
||||
include %reldir%/neon/neon.am
|
||||
@@ -1,18 +1,36 @@
|
||||
|
||||
/* filter_neon.S - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by Mans Rullgard, 2011.
|
||||
* Last changed in libpng 1.6.16 [(PENDING RELEASE)]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
/* This is required to get the symbol renames, which are #defines, and the
|
||||
* definitions (or not) of PNG_ARM_NEON_OPT and PNG_ARM_NEON_IMPLEMENTATION.
|
||||
*/
|
||||
#define PNG_VERSION_INFO_ONLY
|
||||
#include "../../pngpriv.h"
|
||||
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits /* mark stack as non-executable */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
|
||||
/* Assembler NEON support - only works for 32-bit ARM (i.e. it does not work for
|
||||
* ARM64). The code in arm/filter_neon_intrinsics.c supports ARM64, however it
|
||||
* only works if -mfpu=neon is specified on the GCC command line. See pngpriv.h
|
||||
* for the logic which sets PNG_USE_ARM_NEON_ASM:
|
||||
*/
|
||||
#if PNG_ARM_NEON_IMPLEMENTATION == 2 /* hand-coded assembler */
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
|
||||
#ifdef __ELF__
|
||||
# define ELF
|
||||
#else
|
||||
@@ -29,6 +47,13 @@ ELF .size \name, . - \name
|
||||
.purgem endfunc
|
||||
.endm
|
||||
.text
|
||||
|
||||
/* Explicitly specifying alignment here because some versions of
|
||||
* GAS don't align code correctly. This is harmless in correctly
|
||||
* written versions of GAS.
|
||||
*/
|
||||
.align 2
|
||||
|
||||
.if \export
|
||||
.global \name
|
||||
.endif
|
||||
@@ -223,3 +248,6 @@ func png_read_filter_row_paeth3_neon, export=1
|
||||
|
||||
pop {r4,pc}
|
||||
endfunc
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* PNG_ARM_NEON_IMPLEMENTATION == 2 (assembler) */
|
||||
#endif /* READ */
|
||||
384
contrib/neon/filter_neon_intrinsics.c
Normal file
384
contrib/neon/filter_neon_intrinsics.c
Normal file
@@ -0,0 +1,384 @@
|
||||
|
||||
/* filter_neon_intrinsics.c - NEON optimised filter functions
|
||||
*
|
||||
* Copyright (c) 2014 Glenn Randers-Pehrson
|
||||
* Written by James Yu <james.yu at linaro.org>, October 2013.
|
||||
* Based on filter_neon.S, written by Mans Rullgard, 2011.
|
||||
*
|
||||
* Last changed in libpng 1.6.16 [December 22, 2014]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#include "../../pngpriv.h"
|
||||
#define PNG_SRC_FILE PNG_SRC_FILE_arm_filter_neon_intrinsics
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
|
||||
/* This code requires -mfpu=neon on the command line: */
|
||||
#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */
|
||||
|
||||
#include <arm_neon.h>
|
||||
|
||||
/* libpng row pointers are not necessarily aligned to any particular boundary,
|
||||
* however this code will only work with appropriate alignment. arm/arm_init.c
|
||||
* checks for this (and will not compile unless it is done). This code uses
|
||||
* variants of png_aligncast to avoid compiler warnings.
|
||||
*/
|
||||
#define png_ptr(type,pointer) png_aligncast(type *,pointer)
|
||||
#define png_ptrc(type,pointer) png_aligncastconst(const type *,pointer)
|
||||
|
||||
/* The following relies on a variable 'temp_pointer' being declared with type
|
||||
* 'type'. This is written this way just to hide the GCC strict aliasing
|
||||
* warning; note that the code is safe because there never is an alias between
|
||||
* the input and output pointers.
|
||||
*/
|
||||
#define png_ldr(type,pointer)\
|
||||
(temp_pointer = png_ptr(type,pointer), *temp_pointer)
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
|
||||
void
|
||||
png_read_filter_row_up_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint8x16_t qrp, qpp;
|
||||
|
||||
qrp = vld1q_u8(rp);
|
||||
qpp = vld1q_u8(pp);
|
||||
qrp = vaddq_u8(qrp, qpp);
|
||||
vst1q_u8(rp, qrp);
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_sub3_neon(png_alloc_size_t rowbytes, unsigned int bpp, png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
|
||||
uint8x16_t vtmp = vld1q_u8(rp);
|
||||
uint8x8x2_t *vrpt = png_ptr(uint8x8x2_t, &vtmp);
|
||||
uint8x8x2_t vrp = *vrpt;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop;)
|
||||
{
|
||||
uint8x8_t vtmp1, vtmp2;
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);
|
||||
vtmp2 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vdest.val[1] = vadd_u8(vdest.val[0], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
vdest.val[2] = vadd_u8(vdest.val[1], vtmp2);
|
||||
vdest.val[3] = vadd_u8(vdest.val[2], vtmp1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t, &vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
PNG_UNUSED(prev_row)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_sub4_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
uint8x8x4_t *vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
uint8x8x4_t vrp = *vrpt;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[0], vrp.val[1]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[1], vrp.val[2]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[2], vrp.val[3]);
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
PNG_UNUSED(prev_row)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_avg3_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_const_bytep pp = prev_row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
|
||||
uint8x16_t vtmp;
|
||||
uint8x8x2_t *vrpt;
|
||||
uint8x8x2_t vrp;
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
vtmp = vld1q_u8(rp);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
for (; rp < rp_stop; pp += 12)
|
||||
{
|
||||
uint8x8_t vtmp1, vtmp2, vtmp3;
|
||||
|
||||
uint8x8x2_t *vppt;
|
||||
uint8x8x2_t vpp;
|
||||
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp = vld1q_u8(pp);
|
||||
vppt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);
|
||||
vtmp3 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vdest.val[1] = vhadd_u8(vdest.val[0], vtmp2);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 6);
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vdest.val[2] = vhadd_u8(vdest.val[1], vtmp2);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vtmp3);
|
||||
|
||||
vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);
|
||||
|
||||
vdest.val[3] = vhadd_u8(vdest.val[2], vtmp2);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_avg4_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp;
|
||||
uint8x8x4_t *vrpt, *vppt;
|
||||
uint8x8x4_t vrp, vpp;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
vtmp = vld4_u32(png_ptrc(uint32_t,pp));
|
||||
vppt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
vdest.val[1] = vhadd_u8(vdest.val[0], vpp.val[1]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);
|
||||
vdest.val[2] = vhadd_u8(vdest.val[1], vpp.val[2]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);
|
||||
vdest.val[3] = vhadd_u8(vdest.val[2], vpp.val[3]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);
|
||||
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
}
|
||||
|
||||
static uint8x8_t
|
||||
paeth(uint8x8_t a, uint8x8_t b, uint8x8_t c)
|
||||
{
|
||||
uint8x8_t d, e;
|
||||
uint16x8_t p1, pa, pb, pc;
|
||||
|
||||
p1 = vaddl_u8(a, b); /* a + b */
|
||||
pc = vaddl_u8(c, c); /* c * 2 */
|
||||
pa = vabdl_u8(b, c); /* pa */
|
||||
pb = vabdl_u8(a, c); /* pb */
|
||||
pc = vabdq_u16(p1, pc); /* pc */
|
||||
|
||||
p1 = vcleq_u16(pa, pb); /* pa <= pb */
|
||||
pa = vcleq_u16(pa, pc); /* pa <= pc */
|
||||
pb = vcleq_u16(pb, pc); /* pb <= pc */
|
||||
|
||||
p1 = vandq_u16(p1, pa); /* pa <= pb && pa <= pc */
|
||||
|
||||
d = vmovn_u16(pb);
|
||||
e = vmovn_u16(p1);
|
||||
|
||||
d = vbsl_u8(d, b, c);
|
||||
e = vbsl_u8(e, a, d);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_paeth3_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_const_bytep pp = prev_row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
|
||||
uint8x16_t vtmp;
|
||||
uint8x8x2_t *vrpt;
|
||||
uint8x8x2_t vrp;
|
||||
uint8x8_t vlast = vdup_n_u8(0);
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
vtmp = vld1q_u8(rp);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
for (; rp < rp_stop; pp += 12)
|
||||
{
|
||||
uint8x8x2_t *vppt;
|
||||
uint8x8x2_t vpp;
|
||||
uint8x8_t vtmp1, vtmp2, vtmp3;
|
||||
uint32x2_t *temp_pointer;
|
||||
|
||||
vtmp = vld1q_u8(pp);
|
||||
vppt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);
|
||||
vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);
|
||||
vdest.val[1] = paeth(vdest.val[0], vtmp2, vpp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 6);
|
||||
vtmp3 = vext_u8(vpp.val[0], vpp.val[1], 6);
|
||||
vdest.val[2] = paeth(vdest.val[1], vtmp3, vtmp2);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vtmp1);
|
||||
|
||||
vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);
|
||||
vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);
|
||||
|
||||
vtmp = vld1q_u8(rp + 12);
|
||||
vrpt = png_ptr(uint8x8x2_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
|
||||
vdest.val[3] = paeth(vdest.val[2], vtmp2, vtmp3);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);
|
||||
|
||||
vlast = vtmp2;
|
||||
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);
|
||||
rp += 3;
|
||||
vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);
|
||||
rp += 3;
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
}
|
||||
|
||||
void
|
||||
png_read_filter_row_paeth4_neon(png_alloc_size_t rowbytes, unsigned int bpp,
|
||||
png_bytep row, png_const_bytep prev_row)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_bytep rp_stop = row + rowbytes;
|
||||
png_const_bytep pp = prev_row;
|
||||
|
||||
uint8x8_t vlast = vdup_n_u8(0);
|
||||
uint8x8x4_t vdest;
|
||||
vdest.val[3] = vdup_n_u8(0);
|
||||
|
||||
for (; rp < rp_stop; rp += 16, pp += 16)
|
||||
{
|
||||
uint32x2x4_t vtmp;
|
||||
uint8x8x4_t *vrpt, *vppt;
|
||||
uint8x8x4_t vrp, vpp;
|
||||
uint32x2x4_t *temp_pointer;
|
||||
|
||||
vtmp = vld4_u32(png_ptr(uint32_t,rp));
|
||||
vrpt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vrp = *vrpt;
|
||||
vtmp = vld4_u32(png_ptrc(uint32_t,pp));
|
||||
vppt = png_ptr(uint8x8x4_t,&vtmp);
|
||||
vpp = *vppt;
|
||||
|
||||
vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);
|
||||
vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);
|
||||
vdest.val[1] = paeth(vdest.val[0], vpp.val[1], vpp.val[0]);
|
||||
vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);
|
||||
vdest.val[2] = paeth(vdest.val[1], vpp.val[2], vpp.val[1]);
|
||||
vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);
|
||||
vdest.val[3] = paeth(vdest.val[2], vpp.val[3], vpp.val[2]);
|
||||
vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);
|
||||
|
||||
vlast = vpp.val[3];
|
||||
|
||||
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
|
||||
}
|
||||
|
||||
PNG_UNUSED(bpp)
|
||||
}
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
#endif /* PNG_ARM_NEON_IMPLEMENTATION == 1 (intrinsics) */
|
||||
#endif /* READ */
|
||||
47
contrib/neon/neon.ac
Normal file
47
contrib/neon/neon.ac
Normal file
@@ -0,0 +1,47 @@
|
||||
# LIBPNG EXTENSION: NEON
|
||||
#
|
||||
# ARM NEON (SIMD) support.
|
||||
#
|
||||
# This file contains configure.ac additions to libpng configure to enable
|
||||
# building of the ARM NEON filter optimizations.
|
||||
#
|
||||
AC_ARG_ENABLE([arm-neon],
|
||||
AS_HELP_STRING([[[--enable-arm-neon]]],
|
||||
[Enable ARM NEON optimizations: =no/off, check, api, yes/on:]
|
||||
[no/off: disable the optimizations; check: use internal checking code]
|
||||
[(deprecated and poorly supported); api: disable by default, enable by]
|
||||
[a call to png_set_option; yes/on: turn on unconditionally.]
|
||||
[If not specified: determined by the compiler.]),
|
||||
[case "$enableval" in
|
||||
no|off)
|
||||
# disable the default enabling on __ARM_NEON__ systems:
|
||||
AC_DEFINE([PNG_ARM_NEON_OPT], [0],
|
||||
[Disable ARM Neon optimizations])
|
||||
# Prevent inclusion of the assembler files below:
|
||||
enable_arm_neon=no;;
|
||||
check)
|
||||
AC_DEFINE([PNG_ARM_NEON_CHECK_SUPPORTED], [],
|
||||
[Check for ARM Neon support at run-time]);;
|
||||
api)
|
||||
AC_DEFINE([PNG_ARM_NEON_API_SUPPORTED], [],
|
||||
[Turn on ARM Neon optimizations at run-time]);;
|
||||
yes|on)
|
||||
AC_DEFINE([PNG_ARM_NEON_OPT], [2],
|
||||
[Enable ARM Neon optimizations])
|
||||
AC_MSG_WARN([--enable-arm-neon: please specify 'check' or 'api', if]
|
||||
[you want the optimizations unconditionally pass -mfpu=neon]
|
||||
[to the compiler.]);;
|
||||
*)
|
||||
AC_MSG_ERROR([--enable-arm-neon=${enable_arm_neon}: invalid value])
|
||||
esac])
|
||||
|
||||
# Add ARM specific files to all builds where the host_cpu is arm ('arm*') or
|
||||
# where ARM optimizations were explicitly requested (this allows a fallback if a
|
||||
# future host CPU does not match 'arm*')
|
||||
|
||||
AM_CONDITIONAL([PNG_ARM_NEON],
|
||||
[test "$enable_arm_neon" != 'no' &&
|
||||
case "$host_cpu" in
|
||||
arm*|aarch64*) :;;
|
||||
*) test "$enable_arm_neon" != '';;
|
||||
esac])
|
||||
27
contrib/neon/neon.am
Normal file
27
contrib/neon/neon.am
Normal file
@@ -0,0 +1,27 @@
|
||||
# contrib/neon/neon.am
|
||||
#
|
||||
# This is an automake fragment included by the top-level Makefile.am if
|
||||
# contrib/neon/neon.ac is included in configure
|
||||
#
|
||||
# It builds the source files in this directory into ARM hardware support for
|
||||
# libpng.
|
||||
#
|
||||
if PNG_ARM_NEON
|
||||
libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += %D%/arm_init.c\
|
||||
%D%/filter_neon.S %D%/filter_neon_intrinsics.c
|
||||
|
||||
DFA_EXTENSION += ${srcdir}/%D%/neon.dfa
|
||||
|
||||
# This causes pngpriv.h to include the named header. It is VERY important to
|
||||
# understand that this MUST be defined and the header MUST define internal
|
||||
# 'extern' functions with PNG_INTERNAL_FUNCTION. This allows vendors to use
|
||||
# static library builds of libpng without clashing with the installed system
|
||||
# libpng; see the libpng-prefix option in configure.ac The value of this
|
||||
# #define is included in pnglibconf.h
|
||||
#
|
||||
# NOTE: you must include the double quotes in the value and you must therefore
|
||||
# support the whole thing with single quotes. If you need to use <> for a
|
||||
# header be aware that if you miss out the single quotes you will create a
|
||||
# random file.
|
||||
AM_CPPFLAGS += -DPNG_EXTENSION_HEADER='"%D%/neon.h"'
|
||||
endif
|
||||
41
contrib/neon/neon.dfa
Normal file
41
contrib/neon/neon.dfa
Normal file
@@ -0,0 +1,41 @@
|
||||
# contrib/arm/neon.dfa
|
||||
#
|
||||
# This is a dfa fragment that is added to DFA_HARDWARE in Makefile.am and
|
||||
# consequently is inserted after scripts/pnglibconf.dfa to define extra,
|
||||
# hardware, options.
|
||||
#
|
||||
# The following are required in any fragment to record the copyright holder of
|
||||
# the *changes* and the appropriate email for bug reports. Note that the
|
||||
# copyright here is just for the specific configuration; additional files may
|
||||
# have additional and/or different copyrights.
|
||||
#
|
||||
# Later settings (e.g. in user.dfa) will override these settings.
|
||||
#
|
||||
setting USER_PRIVATEBUILD default "John Bowler"
|
||||
setting USER_BUG_REPORTS default "jbowler@acm.org"
|
||||
#
|
||||
# These options are specific to the ARM NEON hardware optimizations. At present
|
||||
# these optimizations depend on GCC specific pre-processing of an assembler (.S)
|
||||
# file so they probably won't work with other compilers.
|
||||
#
|
||||
# ARM_NEON_OPT: unset: check at compile time (__ARM_NEON__ must be defined by
|
||||
# the compiler, typically as a result of specifying
|
||||
# CC="gcc -mfpu=neon".)
|
||||
# 0: disable (even if the CPU has a NEON FPU.)
|
||||
# 1: check at run time (via ARM_NEON_{API,CHECK})
|
||||
# 2: switch on unconditionally (inadvisable - instead pass
|
||||
# -mfpu=neon to GCC in CC)
|
||||
# When building libpng avoid using any setting other than '0'; '1' is
|
||||
# set automatically when either 'API' or 'CHECK' are configured in,
|
||||
# '2' should not be necessary as -mfpu=neon will achieve the same
|
||||
# effect as well as applying NEON optimizations to the rest of the
|
||||
# libpng code.
|
||||
# NOTE: any setting other than '0' requires ALIGNED_MEMORY
|
||||
# ARM_NEON_API: (PNG_ARM_NEON == 1) allow the optimization to be switched on
|
||||
# with png_set_option
|
||||
# ARM_NEON_CHECK: (PNG_ARM_NEON == 1) compile a run-time check to see if Neon
|
||||
# extensions are supported. This is poorly supported and
|
||||
# deprecated - use the png_set_option API.
|
||||
setting ARM_NEON_OPT
|
||||
option ARM_NEON_API disabled enables SET_OPTION sets ARM_NEON_OPT 1
|
||||
option ARM_NEON_CHECK disabled sets ARM_NEON_OPT 1
|
||||
124
contrib/neon/neon.h
Normal file
124
contrib/neon/neon.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/* Compile time options.
|
||||
* =====================
|
||||
* In a multi-arch build the compiler may compile the code several times for the
|
||||
* same object module, producing different binaries for different architectures.
|
||||
* When this happens configure-time setting of the target host options cannot be
|
||||
* done. An example is iOS vs Android compilation of ARM NEON support.
|
||||
*
|
||||
* NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because
|
||||
* this is not possible with certain compilers (Oracle SUN OS CC), as a result
|
||||
* it is necessary to ensure that all extern functions that *might* be used
|
||||
* regardless of $(CFLAGS) get declared in this file. The test on __ARM_NEON
|
||||
* below is one example of this behavior because it is controlled by the
|
||||
* presence or not of -mfpu=neon on the GCC command line, it is possible to do
|
||||
* this in $(CC), e.g. "CC=gcc -mfpu=neon", but people who build libpng rarely
|
||||
* do this.
|
||||
*/
|
||||
#ifndef PNG_ARM_NEON_OPT
|
||||
/* ARM NEON optimizations are being controlled by the compiler settings,
|
||||
* typically the target FPU. If the FPU supports NEON instructions then the
|
||||
* compiler will define __ARM_NEON and we can rely unconditionally on NEON
|
||||
* instructions not crashing, otherwise we must disable use of NEON
|
||||
* instructions.
|
||||
*
|
||||
* NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they
|
||||
* can only be turned on automatically if that is supported too. If
|
||||
* PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail
|
||||
* to compile with an appropriate #error if ALIGNED_MEMORY has been turned
|
||||
* off.
|
||||
*
|
||||
* Note that older versions of GCC defined __ARM_NEON__; this is no longer
|
||||
* supported. Also 32-bit ARM versions of GCC required the NEON FPU mode to
|
||||
* be turned on explicitly on the command line. If this is not done (on
|
||||
* 32-bit ARM) NEON code will not be included.
|
||||
*
|
||||
* To disable ARM_NEON optimizations entirely, and skip compiling the
|
||||
* associated assembler code, pass --enable-arm-neon=no to configure
|
||||
* or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS.
|
||||
*/
|
||||
# if defined(__ARM_NEON) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)
|
||||
# define PNG_ARM_NEON_OPT 2
|
||||
# else
|
||||
# define PNG_ARM_NEON_OPT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
/* NEON optimizations are to be at least considered by libpng, so enable the
|
||||
* callbacks to do this.
|
||||
*/
|
||||
# define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon
|
||||
|
||||
/* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used
|
||||
* if possible - if __ARM_NEON is set and the compiler version is not known
|
||||
* to be broken. This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can
|
||||
* be:
|
||||
*
|
||||
* 1 The intrinsics code (the default with __ARM_NEON)
|
||||
* 2 The hand coded assembler (the default without __ARM_NEON)
|
||||
*
|
||||
* It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however
|
||||
* this is *NOT* supported and may cease to work even after a minor revision
|
||||
* to libpng. It *is* valid to do this for testing purposes, e.g. speed
|
||||
* testing or a new compiler, but the results should be communicated to the
|
||||
* libpng implementation list for incorporation in the next minor release.
|
||||
*/
|
||||
# ifndef PNG_ARM_NEON_IMPLEMENTATION
|
||||
# ifdef __ARM_NEON
|
||||
# if defined(__clang__)
|
||||
/* At present it is unknown by the libpng developers which versions
|
||||
* of clang support the intrinsics, however some or perhaps all
|
||||
* versions do not work with the assembler so this may be
|
||||
* irrelevant, so just use the default (do nothing here.)
|
||||
*/
|
||||
# elif defined(__GNUC__)
|
||||
/* GCC 4.5.4 NEON support is known to be broken. 4.6.3 is known to
|
||||
* work, so if this *is* GCC, or G++, look for a version >4.5
|
||||
*/
|
||||
# if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 2
|
||||
# endif /* no GNUC support */
|
||||
# endif /* __GNUC__ */
|
||||
# else /* !defined __ARM_NEON */
|
||||
/* The 'intrinsics' code simply won't compile without compiler support
|
||||
* and that support switches on __ARM_NEON, so use the assembler:
|
||||
*/
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 2
|
||||
# endif /* __ARM_NEON */
|
||||
# endif /* !defined PNG_ARM_NEON_IMPLEMENTATION */
|
||||
|
||||
# ifndef PNG_ARM_NEON_IMPLEMENTATION
|
||||
/* Use the intrinsics code by default. */
|
||||
# define PNG_ARM_NEON_IMPLEMENTATION 1
|
||||
# endif
|
||||
#endif /* PNG_ARM_NEON_OPT > 0 */
|
||||
|
||||
#ifdef PNG_SET_OPTION_SUPPORTED
|
||||
#ifdef PNG_ARM_NEON_API_SUPPORTED
|
||||
# define PNG_ARM_NEON 0 /* HARDWARE: ARM Neon SIMD instructions supported */
|
||||
#endif
|
||||
#endif /* SET_OPTION */
|
||||
|
||||
#if PNG_ARM_NEON_OPT > 0
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,
|
||||
(png_alloc_size_t row_bytes, unsigned int bpp, png_bytep row,
|
||||
png_const_bytep prev_row),PNG_EMPTY);
|
||||
#endif
|
||||
@@ -14,7 +14,8 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
COPY=cp
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP -I. -O1
|
||||
CPPFLAGS=-I. -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -81,7 +82,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
|
||||
# note: dependencies do not work on implicit rule lines
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -95,16 +96,16 @@ pngm2pnm$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) pngm2pnm$(O)
|
||||
$(RM) pngm2pnm$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/decoder/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -36,5 +36,6 @@ option FLOATING_ARITHMETIC off
|
||||
option SETJMP on
|
||||
option STDIO on
|
||||
option READ_EXPAND on
|
||||
option READ_DEINTERLACE on
|
||||
option READ_STRIP_16_TO_8 on
|
||||
option USER_LIMITS on
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minrdpngconf.h: headers to make a minimal png-read-only library
|
||||
*
|
||||
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,7 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_RELEASE_BUILD 1
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINRDPNGCONF_H */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
This demonstrates the use of PNG_USER_CONFIG and pngusr.h
|
||||
|
||||
The makefile builds a minimal write-only decoder with embedded libpng
|
||||
The makefile builds a minimal write-only encoder with embedded libpng
|
||||
and zlib.
|
||||
|
||||
Specify the location of the zlib source (1.2.1 or later) as ZLIBSRC
|
||||
|
||||
@@ -14,7 +14,8 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
COPY=cp
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DZ_SOLO -DNO_GZIP -I. -O1
|
||||
CPPFLAGS=-I. -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -80,7 +81,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -94,16 +95,16 @@ pnm2pngm$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) pnm2pngm$(O)
|
||||
$(RM) pnm2pngm$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/encoder/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -14,6 +14,10 @@ everything = off
|
||||
|
||||
option WRITE on
|
||||
|
||||
# These 2 options are required if you need to read PBM (P1 or P4) files.
|
||||
option WRITE_INVERT on
|
||||
option WRITE_PACK on
|
||||
|
||||
# You must choose fixed or floating point arithmetic:
|
||||
# option FLOATING_POINT on
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minwrpngconf.h: headers to make a minimal png-write-only library
|
||||
*
|
||||
* Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,7 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_RELEASE_BUILD 1
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINWRPNGCONF_H */
|
||||
|
||||
@@ -30,7 +30,8 @@ XLIB = -L/usr/X11R6/lib -lX11
|
||||
#LIBS = $(XLIB)
|
||||
LIBS = $(XLIB) -lm #platforms that need libm
|
||||
|
||||
CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP -I. $(XINC) -O1
|
||||
CPPFLAGS=-I. $(XINC) -DPNG_USER_CONFIG -DNO_GZCOMPRESS -DZ_SOLO -DNO_GZIP
|
||||
CFLAGS=-O1 -Wall
|
||||
|
||||
C=.c
|
||||
O=.o
|
||||
@@ -96,7 +97,7 @@ OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
|
||||
# implicit make rules -------------------------------------------------------
|
||||
|
||||
.c$(O):
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
$(CC) -c $(CPPFLAGS) $(CFLAGS) $<
|
||||
|
||||
# dependencies
|
||||
|
||||
@@ -110,16 +111,16 @@ rpng2-x$(E): $(OBJS)
|
||||
# The CPP_FLAGS setting causes pngusr.h to be included in
|
||||
# both the build of pnglibconf.h and, subsequently, when
|
||||
# building libpng itself.
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
|
||||
$(PNGSRC)/scripts/pnglibconf.dfa \
|
||||
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
|
||||
$(RM) pnglibconf.h pnglibconf.dfn
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
|
||||
DFA_XTRA="pngusr.dfa" $@
|
||||
|
||||
clean:
|
||||
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
|
||||
$(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
|
||||
srcdir=$(PNGSRC) clean
|
||||
$(RM) rpng2-x$(O)
|
||||
$(RM) rpng2-x$(E)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pngminim/preader/pngusr.dfa
|
||||
#
|
||||
# Copyright (c) 2010-2011 Glenn Randers-Pehrson
|
||||
# Copyright (c) 2010-2013 Glenn Randers-Pehrson
|
||||
#
|
||||
# This code is released under the libpng license.
|
||||
# For conditions of distribution and use, see the disclaimer
|
||||
@@ -36,5 +36,6 @@ option STDIO on
|
||||
option READ_bKGD on
|
||||
option READ_GAMMA on
|
||||
option READ_EXPAND on
|
||||
option READ_DEINTERLACE on
|
||||
option READ_STRIP_16_TO_8 on
|
||||
option READ_GRAY_TO_RGB on
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* minrdpngconf.h: headers to make a minimal png-read-only library
|
||||
*
|
||||
* Copyright (c) 2009, 2010-2011 Glenn Randers-Pehrson
|
||||
* Copyright (c) 2009, 2010-2013 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@@ -18,7 +18,7 @@
|
||||
* affect the API (so are not recorded in pnglibconf.h)
|
||||
*/
|
||||
|
||||
#define PNG_NO_WARNINGS
|
||||
#define PNG_RELEASE_BUILD 1
|
||||
#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
|
||||
|
||||
#endif /* MINPRDPNGCONF_H */
|
||||
|
||||
@@ -8,9 +8,9 @@ LD=$(CC)
|
||||
RM=rm -f
|
||||
|
||||
#PNGPATH = /usr/local
|
||||
#PNGINC = -I$(PNGPATH)/include/libpng16
|
||||
#PNGLIB = -L$(PNGPATH)/lib -lpng16
|
||||
#PNGLIBS = $(PNGPATH)/lib/libpng16.a
|
||||
#PNGINC = -I$(PNGPATH)/include/libpng17
|
||||
#PNGLIB = -L$(PNGPATH)/lib -lpng17
|
||||
#PNGLIBS = $(PNGPATH)/lib/libpng17.a
|
||||
PNGINC = -I../..
|
||||
PNGLIB = -L../.. -lpng
|
||||
PNGLIBS = ../../libpng.a
|
||||
|
||||
0
contrib/pngminus/png2pnm.bat
Normal file → Executable file
0
contrib/pngminus/png2pnm.bat
Normal file → Executable file
0
contrib/pngminus/png2pnm.sh
Normal file → Executable file
0
contrib/pngminus/png2pnm.sh
Normal file → Executable file
0
contrib/pngminus/pngminus.bat
Normal file → Executable file
0
contrib/pngminus/pngminus.bat
Normal file → Executable file
0
contrib/pngminus/pngminus.sh
Normal file → Executable file
0
contrib/pngminus/pngminus.sh
Normal file → Executable file
0
contrib/pngminus/pnm2png.bat
Normal file → Executable file
0
contrib/pngminus/pnm2png.bat
Normal file → Executable file
@@ -3,6 +3,7 @@
|
||||
* copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
|
||||
*
|
||||
* version 1.0 - 1999.10.15 - First version.
|
||||
* version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and
|
||||
* its documentation for any purpose and without fee is hereby granted,
|
||||
@@ -50,7 +51,8 @@
|
||||
|
||||
int main (int argc, char *argv[]);
|
||||
void usage ();
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha);
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
BOOL alpha);
|
||||
void get_token(FILE *pnm_file, char *token);
|
||||
png_uint_32 get_data (FILE *pnm_file, int depth);
|
||||
png_uint_32 get_value (FILE *pnm_file, int depth);
|
||||
@@ -176,7 +178,8 @@ void usage()
|
||||
fprintf (stderr, " or: ... | pnm2png [options]\n");
|
||||
fprintf (stderr, "Options:\n");
|
||||
fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
|
||||
fprintf (stderr, " -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr,
|
||||
" -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
|
||||
fprintf (stderr, " -h | -? print this help-information\n");
|
||||
}
|
||||
|
||||
@@ -184,32 +187,36 @@ void usage()
|
||||
* pnm2png
|
||||
*/
|
||||
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha)
|
||||
BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
BOOL alpha)
|
||||
{
|
||||
png_struct *png_ptr = NULL;
|
||||
png_info *info_ptr = NULL;
|
||||
png_byte *png_pixels = NULL;
|
||||
png_byte **row_pointers = NULL;
|
||||
png_byte *pix_ptr = NULL;
|
||||
png_uint_32 row_bytes;
|
||||
volatile png_uint_32 row_bytes;
|
||||
|
||||
char type_token[16];
|
||||
char width_token[16];
|
||||
char height_token[16];
|
||||
char maxval_token[16];
|
||||
int color_type;
|
||||
unsigned long ul_width, ul_alpha_width;
|
||||
unsigned long ul_height, ul_alpha_height;
|
||||
unsigned long ul_maxval;
|
||||
png_uint_32 width, alpha_width;
|
||||
png_uint_32 height, alpha_height;
|
||||
volatile int color_type=1;
|
||||
unsigned long ul_width=0, ul_alpha_width=0;
|
||||
unsigned long ul_height=0, ul_alpha_height=0;
|
||||
unsigned long ul_maxval=0;
|
||||
volatile png_uint_32 width=0, height=0;
|
||||
volatile png_uint_32 alpha_width=0, alpha_height=0;
|
||||
png_uint_32 maxval;
|
||||
int bit_depth = 0;
|
||||
int channels;
|
||||
volatile int bit_depth = 0;
|
||||
int channels=0;
|
||||
int alpha_depth = 0;
|
||||
int alpha_present;
|
||||
int alpha_present=0;
|
||||
int row, col;
|
||||
BOOL raw, alpha_raw = FALSE;
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
BOOL packed_bitmap = FALSE;
|
||||
#endif
|
||||
png_uint_32 tmp16;
|
||||
int i;
|
||||
|
||||
@@ -222,9 +229,21 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
}
|
||||
else if ((type_token[1] == '1') || (type_token[1] == '4'))
|
||||
{
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
raw = (type_token[1] == '4');
|
||||
color_type = PNG_COLOR_TYPE_GRAY;
|
||||
get_token(pnm_file, width_token);
|
||||
sscanf (width_token, "%lu", &ul_width);
|
||||
width = (png_uint_32) ul_width;
|
||||
get_token(pnm_file, height_token);
|
||||
sscanf (height_token, "%lu", &ul_height);
|
||||
height = (png_uint_32) ul_height;
|
||||
bit_depth = 1;
|
||||
packed_bitmap = TRUE;
|
||||
#else
|
||||
fprintf (stderr, "PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and \n");
|
||||
fprintf (stderr, "PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\n");
|
||||
#endif
|
||||
}
|
||||
else if ((type_token[1] == '2') || (type_token[1] == '5'))
|
||||
{
|
||||
@@ -338,76 +357,108 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
channels = 3;
|
||||
else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
channels = 4;
|
||||
#if 0
|
||||
else
|
||||
channels = 0; /* should not happen */
|
||||
channels = 0; /* cannot happen */
|
||||
#endif
|
||||
|
||||
alpha_present = (channels - 1) % 2;
|
||||
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap)
|
||||
/* row data is as many bytes as can fit width x channels x bit_depth */
|
||||
row_bytes = (width * channels * bit_depth + 7) / 8;
|
||||
else
|
||||
#endif
|
||||
/* row_bytes is the width x number of channels x (bit-depth / 8) */
|
||||
row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
|
||||
|
||||
if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||
if ((png_pixels = (png_byte *)
|
||||
malloc (row_bytes * height * sizeof (png_byte))) == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* read data from PNM file */
|
||||
pix_ptr = png_pixels;
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
for (row = 0; row < (int) height; row++)
|
||||
{
|
||||
for (col = 0; col < width; col++)
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap) {
|
||||
for (i = 0; i < (int) row_bytes; i++)
|
||||
/* png supports this format natively so no conversion is needed */
|
||||
*pix_ptr++ = get_data (pnm_file, 8);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
for (col = 0; col < (int) width; col++)
|
||||
{
|
||||
if (raw)
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
else
|
||||
if (bit_depth <= 8)
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
for (i = 0; i < (channels - alpha_present); i++)
|
||||
{
|
||||
if (raw)
|
||||
*pix_ptr++ = get_data (pnm_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
if (bit_depth <= 8)
|
||||
*pix_ptr++ = get_value (pnm_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (pnm_file, bit_depth);
|
||||
*pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
pix_ptr++;
|
||||
*pix_ptr = (png_byte) (tmp16 & 0xFF);
|
||||
pix_ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
else
|
||||
if (alpha_depth <= 8)
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
if (alpha) /* read alpha-channel from pgm file */
|
||||
{
|
||||
if (alpha_raw)
|
||||
*pix_ptr++ = get_data (alpha_file, alpha_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
} /* if alpha */
|
||||
|
||||
if (alpha_depth <= 8)
|
||||
*pix_ptr++ = get_value (alpha_file, bit_depth);
|
||||
else
|
||||
{
|
||||
tmp16 = get_value (alpha_file, bit_depth);
|
||||
*pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
|
||||
*pix_ptr++ = (png_byte) (tmp16 & 0xFF);
|
||||
}
|
||||
} /* if alpha */
|
||||
} /* if packed_bitmap */
|
||||
} /* end for col */
|
||||
} /* end for row */
|
||||
|
||||
/* prepare the standard PNG structures */
|
||||
png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
png_ptr = png_create_write_struct (png_get_libpng_ver(NULL), NULL, NULL,
|
||||
NULL);
|
||||
if (!png_ptr)
|
||||
{
|
||||
free (png_pixels);
|
||||
png_pixels = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (!info_ptr)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
free (png_pixels);
|
||||
png_pixels = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (packed_bitmap == TRUE)
|
||||
{
|
||||
png_set_packing (png_ptr);
|
||||
png_set_invert_mono (png_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* setjmp() must be called in every function that calls a PNG-reading libpng function */
|
||||
if (setjmp (png_jmpbuf(png_ptr)))
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
free (png_pixels);
|
||||
png_pixels = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -425,25 +476,28 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
/* if needed we will allocate memory for an new array of row-pointers */
|
||||
if (row_pointers == (unsigned char**) NULL)
|
||||
{
|
||||
if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
|
||||
if ((row_pointers = (png_byte **)
|
||||
malloc (height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
free (png_pixels);
|
||||
png_pixels = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (i = 0; i < (height); i++)
|
||||
for (i = 0; i < (int) height; i++)
|
||||
row_pointers[i] = png_pixels + i * row_bytes;
|
||||
|
||||
/* write out the entire image data in one call */
|
||||
png_write_image (png_ptr, row_pointers);
|
||||
|
||||
/* write the additional chuncks to the PNG file (not really needed) */
|
||||
/* write the additional chunks to the PNG file (not really needed) */
|
||||
png_write_end (png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
|
||||
if (row_pointers != (unsigned char**) NULL)
|
||||
free (row_pointers);
|
||||
@@ -460,19 +514,32 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
|
||||
void get_token(FILE *pnm_file, char *token)
|
||||
{
|
||||
int i = 0;
|
||||
int ret;
|
||||
|
||||
/* remove white-space */
|
||||
/* remove white-space and comment lines */
|
||||
do
|
||||
{
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
ret = fgetc(pnm_file);
|
||||
if (ret == '#') {
|
||||
/* the rest of this line is a comment */
|
||||
do
|
||||
{
|
||||
ret = fgetc(pnm_file);
|
||||
}
|
||||
while ((ret != '\n') && (ret != '\r') && (ret != EOF));
|
||||
}
|
||||
if (ret == EOF) break;
|
||||
token[i] = (unsigned char) ret;
|
||||
}
|
||||
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
|
||||
|
||||
/* read string */
|
||||
do
|
||||
{
|
||||
ret = fgetc(pnm_file);
|
||||
if (ret == EOF) break;
|
||||
i++;
|
||||
token[i] = (unsigned char) fgetc (pnm_file);
|
||||
token[i] = (unsigned char) ret;
|
||||
}
|
||||
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
|
||||
|
||||
|
||||
0
contrib/pngminus/pnm2png.sh
Normal file → Executable file
0
contrib/pngminus/pnm2png.sh
Normal file → Executable file
@@ -1,8 +1,8 @@
|
||||
/* checksum-icc.c
|
||||
*
|
||||
* Copyright (c) 2012 John Cunningham Bowler
|
||||
* Copyright (c) 2013 John Cunningham Bowler
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
|
||||
437
contrib/tools/chunkhash.c
Normal file
437
contrib/tools/chunkhash.c
Normal file
@@ -0,0 +1,437 @@
|
||||
/* chunkhash.c -- build a perfect hash code for the chunk names on stdin.
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2014.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
*
|
||||
* Feed this program all the known chunks that libpng must recognize. It will
|
||||
* generate an appropriate hash key for the macro in pngpriv.h To generate the
|
||||
* list of chunks currently defined in png.h do this:
|
||||
*
|
||||
* sed -n -e 's/^#define png_\(....\) PNG_U32.*$/\1/p' png.h
|
||||
*
|
||||
* An alternative to using this program is to pipe the output of the above
|
||||
* through gperf, however the code generated by perf is somewhat more verbose
|
||||
* and it doesn't generate as good a result (however it's a heck of a lot faster
|
||||
* than this program!)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <png.h> /* for the libpng types for this platform */
|
||||
|
||||
/* The machine generated file is checked in, so this works and it obtains the
|
||||
* definition of the PNG_CHUNK_HASH macro. To change this definition only ever
|
||||
* alter the strings below!
|
||||
*/
|
||||
#include "chunkhash.h"
|
||||
|
||||
/* The best_ variables are local variables defined in the functions below. When
|
||||
* used in libpng code, however, they are just constants.
|
||||
*/
|
||||
#define PNG_CHUNK_HASH_MASK best_mask
|
||||
#define PNG_CHUNK_HASH_C0 best_c[0]
|
||||
#define PNG_CHUNK_HASH_C1 best_c[1]
|
||||
#define PNG_CHUNK_HASH_C2 best_c[2]
|
||||
#define PNG_CHUNK_HASH_C3 best_c[3]
|
||||
|
||||
/* These strings contain the C text to copy into the new version of
|
||||
* contrib/tools/chunkhash.c
|
||||
*/
|
||||
static const char *strings[] = {
|
||||
"/* chunkhash.h -- a perfect hash code for the chunk names in png.h",
|
||||
" *",
|
||||
" * Last changed in libpng 1.7.0 [(PENDING RELEASE)]",
|
||||
" *",
|
||||
" * THIS IS A MACHINE GENERATED FILE. See contrib/tools/chunkhash.c for",
|
||||
" * copyright and other information.",
|
||||
" *",
|
||||
" * USAGE: To include the PNG_CHUNK_HASH macro and associated definitions:",
|
||||
" *",
|
||||
" * #define PNG_CHUNKHASH_DEFS",
|
||||
" * #include \"contrib/tools/chunkhash.h\"",
|
||||
" *",
|
||||
" * To define the png_chunk_hash array used by the macro:",
|
||||
" *",
|
||||
" * #define PNG_CHUNKHASH_CODE",
|
||||
" * #include \"contrib/tools/chunkhash.h\"",
|
||||
" *",
|
||||
" * One or both of the defines must be given except when building chunkhash",
|
||||
" * itself.",
|
||||
" */",
|
||||
"#ifdef PNG_CHUNKHASH_DEFS",
|
||||
"#ifndef PNG_CHUNKHASH_H",
|
||||
"#define PNG_CHUNKHASH_H",
|
||||
"/* A perfect hash code - returns a value 0..(PNG_KNOWN_CHUNK_COUNT-1) and is",
|
||||
" * generated by the ridiculously simple program in contrib/tools/chunkhash.c",
|
||||
" *",
|
||||
" * The hash code used here multiplies each byte by a different constant to",
|
||||
" * return a single number:",
|
||||
" *",
|
||||
" * b0 * c[0] + b1 * [c1] + b2 * c[2] + b3 * c[3]",
|
||||
" *",
|
||||
" * The values of the constants are found by search using the a table of",
|
||||
" * primes, including 0, and may be (in fact are at present) 0 for some of the",
|
||||
" * bytes, the compiler is expected to optimize multiply by zero, or one!",
|
||||
" *",
|
||||
" * The lookup table reduces the sparse result of the hash calculation to the",
|
||||
" * correct index values. The chunks are indexed in the string order of the",
|
||||
" * png_uint_32 chunk names.",
|
||||
" */",
|
||||
0, /* HEADER definitions go here */
|
||||
"",
|
||||
"extern const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1];",
|
||||
"#endif /* !PNG_CHUNKHASH_H */",
|
||||
"#endif /* PNG_CHUNKHASH_DEFS */",
|
||||
"",
|
||||
"#ifndef PNG_CHUNK_HASH",
|
||||
"#define PNG_CHUNK_HASH(chunk) (png_chunk_hash[PNG_CHUNK_HASH_MASK & (\\",
|
||||
" ((chunk) >> 24) * PNG_CHUNK_HASH_C0 +\\",
|
||||
" ((chunk) >> 16) * PNG_CHUNK_HASH_C1 +\\",
|
||||
" ((chunk) >> 8) * PNG_CHUNK_HASH_C2 +\\",
|
||||
" ((chunk) ) * PNG_CHUNK_HASH_C3)])",
|
||||
"#endif",
|
||||
"",
|
||||
"#ifdef PNG_CHUNKHASH_CODE",
|
||||
"#ifndef PNG_CHUNKHASH_C",
|
||||
"#define PNG_CHUNKHASH_C",
|
||||
"const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1] = {",
|
||||
0, /* png.c definitions go here */
|
||||
"};",
|
||||
"#endif /* !PNG_CHUNKHASH_C */",
|
||||
"#endif /* PNG_CHUNKHASH_CODE */",
|
||||
0 /* end of file */
|
||||
};
|
||||
|
||||
#define CHUNK_COUNT_MAX 32
|
||||
/* If necessary this is easy to increase; just don't use a png_uint_32
|
||||
* bitmask below, however it doesn't seem likely that the limit will be hit
|
||||
* any time soon.
|
||||
*/
|
||||
|
||||
static const png_byte
|
||||
chunk_hash[256] =
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
|
||||
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
|
||||
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
|
||||
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
|
||||
98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113,
|
||||
114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128,
|
||||
129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
|
||||
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158,
|
||||
159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173,
|
||||
174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188,
|
||||
189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
|
||||
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218,
|
||||
219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
|
||||
234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248,
|
||||
249, 250, 251, 252, 253, 254, 255
|
||||
};
|
||||
|
||||
static void
|
||||
error(const char *string)
|
||||
{
|
||||
fprintf(stderr, "chunkhash: %s\n", string);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Return a hash code for the given chunk; this is the same as the pngpriv.h
|
||||
* macro, but parameterized. The names of the parameters have to be chosen to
|
||||
* match the above #defines.
|
||||
*/
|
||||
static png_uint_32
|
||||
test_hash(png_uint_32 chunk, const unsigned int *best_c, png_uint_32 best_mask)
|
||||
{
|
||||
# define png_chunk_hash chunk_hash /* prevents lookup */
|
||||
return PNG_CHUNK_HASH(chunk);
|
||||
# undef png_chunk_hash
|
||||
}
|
||||
|
||||
static void
|
||||
print_chunks(const png_uint_32 *chunks, unsigned int nchunks, png_uint_32 first,
|
||||
png_uint_32 last, const unsigned int *best_c, png_uint_32 best_mask,
|
||||
const png_byte *lut)
|
||||
{
|
||||
/* 'last' is the last code to print plus 1, this is used to detect duplicates
|
||||
* (which should not happen - if there are any it's an internal error!)
|
||||
*/
|
||||
if (nchunks > 0)
|
||||
{
|
||||
/* Recursive algorithm; find the hash code of the next chunk, then print
|
||||
* all remaining chunks with codes in the range first..code (including
|
||||
* duplicates) and after print all remaining chunks with codes in the
|
||||
* range (code+1)..last
|
||||
*/
|
||||
const png_uint_32 chunk = *chunks++;
|
||||
# define png_chunk_hash lut
|
||||
const png_uint_32 code = PNG_CHUNK_HASH(chunk);
|
||||
# undef png_chunk_hash
|
||||
|
||||
--nchunks;
|
||||
|
||||
/* The code might be out of the print range */
|
||||
if (code >= first && code <= last)
|
||||
{
|
||||
if (code >= first) /* not time yet */
|
||||
print_chunks(chunks, nchunks, first, code, best_c, best_mask, lut);
|
||||
|
||||
printf("#define PNG_CHUNK_%c%c%c%c_TAG %lu%s\n", (char)(chunk>>24),
|
||||
(char)(chunk>>16), (char)(chunk>>8), (char)chunk,
|
||||
(unsigned long)code, code == last ? " /* DUPLICATE */" : "");
|
||||
|
||||
if (code < last) /* still some to go */
|
||||
print_chunks(chunks, nchunks, code+1, last, best_c, best_mask, lut);
|
||||
}
|
||||
|
||||
else
|
||||
print_chunks(chunks, nchunks, first, last, best_c, best_mask, lut);
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int primes[] =
|
||||
{
|
||||
0, 1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
|
||||
71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
|
||||
151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
|
||||
233, 239, 241, 251
|
||||
};
|
||||
|
||||
#define NPRIMES ((sizeof primes)/(sizeof primes[0]))
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
/* Stdin should just contain chunk names, one per line */
|
||||
png_uint_32 best_mask;
|
||||
unsigned int best_c[4];
|
||||
png_uint_32 chunks[CHUNK_COUNT_MAX];
|
||||
png_byte known_chunk_count;
|
||||
|
||||
/* Not required; stop GCC whining: */
|
||||
memset(best_c, 0xab, sizeof best_c);
|
||||
best_mask = 0x12345678;
|
||||
|
||||
{
|
||||
png_uint_32 this_chunk = 0;
|
||||
png_byte n_chunks = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int ch = getchar();
|
||||
|
||||
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
|
||||
{
|
||||
if (this_chunk > 0xffffffU)
|
||||
error("chunk name too long");
|
||||
|
||||
this_chunk = (this_chunk << 8) + (unsigned)ch;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (this_chunk > 0)
|
||||
{
|
||||
if (this_chunk <= 0xffffffU)
|
||||
error("chunk name too short");
|
||||
|
||||
if (n_chunks >= CHUNK_COUNT_MAX)
|
||||
error("too many chunks (check CHUNK_COUNT_MAX)");
|
||||
|
||||
chunks[n_chunks++] = this_chunk;
|
||||
this_chunk = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* 22 is the number of chunks currently defined (excluding fRAc), at any
|
||||
* time it should also be in PNG_KNOWN_CHUNK_COUNT, but this run of
|
||||
* chunkhash may be trying to add a chunk so allow bigger numbers.
|
||||
*/
|
||||
# ifdef PNG_KNOWN_CHUNK_COUNT
|
||||
# define CHUNK_COUNT_MIN PNG_KNOWN_CHUNK_COUNT
|
||||
# else
|
||||
# define CHUNK_COUNT_MIN 26
|
||||
# endif
|
||||
if (n_chunks < CHUNK_COUNT_MIN)
|
||||
error("too few chunks (expecting at least 26)");
|
||||
|
||||
known_chunk_count = n_chunks;
|
||||
}
|
||||
|
||||
/* Exhaustive search of the hash parameters - in fact this isn't very slow at
|
||||
* all.
|
||||
*/
|
||||
{
|
||||
unsigned int i1, c_zero = 0, c_one = 0;
|
||||
|
||||
for (i1=0; i1<NPRIMES; ++i1)
|
||||
{
|
||||
unsigned int i2;
|
||||
unsigned int c[4];
|
||||
|
||||
fprintf(stderr, "TEST: %u\n", primes[i1]);
|
||||
c[0] = primes[i1];
|
||||
|
||||
for (i2=0; i2<NPRIMES; ++i2)
|
||||
{
|
||||
unsigned int i3;
|
||||
|
||||
c[1] = primes[i2];
|
||||
|
||||
for (i3=0; i3<NPRIMES; ++i3)
|
||||
{
|
||||
unsigned int i4;
|
||||
|
||||
c[2] = primes[i3];
|
||||
|
||||
for (i4=0; i4<NPRIMES; ++i4)
|
||||
{
|
||||
unsigned int i;
|
||||
png_uint_32 hash_mask = 0xffU;
|
||||
png_uint_32 hashes[CHUNK_COUNT_MAX];
|
||||
|
||||
c[3] = primes[i4];
|
||||
|
||||
while (hash_mask > 0xfU)
|
||||
{
|
||||
for (i=0; i<known_chunk_count; ++i)
|
||||
{
|
||||
unsigned int j;
|
||||
png_uint_32 hash = test_hash(chunks[i], c, hash_mask);
|
||||
|
||||
for (j=0; j<i; ++j) if (hashes[j] == hash) goto next_i4;
|
||||
|
||||
hashes[i] = hash;
|
||||
}
|
||||
|
||||
hash_mask >>= 1;
|
||||
}
|
||||
|
||||
next_i4:
|
||||
if (hash_mask < 0xffU)
|
||||
{
|
||||
/* This worked */
|
||||
unsigned int best, c0 = 0, c1 = 0;
|
||||
|
||||
hash_mask <<= 1;
|
||||
hash_mask += 1;
|
||||
|
||||
for (i=0; i<4; ++i)
|
||||
{
|
||||
if (c[i] == 0)
|
||||
++c0;
|
||||
|
||||
else if (c[i] == 1)
|
||||
++c1;
|
||||
}
|
||||
|
||||
if (hash_mask == best_mask)
|
||||
best = (c0 > c_zero) || (c0 == c_zero && c1 > c_one);
|
||||
|
||||
else
|
||||
best = (hash_mask < best_mask);
|
||||
|
||||
if (best)
|
||||
{
|
||||
fprintf(stderr, "{%u,%u,%u,%u} & 0x%lx\n",
|
||||
c[0], c[1], c[2], c[3],
|
||||
(unsigned long)hash_mask);
|
||||
|
||||
c_zero = c0;
|
||||
c_one = c1;
|
||||
best_mask = hash_mask;
|
||||
memcpy(best_c, c, sizeof best_c);
|
||||
}
|
||||
}
|
||||
} /* i4 */
|
||||
} /* i3 */
|
||||
} /* i2 */
|
||||
} /* i1 */
|
||||
}
|
||||
|
||||
/* Calculate the LUT (png_chunk_hash) */
|
||||
{
|
||||
png_byte b;
|
||||
png_byte lut[256];
|
||||
|
||||
/* A failure returns PNG_KNOWN_CHUNK_COUNT: */
|
||||
memset(lut, known_chunk_count, sizeof lut);
|
||||
|
||||
for (b=0; b<known_chunk_count; ++b)
|
||||
lut[test_hash(chunks[b], best_c, best_mask)] = b;
|
||||
|
||||
/* Validate the pngpriv.h hash function. */
|
||||
# define png_chunk_hash lut
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<known_chunk_count; ++i)
|
||||
{
|
||||
png_uint_32 chunk = chunks[i];
|
||||
|
||||
if (PNG_CHUNK_HASH(chunk) != i)
|
||||
error("internal error: hash didn't work!");
|
||||
}
|
||||
}
|
||||
# undef lut
|
||||
|
||||
/* Print all the results, first the stuff for pngpriv.h */
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
while (strings[i] != 0)
|
||||
puts(strings[i++]);
|
||||
|
||||
printf("#define PNG_CHUNK_HASH_MASK 0x%lxU\n",
|
||||
(unsigned long)best_mask);
|
||||
printf("#define PNG_CHUNK_HASH_C0 %u\n", best_c[0]);
|
||||
printf("#define PNG_CHUNK_HASH_C1 %u\n", best_c[1]);
|
||||
printf("#define PNG_CHUNK_HASH_C2 %u\n", best_c[2]);
|
||||
printf("#define PNG_CHUNK_HASH_C3 %u\n", best_c[3]);
|
||||
|
||||
/* Print the hash codes of all the chunks */
|
||||
putchar('\n');
|
||||
print_chunks(chunks, known_chunk_count, 0, 0xffffffff, best_c,
|
||||
best_mask, lut);
|
||||
putchar('\n');
|
||||
printf("#define PNG_KNOWN_CHUNK_COUNT %u\n", known_chunk_count);
|
||||
|
||||
while (strings[++i] != 0)
|
||||
puts(strings[i]);
|
||||
|
||||
/* Now print the LUT */
|
||||
fputs(" ", stdout);
|
||||
{
|
||||
unsigned int j;
|
||||
|
||||
for (j=0; j<=best_mask; ++j)
|
||||
{
|
||||
printf("%d", lut[j]);
|
||||
|
||||
if ((j % 16) == 15 && j < best_mask)
|
||||
printf(",\n ");
|
||||
|
||||
else if (j < best_mask)
|
||||
printf(", ");
|
||||
|
||||
else
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* And the trailing text */
|
||||
while (strings[++i] != 0)
|
||||
puts(strings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
97
contrib/tools/chunkhash.h
Normal file
97
contrib/tools/chunkhash.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/* chunkhash.h -- a perfect hash code for the chunk names in png.h
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
*
|
||||
* THIS IS A MACHINE GENERATED FILE. See contrib/tools/chunkhash.c for
|
||||
* copyright and other information.
|
||||
*
|
||||
* USAGE: To include the PNG_CHUNK_HASH macro and associated definitions:
|
||||
*
|
||||
* #define PNG_CHUNKHASH_DEFS
|
||||
* #include "contrib/tools/chunkhash.h"
|
||||
*
|
||||
* To define the png_chunk_hash array used by the macro:
|
||||
*
|
||||
* #define PNG_CHUNKHASH_CODE
|
||||
* #include "contrib/tools/chunkhash.h"
|
||||
*
|
||||
* One or both of the defines must be given except when building chunkhash
|
||||
* itself.
|
||||
*/
|
||||
#ifdef PNG_CHUNKHASH_DEFS
|
||||
#ifndef PNG_CHUNKHASH_H
|
||||
#define PNG_CHUNKHASH_H
|
||||
/* A perfect hash code - returns a value 0..(PNG_KNOWN_CHUNK_COUNT-1) and is
|
||||
* generated by the ridiculously simple program in contrib/tools/chunkhash.c
|
||||
*
|
||||
* The hash code used here multiplies each byte by a different constant to
|
||||
* return a single number:
|
||||
*
|
||||
* b0 * c[0] + b1 * [c1] + b2 * c[2] + b3 * c[3]
|
||||
*
|
||||
* The values of the constants are found by search using the a table of
|
||||
* primes, including 0, and may be (in fact are at present) 0 for some of the
|
||||
* bytes, the compiler is expected to optimize multiply by zero, or one!
|
||||
*
|
||||
* The lookup table reduces the sparse result of the hash calculation to the
|
||||
* correct index values. The chunks are indexed in the string order of the
|
||||
* png_uint_32 chunk names.
|
||||
*/
|
||||
#define PNG_CHUNK_HASH_MASK 0x3fU
|
||||
#define PNG_CHUNK_HASH_C0 103
|
||||
#define PNG_CHUNK_HASH_C1 1
|
||||
#define PNG_CHUNK_HASH_C2 0
|
||||
#define PNG_CHUNK_HASH_C3 1
|
||||
|
||||
#define PNG_CHUNK_IDAT_TAG 0
|
||||
#define PNG_CHUNK_IEND_TAG 1
|
||||
#define PNG_CHUNK_IHDR_TAG 2
|
||||
#define PNG_CHUNK_PLTE_TAG 3
|
||||
#define PNG_CHUNK_bKGD_TAG 4
|
||||
#define PNG_CHUNK_cHRM_TAG 5
|
||||
#define PNG_CHUNK_fRAc_TAG 6
|
||||
#define PNG_CHUNK_gAMA_TAG 7
|
||||
#define PNG_CHUNK_gIFg_TAG 8
|
||||
#define PNG_CHUNK_gIFt_TAG 9
|
||||
#define PNG_CHUNK_gIFx_TAG 10
|
||||
#define PNG_CHUNK_hIST_TAG 11
|
||||
#define PNG_CHUNK_iCCP_TAG 12
|
||||
#define PNG_CHUNK_iTXt_TAG 13
|
||||
#define PNG_CHUNK_oFFs_TAG 14
|
||||
#define PNG_CHUNK_pCAL_TAG 15
|
||||
#define PNG_CHUNK_pHYs_TAG 16
|
||||
#define PNG_CHUNK_sBIT_TAG 17
|
||||
#define PNG_CHUNK_sCAL_TAG 18
|
||||
#define PNG_CHUNK_sPLT_TAG 19
|
||||
#define PNG_CHUNK_sRGB_TAG 20
|
||||
#define PNG_CHUNK_sTER_TAG 21
|
||||
#define PNG_CHUNK_tEXt_TAG 22
|
||||
#define PNG_CHUNK_tIME_TAG 23
|
||||
#define PNG_CHUNK_tRNS_TAG 24
|
||||
#define PNG_CHUNK_zTXt_TAG 25
|
||||
|
||||
#define PNG_KNOWN_CHUNK_COUNT 26
|
||||
|
||||
extern const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1];
|
||||
#endif /* !PNG_CHUNKHASH_H */
|
||||
#endif /* PNG_CHUNKHASH_DEFS */
|
||||
|
||||
#ifndef PNG_CHUNK_HASH
|
||||
#define PNG_CHUNK_HASH(chunk) (png_chunk_hash[PNG_CHUNK_HASH_MASK & (\
|
||||
((chunk) >> 24) * PNG_CHUNK_HASH_C0 +\
|
||||
((chunk) >> 16) * PNG_CHUNK_HASH_C1 +\
|
||||
((chunk) >> 8) * PNG_CHUNK_HASH_C2 +\
|
||||
((chunk) ) * PNG_CHUNK_HASH_C3)])
|
||||
#endif
|
||||
|
||||
#ifdef PNG_CHUNKHASH_CODE
|
||||
#ifndef PNG_CHUNKHASH_C
|
||||
#define PNG_CHUNKHASH_C
|
||||
const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1] = {
|
||||
26, 3, 26, 26, 26, 26, 26, 13, 26, 26, 26, 16, 26, 26, 26, 26,
|
||||
26, 24, 12, 26, 18, 26, 26, 26, 26, 20, 26, 17, 26, 26, 25, 15,
|
||||
26, 8, 14, 26, 26, 22, 26, 26, 1, 19, 5, 21, 26, 26, 9, 26,
|
||||
26, 26, 10, 7, 26, 11, 26, 0, 26, 2, 23, 26, 26, 4, 26, 6
|
||||
};
|
||||
#endif /* !PNG_CHUNKHASH_C */
|
||||
#endif /* PNG_CHUNKHASH_CODE */
|
||||
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* convert.c
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
|
||||
208
contrib/tools/dynamic-range.c
Normal file
208
contrib/tools/dynamic-range.c
Normal file
@@ -0,0 +1,208 @@
|
||||
/* dynamic-range.c
|
||||
*
|
||||
* Last changed in libpng 1.7.0
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2015
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
*
|
||||
* Find the dynamic range of a given gamma encoding given a (linear) precision
|
||||
* and a maximum number of encoded values.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
double range(unsigned int steps, double factor, double gamma)
|
||||
{
|
||||
return pow((steps * (pow(factor, 1/gamma) - 1)), gamma);
|
||||
}
|
||||
|
||||
double max_range_gamma(unsigned int steps, double factor, double *max_range,
|
||||
double glo, double rlo, double gmid, double rmid, double ghi, double rhi)
|
||||
{
|
||||
/* Given three values which contain a peak value (so rmid > rlo and rmid >
|
||||
* rhi) find the peak by repeated division of the range. The algorithm is to
|
||||
* find the range for two gamma values mid-way between the two pairs
|
||||
* (glo,gmid), (ghi,gmid) then find the max; this gives us a new glo/ghi
|
||||
* which must be half the distance apart of the previous pair.
|
||||
*/
|
||||
double gammas[5];
|
||||
double ranges[5];
|
||||
|
||||
gammas[0] = glo; ranges[0] = rlo;
|
||||
gammas[2] = gmid; ranges[2] = rmid;
|
||||
gammas[4] = ghi; ranges[4] = rhi;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i, m;
|
||||
|
||||
ranges[1] = range(steps, factor, gammas[1] = (gammas[0]+gammas[2])/2);
|
||||
ranges[3] = range(steps, factor, gammas[3] = (gammas[2]+gammas[4])/2);
|
||||
|
||||
for (m=1, i=2; i<4; ++i)
|
||||
if (ranges[i] >= ranges[m])
|
||||
m = i;
|
||||
|
||||
assert(gammas[0] < gammas[m] && gammas[m] < gammas[4]);
|
||||
assert(ranges[0] < ranges[m] && ranges[m] > ranges[4]);
|
||||
|
||||
gammas[0] = gammas[m-1]; ranges[0] = ranges[m-1];
|
||||
gammas[4] = gammas[m+1]; ranges[4] = ranges[m+1];
|
||||
gammas[2] = gammas[m]; ranges[2] = ranges[m];
|
||||
|
||||
if (((gammas[4] - gammas[0])/gammas[2]-1) < 3*DBL_EPSILON ||
|
||||
((ranges[2] - ranges[0])/ranges[2]-1) < 6*DBL_EPSILON)
|
||||
{
|
||||
*max_range = ranges[2];
|
||||
return gammas[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double best_gamma(unsigned int values, double precision, double *best_range)
|
||||
{
|
||||
/* The 'guess' gamma value is determined by the following formula, which is
|
||||
* itself derived from linear regression using values returned by this
|
||||
* program:
|
||||
*/
|
||||
double gtry = values * precision / 2.736;
|
||||
double rtry;
|
||||
|
||||
/* 'values' needs to be the number of steps after the first, we have to
|
||||
* reserve the first value, 0, for 0, so subtract 2 from values. precision
|
||||
* must be adjusted to the step factor.
|
||||
*/
|
||||
values -= 2U;
|
||||
precision += 1;
|
||||
rtry = range(values, precision, gtry);
|
||||
|
||||
/* Now find two values either side of gtry with a lower range. */
|
||||
{
|
||||
double glo, ghi, rlo, rhi, gbest, rbest;
|
||||
|
||||
glo = gtry;
|
||||
do
|
||||
{
|
||||
glo *= 0.9;
|
||||
rlo = range(values, precision, glo);
|
||||
}
|
||||
while (rlo >= rtry);
|
||||
|
||||
ghi = gtry;
|
||||
do
|
||||
{
|
||||
ghi *= 1.1;
|
||||
rhi = range(values, precision, ghi);
|
||||
}
|
||||
while (rhi >= rtry);
|
||||
|
||||
gbest = max_range_gamma(values, precision, &rbest,
|
||||
glo, rlo, gtry, rtry, ghi, rhi);
|
||||
|
||||
*best_range = rbest / precision;
|
||||
return gbest;
|
||||
}
|
||||
}
|
||||
|
||||
double linear_regression(double precision, double *bp)
|
||||
{
|
||||
unsigned int values, count = 0;
|
||||
double g_sum = 0, g2_sum = 0, v_sum = 0, v2_sum = 0, gv_sum = 0;
|
||||
|
||||
/* Perform simple linear regression to get:
|
||||
*
|
||||
* gamma = a + b.values
|
||||
*/
|
||||
for (values = 128; values < 65536; ++values, ++count)
|
||||
{
|
||||
double range;
|
||||
double gamma = best_gamma(values, precision, &range);
|
||||
|
||||
g_sum += gamma;
|
||||
g2_sum += gamma * gamma;
|
||||
v_sum += values;
|
||||
v2_sum += values * (double)values;
|
||||
gv_sum += gamma * values;
|
||||
/* printf("%u %g %g\n", values, gamma, range); */
|
||||
}
|
||||
|
||||
g_sum /= count;
|
||||
g2_sum /= count;
|
||||
v_sum /= count;
|
||||
v2_sum /= count;
|
||||
gv_sum /= count;
|
||||
|
||||
{
|
||||
double b = (gv_sum - g_sum * v_sum) / (v2_sum - v_sum * v_sum);
|
||||
*bp = b;
|
||||
return g_sum - b * v_sum;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
double precision = argc == 2 ? atof(argv[1]) : 0;
|
||||
|
||||
/* Perform a second linear regression here on b:
|
||||
*
|
||||
* b = bA + bB * precision
|
||||
*/
|
||||
if (precision == 0)
|
||||
{
|
||||
double b_sum = 0, b2_sum = 0, p_sum = 0, p2_sum = 0, bp_sum = 0,
|
||||
a_sum = 0, count = 0;
|
||||
|
||||
for (precision = .001; precision <= 0.01; precision += .001, count += 1)
|
||||
{
|
||||
double b;
|
||||
double a = linear_regression(precision, &b);
|
||||
|
||||
b_sum += b;
|
||||
b2_sum += b * b;
|
||||
p_sum += precision;
|
||||
p2_sum += precision * precision;
|
||||
bp_sum += b * precision;
|
||||
a_sum += a;
|
||||
}
|
||||
|
||||
b_sum /= count;
|
||||
b2_sum /= count;
|
||||
p_sum /= count;
|
||||
p2_sum /= count;
|
||||
bp_sum /= count;
|
||||
a_sum /= count;
|
||||
|
||||
{
|
||||
double bB = (bp_sum - b_sum * p_sum) / (p2_sum - p_sum * p_sum);
|
||||
double bA = b_sum - bB * p_sum;
|
||||
|
||||
printf("a = %g, b = %g + precision/%g\n", a_sum, bA, 1/bB);
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
unsigned int bits;
|
||||
double b;
|
||||
double a = linear_regression(precision, &b);
|
||||
printf("precision %g: gamma = %g + values*%g\n", precision, a, b);
|
||||
|
||||
/* For information, given a precision: */
|
||||
for (bits=7U; bits <= 16U; ++bits)
|
||||
{
|
||||
unsigned int values = 1U<<bits;
|
||||
double gamma = values*precision/2.736;
|
||||
double r = range(values-2U, 1+precision, gamma);
|
||||
|
||||
printf("bits: %u, gamma: %g, range: 1:%g\n", bits, gamma, r);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
867
contrib/tools/genpng.c
Normal file
867
contrib/tools/genpng.c
Normal file
@@ -0,0 +1,867 @@
|
||||
/*- genpng
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2015.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
*
|
||||
* Generate a PNG with an alpha channel, correctly.
|
||||
*
|
||||
* This is a test case generator; the resultant PNG files are only of interest
|
||||
* to those of us who care about whether the edges of circles are green, red,
|
||||
* or yellow.
|
||||
*
|
||||
* The program generates an RGB+Alpha PNG of a given size containing the given
|
||||
* shapes on a transparent background:
|
||||
*
|
||||
* genpng width height { shape }
|
||||
* shape ::= color width shape x1 y1 x2 y2
|
||||
*
|
||||
* 'color' is:
|
||||
*
|
||||
* black white red green yellow blue brown purple pink orange gray cyan
|
||||
*
|
||||
* The point is to have colors that are linguistically meaningful plus that old
|
||||
* bugbear of the department store dress murders, Cyan, the only color we argue
|
||||
* about.
|
||||
*
|
||||
* 'shape' is:
|
||||
*
|
||||
* circle: an ellipse
|
||||
* square: a rectangle
|
||||
* line: a straight line
|
||||
*
|
||||
* Each shape is followed by four numbers, these are two points in the output
|
||||
* coordinate space (as real numbers) which describe the circle, square, or
|
||||
* line. The shape is filled if it is preceded by 'filled' (not valid for
|
||||
* 'line') or is drawn with a line, in which case the width of the line must
|
||||
* precede the shape.
|
||||
*
|
||||
* The whole set of information can be repeated as many times as desired:
|
||||
*
|
||||
* shape ::= color width shape x1 y1 x2 y2
|
||||
*
|
||||
* color ::= black|white|red|green|yellow|blue
|
||||
* color ::= brown|purple|pink|orange|gray|cyan
|
||||
* width ::= filled
|
||||
* width ::= <number>
|
||||
* shape ::= circle|square|line
|
||||
* x1 ::= <number>
|
||||
* x2 ::= <number>
|
||||
* y1 ::= <number>
|
||||
* y2 ::= <number>
|
||||
*
|
||||
* The output PNG is generated by down-sampling a 4x supersampled image using
|
||||
* a bi-cubic filter. The bi-cubic has a 2 (output) pixel width, so an 8x8
|
||||
* array of super-sampled points contribute to each output pixel. The value of
|
||||
* a super-sampled point is found using an unfiltered, aliased, infinite
|
||||
* precision image: Each shape from the last to the first is checked to see if
|
||||
* the point is in the drawn area and, if it is, the color of the point is the
|
||||
* color of the shape and the alpha is 1, if not the previous shape is checked.
|
||||
*
|
||||
* This is an aliased algorithm because no filtering is done; a point is either
|
||||
* inside or outside each shape and 'close' points do not contribute to the
|
||||
* sample. The down-sampling is relied on to correct the error of not using
|
||||
* a filter.
|
||||
*
|
||||
* The line end-caps are 'flat'; they go through the points. The square line
|
||||
* joins are mitres; the outside of the lines are continued to the point of
|
||||
* intersection.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/* Normally use <png.h> here to get the installed libpng, but this is done to
|
||||
* ensure the code picks up the local libpng implementation:
|
||||
*/
|
||||
#include "../../png.h"
|
||||
|
||||
#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
|
||||
|
||||
static const struct color
|
||||
{
|
||||
const char *name;
|
||||
double red;
|
||||
double green;
|
||||
double blue;
|
||||
} colors[] =
|
||||
/* color ::= black|white|red|green|yellow|blue
|
||||
* color ::= brown|purple|pink|orange|gray|cyan
|
||||
*/
|
||||
{
|
||||
{ "black", 0, 0, 0 },
|
||||
{ "white", 1, 1, 1 },
|
||||
{ "red", 1, 0, 0 },
|
||||
{ "green", 0, 1, 0 },
|
||||
{ "yellow", 1, 1, 0 },
|
||||
{ "blue", 0, 0, 1 },
|
||||
{ "brown", .5, .125, 0 },
|
||||
{ "purple", 1, 0, 1 },
|
||||
{ "pink", 1, .5, .5 },
|
||||
{ "orange", 1, .5, 0 },
|
||||
{ "gray", 0, .5, .5 },
|
||||
{ "cyan", 0, 1, 1 }
|
||||
};
|
||||
#define color_count ((sizeof colors)/(sizeof colors[0]))
|
||||
|
||||
static const struct color *
|
||||
color_of(const char *arg)
|
||||
{
|
||||
int icolor = color_count;
|
||||
|
||||
while (--icolor >= 0)
|
||||
{
|
||||
if (strcmp(colors[icolor].name, arg) == 0)
|
||||
return colors+icolor;
|
||||
}
|
||||
|
||||
fprintf(stderr, "genpng: invalid color %s\n", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static double
|
||||
width_of(const char *arg)
|
||||
{
|
||||
if (strcmp(arg, "filled") == 0)
|
||||
return 0;
|
||||
|
||||
else
|
||||
{
|
||||
char *ep = NULL;
|
||||
double w = strtod(arg, &ep);
|
||||
|
||||
if (ep != NULL && *ep == 0 && w > 0)
|
||||
return w;
|
||||
}
|
||||
|
||||
fprintf(stderr, "genpng: invalid line width %s\n", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static double
|
||||
coordinate_of(const char *arg)
|
||||
{
|
||||
char *ep = NULL;
|
||||
double w = strtod(arg, &ep);
|
||||
|
||||
if (ep != NULL && *ep == 0)
|
||||
return w;
|
||||
|
||||
fprintf(stderr, "genpng: invalid coordinate value %s\n", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct arg; /* forward declaration */
|
||||
|
||||
typedef int (*shape_fn_ptr)(const struct arg *arg, double x, double y);
|
||||
/* A function to determine if (x,y) is inside the shape.
|
||||
*
|
||||
* There are two implementations:
|
||||
*
|
||||
* inside_fn: returns true if the point is inside
|
||||
* check_fn: returns;
|
||||
* -1: the point is outside the shape by more than the filter width (2)
|
||||
* 0: the point may be inside the shape
|
||||
* +1: the point is inside the shape by more than the filter width
|
||||
*/
|
||||
#define OUTSIDE (-1)
|
||||
#define INSIDE (1)
|
||||
|
||||
struct arg
|
||||
{
|
||||
const struct color *color;
|
||||
shape_fn_ptr inside_fn;
|
||||
shape_fn_ptr check_fn;
|
||||
double width; /* line width, 0 for 'filled' */
|
||||
double x1, y1, x2, y2;
|
||||
};
|
||||
|
||||
/* IMPLEMENTATION NOTE:
|
||||
*
|
||||
* We want the contribution of each shape to the sample corresponding to each
|
||||
* pixel. This could be obtained by super sampling the image to infinite
|
||||
* dimensions, finding each point within the shape and assigning that a value
|
||||
* '1' while leaving every point outside the shape with value '0' then
|
||||
* downsampling to the image size with sinc; computationally very expensive.
|
||||
*
|
||||
* Approximations are as follows:
|
||||
*
|
||||
* 1) If the pixel coordinate is within the shape assume the sample has the
|
||||
* shape color and is opaque, else assume there is no contribution from
|
||||
* the shape.
|
||||
*
|
||||
* This is the equivalent of aliased rendering or resampling an image with
|
||||
* a block filter. The maximum error in the calculated alpha (which will
|
||||
* always be 0 or 1) is 0.5.
|
||||
*
|
||||
* 2) If the shape is within a square of size 1x1 centered on the pixel assume
|
||||
* that the shape obscures an amount of the pixel equal to its area within
|
||||
* that square.
|
||||
*
|
||||
* This is the equivalent of 'pixel coverage' alpha calculation or resampling
|
||||
* an image with a bi-linear filter. The maximum error is over 0.2, but the
|
||||
* results are often acceptable.
|
||||
*
|
||||
* This can be approximated by applying (1) to a super-sampled image then
|
||||
* downsampling with a bi-linear filter. The error in the super-sampled
|
||||
* image is 0.5 per sample, but the resampling reduces this.
|
||||
*
|
||||
* 3) Use a better filter with a super-sampled image; in the limit this is the
|
||||
* sinc() approach.
|
||||
*
|
||||
* 4) Do the geometric calculation; a bivariate definite integral across the
|
||||
* shape, unfortunately this means evaluating Si(x), the integral of sinc(x),
|
||||
* which is still a lot of math.
|
||||
*
|
||||
* This code uses approach (3) with a bi-cubic filter and 8x super-sampling
|
||||
* and method (1) for the super-samples. This means that the sample is either
|
||||
* 0 or 1, depending on whether the sub-pixel is within or outside the shape.
|
||||
* The bi-cubic weights are also fixed and the 16 required weights are
|
||||
* pre-computed here (note that the 'scale' setting will need to be changed if
|
||||
* 'super' is increased).
|
||||
*
|
||||
* The code also calculates a sum to the edge of the filter. This is not
|
||||
* currently used by could be used to optimize the calculation.
|
||||
*/
|
||||
#if 0 /* bc code */
|
||||
scale=10
|
||||
super=8
|
||||
define bicubic(x) {
|
||||
if (x <= 1) return (1.5*x - 2.5)*x*x + 1;
|
||||
if (x < 2) return (((2.5 - 0.5*x)*x - 4)*x + 2);
|
||||
return 0;
|
||||
}
|
||||
define sum(x) {
|
||||
auto s;
|
||||
s = 0;
|
||||
while (x < 2*super) {
|
||||
s = s + bicubic(x/super);
|
||||
x = x + 1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
define results(x) {
|
||||
auto b, s;
|
||||
b = bicubic(x/super);
|
||||
s = sum(x);
|
||||
|
||||
print " /*", x, "*/ { ", b, ", ", s, " }";
|
||||
return 1;
|
||||
}
|
||||
x=0
|
||||
while (x<2*super) {
|
||||
x = x + results(x)
|
||||
if (x < 2*super) print ","
|
||||
print "\n"
|
||||
}
|
||||
quit
|
||||
#endif
|
||||
|
||||
#define BICUBIC1(x) /* |x| <= 1 */ ((1.5*(x)* - 2.5)*(x)*(x) + 1)
|
||||
#define BICUBIC2(x) /* 1 < |x| < 2 */ (((2.5 - 0.5*(x))*(x) - 4)*(x) + 2)
|
||||
#define FILTER_WEIGHT 9 /* Twice the first sum below */
|
||||
#define FILTER_WIDTH 2 /* Actually half the width; -2..+2 */
|
||||
#define FILTER_STEPS 8 /* steps per filter unit */
|
||||
static const double
|
||||
bicubic[16][2] =
|
||||
{
|
||||
/* These numbers are exact; the weight for the filter is 1/9, but this
|
||||
* would make the numbers inexact, so it is not included here.
|
||||
*/
|
||||
/* bicubic sum */
|
||||
/* 0*/ { 1.0000000000, 4.5000000000 },
|
||||
/* 1*/ { .9638671875, 3.5000000000 },
|
||||
/* 2*/ { .8671875000, 2.5361328125 },
|
||||
/* 3*/ { .7275390625, 1.6689453125 },
|
||||
/* 4*/ { .5625000000, .9414062500 },
|
||||
/* 5*/ { .3896484375, .3789062500 },
|
||||
/* 6*/ { .2265625000, -.0107421875 },
|
||||
/* 7*/ { .0908203125, -.2373046875 },
|
||||
/* 8*/ { 0, -.3281250000 },
|
||||
/* 9*/ { -.0478515625, -.3281250000 },
|
||||
/*10*/ { -.0703125000, -.2802734375 },
|
||||
/*11*/ { -.0732421875, -.2099609375 },
|
||||
/*12*/ { -.0625000000, -.1367187500 },
|
||||
/*13*/ { -.0439453125, -.0742187500 },
|
||||
/*14*/ { -.0234375000, -.0302734375 },
|
||||
/*15*/ { -.0068359375, -.0068359375 }
|
||||
};
|
||||
|
||||
static double
|
||||
alpha_calc(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* For [x-2..x+2],[y-2,y+2] calculate the weighted bicubic given a function
|
||||
* which tells us whether a point is inside or outside the shape. First
|
||||
* check if we need to do this at all:
|
||||
*/
|
||||
switch (arg->check_fn(arg, x, y))
|
||||
{
|
||||
case OUTSIDE:
|
||||
return 0; /* all samples outside the shape */
|
||||
|
||||
case INSIDE:
|
||||
return 1; /* all samples inside the shape */
|
||||
|
||||
default:
|
||||
{
|
||||
int dy;
|
||||
double alpha = 0;
|
||||
|
||||
# define FILTER_D (FILTER_WIDTH*FILTER_STEPS-1)
|
||||
for (dy=-FILTER_D; dy<=FILTER_D; ++dy)
|
||||
{
|
||||
double wy = bicubic[abs(dy)][0];
|
||||
|
||||
if (wy != 0)
|
||||
{
|
||||
double alphay = 0;
|
||||
int dx;
|
||||
|
||||
for (dx=-FILTER_D; dx<=FILTER_D; ++dx)
|
||||
{
|
||||
double wx = bicubic[abs(dx)][0];
|
||||
|
||||
if (wx != 0 && arg->inside_fn(arg, x+dx/16, y+dy/16))
|
||||
alphay += wx;
|
||||
}
|
||||
|
||||
alpha += wy * alphay;
|
||||
}
|
||||
}
|
||||
|
||||
/* This needs to be weighted for each dimension: */
|
||||
return alpha / (FILTER_WEIGHT*FILTER_WEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* These are the shape functions. */
|
||||
/* "square",
|
||||
* { inside_square_filled, check_square_filled },
|
||||
* { inside_square, check_square }
|
||||
*/
|
||||
static int
|
||||
square_check(double x, double y, double x1, double y1, double x2, double y2)
|
||||
/* Is x,y inside the square (x1,y1)..(x2,y2)? */
|
||||
{
|
||||
/* Do a modified Cohen-Sutherland on one point, bit patterns that indicate
|
||||
* 'outside' are:
|
||||
*
|
||||
* x<x1 | x<y1 | x<x2 | x<y2
|
||||
* 0 x 0 x To the right
|
||||
* 1 x 1 x To the left
|
||||
* x 0 x 0 Below
|
||||
* x 1 x 1 Above
|
||||
*
|
||||
* So 'inside' is (x<x1) != (x<x2) && (y<y1) != (y<y2);
|
||||
*/
|
||||
return ((x<x1) ^ (x<x2)) & ((y<y1) ^ (y<y2));
|
||||
}
|
||||
|
||||
static int
|
||||
inside_square_filled(const struct arg *arg, double x, double y)
|
||||
{
|
||||
return square_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2);
|
||||
}
|
||||
|
||||
static int
|
||||
square_check_line(const struct arg *arg, double x, double y, double w)
|
||||
/* Check for a point being inside the boundaries implied by the given arg
|
||||
* and assuming a width 2*w each side of the boundaries. This returns the
|
||||
* 'check' INSIDE/OUTSIDE/0 result but note the semantics:
|
||||
*
|
||||
* +--------------+
|
||||
* | | OUTSIDE
|
||||
* | INSIDE |
|
||||
* | |
|
||||
* +--------------+
|
||||
*
|
||||
* And '0' means within the line boundaries.
|
||||
*/
|
||||
{
|
||||
double cx = (arg->x1+arg->x2)/2;
|
||||
double wx = fabs(arg->x1-arg->x2)/2;
|
||||
double cy = (arg->y1+arg->y2)/2;
|
||||
double wy = fabs(arg->y1-arg->y2)/2;
|
||||
|
||||
if (square_check(x, y, cx-wx-w, cy-wy-w, cx+wx+w, cy+wy+w))
|
||||
{
|
||||
/* Inside, but maybe too far; check for the redundant case where
|
||||
* the lines overlap:
|
||||
*/
|
||||
wx -= w;
|
||||
wy -= w;
|
||||
if (wx > 0 && wy > 0 && square_check(x, y, cx-wx, cy-wy, cx+wx, cy+wy))
|
||||
return INSIDE; /* between (inside) the boundary lines. */
|
||||
|
||||
return 0; /* inside the lines themselves. */
|
||||
}
|
||||
|
||||
return OUTSIDE; /* outside the boundary lines. */
|
||||
}
|
||||
|
||||
static int
|
||||
check_square_filled(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* The filter extends +/-FILTER_WIDTH each side of each output point, so
|
||||
* the check has to expand and contract the square by that amount; '0'
|
||||
* means close enough to the edge of the square that the bicubic filter has
|
||||
* to be run, OUTSIDE means alpha==0, INSIDE means alpha==1.
|
||||
*/
|
||||
return square_check_line(arg, x, y, FILTER_WIDTH);
|
||||
}
|
||||
|
||||
static int
|
||||
inside_square(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* Return true if within the drawn lines, else false, no need to distinguish
|
||||
* INSIDE vs OUTSIDE here:
|
||||
*/
|
||||
return square_check_line(arg, x, y, arg->width/2) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
check_square(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* So for this function a result of 'INSIDE' means inside the actual lines.
|
||||
*/
|
||||
double w = arg->width/2;
|
||||
|
||||
if (square_check_line(arg, x, y, w+FILTER_WIDTH) == 0)
|
||||
{
|
||||
/* Somewhere close to the boundary lines. If far enough inside one of
|
||||
* them then we can return INSIDE:
|
||||
*/
|
||||
w -= FILTER_WIDTH;
|
||||
|
||||
if (w > 0 && square_check_line(arg, x, y, w) == 0)
|
||||
return INSIDE;
|
||||
|
||||
/* Point is somewhere in the filter region: */
|
||||
return 0;
|
||||
}
|
||||
|
||||
else /* Inside or outside the square by more than w+FILTER_WIDTH. */
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
/* "circle",
|
||||
* { inside_circle_filled, check_circle_filled },
|
||||
* { inside_circle, check_circle }
|
||||
*
|
||||
* The functions here are analoguous to the square ones; however, they check
|
||||
* the corresponding ellipse as opposed to the rectangle.
|
||||
*/
|
||||
static int
|
||||
circle_check(double x, double y, double x1, double y1, double x2, double y2)
|
||||
{
|
||||
if (square_check(x, y, x1, y1, x2, y2))
|
||||
{
|
||||
/* Inside the square, so maybe inside the circle too: */
|
||||
const double cx = (x1 + x2)/2;
|
||||
const double cy = (y1 + y2)/2;
|
||||
const double dx = x1 - x2;
|
||||
const double dy = y1 - y2;
|
||||
|
||||
x = (x - cx)/dx;
|
||||
y = (y - cy)/dy;
|
||||
|
||||
/* It is outside if the distance from the center is more than half the
|
||||
* diameter:
|
||||
*/
|
||||
return x*x+y*y < .25;
|
||||
}
|
||||
|
||||
return 0; /* outside */
|
||||
}
|
||||
|
||||
static int
|
||||
inside_circle_filled(const struct arg *arg, double x, double y)
|
||||
{
|
||||
return circle_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2);
|
||||
}
|
||||
|
||||
static int
|
||||
circle_check_line(const struct arg *arg, double x, double y, double w)
|
||||
/* Check for a point being inside the boundaries implied by the given arg
|
||||
* and assuming a width 2*w each side of the boundaries. This function has
|
||||
* the same semantic as square_check_line but tests the circle.
|
||||
*/
|
||||
{
|
||||
double cx = (arg->x1+arg->x2)/2;
|
||||
double wx = fabs(arg->x1-arg->x2)/2;
|
||||
double cy = (arg->y1+arg->y2)/2;
|
||||
double wy = fabs(arg->y1-arg->y2)/2;
|
||||
|
||||
if (circle_check(x, y, cx-wx-w, cy-wy-w, cx+wx+w, cy+wy+w))
|
||||
{
|
||||
/* Inside, but maybe too far; check for the redundant case where
|
||||
* the lines overlap:
|
||||
*/
|
||||
wx -= w;
|
||||
wy -= w;
|
||||
if (wx > 0 && wy > 0 && circle_check(x, y, cx-wx, cy-wy, cx+wx, cy+wy))
|
||||
return INSIDE; /* between (inside) the boundary lines. */
|
||||
|
||||
return 0; /* inside the lines themselves. */
|
||||
}
|
||||
|
||||
return OUTSIDE; /* outside the boundary lines. */
|
||||
}
|
||||
|
||||
static int
|
||||
check_circle_filled(const struct arg *arg, double x, double y)
|
||||
{
|
||||
return circle_check_line(arg, x, y, FILTER_WIDTH);
|
||||
}
|
||||
|
||||
static int
|
||||
inside_circle(const struct arg *arg, double x, double y)
|
||||
{
|
||||
return circle_check_line(arg, x, y, arg->width/2) == 0;
|
||||
}
|
||||
|
||||
static int
|
||||
check_circle(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* Exactly as the 'square' code. */
|
||||
double w = arg->width/2;
|
||||
|
||||
if (circle_check_line(arg, x, y, w+FILTER_WIDTH) == 0)
|
||||
{
|
||||
w -= FILTER_WIDTH;
|
||||
|
||||
if (w > 0 && circle_check_line(arg, x, y, w) == 0)
|
||||
return INSIDE;
|
||||
|
||||
/* Point is somewhere in the filter region: */
|
||||
return 0;
|
||||
}
|
||||
|
||||
else /* Inside or outside the square by more than w+FILTER_WIDTH. */
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
/* "line",
|
||||
* { NULL, NULL }, There is no 'filled' line.
|
||||
* { inside_line, check_line }
|
||||
*/
|
||||
static int
|
||||
line_check(double x, double y, double x1, double y1, double x2, double y2,
|
||||
double w, double expand)
|
||||
{
|
||||
/* Shift all the points to (arg->x1, arg->y1) */
|
||||
double lx = x2 - x1;
|
||||
double ly = y2 - y1;
|
||||
double len2 = lx*lx + ly*ly;
|
||||
double cross, dot;
|
||||
|
||||
x -= x1;
|
||||
y -= y1;
|
||||
|
||||
/* The dot product is the distance down the line, the cross product is
|
||||
* the distance away from the line:
|
||||
*
|
||||
* distance = |cross| / sqrt(len2)
|
||||
*/
|
||||
cross = x * ly - y * lx;
|
||||
|
||||
/* If 'distance' is more than w the point is definitely outside the line:
|
||||
*
|
||||
* distance >= w
|
||||
* |cross| >= w * sqrt(len2)
|
||||
* cross^2 >= w^2 * len2:
|
||||
*/
|
||||
if (cross*cross >= (w+expand)*(w+expand)*len2)
|
||||
return 0; /* outside */
|
||||
|
||||
/* Now find the distance *along* the line; this comes from the dot product
|
||||
* lx.x+ly.y. The actual distance (in pixels) is:
|
||||
*
|
||||
* distance = dot / sqrt(len2)
|
||||
*/
|
||||
dot = lx * x + ly * y;
|
||||
|
||||
/* The test for 'outside' is:
|
||||
*
|
||||
* distance < 0 || distance > sqrt(len2)
|
||||
* -> dot / sqrt(len2) > sqrt(len2)
|
||||
* -> dot > len2
|
||||
*
|
||||
* But 'expand' is used for the filter width and needs to be handled too:
|
||||
*/
|
||||
return dot > -expand && dot < len2+expand;
|
||||
}
|
||||
|
||||
static int
|
||||
inside_line(const struct arg *arg, double x, double y)
|
||||
{
|
||||
return line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
check_line(const struct arg *arg, double x, double y)
|
||||
{
|
||||
/* The end caps of the line must be checked too; it's not enough just to
|
||||
* widen the line by FILTER_WIDTH; 'expand' exists for this purpose:
|
||||
*/
|
||||
if (line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2,
|
||||
FILTER_WIDTH))
|
||||
{
|
||||
/* Inside the line+filter; far enough inside that the filter isn't
|
||||
* required?
|
||||
*/
|
||||
if (arg->width > 2*FILTER_WIDTH &&
|
||||
line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2,
|
||||
-FILTER_WIDTH))
|
||||
return INSIDE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return OUTSIDE;
|
||||
}
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *name;
|
||||
shape_fn_ptr function[2/*fill,line*/][2];
|
||||
# define FN_INSIDE 0
|
||||
# define FN_CHECK 1
|
||||
} shape_defs[] =
|
||||
{
|
||||
{ "square",
|
||||
{ { inside_square_filled, check_square_filled },
|
||||
{ inside_square, check_square } }
|
||||
},
|
||||
{ "circle",
|
||||
{ { inside_circle_filled, check_circle_filled },
|
||||
{ inside_circle, check_circle } }
|
||||
},
|
||||
{ "line",
|
||||
{ { NULL, NULL },
|
||||
{ inside_line, check_line } }
|
||||
}
|
||||
};
|
||||
|
||||
#define shape_count ((sizeof shape_defs)/(sizeof shape_defs[0]))
|
||||
|
||||
static shape_fn_ptr
|
||||
shape_of(const char *arg, double width, int f)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i=0; i<shape_count; ++i) if (strcmp(shape_defs[i].name, arg) == 0)
|
||||
{
|
||||
shape_fn_ptr fn = shape_defs[i].function[width != 0][f];
|
||||
|
||||
if (fn != NULL)
|
||||
return fn;
|
||||
|
||||
fprintf(stderr, "genpng: %s %s not supported\n",
|
||||
width == 0 ? "filled" : "unfilled", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "genpng: %s: not a valid shape name\n", arg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_arg(struct arg *arg, const char **argv/*7 arguments*/)
|
||||
{
|
||||
/* shape ::= color width shape x1 y1 x2 y2 */
|
||||
arg->color = color_of(argv[0]);
|
||||
arg->width = width_of(argv[1]);
|
||||
arg->inside_fn = shape_of(argv[2], arg->width, FN_INSIDE);
|
||||
arg->check_fn = shape_of(argv[2], arg->width, FN_CHECK);
|
||||
arg->x1 = coordinate_of(argv[3]);
|
||||
arg->y1 = coordinate_of(argv[4]);
|
||||
arg->x2 = coordinate_of(argv[5]);
|
||||
arg->y2 = coordinate_of(argv[6]);
|
||||
}
|
||||
|
||||
static png_uint_32
|
||||
read_wh(const char *name, const char *str)
|
||||
/* read a PNG width or height */
|
||||
{
|
||||
char *ep = NULL;
|
||||
unsigned long ul = strtoul(str, &ep, 10);
|
||||
|
||||
if (ep != NULL && *ep == 0 && ul > 0 && ul <= 0x7fffffff)
|
||||
return (png_uint_32)/*SAFE*/ul;
|
||||
|
||||
fprintf(stderr, "genpng: %s: invalid number %s\n", name, str);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
pixel(png_uint_16p p, struct arg *args, int nargs, double x, double y)
|
||||
{
|
||||
/* Fill in the pixel by checking each shape (args[nargs]) for effects on
|
||||
* the corresponding sample:
|
||||
*/
|
||||
double r=0, g=0, b=0, a=0;
|
||||
|
||||
while (--nargs >= 0 && a != 1)
|
||||
{
|
||||
/* NOTE: alpha_calc can return a value outside the range 0..1 with the
|
||||
* bicubic filter.
|
||||
*/
|
||||
const double alpha = alpha_calc(args+nargs, x, y) * (1-a);
|
||||
|
||||
r += alpha * args[nargs].color->red;
|
||||
g += alpha * args[nargs].color->green;
|
||||
b += alpha * args[nargs].color->blue;
|
||||
a += alpha;
|
||||
}
|
||||
|
||||
/* 'a' may be negative or greater than 1; if it is, negative clamp the
|
||||
* pixel to 0 if >1 clamp r/g/b:
|
||||
*/
|
||||
if (a > 0)
|
||||
{
|
||||
if (a > 1)
|
||||
{
|
||||
if (r > 1) r = 1;
|
||||
if (g > 1) g = 1;
|
||||
if (b > 1) b = 1;
|
||||
a = 1;
|
||||
}
|
||||
|
||||
/* And fill in the pixel: */
|
||||
p[0] = (png_uint_16)/*SAFE*/round(r * 65535);
|
||||
p[1] = (png_uint_16)/*SAFE*/round(g * 65535);
|
||||
p[2] = (png_uint_16)/*SAFE*/round(b * 65535);
|
||||
p[3] = (png_uint_16)/*SAFE*/round(a * 65535);
|
||||
}
|
||||
|
||||
else
|
||||
p[3] = p[2] = p[1] = p[0] = 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
int convert_to_8bit = 0;
|
||||
|
||||
/* There is one option: --8bit: */
|
||||
if (argc > 1 && strcmp(argv[1], "--8bit") == 0)
|
||||
--argc, ++argv, convert_to_8bit = 1;
|
||||
|
||||
if (argc >= 3)
|
||||
{
|
||||
png_uint_16p buffer;
|
||||
int nshapes;
|
||||
png_image image;
|
||||
# define max_shapes 256
|
||||
struct arg arg_list[max_shapes];
|
||||
|
||||
/* The libpng Simplified API write code requires a fully initialized
|
||||
* structure.
|
||||
*/
|
||||
memset(&image, 0, sizeof image);
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
image.opaque = NULL;
|
||||
image.width = read_wh("width", argv[1]);
|
||||
image.height = read_wh("height", argv[2]);
|
||||
image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;
|
||||
image.flags = 0;
|
||||
image.colormap_entries = 0;
|
||||
|
||||
/* Check the remainder of the arguments */
|
||||
for (nshapes=0; 3+7*(nshapes+1) <= argc && nshapes < max_shapes;
|
||||
++nshapes)
|
||||
parse_arg(arg_list+nshapes, argv+3+7*nshapes);
|
||||
|
||||
if (3+7*nshapes != argc)
|
||||
{
|
||||
fprintf(stderr, "genpng: %s: too many arguments\n", argv[3+7*nshapes]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create the buffer: */
|
||||
buffer = malloc(PNG_IMAGE_SIZE(image));
|
||||
|
||||
if (buffer != NULL)
|
||||
{
|
||||
png_uint_32 y;
|
||||
|
||||
/* Write each row... */
|
||||
for (y=0; y<image.height; ++y)
|
||||
{
|
||||
png_uint_32 x;
|
||||
|
||||
/* Each pixel in each row: */
|
||||
for (x=0; x<image.width; ++x)
|
||||
pixel(buffer + 4*(x + y*image.width), arg_list, nshapes, x, y);
|
||||
}
|
||||
|
||||
/* Write the result (to stdout) */
|
||||
if (png_image_write_to_stdio(&image, stdout, convert_to_8bit,
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/))
|
||||
{
|
||||
free(buffer);
|
||||
return 0; /* success */
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "genpng: write stdout: %s\n", image.message);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "genpng: out of memory: %lu bytes\n",
|
||||
(unsigned long)PNG_IMAGE_SIZE(image));
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
/* Wrong number of arguments */
|
||||
fprintf(stderr, "genpng: usage: genpng [--8bit] width height {shape}\n"
|
||||
" Generate a transparent PNG in RGBA (truecolor+alpha) format\n"
|
||||
" containing the given shape or shapes. Shapes are defined:\n"
|
||||
"\n"
|
||||
" shape ::= color width shape x1 y1 x2 y2\n"
|
||||
" color ::= black|white|red|green|yellow|blue\n"
|
||||
" color ::= brown|purple|pink|orange|gray|cyan\n"
|
||||
" width ::= filled|<number>\n"
|
||||
" shape ::= circle|square|line\n"
|
||||
" x1,x2 ::= <number>\n"
|
||||
" y1,y2 ::= <number>\n"
|
||||
"\n"
|
||||
" Numbers are floating point numbers describing points relative to\n"
|
||||
" the top left of the output PNG as pixel coordinates. The 'width'\n"
|
||||
" parameter is either the width of the line (in output pixels) used\n"
|
||||
" to draw the shape or 'filled' to indicate that the shape should\n"
|
||||
" be filled with the color.\n"
|
||||
"\n"
|
||||
" Colors are interpreted loosely to give access to the eight full\n"
|
||||
" intensity RGB values:\n"
|
||||
"\n"
|
||||
" black, red, green, blue, yellow, cyan, purple, white,\n"
|
||||
"\n"
|
||||
" Cyan is full intensity blue+green; RGB(0,1,1), plus the following\n"
|
||||
" lower intensity values:\n"
|
||||
"\n"
|
||||
" brown: red+orange: RGB(0.5, 0.125, 0) (dark red+orange)\n"
|
||||
" pink: red+white: RGB(1.0, 0.5, 0.5)\n"
|
||||
" orange: red+yellow: RGB(1.0, 0.5, 0)\n"
|
||||
" gray: black+white: RGB(0.5, 0.5, 0.5)\n"
|
||||
"\n"
|
||||
" The RGB values are selected to make detection of aliasing errors\n"
|
||||
" easy. The names are selected to make the description of errors\n"
|
||||
" easy.\n"
|
||||
"\n"
|
||||
" The PNG is written to stdout, if --8bit is given a 32bpp RGBA sRGB\n"
|
||||
" file is produced, otherwise a 64bpp RGBA linear encoded file is\n"
|
||||
" written.\n");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* SIMPLIFIED_WRITE && STDIO */
|
||||
4
contrib/tools/intgamma.sh
Normal file → Executable file
4
contrib/tools/intgamma.sh
Normal file → Executable file
@@ -2,9 +2,9 @@
|
||||
#
|
||||
# intgamma.sh
|
||||
#
|
||||
# Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
# Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
#
|
||||
# COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
# COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
# To the extent possible under law, the author has waived all copyright and
|
||||
# related or neighboring rights to this work. This work is published from:
|
||||
# United States.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
|
||||
164
contrib/tools/png-fix-itxt.c
Normal file
164
contrib/tools/png-fix-itxt.c
Normal file
@@ -0,0 +1,164 @@
|
||||
|
||||
/* png-fix-itxt version 1.0.0
|
||||
*
|
||||
* Copyright 2015 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* png-fix-itxt.exe < bad.png > good.png
|
||||
*
|
||||
* Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more
|
||||
* uncompressed iTXt chunks. Assumes that the actual length is greater
|
||||
* than or equal to the value in the length byte, and that the CRC is
|
||||
* correct for the actual length. This program hunts for the CRC and
|
||||
* adjusts the length byte accordingly. It is not an error to process a
|
||||
* PNG file that has no iTXt chunks or one that has valid iTXt chunks;
|
||||
* such files will simply be copied.
|
||||
*
|
||||
* Requires zlib (for crc32 and Z_NULL); build with
|
||||
*
|
||||
* gcc -O -o png-fix-itxt png-fix-itxt.c -lz
|
||||
*
|
||||
* If you need to handle iTXt chunks larger than 500000 kbytes you must
|
||||
* rebuild png-fix-itxt with a larger values of MAX_LENGTH (or a smaller value
|
||||
* if you know you will never encounter such huge iTXt chunks).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define MAX_LENGTH 500000
|
||||
|
||||
/* Read one character (inchar), also return octet (c), break if EOF */
|
||||
#define GETBREAK inchar=getchar(); \
|
||||
c=(inchar & 0xffU);\
|
||||
if (inchar != c) break
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char buf[MAX_LENGTH];
|
||||
unsigned long crc;
|
||||
unsigned char c;
|
||||
int inchar;
|
||||
|
||||
/* Skip 8-byte signature */
|
||||
for (i=8; i; i--)
|
||||
{
|
||||
GETBREAK;
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (inchar == c) /* !EOF */
|
||||
for (;;)
|
||||
{
|
||||
/* Read the length */
|
||||
unsigned long length; /* must be 32 bits! */
|
||||
GETBREAK; buf[0] = c; length = c; length <<= 8;
|
||||
GETBREAK; buf[1] = c; length += c; length <<= 8;
|
||||
GETBREAK; buf[2] = c; length += c; length <<= 8;
|
||||
GETBREAK; buf[3] = c; length += c;
|
||||
|
||||
/* Read the chunkname */
|
||||
GETBREAK; buf[4] = c;
|
||||
GETBREAK; buf[5] = c;
|
||||
GETBREAK; buf[6] = c;
|
||||
GETBREAK; buf[7] = c;
|
||||
|
||||
|
||||
/* The iTXt chunk type expressed as integers is (105, 84, 88, 116) */
|
||||
if (buf[4] == 105 && buf[5] == 84 && buf[6] == 88 && buf[7] == 116)
|
||||
{
|
||||
if (length >= MAX_LENGTH-12)
|
||||
break; /* To do: handle this more gracefully */
|
||||
|
||||
/* Initialize the CRC */
|
||||
crc = crc32(0, Z_NULL, 0);
|
||||
|
||||
/* Copy the data bytes */
|
||||
for (i=8; i < length + 12; i++)
|
||||
{
|
||||
GETBREAK; buf[i] = c;
|
||||
}
|
||||
|
||||
if (inchar != c) /* EOF */
|
||||
break;
|
||||
|
||||
/* Calculate the CRC */
|
||||
crc = crc32(crc, buf+4, (uInt)length+4);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Check the CRC */
|
||||
if (((crc >> 24) & 0xffU) == buf[length+8] &&
|
||||
((crc >> 16) & 0xffU) == buf[length+9] &&
|
||||
((crc >> 8) & 0xffU) == buf[length+10] &&
|
||||
((crc ) & 0xffU) == buf[length+11])
|
||||
break;
|
||||
|
||||
length++;
|
||||
|
||||
if (length >= MAX_LENGTH-12)
|
||||
break;
|
||||
|
||||
GETBREAK;
|
||||
buf[length+11] = c;
|
||||
|
||||
/* Update the CRC */
|
||||
crc = crc32(crc, buf+7+length, 1);
|
||||
}
|
||||
|
||||
if (inchar != c) /* EOF */
|
||||
break;
|
||||
|
||||
/* Update length bytes */
|
||||
buf[0] = (unsigned char)((length >> 24) & 0xffU);
|
||||
buf[1] = (unsigned char)((length >> 16) & 0xffU);
|
||||
buf[2] = (unsigned char)((length >> 8) & 0xffU);
|
||||
buf[3] = (unsigned char)((length ) & 0xffU);
|
||||
|
||||
/* Write the fixed iTXt chunk (length, name, data, crc) */
|
||||
for (i=0; i<length+12; i++)
|
||||
putchar(buf[i]);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (inchar != c) /* EOF */
|
||||
break;
|
||||
|
||||
/* Copy bytes that were already read (length and chunk name) */
|
||||
for (i=0; i<8; i++)
|
||||
putchar(buf[i]);
|
||||
|
||||
/* Copy data bytes and CRC */
|
||||
for (i=8; i< length+12; i++)
|
||||
{
|
||||
GETBREAK;
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
if (inchar != c) /* EOF */
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* The IEND chunk type expressed as integers is (73, 69, 78, 68) */
|
||||
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
|
||||
break;
|
||||
}
|
||||
|
||||
if (inchar != c) /* EOF */
|
||||
break;
|
||||
|
||||
if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
4047
contrib/tools/pngfix.c
Normal file
4047
contrib/tools/pngfix.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,9 @@
|
||||
/*-
|
||||
* sRGB.h
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
*
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2012.
|
||||
* COPYRIGHT: Written by John Cunningham Bowler, 2013.
|
||||
* To the extent possible under law, the author has waived all copyright and
|
||||
* related or neighboring rights to this work. This work is published from:
|
||||
* United States.
|
||||
|
||||
238
contrib/tools/scale.c
Normal file
238
contrib/tools/scale.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/* Given a target range and a source range work out an expression to scale from
|
||||
* the source to the target of the form:
|
||||
*
|
||||
* (number * mult + add)>>16
|
||||
*
|
||||
* The command arguments are:
|
||||
*
|
||||
* scale target source
|
||||
*
|
||||
* and the program works out a pair of numbers, mult and add, that evaluate:
|
||||
*
|
||||
* number * target
|
||||
* round( --------------- )
|
||||
* source
|
||||
*
|
||||
* exactly for number in the range 0..source
|
||||
*/
|
||||
#define _ISOC99_SOURCE 1
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
static double minerr;
|
||||
static unsigned long minmult, minadd, minshift;
|
||||
static long mindelta;
|
||||
|
||||
static int
|
||||
test(unsigned long target, unsigned long source, unsigned long mult,
|
||||
long add, unsigned long shift, long delta)
|
||||
{
|
||||
unsigned long i;
|
||||
double maxerr = 0;
|
||||
double rs = (double)target/source;
|
||||
|
||||
for (i=0; i<=source; ++i)
|
||||
{
|
||||
unsigned long t = i*mult+add;
|
||||
double err = fabs((t >> shift) - i*rs);
|
||||
|
||||
if (err > minerr)
|
||||
return 0;
|
||||
|
||||
if (err > maxerr)
|
||||
maxerr = err;
|
||||
}
|
||||
|
||||
if (maxerr < minerr)
|
||||
{
|
||||
minerr = maxerr;
|
||||
minmult = mult;
|
||||
minadd = add;
|
||||
minshift = shift;
|
||||
mindelta = delta;
|
||||
}
|
||||
|
||||
return maxerr < .5;
|
||||
}
|
||||
|
||||
static int
|
||||
dotest(unsigned long target, unsigned long source, unsigned long mult,
|
||||
long add, unsigned long shift, long delta, int print)
|
||||
{
|
||||
if (test(target, source, mult, add, shift, delta))
|
||||
{
|
||||
if (print & 4)
|
||||
printf(" {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu */\n",
|
||||
mult, add, shift, target, source);
|
||||
|
||||
else if (print & 2)
|
||||
printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu */\n",
|
||||
mult, add, shift, target, source);
|
||||
|
||||
else if (print)
|
||||
printf("number * %lu/%lu = (number * %lu + %ld) >> %lu [delta %ld]\n",
|
||||
target, source, mult, add, shift, delta);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
find(unsigned long target, unsigned long source, int print, int fixshift)
|
||||
{
|
||||
unsigned long shift = 0;
|
||||
unsigned long shiftlim = 0;
|
||||
|
||||
/* In the final math the sum is at most (source*mult+add) >> shift, so:
|
||||
*
|
||||
* source*mult+add < 1<<32
|
||||
* mult < (1<<32)/source
|
||||
*
|
||||
* but:
|
||||
*
|
||||
* mult = (target<<shift)/source
|
||||
*
|
||||
* so:
|
||||
*
|
||||
* (target<<shift) < (1<<32)
|
||||
*/
|
||||
if (fixshift < 0)
|
||||
while ((target<<shiftlim) < 0x80000000U) ++shiftlim;
|
||||
|
||||
else
|
||||
shift = shiftlim = (unsigned long)fixshift;
|
||||
|
||||
minerr = 1E8;
|
||||
|
||||
for (; shift<=shiftlim; ++shift)
|
||||
{
|
||||
unsigned long mult = ((target<<shift) + (source>>1)) / source;
|
||||
long delta;
|
||||
long limit = 1; /* seems to be sufficient */
|
||||
long add, start, end;
|
||||
|
||||
end = 1<<shift;
|
||||
start = -end;
|
||||
|
||||
for (add=start; add<=end; ++add)
|
||||
if (dotest(target,source,mult,add,shift,0,print))
|
||||
return 1;
|
||||
|
||||
for (delta=1; delta<=limit; ++delta)
|
||||
{
|
||||
# if 0
|
||||
fprintf(stderr, "%lu/%lu: shift %lu, delta %lu\n", target, source,
|
||||
shift, delta);
|
||||
# endif
|
||||
|
||||
for (add=start; add<=end; ++add)
|
||||
{
|
||||
if (dotest(target, source, mult-delta, add, shift, -delta, print))
|
||||
return 1;
|
||||
|
||||
if (dotest(target, source, mult+delta, add, shift, delta, print))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (print & 4)
|
||||
printf(" {%11lu,%6ld /* >>%lu */ }, /* %lu/%lu ERROR: .5+%g*/\n",
|
||||
minmult, minadd, minshift, target, source, minerr-.5);
|
||||
|
||||
else if (print & 2)
|
||||
printf(" {%11lu,%6ld,%3lu }, /* %lu/%lu ERROR: .5+%g*/\n",
|
||||
minmult, minadd, minshift, target, source, minerr-.5);
|
||||
|
||||
else if (print)
|
||||
printf(
|
||||
"number * %lu/%lu ~= (number * %lu + %ld) >> %lu +/-.5+%g [delta %ld]\n",
|
||||
target, source, minmult, minadd, minshift, minerr-.5, mindelta);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
usage(const char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s {--denominator|--maxshift|--code} target {source}\n"
|
||||
" For each 'source' prints 'mult' and 'add' such that:\n\n"
|
||||
" (number * mult + add) >> 16 = round(number*target/source)\n\n"
|
||||
" for all integer values of number in the range 0..source.\n\n"
|
||||
" --denominator: swap target and source (specify a single source first\n"
|
||||
" and follow with multiple targets.)\n"
|
||||
" --maxshift: find the lowest shift value that works for all the\n"
|
||||
" repeated 'source' values\n"
|
||||
" --code: output C code for array/structure initialization\n",
|
||||
prog);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char **argv)
|
||||
{
|
||||
int i, err = 0, maxshift = 0, firstsrc = 1, code = 0, denominator = 0;
|
||||
unsigned long target, shift = 0;
|
||||
|
||||
while (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[firstsrc], "--maxshift") == 0)
|
||||
{
|
||||
maxshift = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[firstsrc], "--code") == 0)
|
||||
{
|
||||
code = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[firstsrc], "--denominator") == 0)
|
||||
{
|
||||
denominator = 1;
|
||||
++firstsrc;
|
||||
}
|
||||
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (argc < 2+firstsrc)
|
||||
usage(argv[0]);
|
||||
|
||||
target = strtoul(argv[firstsrc++], 0, 0);
|
||||
if (target == 0) usage(argv[0]);
|
||||
|
||||
for (i=firstsrc; i<argc; ++i)
|
||||
{
|
||||
unsigned long source = strtoul(argv[i], 0, 0);
|
||||
|
||||
if (source == 0) usage(argv[0]);
|
||||
|
||||
if (!find(denominator ? source : target, denominator ? target : source,
|
||||
maxshift ? 0 : 1+code, -1))
|
||||
err = 1;
|
||||
|
||||
if (minshift > shift) shift = minshift;
|
||||
}
|
||||
|
||||
if (maxshift) for (i=firstsrc; i<argc; ++i)
|
||||
{
|
||||
unsigned long source = strtoul(argv[i], 0, 0);
|
||||
|
||||
if (!find(denominator ? source : target, denominator ? target : source,
|
||||
code ? 4 : 1, shift))
|
||||
err = 1;
|
||||
}
|
||||
|
||||
/* Just an exit code - the printout above lists the problem */
|
||||
return err;
|
||||
}
|
||||
66
example.c
66
example.c
@@ -2,8 +2,8 @@
|
||||
#if 0 /* in case someone actually tries to compile this */
|
||||
|
||||
/* example.c - an example of using libpng
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Maintained 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Maintained 1998-2015 Glenn Randers-Pehrson
|
||||
* Maintained 1996, 1997 Andreas Dilger)
|
||||
* Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
* To the extent possible under law, the authors have waived
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <png.h>
|
||||
#include <zlib.h>
|
||||
#include PNG_ZLIB_HEADER /* this is the header libpng was built with */
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ int main(int argc, const char **argv)
|
||||
image.version = PNG_IMAGE_VERSION;
|
||||
|
||||
/* The first argument is the file to read: */
|
||||
if (png_image_begin_read_from_file(&image, argv[1]))
|
||||
if (png_image_begin_read_from_file(&image, argv[1]) != 0)
|
||||
{
|
||||
png_bytep buffer;
|
||||
|
||||
@@ -97,7 +97,7 @@ int main(int argc, const char **argv)
|
||||
*/
|
||||
if (buffer != NULL &&
|
||||
png_image_finish_read(&image, NULL/*background*/, buffer,
|
||||
0/*row_stride*/, NULL/*colormap*/))
|
||||
0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
{
|
||||
/* Now write the image out to the second argument. In the write
|
||||
* call 'convert_to_8bit' allows 16-bit data to be squashed down to
|
||||
@@ -105,7 +105,7 @@ int main(int argc, const char **argv)
|
||||
* to the 8-bit format.
|
||||
*/
|
||||
if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/,
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/))
|
||||
buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)
|
||||
{
|
||||
/* The image has been written successfully. */
|
||||
exit(0);
|
||||
@@ -188,13 +188,13 @@ int main(int argc, const char **argv)
|
||||
*
|
||||
* Don't repeatedly convert between the 8-bit and 16-bit forms. There is
|
||||
* significant data loss when 16-bit data is converted to the 8-bit encoding and
|
||||
* the current libpng implementation of convertion to 16-bit is also
|
||||
* the current libpng implementation of conversion to 16-bit is also
|
||||
* significantly lossy. The latter will be fixed in the future, but the former
|
||||
* is unavoidable - the 8-bit format just doesn't have enough resolution.
|
||||
*/
|
||||
|
||||
/* If your program needs more information from the PNG data it reads, or if you
|
||||
* need to do more complex transformations, or minimise transformations, on the
|
||||
* need to do more complex transformations, or minimize transformations, on the
|
||||
* data you read, then you must use one of the several lower level libpng
|
||||
* interfaces.
|
||||
*
|
||||
@@ -271,7 +271,7 @@ void read_png(char *file_name) /* We need to open the file */
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
unsigned int sig_read = 0;
|
||||
int sig_read = 0;
|
||||
png_uint_32 width, height;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
FILE *fp;
|
||||
@@ -280,7 +280,7 @@ void read_png(char *file_name) /* We need to open the file */
|
||||
return (ERROR);
|
||||
|
||||
#else no_open_file /* prototype 2 */
|
||||
void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
void read_png(FILE *fp, int sig_read) /* File is already open */
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
@@ -370,7 +370,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
* are mutually exclusive.
|
||||
*/
|
||||
|
||||
/* Tell libpng to strip 16 bit/color files down to 8 bits/color.
|
||||
/* Tell libpng to strip 16 bits/color files down to 8 bits/color.
|
||||
* Use accurate scaling if it's available, otherwise just chop off the
|
||||
* low byte.
|
||||
*/
|
||||
@@ -405,7 +405,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
/* Expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)
|
||||
png_set_tRNS_to_alpha(png_ptr);
|
||||
|
||||
/* Set the background color to draw transparent and alpha images over.
|
||||
@@ -417,7 +417,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
|
||||
png_color_16 my_background, *image_background;
|
||||
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &image_background))
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0)
|
||||
png_set_background(png_ptr, image_background,
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
else
|
||||
@@ -441,9 +441,9 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
/* If we don't have another value */
|
||||
else
|
||||
{
|
||||
screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly
|
||||
lit room */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
screen_gamma = PNG_DEFAULT_sRGB; /* A good guess for a PC monitor
|
||||
in a dimly lit room */
|
||||
screen_gamma = PNG_GAMMA_MAC_18 or 1.0; /* Good guesses for Mac systems */
|
||||
}
|
||||
|
||||
/* Tell libpng to handle the gamma conversion for you. The final call
|
||||
@@ -454,22 +454,22 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent) != 0)
|
||||
png_set_gamma(png_ptr, screen_gamma, PNG_DEFAULT_sRGB);
|
||||
else
|
||||
{
|
||||
double image_gamma;
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma) != 0)
|
||||
png_set_gamma(png_ptr, screen_gamma, image_gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_QUANTIZE_SUPPORTED
|
||||
/* Quantize RGB files down to 8 bit palette or reduce palettes
|
||||
/* Quantize RGB files down to 8-bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
*/
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
int num_palette;
|
||||
png_colorp palette;
|
||||
@@ -484,7 +484,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
MAX_SCREEN_COLORS, NULL, 0);
|
||||
}
|
||||
/* This reduces the image to the palette supplied in the file */
|
||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
|
||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) != 0)
|
||||
{
|
||||
png_uint_16p histogram = NULL;
|
||||
|
||||
@@ -494,7 +494,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
max_screen_colors, histogram, 0);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_QUANTIZE_SUPPORTED */
|
||||
#endif /* READ_QUANTIZE */
|
||||
|
||||
/* Invert monochrome files to have 0 as white and 1 as black */
|
||||
png_set_invert_mono(png_ptr);
|
||||
@@ -503,7 +503,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
* [0,65535] to the original [0,7] or [0,31], or whatever range the
|
||||
* colors were originally in:
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT) != 0)
|
||||
{
|
||||
png_color_8p sig_bit_p;
|
||||
|
||||
@@ -512,19 +512,19 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
}
|
||||
|
||||
/* Flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||
png_set_swap_alpha(png_ptr);
|
||||
|
||||
/* Swap bytes of 16 bit files to least significant byte first */
|
||||
/* Swap bytes of 16-bit files to least significant byte first */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* Add filler (or alpha) byte (before/after each RGB triplet) */
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
#ifdef PNG_READ_DEINTERLACE_SUPPORTED
|
||||
/* Turn on interlace handling. REQUIRED if you are not using
|
||||
* png_read_image(). To see how to handle interlacing passes,
|
||||
* see the png_read_row() method below:
|
||||
@@ -532,7 +532,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
#else
|
||||
number_passes = 1;
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_DEINTERLACE */
|
||||
|
||||
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
@@ -715,7 +715,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
*/
|
||||
png_bytep old_row = ((png_bytep *)our_data)[row_num];
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
#ifdef PNG_READ_DEINTERLACE_SUPPORTED
|
||||
/* If both rows are allocated then copy the new row
|
||||
* data to the corresponding row data.
|
||||
*/
|
||||
@@ -744,7 +744,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
* to pass the current row as new_row, and the function will combine
|
||||
* the old row and the new row.
|
||||
*/
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_DEINTERLACE */
|
||||
}
|
||||
|
||||
end_callback(png_structp png_ptr, png_infop info)
|
||||
@@ -932,7 +932,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
*/
|
||||
|
||||
/* Once we write out the header, the compression type on the text
|
||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* chunk gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||
* at the end.
|
||||
*/
|
||||
@@ -966,11 +966,11 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
/* Swap bytes of 16-bit files to most significant byte first */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* Swap bits of 1, 2, 4 bit packed pixel formats */
|
||||
/* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */
|
||||
png_set_packswap(png_ptr);
|
||||
|
||||
/* Turn on interlace handling if you are not using png_write_image() */
|
||||
if (interlacing)
|
||||
if (interlacing != 0)
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
else
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
16
libpngpf.3
16
libpngpf.3
@@ -1,21 +1,11 @@
|
||||
.TH LIBPNGPF 3 "December 10, 2012"
|
||||
.TH LIBPNGPF 3 "September 16, 2015"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.6.0beta33
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.7.0beta65
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
\fB#include \fI"pngpriv.h"
|
||||
|
||||
\fI\fB
|
||||
|
||||
\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now \fIthat
|
||||
|
||||
\fBthe private function prototypes are hidden in pngpriv.h and not \fIaccessible
|
||||
|
||||
\fBto applications. Look in pngpriv.h for the prototypes and a short \fIdescription
|
||||
|
||||
\fBof each \fIfunction.
|
||||
|
||||
\fI\fB
|
||||
\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now that the private function prototypes are hidden in pngpriv.h and not accessible to applications. Look in pngpriv.h for the prototypes and a short description of each \fIfunction.
|
||||
|
||||
.SH DESCRIPTION
|
||||
The functions previously listed here are used privately by libpng and are not
|
||||
|
||||
9
png.5
9
png.5
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "December 10, 2012"
|
||||
.TH PNG 5 "September 16, 2015"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
@@ -24,10 +24,11 @@ PNG specification (second edition), November 2003:
|
||||
.IP
|
||||
.br
|
||||
<http://www.w3.org/TR/2003/REC-PNG-20031110/
|
||||
.LP
|
||||
PNG 1.2 specification, July 1999:
|
||||
.IP
|
||||
.br
|
||||
http://www.libpng.org/pub/png
|
||||
http://png-mng.sourceforge.net/pub/png/spec/1.2/
|
||||
.LP
|
||||
PNG 1.0 specification, October 1996:
|
||||
.IP
|
||||
@@ -39,7 +40,7 @@ ftp://ds.internic.net/rfc/rfc2083.txt
|
||||
.br
|
||||
or (as a W3C Recommendation) at
|
||||
.br
|
||||
http://www.w3.org/TR/REC-png.html
|
||||
http://www.w3.org/TR/REC-png-961001
|
||||
.SH AUTHORS
|
||||
This man page: Glenn Randers-Pehrson
|
||||
.LP
|
||||
@@ -58,7 +59,7 @@ Thomas Boutell and others (png-list).
|
||||
|
||||
.SH COPYRIGHT NOTICE
|
||||
.LP
|
||||
This man page is Copyright (c) 1998-2006 Glenn Randers-Pehrson. See png.h
|
||||
This man page is Copyright (c) 1998-2012 Glenn Randers-Pehrson. See png.h
|
||||
for conditions of use and distribution.
|
||||
.LP
|
||||
The PNG Specification (Second Edition) is
|
||||
|
||||
47
pngchunk.h
Normal file
47
pngchunk.h
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
/* pngchunk.h - PNG chunk descriptions
|
||||
*
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 2015 Glenn Randers-Pehrson
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
* If this list is changed in any way scripts/chunkhash.c must be rebuilt and
|
||||
* run to regenerate the lookup functions for the tables described from this
|
||||
* list.
|
||||
*
|
||||
* IDAT MUST be first in the list; it must have index '0'. The order of the
|
||||
* remaining chunks comes from section 5.6 "Chunk ordering" in the ISO spec
|
||||
* plus the ordering rules in the PNG extensions documnet.
|
||||
*
|
||||
* Keep PNG_CHUNK_BEGIN and PNG_CHUNK_END at the beginning and end.
|
||||
*/
|
||||
PNG_CHUNK_BEGIN(IDAT, 73, 68, 65, 84, within_IDAT, after_start)
|
||||
PNG_CHUNK( IHDR, 73, 72, 68, 82, before_start, at_start)
|
||||
PNG_CHUNK( cHRM, 99, 72, 82, 77, before_PLTE, after_start)
|
||||
PNG_CHUNK( gAMA, 103, 65, 77, 65, before_PLTE, after_start)
|
||||
PNG_CHUNK( iCCP, 105, 67, 67, 80, before_PLTE, after_start)
|
||||
PNG_CHUNK( sBIT, 115, 66, 73, 84, before_PLTE, after_start)
|
||||
PNG_CHUNK( sRGB, 115, 82, 71, 66, before_PLTE, after_start)
|
||||
PNG_CHUNK( PLTE, 80, 76, 84, 69, before_PLTE, after_start)
|
||||
PNG_CHUNK( bKGD, 98, 75, 71, 68, before_IDAT, after_PLTE)
|
||||
PNG_CHUNK( hIST, 104, 73, 83, 84, before_IDAT, after_PLTE)
|
||||
PNG_CHUNK( tRNS, 116, 82, 78, 83, before_IDAT, after_PLTE)
|
||||
PNG_CHUNK( oFFs, 111, 70, 70, 115, before_IDAT, after_start)
|
||||
PNG_CHUNK( pCAL, 112, 67, 65, 76, before_IDAT, after_start)
|
||||
PNG_CHUNK( sCAL, 115, 67, 65, 76, before_IDAT, after_start)
|
||||
PNG_CHUNK( sTER, 115, 84, 69, 82, before_IDAT, after_start)
|
||||
PNG_CHUNK( pHYs, 112, 72, 89, 115, before_IDAT, after_start)
|
||||
PNG_CHUNK( sPLT, 115, 80, 76, 84, before_IDAT, after_start)
|
||||
PNG_CHUNK( tIME, 116, 73, 77, 69, before_end, after_start)
|
||||
PNG_CHUNK( iTXt, 105, 84, 88, 116, before_end, after_start)
|
||||
PNG_CHUNK( tEXt, 116, 69, 88, 116, before_end, after_start)
|
||||
PNG_CHUNK( zTXt, 122, 84, 88, 116, before_end, after_start)
|
||||
PNG_CHUNK( fRAc, 102, 82, 65, 99, before_end, after_start)
|
||||
PNG_CHUNK( gIFg, 103, 73, 70, 103, before_end, after_start)
|
||||
PNG_CHUNK( gIFt, 103, 73, 70, 116, before_end, after_start)
|
||||
PNG_CHUNK( gIFx, 103, 73, 70, 120, before_end, after_start)
|
||||
PNG_CHUNK( dSIG, 100, 83, 73, 71, before_end, after_start)
|
||||
PNG_CHUNK_END( IEND, 73, 69, 78, 68, before_end, after_IDAT)
|
||||
111
pngconf.h
111
pngconf.h
@@ -1,9 +1,9 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng version 1.6.0beta33 - December 10, 2012
|
||||
* libpng version 1.7.0beta65, September 16, 2015
|
||||
*
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@@ -11,9 +11,7 @@
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
* Any machine specific code is near the front of this file, so if you
|
||||
* are configuring libpng for a machine, you may want to read the section
|
||||
* starting here down to where it starts to typedef png_color, png_text,
|
||||
* and png_info.
|
||||
@@ -22,26 +20,6 @@
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
/* To do: Do all of this in scripts/pnglibconf.dfa */
|
||||
#ifdef PNG_SAFE_LIMITS_SUPPORTED
|
||||
# ifdef PNG_USER_WIDTH_MAX
|
||||
# undef PNG_USER_WIDTH_MAX
|
||||
# define PNG_USER_WIDTH_MAX 1000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_HEIGHT_MAX
|
||||
# undef PNG_USER_HEIGHT_MAX
|
||||
# define PNG_USER_HEIGHT_MAX 1000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_CHUNK_MALLOC_MAX
|
||||
# undef PNG_USER_CHUNK_MALLOC_MAX
|
||||
# define PNG_USER_CHUNK_MALLOC_MAX 4000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_CHUNK_CACHE_MAX
|
||||
# undef PNG_USER_CHUNK_CACHE_MAX
|
||||
# define PNG_USER_CHUNK_CACHE_MAX 128
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */
|
||||
|
||||
/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C
|
||||
@@ -198,18 +176,16 @@
|
||||
* ==========================
|
||||
* This code is used at build time to find PNG_IMPEXP, the API settings
|
||||
* and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
|
||||
* import processing is possible. On Windows/x86 systems it also sets
|
||||
* import processing is possible. On Windows systems it also sets
|
||||
* compiler-specific macros to the values required to change the calling
|
||||
* conventions of the various functions.
|
||||
*/
|
||||
#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
|
||||
defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\
|
||||
( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\
|
||||
defined(_M_X64) || defined(_M_IA64) )
|
||||
/* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes
|
||||
* builds under Cygwin or MinGW. Also includes Watcom builds but these need
|
||||
* special treatment because they are not compatible with GCC or Visual C
|
||||
* because of different calling conventions.
|
||||
#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
|
||||
defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
|
||||
/* Windows system (DOS doesn't support DLLs). Includes builds under Cygwin or
|
||||
* MinGW on any architecture currently supported by Windows. Also includes
|
||||
* Watcom builds but these need special treatment because they are not
|
||||
* compatible with GCC or Visual C because of different calling conventions.
|
||||
*/
|
||||
# if PNG_API_RULE == 2
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
@@ -220,9 +196,12 @@
|
||||
# define PNGCAPI __watcall
|
||||
# endif
|
||||
|
||||
# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
|
||||
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
|
||||
# define PNGCAPI __cdecl
|
||||
# if PNG_API_RULE == 1
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
# define PNGAPI __stdcall
|
||||
# endif
|
||||
# else
|
||||
@@ -237,6 +216,7 @@
|
||||
# define PNGAPI _stdcall
|
||||
# endif
|
||||
# endif /* compiler/api */
|
||||
|
||||
/* NOTE: PNGCBAPI always defaults to PNGCAPI. */
|
||||
|
||||
# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
|
||||
@@ -260,7 +240,7 @@
|
||||
# endif
|
||||
# endif /* compiler */
|
||||
|
||||
#else /* !Windows/x86 */
|
||||
#else /* !Windows */
|
||||
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
|
||||
# define PNGAPI _System
|
||||
# else /* !Windows/x86 && !OS/2 */
|
||||
@@ -359,7 +339,33 @@
|
||||
* version 1.2.41. Disabling these removes the warnings but may also produce
|
||||
* less efficient code.
|
||||
*/
|
||||
# if defined(__GNUC__)
|
||||
# if defined(__clang__) && defined(__has_attribute)
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
|
||||
# define PNG_NORETURN __attribute__((__noreturn__))
|
||||
# endif
|
||||
# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)
|
||||
# define PNG_ALLOCATED __attribute__((__malloc__))
|
||||
# endif
|
||||
# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
|
||||
# define PNG_DEPRECATED __attribute__((__deprecated__))
|
||||
# endif
|
||||
# if !defined(PNG_PRIVATE)
|
||||
# ifdef __has_extension
|
||||
# if __has_extension(attribute_unavailable_with_message)
|
||||
# define PNG_PRIVATE __attribute__((__unavailable__(\
|
||||
"This function is not exported by libpng.")))
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
|
||||
# elif defined(__GNUC__)
|
||||
# ifndef PNG_USE_RESULT
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
@@ -382,12 +388,12 @@
|
||||
__attribute__((__deprecated__))
|
||||
# endif
|
||||
# endif
|
||||
# if ((__GNUC__ != 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* __GNUC__ == 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
# ifndef PNG_USE_RESULT
|
||||
@@ -417,7 +423,7 @@
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* _MSC_VER */
|
||||
# endif
|
||||
#endif /* PNG_PEDANTIC_WARNINGS */
|
||||
|
||||
#ifndef PNG_DEPRECATED
|
||||
@@ -438,6 +444,15 @@
|
||||
#ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT /* The C99 "restrict" feature */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_FP_EXPORT /* A floating point API. */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
PNG_EXPORT(ordinal, type, name, args);
|
||||
# else /* No floating point APIs */
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef PNG_FP_EXPORT /* A floating point API. */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
@@ -510,6 +525,8 @@
|
||||
|
||||
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,
|
||||
* requires an ISOC90 compiler and relies on consistent behavior of sizeof.
|
||||
*
|
||||
* DEPRECATED: don't use these types, instead use size_t and ptrdiff_t.
|
||||
*/
|
||||
typedef size_t png_size_t;
|
||||
typedef ptrdiff_t png_ptrdiff_t;
|
||||
@@ -530,13 +547,13 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no
|
||||
* smaller than png_uint_32. Casts from png_size_t or png_uint_32 to
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than size_t, and no
|
||||
* smaller than png_uint_32. Casts from size_t or png_uint_32 to
|
||||
* png_alloc_size_t are not necessary; in fact, it is recommended not to use
|
||||
* them at all so that the compiler can complain when something turns out to be
|
||||
* problematic.
|
||||
*
|
||||
* Casts in the other direction (from png_alloc_size_t to png_size_t or
|
||||
* Casts in the other direction (from png_alloc_size_t to size_t or
|
||||
* png_uint_32) should be explicitly applied; however, we do not expect to
|
||||
* encounter practical situations that require such conversions.
|
||||
*
|
||||
@@ -546,7 +563,7 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
#ifdef PNG_SMALL_SIZE_T
|
||||
typedef png_uint_32 png_alloc_size_t;
|
||||
#else
|
||||
typedef png_size_t png_alloc_size_t;
|
||||
typedef size_t png_alloc_size_t;
|
||||
#endif
|
||||
|
||||
/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
|
||||
@@ -582,8 +599,8 @@ typedef char * png_charp;
|
||||
typedef const char * png_const_charp;
|
||||
typedef png_fixed_point * png_fixed_point_p;
|
||||
typedef const png_fixed_point * png_const_fixed_point_p;
|
||||
typedef png_size_t * png_size_tp;
|
||||
typedef const png_size_t * png_const_size_tp;
|
||||
typedef size_t * png_size_tp;
|
||||
typedef const size_t * png_const_size_tp;
|
||||
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
typedef FILE * png_FILE_p;
|
||||
|
||||
28
pngdebug.h
28
pngdebug.h
@@ -1,12 +1,11 @@
|
||||
|
||||
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
|
||||
*
|
||||
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.8 [December 19, 2013]
|
||||
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* Last changed in libpng 1.5.0 [January 6, 2011]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
@@ -25,7 +24,7 @@
|
||||
* (actually ((void)0)).
|
||||
*
|
||||
* level: level of detail of message, starting at 0. A level 'n'
|
||||
* message is preceded by 'n' tab characters (not implemented
|
||||
* message is preceded by 'n' 3-space indentations (not implemented
|
||||
* on Microsoft compilers unless PNG_DEBUG_FILE is also
|
||||
* defined, to allow debug DLL compilation with no standard IO).
|
||||
* message: a printf(3) style text string. A trailing '\n' is added
|
||||
@@ -37,13 +36,13 @@
|
||||
/* These settings control the formatting of messages in png.c and pngerror.c */
|
||||
/* Moved to pngdebug.h at 1.5.0 */
|
||||
# ifndef PNG_LITERAL_SHARP
|
||||
# define PNG_LITERAL_SHARP 0x23
|
||||
# define PNG_LITERAL_SHARP 0x23U
|
||||
# endif
|
||||
# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
|
||||
# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
|
||||
# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5bU
|
||||
# endif
|
||||
# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
|
||||
# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
|
||||
# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5dU
|
||||
# endif
|
||||
# ifndef PNG_STRING_NEWLINE
|
||||
# define PNG_STRING_NEWLINE "\n"
|
||||
@@ -77,32 +76,29 @@
|
||||
# endif /* PNG_DEBUG_FILE */
|
||||
|
||||
# if (PNG_DEBUG > 1)
|
||||
/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
|
||||
* non-ISO compilers
|
||||
*/
|
||||
# ifdef __STDC__
|
||||
# ifndef png_debug
|
||||
# define png_debug(l,m) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug1
|
||||
# define png_debug1(l,m,p1) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug2
|
||||
# define png_debug2(l,m,p1,p2) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
|
||||
} while (0)
|
||||
# endif
|
||||
# else /* __STDC __ */
|
||||
|
||||
436
pngerror.c
436
pngerror.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "pngpriv.h"
|
||||
#define PNG_SRC_FILE PNG_SRC_FILE_pngerror
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
|
||||
@@ -27,7 +28,7 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
@@ -43,8 +44,8 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
char msg[16];
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
|
||||
{
|
||||
if (*error_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
@@ -54,7 +55,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
if (error_message[offset] == ' ')
|
||||
break;
|
||||
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < offset - 1; i++)
|
||||
@@ -69,7 +70,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
msg[0] = '0';
|
||||
msg[1] = '\0';
|
||||
@@ -103,7 +104,7 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
|
||||
use the default handler, which will not return. */
|
||||
png_default_error(png_ptr, "");
|
||||
}
|
||||
#endif /* PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* ERROR_TEXT */
|
||||
|
||||
/* Utility to safely appends strings to a buffer. This never errors out so
|
||||
* error checking is not required in the caller.
|
||||
@@ -129,6 +130,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
* and end pointer (which should point just *beyond* the end of the buffer!)
|
||||
* Returns the pointer to the start of the formatted string.
|
||||
*/
|
||||
#define PNG_HAVE_FORMAT_NUMBER /* for the code below */
|
||||
png_charp
|
||||
png_format_number(png_const_charp start, png_charp end, int format,
|
||||
png_alloc_size_t number)
|
||||
@@ -152,7 +154,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
case PNG_NUMBER_FORMAT_fixed:
|
||||
/* Needs five digits (the fraction) */
|
||||
mincount = 5;
|
||||
if (output || number % 10 != 0)
|
||||
if (output != 0 || number % 10 != 0)
|
||||
{
|
||||
*--end = digits[number % 10];
|
||||
output = 1;
|
||||
@@ -189,13 +191,13 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
++count;
|
||||
|
||||
/* Float a fixed number here: */
|
||||
if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
|
||||
if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
|
||||
{
|
||||
/* End of the fraction, but maybe nothing was output? In that case
|
||||
* drop the decimal point. If the number is a true zero handle that
|
||||
* here.
|
||||
*/
|
||||
if (output)
|
||||
if (output != 0)
|
||||
*--end = '.';
|
||||
else if (number == 0) /* and !output */
|
||||
*--end = '0';
|
||||
@@ -219,8 +221,8 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
|
||||
#endif
|
||||
{
|
||||
if (*warning_message == PNG_LITERAL_SHARP)
|
||||
@@ -355,17 +357,16 @@ png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
*/
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
{
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
|
||||
png_ptr->chunk_name != 0)
|
||||
if (png_ptr->read_struct && png_ptr->chunk_name != 0)
|
||||
png_chunk_warning(png_ptr, error_message);
|
||||
else
|
||||
# endif
|
||||
@@ -375,39 +376,57 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
else
|
||||
{
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
|
||||
png_ptr->chunk_name != 0)
|
||||
if (png_ptr->read_struct && png_ptr->chunk_name != 0)
|
||||
png_chunk_error(png_ptr, error_message);
|
||||
else
|
||||
# endif
|
||||
png_error(png_ptr, error_message);
|
||||
}
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
#endif /* BENIGN_ERRORS */
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || \
|
||||
(defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
|
||||
/* These utilities are used internally to build an error message that relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name unless
|
||||
* png_ptr->zowner is set in which case that is used in preference. This is
|
||||
* used to prefix the message. The message is limited in length to 63 bytes.
|
||||
* The name characters are output as hex digits wrapped in [] if the character
|
||||
* is invalid.
|
||||
*
|
||||
* Using 'zowner' means that IDAT errors at the end of the IDAT stream are still
|
||||
* reported as from the IDAT chunks.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
static PNG_CONST char png_digit[16] = {
|
||||
@@ -415,21 +434,22 @@ static PNG_CONST char png_digit[16] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
static void /* PRIVATE */
|
||||
png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
error_message)
|
||||
{
|
||||
png_uint_32 chunk_name = png_ptr->chunk_name;
|
||||
png_uint_32 chunk_name = png_ptr->zowner;
|
||||
int iout = 0, ishift = 24;
|
||||
|
||||
if (chunk_name == 0)
|
||||
chunk_name = png_ptr->chunk_name;
|
||||
|
||||
while (ishift >= 0)
|
||||
{
|
||||
int c = (int)(chunk_name >> ishift) & 0xff;
|
||||
|
||||
ishift -= 8;
|
||||
if (isnonalpha(c))
|
||||
if (isnonalpha(c) != 0)
|
||||
{
|
||||
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
@@ -439,7 +459,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
|
||||
else
|
||||
{
|
||||
buffer[iout++] = (char)c;
|
||||
buffer[iout++] = png_check_char(png_ptr, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -460,7 +480,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
buffer[iout] = '\0';
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* WARNINGS || ERROR_TEXT */
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
@@ -477,7 +497,7 @@ png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* READ && ERROR_TEXT */
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void PNGAPI
|
||||
@@ -493,7 +513,7 @@ png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
@@ -501,23 +521,28 @@ void PNGAPI
|
||||
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
|
||||
error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
png_chunk_warning(png_ptr, error_message);
|
||||
|
||||
else
|
||||
png_chunk_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
(png_chunk_report)(png_const_structrp png_ptr, png_const_charp message,
|
||||
int error)
|
||||
{
|
||||
/* This is always supported, but for just read or just write it
|
||||
* unconditionally does the right thing.
|
||||
*/
|
||||
# if (defined PNG_READ_SUPPORTED) && (defined PNG_WRITE_SUPPORTED)
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
if (png_ptr->read_struct)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
@@ -525,13 +550,16 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
if (error < PNG_CHUNK_ERROR)
|
||||
png_chunk_warning(png_ptr, message);
|
||||
|
||||
else
|
||||
else if (error < PNG_CHUNK_FATAL)
|
||||
png_chunk_benign_error(png_ptr, message);
|
||||
|
||||
else
|
||||
png_chunk_error(png_ptr, message);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if (defined PNG_READ_SUPPORTED) && (defined PNG_WRITE_SUPPORTED)
|
||||
else if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
else if (!png_ptr->read_struct)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
@@ -539,14 +567,27 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
if (error < PNG_CHUNK_WRITE_ERROR)
|
||||
png_app_warning(png_ptr, message);
|
||||
|
||||
else
|
||||
else if (error < PNG_CHUNK_FATAL)
|
||||
png_app_error(png_ptr, message);
|
||||
|
||||
else
|
||||
png_error(png_ptr, message);
|
||||
}
|
||||
# endif
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(message)
|
||||
# endif
|
||||
}
|
||||
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
||||
(defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \
|
||||
defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \
|
||||
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \
|
||||
(defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) &&\
|
||||
defined(PNG_sCAL_SUPPORTED))
|
||||
PNG_FUNCTION(void,
|
||||
png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
||||
{
|
||||
@@ -556,11 +597,12 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
||||
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
|
||||
memcpy(msg, fixed_message, fixed_message_ln);
|
||||
iin = 0;
|
||||
if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
if (name != NULL)
|
||||
while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
msg[fixed_message_ln + iin] = 0;
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
@@ -619,9 +661,9 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
|
||||
/* This is an internal error in libpng: somehow we have been left
|
||||
* with a stack allocated jmp_buf when the application regained
|
||||
* control. It's always possible to fix this up, but for the moment
|
||||
* this is a png_error because that makes it easy to detect.
|
||||
* this is an affirm because that makes it easy to detect.
|
||||
*/
|
||||
png_error(png_ptr, "Libpng jmp_buf still allocated");
|
||||
impossible("Libpng jmp_buf still allocated");
|
||||
/* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */
|
||||
}
|
||||
}
|
||||
@@ -736,12 +778,25 @@ PNG_FUNCTION(void,PNGAPI
|
||||
png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr)
|
||||
if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&
|
||||
png_ptr->jmp_buf_ptr != NULL)
|
||||
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(val)
|
||||
#endif
|
||||
|
||||
/* Here if not setjmp support or if png_ptr is null. */
|
||||
PNG_ABORT();
|
||||
/* If control reaches this point, png_longjmp() must not return. The only
|
||||
* choice is to terminate the whole process (or maybe the thread); to do
|
||||
* this the ANSI-C abort() function is used unless a different method is
|
||||
* implemented by overriding the default configuration setting for
|
||||
* PNG_ABORT (see scripts/pnglibconf.dfa).
|
||||
*
|
||||
* API change: prior to 1.7.0 PNG_ABORT was invoked as a function type macro
|
||||
* with no arguments 'PNG_ABORT();', in 1.7.0 this is changed to a simple
|
||||
* macro that is defined in the configuration.
|
||||
*/
|
||||
PNG_ABORT
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
@@ -793,7 +848,7 @@ png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
#endif
|
||||
PNG_UNUSED(png_ptr) /* Make compiler happy */
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
@@ -838,20 +893,20 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
png_ptr->flags &=
|
||||
((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
|
||||
((PNG_BIC_MASK(PNG_FLAG_STRIP_ERROR_NUMBERS |
|
||||
PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
|
||||
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
|
||||
#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\
|
||||
defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)
|
||||
/* Currently the above both depend on SETJMP_SUPPORTED, however it would be
|
||||
* possible to implement without setjmp support just so long as there is some
|
||||
* way to handle the error return here:
|
||||
*/
|
||||
PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
|
||||
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
@@ -886,7 +941,7 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
void /* PRIVATE */ PNGCBAPI
|
||||
png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
@@ -913,7 +968,7 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
saved_error_buf = image->opaque->error_buf;
|
||||
result = setjmp(safe_jmpbuf) == 0;
|
||||
|
||||
if (result)
|
||||
if (result != 0)
|
||||
{
|
||||
|
||||
image->opaque->error_buf = safe_jmpbuf;
|
||||
@@ -923,10 +978,263 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
image->opaque->error_buf = saved_error_buf;
|
||||
|
||||
/* And do the cleanup prior to any failure return. */
|
||||
if (!result)
|
||||
if (result == 0)
|
||||
png_image_free(image);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* SIMPLIFIED READ/WRITE */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */
|
||||
|
||||
/* Affirms: minimal code in 'STABLE' builds to return control to the
|
||||
* application via png_error(), more verbose code followed by PNG_ABORT for
|
||||
* all other builds to ensure that internal errors are detected.
|
||||
*
|
||||
* The code always produces a message if it is possible, regardless of the
|
||||
* setting of PNG_ERROR_TEXT_SUPPORTED, except that in stable builds
|
||||
* PNG_ERROR_TEXT_SUPPORTED is honored. See pngpriv.h for the calculation of
|
||||
* the two control macros PNG_RELEASE_BUILD (don't abort; stable build or rc)
|
||||
* and PNG_AFFIRM_TEXT (output text.)
|
||||
*/
|
||||
#if PNG_AFFIRM_TEXT
|
||||
# ifdef PNG_HAVE_FORMAT_NUMBER
|
||||
static size_t
|
||||
png_affirm_number(png_charp buffer, size_t bufsize, size_t pos,
|
||||
unsigned int number, int format)
|
||||
{
|
||||
char numbuf[PNG_NUMBER_BUFFER_SIZE];
|
||||
return png_safecat(buffer, bufsize, pos,
|
||||
png_format_number(numbuf, numbuf + sizeof numbuf, format, number));
|
||||
}
|
||||
# define affirm_number(a,b,c,d,e) png_affirm_number(a,b,c,d,e)
|
||||
# else /* !HAVE_FORMAT_NUMBER */
|
||||
static size_t
|
||||
png_affirm_number(png_charp buffer, size_t bufsize, size_t pos,
|
||||
unsigned int number)
|
||||
{
|
||||
/* binhex it; highly non-portable, assumes the ASCII character set, but
|
||||
* if warnings are turned off then it is unlikely the text will get read
|
||||
* anyway. This binhex variant is (48+val), where 'val' is the next 6
|
||||
* bits of the number, so it starts as '0' (for 0) and ends at 'I' for
|
||||
* 63. The number is wrapped in {}, so 0 comes out as '{}' and 9 comes
|
||||
* out as '{9}' and so on.
|
||||
*/
|
||||
char numbuf[32];
|
||||
int i = sizeof numbuf;
|
||||
|
||||
numbuf[--i] = 0;
|
||||
numbuf[--i] = '}';
|
||||
|
||||
do
|
||||
{
|
||||
if (number > 0)
|
||||
numbuf[--i] = (char)/*SAFE*/((number & 63) + 48), number >>= 6;
|
||||
else
|
||||
{
|
||||
numbuf[--i] = '{';
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (i > 0);
|
||||
|
||||
return png_safecat(buffer, bufsize, pos, numbuf+i);
|
||||
}
|
||||
# define affirm_number(a,b,c,d,e) png_affirm_number(a,b,c,d)
|
||||
#endif /* !HAVE_FORMAT_NUMBER */
|
||||
|
||||
static void
|
||||
affirm_text(png_charp buffer, size_t bufsize,
|
||||
param_deb(png_const_charp condition) unsigned int position)
|
||||
{
|
||||
/* Format the 'position' number and output:
|
||||
*
|
||||
* "<file> <line>: affirm 'condition' failed\n"
|
||||
* " libpng version <version> - <date>\n"
|
||||
* " translated __DATE__ __TIME__"
|
||||
*
|
||||
* In the STABLE versions the output is the same for the last two lines
|
||||
* but the first line becomes:
|
||||
*
|
||||
* "<position>: affirm failed"
|
||||
*
|
||||
* If there is no number formatting the numbers just get replaced by
|
||||
* some binhex (see the utility above).
|
||||
*/
|
||||
size_t pos = 0;
|
||||
|
||||
# if PNG_RELEASE_BUILD /* no 'condition' parameter: minimal text */
|
||||
pos = affirm_number(buffer, bufsize, pos, position, PNG_NUMBER_FORMAT_x);
|
||||
pos = png_safecat(buffer, bufsize, pos, ": affirm failed");
|
||||
# else /* !STABLE */
|
||||
/* Break down 'position' into a file name and a line number: */
|
||||
{
|
||||
# define PNG_apply(f) { #f "\0", PNG_SRC_FILE_ ## f },
|
||||
# define PNG_end { "", PNG_SRC_FILE_LAST }
|
||||
static struct {
|
||||
char filename[28]; /* GCC checks this size */
|
||||
unsigned int base;
|
||||
} fileinfo[] = { PNG_FILES };
|
||||
# undef PNG_apply
|
||||
# undef PNG_end
|
||||
|
||||
unsigned int i;
|
||||
png_const_charp filename;
|
||||
|
||||
/* Do 'nfiles' this way to avoid problems with g++ where it whines
|
||||
* about (size_t) being larger than (int), even though this is a
|
||||
* compile time constant:
|
||||
*/
|
||||
# define nfiles ((sizeof fileinfo)/(sizeof (fileinfo[0])))
|
||||
for (i=0; i < nfiles && position > fileinfo[i].base; ++i) {}
|
||||
|
||||
if (i == 0 || i > nfiles)
|
||||
filename = "UNKNOWN";
|
||||
else
|
||||
{
|
||||
filename = fileinfo[i-1].filename;
|
||||
position -= fileinfo[i-1].base;
|
||||
}
|
||||
# undef nfiles
|
||||
|
||||
pos = png_safecat(buffer, bufsize, pos, filename);
|
||||
pos = png_safecat(buffer, bufsize, pos, ".c ");
|
||||
pos = affirm_number(buffer, bufsize, pos, position,
|
||||
PNG_NUMBER_FORMAT_u);
|
||||
}
|
||||
|
||||
pos = png_safecat(buffer, bufsize, pos, ": affirm '");
|
||||
pos = png_safecat(buffer, bufsize, pos, condition);
|
||||
pos = png_safecat(buffer, bufsize, pos, "' failed\n");
|
||||
# endif /* !STABLE */
|
||||
|
||||
pos = png_safecat(buffer, bufsize, pos, PNG_HEADER_VERSION_STRING);
|
||||
pos = png_safecat(buffer, bufsize, pos,
|
||||
" translated " __DATE__ " " __TIME__);
|
||||
}
|
||||
|
||||
#define affirm_text(b, c, p)\
|
||||
do {\
|
||||
(affirm_text)(b, sizeof b, param_deb(c) (p));\
|
||||
} while (0)
|
||||
|
||||
#endif /* AFFIRM_TEXT */
|
||||
|
||||
PNG_FUNCTION(void,png_affirm,(png_const_structrp png_ptr,
|
||||
param_deb(png_const_charp condition) unsigned int position),PNG_NORETURN)
|
||||
{
|
||||
# if PNG_AFFIRM_TEXT
|
||||
char buffer[512];
|
||||
|
||||
affirm_text(buffer, condition, position);
|
||||
# else /* !AFFIRM_TEXT */
|
||||
PNG_UNUSED(position)
|
||||
# if !PNG_RELEASE_BUILD
|
||||
PNG_UNUSED(condition)
|
||||
# endif
|
||||
# endif /* AFFIRM_TEXT */
|
||||
|
||||
/* Now in STABLE do a png_error, but in other builds output the message
|
||||
* (if possible) then abort (PNG_ABORT).
|
||||
*/
|
||||
# if PNG_RELEASE_BUILD
|
||||
png_error(png_ptr, buffer/*macro parameter used only if ERROR_TEXT*/);
|
||||
# else /* !AFFIRM_ERROR */
|
||||
/* Use console IO if possible; this is because there is no guarantee that
|
||||
* the app 'warning' will output anything. For certain the simplified
|
||||
* API implementation just copies the message (truncated) to the image
|
||||
* message buffer, which makes debugging much more difficult.
|
||||
*
|
||||
* Note that it is possible that neither WARNINGS nor CONSOLE_IO are
|
||||
* supported; in that case no text will be output (and PNG_AFFIRM_TEXT
|
||||
* will be false.)
|
||||
*/
|
||||
# ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
PNG_UNUSED(png_ptr)
|
||||
# elif defined PNG_WARNINGS_SUPPORTED
|
||||
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
|
||||
png_ptr->warning_fn(png_constcast(png_structrp, png_ptr), buffer);
|
||||
/* else no way to output the text */
|
||||
# else
|
||||
PNG_UNUSED(png_ptr)
|
||||
# endif
|
||||
|
||||
PNG_ABORT
|
||||
# endif /* AFFIRM_ERROR */
|
||||
}
|
||||
|
||||
#ifdef PNG_RANGE_CHECK_SUPPORTED
|
||||
/* The character/byte checking APIs. These do their own calls to png_affirm
|
||||
* because the caller provides the position.
|
||||
*/
|
||||
unsigned int /* PRIVATE */
|
||||
png_bit_affirm(png_const_structrp png_ptr, unsigned int position,
|
||||
unsigned int u, unsigned int bits)
|
||||
{
|
||||
/* The following avoids overflow errors even if 'bits' is 16 or 32: */
|
||||
if (u <= (1U << bits)-1U)
|
||||
return u;
|
||||
|
||||
png_affirm(png_ptr, param_deb("(bit field) range") position);
|
||||
}
|
||||
|
||||
char /* PRIVATE */
|
||||
png_char_affirm(png_const_structrp png_ptr, unsigned int position, int c)
|
||||
{
|
||||
if (c >= CHAR_MIN && c <= CHAR_MAX)
|
||||
return (char)/*SAFE*/c;
|
||||
|
||||
png_affirm(png_ptr, param_deb("(char) range") position);
|
||||
}
|
||||
|
||||
png_byte /* PRIVATE */
|
||||
png_byte_affirm(png_const_structrp png_ptr, unsigned int position, int b)
|
||||
{
|
||||
/* For the type png_byte the limits.h values are ignored and we check
|
||||
* against the values PNG expects to store in a byte:
|
||||
*/
|
||||
if (b >= 0 && b <= 255)
|
||||
return (png_byte)/*SAFE*/b;
|
||||
|
||||
png_affirm(png_ptr, param_deb("PNG byte range") position);
|
||||
}
|
||||
|
||||
#if INT_MAX >= 65535
|
||||
png_uint_16 /* PRIVATE */
|
||||
png_u16_affirm(png_const_structrp png_ptr, unsigned int position, int b)
|
||||
{
|
||||
/* Check against the PNG 16-bit limit, as with png_byte. */
|
||||
if (b >= 0 && b <= 65535)
|
||||
return (png_uint_16)/*SAFE*/b;
|
||||
|
||||
png_affirm(png_ptr, param_deb("PNG 16-bit range") position);
|
||||
}
|
||||
#endif /* INT_MAX >= 65535 */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_handled_affirm(png_const_structrp png_ptr, png_const_charp message,
|
||||
unsigned int position)
|
||||
{
|
||||
# if PNG_RELEASE_BUILD
|
||||
/* testing in RC: we want to return control to the caller, so do not
|
||||
* use png_affirm.
|
||||
*/
|
||||
char buffer[512];
|
||||
|
||||
affirm_text(buffer, message, position);
|
||||
|
||||
# ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
fprintf(stderr, "%s\n", buffer);
|
||||
# elif defined PNG_WARNINGS_SUPPORTED
|
||||
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
|
||||
png_ptr->warning_fn(png_constcast(png_structrp, png_ptr), buffer);
|
||||
/* else no way to output the text */
|
||||
# else
|
||||
PNG_UNUSED(png_ptr)
|
||||
# endif
|
||||
# else
|
||||
png_affirm(png_ptr, message, position);
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* RANGE_CHECK */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
290
pngget.c
290
pngget.c
@@ -1,8 +1,8 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2012 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.7.0 [(PENDING RELEASE)]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
|
||||
#include "pngpriv.h"
|
||||
#define PNG_SRC_FILE PNG_SRC_FILE_pngget
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
|
||||
@@ -26,16 +27,18 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_size_t PNGAPI
|
||||
png_alloc_size_t PNGAPI
|
||||
png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->rowbytes);
|
||||
return png_calc_rowbytes(png_ptr,
|
||||
PNG_FORMAT_CHANNELS(info_ptr->format) * info_ptr->bit_depth,
|
||||
info_ptr->width);
|
||||
|
||||
return(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||
#ifdef PNG_READ_PNG_SUPPORTED
|
||||
png_bytepp PNGAPI
|
||||
png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
@@ -79,7 +82,8 @@ png_byte PNGAPI
|
||||
png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return info_ptr->color_type;
|
||||
return png_check_byte(png_ptr,
|
||||
PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format));
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -116,7 +120,8 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_x_pixels_per_meter");
|
||||
@@ -124,6 +129,9 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -134,7 +142,8 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_y_pixels_per_meter");
|
||||
@@ -142,6 +151,9 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->y_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -151,7 +163,8 @@ png_uint_32 PNGAPI
|
||||
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
|
||||
|
||||
@@ -159,6 +172,9 @@ png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -170,7 +186,8 @@ png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
|
||||
|
||||
@@ -193,10 +210,11 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
|
||||
&& info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
|
||||
&& info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
|
||||
&& info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0 &&
|
||||
info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
|
||||
info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
|
||||
info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
{
|
||||
png_fixed_point res;
|
||||
|
||||
@@ -206,7 +224,7 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
* range of 0..2^31-1; otherwise the cast might overflow.
|
||||
*/
|
||||
if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
|
||||
(png_int_32)info_ptr->x_pixels_per_unit))
|
||||
(png_int_32)info_ptr->x_pixels_per_unit) != 0)
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
@@ -222,13 +240,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -238,13 +260,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -254,13 +280,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -270,13 +300,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@@ -286,7 +320,7 @@ png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
static png_uint_32
|
||||
ppi_from_ppm(png_uint_32 ppm)
|
||||
{
|
||||
#if 0
|
||||
#if 0 /*NOT USED*/
|
||||
/* The conversion is *(2.54/100), in binary (32 digits):
|
||||
* .00000110100000001001110101001001
|
||||
*/
|
||||
@@ -307,7 +341,7 @@ ppi_from_ppm(png_uint_32 ppm)
|
||||
*/
|
||||
png_fixed_point result;
|
||||
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
|
||||
5000))
|
||||
5000) != 0)
|
||||
return result;
|
||||
|
||||
/* Overflow. */
|
||||
@@ -335,14 +369,25 @@ png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
static png_fixed_point
|
||||
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
|
||||
png_fixed_inches_from_microns(png_const_structrp png_ptr,
|
||||
png_int_32 microns)
|
||||
{
|
||||
/* Convert from metres * 1,000,000 to inches * 100,000, meters to
|
||||
* inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
|
||||
* Notice that this can overflow - a warning is output and 0 is
|
||||
* returned.
|
||||
*/
|
||||
return png_muldiv_warn(png_ptr, microns, 500, 127);
|
||||
png_fixed_point result;
|
||||
|
||||
if (png_muldiv(&result, microns, 500, 127) != 0)
|
||||
return result;
|
||||
|
||||
/* TODO: review this, png_error might be better. */
|
||||
png_warning(png_ptr, "inch to microns overflow");
|
||||
return 0;
|
||||
# ifndef PNG_WARNINGS_SUPPORTED
|
||||
PNG_UNUSED(png_ptr)
|
||||
# endif
|
||||
}
|
||||
|
||||
png_fixed_point PNGAPI
|
||||
@@ -352,9 +397,7 @@ png_get_x_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
return png_fixed_inches_from_microns(png_ptr,
|
||||
png_get_x_offset_microns(png_ptr, info_ptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_fixed_point PNGAPI
|
||||
png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr)
|
||||
@@ -362,7 +405,7 @@ png_get_y_offset_inches_fixed(png_const_structrp png_ptr,
|
||||
return png_fixed_inches_from_microns(png_ptr,
|
||||
png_get_y_offset_microns(png_ptr, info_ptr));
|
||||
}
|
||||
#endif
|
||||
#endif /* FIXED_POINT */
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float PNGAPI
|
||||
@@ -393,7 +436,8 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
@@ -424,19 +468,19 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return (retval);
|
||||
}
|
||||
#endif /* PNG_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
|
||||
#endif /* pHYs */
|
||||
#endif /* INCH_CONVERSIONS */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* PNG_EASY_ACCESS_SUPPORTED */
|
||||
#endif /* EASY_ACCESS */
|
||||
|
||||
|
||||
png_byte PNGAPI
|
||||
png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
return(info_ptr->channels);
|
||||
return png_check_byte(png_ptr, PNG_FORMAT_CHANNELS(info_ptr->format));
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -457,8 +501,9 @@ png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
|
||||
&& background != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
|
||||
background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "bKGD");
|
||||
|
||||
@@ -488,7 +533,7 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
* consistent.
|
||||
*/
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
@@ -529,7 +574,7 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
@@ -552,14 +597,14 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
*green_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
if (blue_X != NULL)
|
||||
*blue_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_X,
|
||||
"cHRM blue X");
|
||||
*blue_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
if (blue_Y != NULL)
|
||||
*blue_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_Y,
|
||||
"cHRM blue Y");
|
||||
*blue_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
if (blue_Z != NULL)
|
||||
*blue_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.blue_Z,
|
||||
"cHRM blue Z");
|
||||
*blue_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@@ -577,7 +622,7 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
|
||||
|
||||
@@ -614,7 +659,7 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->colorspace.end_points_xy.whitex;
|
||||
@@ -649,7 +694,7 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
@@ -668,7 +713,7 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA(float)");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
@@ -688,8 +733,8 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sRGB");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
|
||||
&& file_srgb_intent != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
|
||||
{
|
||||
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
@@ -701,15 +746,16 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_iCCP(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_charpp name, int *compression_type,
|
||||
png_bytepp profile, png_uint_32 *proflen)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "iCCP");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && compression_type != NULL && profile != NULL &&
|
||||
proflen != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_iCCP) != 0 &&
|
||||
name != NULL && compression_type != NULL && profile != NULL &&
|
||||
proflen != NULL)
|
||||
{
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
@@ -726,14 +772,14 @@ png_get_iCCP(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sPLT(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int PNGAPI
|
||||
png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_sPLT_tpp spalettes)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
|
||||
{
|
||||
*spalettes = info_ptr->splt_palettes;
|
||||
return ((png_uint_32)info_ptr->splt_palettes_num);
|
||||
return info_ptr->splt_palettes_num;
|
||||
}
|
||||
|
||||
return (0);
|
||||
@@ -742,13 +788,13 @@ png_get_sPLT(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_hIST(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_uint_16p *hist)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "hIST");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
|
||||
&& hist != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
|
||||
{
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
@@ -766,14 +812,20 @@ png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "IHDR");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
|
||||
height == NULL || bit_depth == NULL || color_type == NULL)
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return (0);
|
||||
|
||||
*width = info_ptr->width;
|
||||
*height = info_ptr->height;
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
*color_type = info_ptr->color_type;
|
||||
if (width != NULL)
|
||||
*width = info_ptr->width;
|
||||
|
||||
if (height != NULL)
|
||||
*height = info_ptr->height;
|
||||
|
||||
if (bit_depth != NULL)
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
|
||||
if (color_type != NULL)
|
||||
*color_type = PNG_COLOR_TYPE_FROM_FORMAT(info_ptr->format);
|
||||
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
@@ -784,16 +836,7 @@ png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
if (interlace_type != NULL)
|
||||
*interlace_type = info_ptr->interlace_type;
|
||||
|
||||
/* This is redundant if we can be sure that the info_ptr values were all
|
||||
* assigned in png_set_IHDR(). We do the check anyhow in case an
|
||||
* application has ignored our advice not to mess with the members
|
||||
* of info_ptr directly.
|
||||
*/
|
||||
png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
||||
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
|
||||
info_ptr->compression_type, info_ptr->filter_type);
|
||||
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
@@ -803,8 +846,9 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "oFFs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
|
||||
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0 &&
|
||||
offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
@@ -818,14 +862,15 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_pCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pCAL");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
|
||||
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pCAL) != 0 &&
|
||||
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
@@ -843,15 +888,14 @@ png_get_pCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
# if (defined PNG_FLOATING_ARITHMETIC_SUPPORTED) || \
|
||||
(defined PNG_FLOATING_POINT_SUPPORTED)
|
||||
# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_fixed_point *width, png_fixed_point *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
/*TODO: make this work without FP support; the API is currently eliminated
|
||||
@@ -866,15 +910,15 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return(0);
|
||||
}
|
||||
# endif /* FLOATING_ARITHMETIC */
|
||||
# endif /* FIXED_POINT */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# endif /* FIXED_POINT */
|
||||
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, double *width, double *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = atof(info_ptr->scal_s_width);
|
||||
@@ -884,13 +928,15 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return(0);
|
||||
}
|
||||
# endif /* FLOATING POINT */
|
||||
# endif /* FLOATING POINT */
|
||||
# endif /* FLOATING_ARITHMETIC */
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_charpp width, png_charpp height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_s_width;
|
||||
@@ -912,7 +958,7 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
if (res_x != NULL)
|
||||
{
|
||||
@@ -938,13 +984,13 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
#endif /* pHYs */
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_PLTE(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_colorp *palette, int *num_palette)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "PLTE");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
|
||||
{
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
@@ -962,8 +1008,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sBIT");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
|
||||
{
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
@@ -974,8 +1020,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_text(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int PNGAPI
|
||||
png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_textp *text_ptr, int *num_text)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
|
||||
@@ -989,7 +1035,7 @@ png_get_text(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
if (num_text != NULL)
|
||||
*num_text = info_ptr->num_text;
|
||||
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
return info_ptr->num_text;
|
||||
}
|
||||
|
||||
if (num_text != NULL)
|
||||
@@ -1006,8 +1052,8 @@ png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tIME");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
|
||||
{
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
@@ -1023,11 +1069,12 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tRNS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tRNS");
|
||||
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
if ((info_ptr->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
|
||||
{
|
||||
if (trans_alpha != NULL)
|
||||
{
|
||||
@@ -1039,7 +1086,7 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
*trans_color = &(info_ptr->trans_color);
|
||||
}
|
||||
|
||||
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
|
||||
else /* if (info_ptr->format not colormapped */
|
||||
{
|
||||
if (trans_color != NULL)
|
||||
{
|
||||
@@ -1064,7 +1111,7 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
int PNGAPI
|
||||
png_get_unknown_chunks(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_unknown_chunkpp unknowns)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
|
||||
@@ -1073,15 +1120,17 @@ png_get_unknown_chunks(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
return info_ptr->unknown_chunks_num;
|
||||
}
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_byte PNGAPI
|
||||
png_get_rgb_to_gray_status (png_const_structrp png_ptr)
|
||||
png_get_rgb_to_gray_status(png_const_structrp png_ptr)
|
||||
{
|
||||
return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
|
||||
if (png_ptr)
|
||||
return png_ptr->rgb_to_gray_status;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1089,7 +1138,9 @@ png_get_rgb_to_gray_status (png_const_structrp png_ptr)
|
||||
png_voidp PNGAPI
|
||||
png_get_user_chunk_ptr(png_const_structrp png_ptr)
|
||||
{
|
||||
return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
|
||||
if (png_ptr)
|
||||
return png_ptr->user_chunk_ptr;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1099,21 +1150,21 @@ png_get_compression_buffer_size(png_const_structrp png_ptr)
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
# endif
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
if (png_ptr->read_struct)
|
||||
#endif
|
||||
{
|
||||
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
return png_ptr->IDAT_read_size;
|
||||
# else
|
||||
#else
|
||||
return PNG_IDAT_READ_SIZE;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
else
|
||||
return png_ptr->zbuffer_size;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
@@ -1144,7 +1195,7 @@ png_get_chunk_malloc_max (png_const_structrp png_ptr)
|
||||
{
|
||||
return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
#endif /* SET_USER_LIMITS */
|
||||
|
||||
/* These functions were added to libpng 1.4.0 */
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
@@ -1159,6 +1210,5 @@ png_get_io_chunk_type (png_const_structrp png_ptr)
|
||||
{
|
||||
return png_ptr->chunk_name;
|
||||
}
|
||||
#endif /* ?PNG_IO_STATE_SUPPORTED */
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* IO_STATE */
|
||||
#endif /* READ || WRITE */
|
||||
|
||||
37
pnginfo.h
37
pnginfo.h
@@ -1,18 +1,17 @@
|
||||
|
||||
/* pnginfo.h - header file for PNG reference library
|
||||
*
|
||||
* Copyright (c) 1998-2011 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
* Last changed in libpng 1.5.0 [January 6, 2011]
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
/* png_info is a structure that holds the information in a PNG file so
|
||||
/* png_info is a structure that holds the information in a PNG file so
|
||||
* that the application can find out the characteristics of the image.
|
||||
* If you are reading the file, this structure will tell you what is
|
||||
* in the PNG file. If you are writing the file, fill in the information
|
||||
@@ -58,25 +57,17 @@ struct png_info_def
|
||||
/* The following are necessary for every PNG file */
|
||||
png_uint_32 width; /* width of image in pixels (from IHDR) */
|
||||
png_uint_32 height; /* height of image in pixels (from IHDR) */
|
||||
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
|
||||
png_size_t rowbytes; /* bytes needed to hold an untransformed row */
|
||||
unsigned int valid; /* valid chunk data (see PNG_INFO_ in png.h) */
|
||||
png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
|
||||
png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
|
||||
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
|
||||
png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
|
||||
png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
|
||||
unsigned int num_palette:9; /* number of color entries in "palette" (PLTE) */
|
||||
unsigned int num_trans:9; /* number of transparent palette color (tRNS) */
|
||||
unsigned int bit_depth:6; /* 1, 2, 4, 8, 16 or 32 bits/channel */
|
||||
unsigned int format:PNG_RF_BITS; /* row format; see png_struct.h */
|
||||
/* The following three should have been named *_method not *_type */
|
||||
png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
|
||||
png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
|
||||
png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
|
||||
/* The following are set by png_set_IHDR, called from the application on
|
||||
* write, but the are never actually used by the write code.
|
||||
*/
|
||||
png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
|
||||
png_byte pixel_depth; /* number of bits per pixel */
|
||||
png_byte spare_byte; /* to align the data, and for future use */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* This is never set during write */
|
||||
png_byte signature[8]; /* magic bytes read by libpng from start of file */
|
||||
@@ -88,7 +79,7 @@ struct png_info_def
|
||||
* and initialize the appropriate fields below.
|
||||
*/
|
||||
|
||||
#if defined PNG_COLORSPACE_SUPPORTED || defined PNG_GAMMA_SUPPORTED
|
||||
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
|
||||
/* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are
|
||||
* defined. When COLORSPACE is switched on all the colorspace-defining
|
||||
* chunks should be enabled, when GAMMA is switched on all the gamma-defining
|
||||
@@ -121,7 +112,7 @@ struct png_info_def
|
||||
int num_text; /* number of comments read or comments to write */
|
||||
int max_text; /* current size of text array */
|
||||
png_textp text; /* array of comments read or comments to write */
|
||||
#endif /* PNG_TEXT_SUPPORTED */
|
||||
#endif /* TEXT */
|
||||
|
||||
#ifdef PNG_tIME_SUPPORTED
|
||||
/* The tIME chunk holds the last time the displayed image data was
|
||||
@@ -223,13 +214,17 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
||||
/* Storage for unknown chunks that the library doesn't recognize. */
|
||||
png_unknown_chunkp unknown_chunks;
|
||||
unsigned int unknown_chunks_num;
|
||||
|
||||
/* The type of this field is limited by the type of
|
||||
* png_struct::user_chunk_cache_max, else overflow can occur.
|
||||
*/
|
||||
int unknown_chunks_num;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
/* Data on sPLT chunks (there may be more than one). */
|
||||
png_sPLT_tp splt_palettes;
|
||||
png_uint_32 splt_palettes_num;
|
||||
int splt_palettes_num; /* Match type returned by png_get API */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user