aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/libpng
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/libpng')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/ANNOUNCE42
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/CHANGES3820
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/CMakeLists.txt348
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/INSTALL135
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/LICENSE111
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/README202
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/TODO27
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/configure19
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/README.txt4
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING340
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE50
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32130
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi104
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx132
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32113
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README186
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com132
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c311
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h88
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c511
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h116
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c179
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c728
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c904
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c1253
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c2107
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.pngbin0 -> 12901 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c853
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c400
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h133
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/libtests/pngvalid.c9837
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/README10
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/makefile150
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.dfa39
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.h24
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/README10
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/makefile149
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.dfa35
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.h24
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/README15
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/makefile165
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.dfa40
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.h24
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/README153
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.std65
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.tc338
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makevms.com92
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.bat41
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.c430
-rwxr-xr-xlibraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.sh42
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.bat4
-rwxr-xr-xlibraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.sh5
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.bat41
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.c533
-rwxr-xr-xlibraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.sh42
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g01.pngbin0 -> 164 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g02.pngbin0 -> 104 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g04.pngbin0 -> 145 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g08.pngbin0 -> 138 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g16.pngbin0 -> 167 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c08.pngbin0 -> 145 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c16.pngbin0 -> 302 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p01.pngbin0 -> 112 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p02.pngbin0 -> 146 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p04.pngbin0 -> 216 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p08.pngbin0 -> 1286 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a08.pngbin0 -> 126 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a16.pngbin0 -> 2206 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a08.pngbin0 -> 184 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a16.pngbin0 -> 3435 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn1g04.pngbin0 -> 429 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn2c16.pngbin0 -> 2041 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn3p08.pngbin0 -> 1499 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn2c16.pngbin0 -> 2041 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn3p08.pngbin0 -> 1499 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbrn2c08.pngbin0 -> 1633 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn1g16.pngbin0 -> 1313 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn3p08.pngbin0 -> 1496 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbyn3p08.pngbin0 -> 1499 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n1g08.pngbin0 -> 719 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n2c08.pngbin0 -> 1594 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n3p08.pngbin0 -> 1476 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp1n3p08.pngbin0 -> 1483 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.c450
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.h30
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/README.txt61
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.c969
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.icobin0 -> 766 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.pngbin0 -> 208 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.rc152
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/cexcept.h248
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/resource.h23
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/example.c862
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-config.in127
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-manual.txt4628
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.35952
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.pc.in11
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/libpngpf.328
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/png.574
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/png.c2870
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/png.h2658
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.jpgbin0 -> 2498 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.pngbin0 -> 2399 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngconf.h596
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngdebug.h157
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngerror.c685
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngget.c1124
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pnginfo.h269
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pnglibconf.h187
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngmem.c667
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngnow.pngbin0 -> 2069 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpread.c1843
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpriv.h1629
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngread.c1308
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrio.c176
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrtran.c5023
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrutil.c4158
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngset.c1284
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngstruct.h358
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.c1820
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.pngbin0 -> 8695 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtrans.c678
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwio.c254
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwrite.c1655
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c633
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwutil.c3180
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/PRJ0041.mak21
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README.txt58
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README_zlib.txt44
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.sln60
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.vcproj419
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/pngtest.vcproj267
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/zlib.vcproj391
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/libpng/libpng.vcxproj233
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj60
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngtest/pngtest.vcxproj219
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj218
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/readme.txt64
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/vstudio.sln87
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib.props37
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib/zlib.vcxproj174
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/README.txt76
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/SCOPTIONS.ppc7
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/checksym.awk161
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/chkfmt137
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/def.dfn38
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/descrip.mms52
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-body.in96
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-head.in24
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng.pc.in10
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.32sunu241
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.64sunu241
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.acorn57
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.aix121
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.amiga56
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.atari63
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bc32151
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.beos215
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bor161
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.cegcc116
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.darwin220
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dec202
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dj262
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.elf263
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.freebsd53
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.gcc87
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hp64224
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpgcc230
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpux221
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ibmc82
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.intel110
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.knr109
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.linux239
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.mips94
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.msc95
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ne12bsd50
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.netbsd50
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.openbsd82
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sco218
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sggcc228
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sgi229
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.so9239
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris236
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris-x86236
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.std123
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sunos107
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.tc393
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.vcwin32108
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makevms.com142
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/options.awk777
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.dfa578
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.h.prebuilt187
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.mak58
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pngwin.rc112
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/smakefile.ppc34
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/sym.dfn15
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.def241
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.dfn57
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/vers.dfn26
199 files changed, 83205 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/ANNOUNCE b/libraries/irrlicht-1.8/source/Irrlicht/libpng/ANNOUNCE
new file mode 100644
index 0000000..e8498a3
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/ANNOUNCE
@@ -0,0 +1,42 @@
1
2Libpng 1.5.9 - February 18, 2012
3
4This is a public release of libpng, intended for use in production codes.
5
6Files available for download:
7
8Source files with LF line endings (for Unix/Linux) and with a
9"configure" script
10
11 libpng-1.5.9.tar.xz (LZMA-compressed, recommended)
12 libpng-1.5.9.tar.gz
13 libpng-1.5.9.tar.bz2
14
15Source files with CRLF line endings (for Windows), without the
16"configure" script
17
18 lpng159.7z (LZMA-compressed, recommended)
19 lpng159.zip
20
21Other information:
22
23 libpng-1.5.9-README.txt
24 libpng-1.5.9-LICENSE.txt
25
26Changes since the last public release (1.5.8):
27
28 Rebuilt configure scripts in the tar distributions.
29 Removed two unused definitions from scripts/pnglibconf.h.prebuilt
30 Removed some unused arrays (with #ifdef) from png_read_push_finish_row().
31 Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h
32 Fixed CVE-2011-3026 buffer overrun bug. Deal more correctly with the test
33 on iCCP chunk length. Also removed spurious casts that may hide problems
34 on 16-bit systems.
35
36Send comments/corrections/commendations to png-mng-implement at lists.sf.net
37(subscription required; visit
38https://lists.sourceforge.net/lists/listinfo/png-mng-implement
39to subscribe)
40or to glennrp at users.sourceforge.net
41
42Glenn R-P
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/CHANGES b/libraries/irrlicht-1.8/source/Irrlicht/libpng/CHANGES
new file mode 100644
index 0000000..fb3a90b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/CHANGES
@@ -0,0 +1,3820 @@
1#if 0
2CHANGES - changes for libpng
3
4Version 0.2
5 added reader into png.h
6 fixed small problems in stub file
7
8Version 0.3
9 added pull reader
10 split up pngwrite.c to several files
11 added pnglib.txt
12 added example.c
13 cleaned up writer, adding a few new transformations
14 fixed some bugs in writer
15 interfaced with zlib 0.5
16 added K&R support
17 added check for 64 KB blocks for 16-bit machines
18
19Version 0.4
20 cleaned up code and commented code
21 simplified time handling into png_time
22 created png_color_16 and png_color_8 to handle color needs
23 cleaned up color type defines
24 fixed various bugs
25 made various names more consistent
26 interfaced with zlib 0.71
27 cleaned up zTXt reader and writer (using zlib's Reset functions)
28 split transformations into pngrtran.c and pngwtran.c
29
30Version 0.5
31 interfaced with zlib 0.8
32 fixed many reading and writing bugs
33 saved using 3 spaces instead of tabs
34
35Version 0.6
36 added png_large_malloc() and png_large_free()
37 added png_size_t
38 cleaned up some compiler warnings
39 added png_start_read_image()
40
41Version 0.7
42 cleaned up lots of bugs
43 finished dithering and other stuff
44 added test program
45 changed name from pnglib to libpng
46
47Version 0.71 [June, 1995]
48 changed pngtest.png for zlib 0.93
49 fixed error in libpng.txt and example.c
50
51Version 0.8
52 cleaned up some bugs
53 added png_set_filler()
54 split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
55 added #define's to remove unwanted code
56 moved png_info_init() to png.c
57 added old_size into png_realloc()
58 added functions to manually set filtering and compression info
59 changed compression parameters based on image type
60 optimized filter selection code
61 added version info
62 changed external functions passing floats to doubles (k&r problems?)
63 put all the configurable stuff in pngconf.h
64 enabled png_set_shift to work with paletted images on read
65 added png_read_update_info() - updates info structure with transformations
66
67Version 0.81 [August, 1995]
68 incorporated Tim Wegner's medium model code (thanks, Tim)
69
70Version 0.82 [September, 1995]
71 [unspecified changes]
72
73Version 0.85 [December, 1995]
74 added more medium model code (almost everything's a far)
75 added i/o, error, and memory callback functions
76 fixed some bugs (16-bit, 4-bit interlaced, etc.)
77 added first run progressive reader (barely tested)
78
79Version 0.86 [January, 1996]
80 fixed bugs
81 improved documentation
82
83Version 0.87 [January, 1996]
84 fixed medium model bugs
85 fixed other bugs introduced in 0.85 and 0.86
86 added some minor documentation
87
88Version 0.88 [January, 1996]
89 fixed progressive bugs
90 replaced tabs with spaces
91 cleaned up documentation
92 added callbacks for read/write and warning/error functions
93
94Version 0.89 [July, 1996]
95 Added new initialization API to make libpng work better with shared libs
96 we now have png_create_read_struct(), png_create_write_struct(),
97 png_create_info_struct(), png_destroy_read_struct(), and
98 png_destroy_write_struct() instead of the separate calls to
99 malloc and png_read_init(), png_info_init(), and png_write_init()
100 Changed warning/error callback functions to fix bug - this means you
101 should use the new initialization API if you were using the old
102 png_set_message_fn() calls, and that the old API no longer exists
103 so that people are aware that they need to change their code
104 Changed filter selection API to allow selection of multiple filters
105 since it didn't work in previous versions of libpng anyways
106 Optimized filter selection code
107 Fixed png_set_background() to allow using an arbitrary RGB color for
108 paletted images
109 Fixed gamma and background correction for paletted images, so
110 png_correct_palette is not needed unless you are correcting an
111 external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
112 in pngconf.h) - if nobody uses this, it may disappear in the future.
113 Fixed bug with Borland 64K memory allocation (Alexander Lehmann)
114 Fixed bug in interlace handling (Smarasderagd, I think)
115 Added more error checking for writing and image to reduce invalid files
116 Separated read and write functions so that they won't both be linked
117 into a binary when only reading or writing functionality is used
118 New pngtest image also has interlacing and zTXt
119 Updated documentation to reflect new API
120
121Version 0.90 [January, 1997]
122 Made CRC errors/warnings on critical and ancillary chunks configurable
123 libpng will use the zlib CRC routines by (compile-time) default
124 Changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
125 Added external C++ wrapper statements to png.h (Gilles Dauphin)
126 Allow PNG file to be read when some or all of file signature has already
127 been read from the beginning of the stream. ****This affects the size
128 of info_struct and invalidates all programs that use a shared libpng****
129 Fixed png_filler() declarations
130 Fixed? background color conversions
131 Fixed order of error function pointers to match documentation
132 Current chunk name is now available in png_struct to reduce the number
133 of nearly identical error messages (will simplify multi-lingual
134 support when available)
135 Try to get ready for unknown-chunk callback functions:
136 - previously read critical chunks are flagged, so the chunk handling
137 routines can determine if the chunk is in the right place
138 - all chunk handling routines have the same prototypes, so we will
139 be able to handle all chunks via a callback mechanism
140 Try to fix Linux "setjmp" buffer size problems
141 Removed png_large_malloc, png_large_free, and png_realloc functions.
142
143Version 0.95 [March, 1997]
144 Fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
145 Fixed bug in PNG file signature compares when start != 0
146 Changed parameter type of png_set_filler(...filler...) from png_byte
147 to png_uint_32
148 Added test for MACOS to ensure that both math.h and fp.h are not #included
149 Added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
150 Added "packswap" transformation, which changes the endianness of
151 packed-pixel bytes (Kevin Bracey)
152 Added "strip_alpha" transformation, which removes the alpha channel of
153 input images without using it (not necessarily a good idea)
154 Added "swap_alpha" transformation, which puts the alpha channel in front
155 of the color bytes instead of after
156 Removed all implicit variable tests which assume NULL == 0 (I think)
157 Changed several variables to "png_size_t" to show 16/32-bit limitations
158 Added new pCAL chunk read/write support
159 Added experimental filter selection weighting (Greg Roelofs)
160 Removed old png_set_rgbx() and png_set_xrgb() functions that have been
161 obsolete for about 2 years now (use png_set_filler() instead)
162 Added macros to read 16- and 32-bit ints directly from buffer, to be
163 used only on those systems that support it (namely PowerPC and 680x0)
164 With some testing, this may become the default for MACOS/PPC systems.
165 Only calculate CRC on data if we are going to use it
166 Added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
167 Added macros for simple libpng debugging output selectable at compile time
168 Removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
169 More description of info_struct in libpng.txt and png.h
170 More instructions in example.c
171 More chunk types tested in pngtest.c
172 Renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
173 png_set_<chunk>. We now have corresponding png_get_<chunk>
174 functions in pngget.c to get information in info_ptr. This isolates
175 the application from the internal organization of png_info_struct
176 (good for shared library implementations).
177
178Version 0.96 [May, 1997]
179 Fixed serious bug with < 8bpp images introduced in 0.95
180 Fixed 256-color transparency bug (Greg Roelofs)
181 Fixed up documentation (Greg Roelofs, Laszlo Nyul)
182 Fixed "error" in pngconf.h for Linux setjmp() behavior
183 Fixed DOS medium model support (Tim Wegner)
184 Fixed png_check_keyword() for case with error in static string text
185 Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
186 Added typecasts to quiet compiler errors
187 Added more debugging info
188
189Version 0.97 [January, 1998]
190 Removed PNG_USE_OWN_CRC capability
191 Relocated png_set_crc_action from pngrutil.c to pngrtran.c
192 Fixed typecasts of "new_key", etc. (Andreas Dilger)
193 Added RFC 1152 [sic] date support
194 Fixed bug in gamma handling of 4-bit grayscale
195 Added 2-bit grayscale gamma handling (Glenn R-P)
196 Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
197 Minor corrections in libpng.txt
198 Added simple sRGB support (Glenn R-P)
199 Easier conditional compiling, e.g.,
200 define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
201 all configurable options can be selected from command-line instead
202 of having to edit pngconf.h (Glenn R-P)
203 Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
204 Added more conditions for png_do_background, to avoid changing
205 black pixels to background when a background is supplied and
206 no pixels are transparent
207 Repaired PNG_NO_STDIO behavior
208 Tested NODIV support and made it default behavior (Greg Roelofs)
209 Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
210 Regularized version numbering scheme and bumped shared-library major
211 version number to 2 to avoid problems with libpng 0.89 apps
212 (Greg Roelofs)
213
214Version 0.98 [January, 1998]
215 Cleaned up some typos in libpng.txt and in code documentation
216 Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
217 Cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
218 Changed recommendation about file_gamma for PC images to .51 from .45,
219 in example.c and libpng.txt, added comments to distinguish between
220 screen_gamma, viewing_gamma, and display_gamma.
221 Changed all references to RFC1152 to read RFC1123 and changed the
222 PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
223 Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
224 Changed srgb_intent from png_byte to int to avoid compiler bugs
225
226Version 0.99 [January 30, 1998]
227 Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
228 Fixed a longstanding "packswap" bug in pngtrans.c
229 Fixed some inconsistencies in pngconf.h that prevented compiling with
230 PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
231 Fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
232 Changed recommendation about file_gamma for PC images to .50 from .51 in
233 example.c and libpng.txt, and changed file_gamma for sRGB images to .45
234 Added a number of functions to access information from the png structure
235 png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
236 Added TARGET_MACOS similar to zlib-1.0.8
237 Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
238 Added type casting to all png_malloc() function calls
239
240Version 0.99a [January 31, 1998]
241 Added type casts and parentheses to all returns that return a value.(Tim W.)
242
243Version 0.99b [February 4, 1998]
244 Added type cast png_uint_32 on malloc function calls where needed.
245 Changed type of num_hist from png_uint_32 to int (same as num_palette).
246 Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
247 Renamed makefile.elf to makefile.lnx.
248
249Version 0.99c [February 7, 1998]
250 More type casting. Removed erroneous overflow test in pngmem.c.
251 Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
252 Added UNIX manual pages libpng.3 (incorporating libpng.txt) and png.5.
253
254Version 0.99d [February 11, 1998]
255 Renamed "far_to_near()" "png_far_to_near()"
256 Revised libpng.3
257 Version 99c "buffered" operations didn't work as intended. Replaced them
258 with png_memcpy_check() and png_memset_check().
259 Added many "if (png_ptr == NULL) return" to quell compiler warnings about
260 unused png_ptr, mostly in pngget.c and pngset.c.
261 Check for overlength tRNS chunk present when indexed-color PLTE is read.
262 Cleaned up spelling errors in libpng.3/libpng.txt
263 Corrected a problem with png_get_tRNS() which returned undefined trans array
264
265Version 0.99e [February 28, 1998]
266 Corrected png_get_tRNS() again.
267 Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
268 Touched up example.c to make more of it compileable, although the entire
269 file still can't be compiled (Willem van Schaik)
270 Fixed a bug in png_do_shift() (Bryan Tsai)
271 Added a space in png.h prototype for png_write_chunk_start()
272 Replaced pngtest.png with one created with zlib 1.1.1
273 Changed pngtest to report PASS even when file size is different (Jean-loup G.)
274 Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
275
276Version 0.99f [March 5, 1998]
277 Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
278 Moved makefiles into a "scripts" directory, and added INSTALL instruction file
279 Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
280 Added pointers to "note on libpng versions" in makefile.lnx and README
281 Added row callback feature when reading and writing nonprogressive rows
282 and added a test of this feature in pngtest.c
283 Added user transform callbacks, with test of the feature in pngtest.c
284
285Version 0.99g [March 6, 1998, morning]
286 Minor changes to pngtest.c to suppress compiler warnings.
287 Removed "beta" language from documentation.
288
289Version 0.99h [March 6, 1998, evening]
290 Minor changes to previous minor changes to pngtest.c
291 Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
292 and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
293 Added user transform capability
294
295Version 1.00 [March 7, 1998]
296 Changed several typedefs in pngrutil.c
297 Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
298 Replaced "while(1)" with "for(;;)"
299 Added PNGARG() to prototypes in pngtest.c and removed some prototypes
300 Updated some of the makefiles (Tom Lane)
301 Changed some typedefs (s_start, etc.) in pngrutil.c
302 Fixed dimensions of "short_months" array in pngwrite.c
303 Replaced ansi2knr.c with the one from jpeg-v6
304
305Version 1.0.0 [March 8, 1998]
306 Changed name from 1.00 to 1.0.0 (Adam Costello)
307 Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)
308
309Version 1.0.0a [March 9, 1998]
310 Fixed three bugs in pngrtran.c to make gamma+background handling consistent
311 (Greg Roelofs)
312 Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz
313 for major, minor, and bugfix releases. This is 10001. (Adam Costello,
314 Tom Lane)
315 Make months range from 1-12 in png_convert_to_rfc1123
316
317Version 1.0.0b [March 13, 1998]
318 Quieted compiler complaints about two empty "for" loops in pngrutil.c
319 Minor changes to makefile.s2x
320 Removed #ifdef/#endif around a png_free() in pngread.c
321
322Version 1.0.1 [March 14, 1998]
323 Changed makefile.s2x to reduce security risk of using a relative pathname
324 Fixed some typos in the documentation (Greg).
325 Fixed a problem with value of "channels" returned by png_read_update_info()
326
327Version 1.0.1a [April 21, 1998]
328 Optimized Paeth calculations by replacing abs() function calls with intrinsics
329 plus other loop optimizations. Improves avg decoding speed by about 20%.
330 Commented out i386istic "align" compiler flags in makefile.lnx.
331 Reduced the default warning level in some makefiles, to make them consistent.
332 Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
333 Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
334 Added grayscale and 16-bit capability to png_do_read_filler().
335 Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
336 too large when writing an image with bit_depth < 8 (Bob Dellaca).
337 Corrected some bugs in the experimental weighted filtering heuristics.
338 Moved a misplaced pngrutil code block that truncates tRNS if it has more
339 than num_palette entries -- test was done before num_palette was defined.
340 Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
341 Changed compiler flags in makefile.wat for better optimization
342 (Pawel Mrochen).
343
344Version 1.0.1b [May 2, 1998]
345 Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
346 Relocated the png_composite macros from pngrtran.c to png.h (Greg).
347 Added makefile.sco (contributed by Mike Hopkirk).
348 Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
349 Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
350 More work on the Paeth-filtering, achieving imperceptible speedup
351 (A Kleinert).
352 More work on loop optimization which may help when compiled with C++
353 compilers.
354 Added warnings when people try to use transforms they've defined out.
355 Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
356 Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
357
358Version 1.0.1c [May 11, 1998]
359 Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
360 filler bytes should have been 0xff instead of 0xf.
361 Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
362 Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
363 out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
364 Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
365 for consistency, in pngconf.h
366 Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier
367 to remove unwanted capabilities via the compile line
368 Made some corrections to grammar (which, it's) in documentation (Greg).
369 Corrected example.c, use of row_pointers in png_write_image().
370
371Version 1.0.1d [May 24, 1998]
372 Corrected several statements that used side effects illegally in pngrutil.c
373 and pngtrans.c, that were introduced in version 1.0.1b
374 Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
375 More corrections to example.c, use of row_pointers in png_write_image()
376 and png_read_rows().
377 Added pngdll.mak and pngdef.pas to scripts directory, contributed by
378 Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
379 Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
380 Changed several loops from count-down to count-up, for consistency.
381
382Version 1.0.1e [June 6, 1998]
383 Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
384 added warnings when people try to set png_read_fn and png_write_fn in
385 the same structure.
386 Added a test such that png_do_gamma will be done when num_trans==0
387 for truecolor images that have defined a background. This corrects an
388 error that was introduced in libpng-0.90 that can cause gamma processing
389 to be skipped.
390 Added tests in png.h to include "trans" and "trans_values" in structures
391 when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
392 Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
393 Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
394 Added capability for user-provided malloc_fn() and free_fn() functions,
395 and revised pngtest.c to demonstrate their use, replacing the
396 PNGTEST_DEBUG_MEM feature.
397 Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
398
399Version 1.0.2 [June 14, 1998]
400 Fixed two bugs in makefile.bor .
401
402Version 1.0.2a [December 30, 1998]
403 Replaced and extended code that was removed from png_set_filler() in 1.0.1a.
404 Fixed a bug in png_do_filler() that made it fail to write filler bytes in
405 the left-most pixel of each row (Kevin Bracey).
406 Changed "static pngcharp tIME_string" to "static char tIME_string[30]"
407 in pngtest.c (Duncan Simpson).
408 Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk
409 even when no tIME chunk was present in the source file.
410 Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit.
411 Fixed a problem in png_read_push_finish_row(), which would not skip some
412 passes that it should skip, for images that are less than 3 pixels high.
413 Interchanged the order of calls to png_do_swap() and png_do_shift()
414 in pngwtran.c (John Cromer).
415 Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h .
416 Changed "bad adaptive filter type" from error to warning in pngrutil.c .
417 Fixed a documentation error about default filtering with 8-bit indexed-color.
418 Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO
419 (L. Peter Deutsch).
420 Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions.
421 Added png_get_copyright() and png_get_header_version() functions.
422 Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c
423 Added information about debugging in libpng.txt and libpng.3 .
424 Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and
425 makefile.sco.
426 Removed lines after Dynamic Dependencies" in makefile.aco .
427 Revised makefile.dec to make a shared library (Jeremie Petit).
428 Removed trailing blanks from all files.
429
430Version 1.0.2a [January 6, 1999]
431 Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h
432 Added "if" tests to silence complaints about unused png_ptr in png.h and png.c
433 Changed "check_if_png" function in example.c to return true (nonzero) if PNG.
434 Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()
435 which is obsolete.
436
437Version 1.0.3 [January 14, 1999]
438 Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)
439 Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO.
440
441Version 1.0.3a [August 12, 1999]
442 Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
443 if an attempt is made to read an interlaced image when it's not supported.
444 Added check if png_ptr->trans is defined before freeing it in pngread.c
445 Modified the Y2K statement to include versions back to version 0.71
446 Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c
447 Modified makefile.wat (added -zp8 flag, ".symbolic", changed some comments)
448 Replaced leading blanks with tab characters in makefile.hux
449 Changed "dworkin.wustl.edu" to "ccrc.wustl.edu" in various documents.
450 Changed (float)red and (float)green to (double)red, (double)green
451 in png_set_rgb_to_gray() to avoid "promotion" problems in AIX.
452 Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).
453 Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).
454 Updated documentation to refer to the PNG-1.2 specification.
455 Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c
456 in makefile.knr, INSTALL, and README (L. Peter Deutsch)
457 Fixed bugs in calculation of the length of rowbytes when adding alpha
458 channels to 16-bit images, in pngrtran.c (Chris Nokleberg)
459 Added function png_set_user_transform_info() to store user_transform_ptr,
460 user_depth, and user_channels into the png_struct, and a function
461 png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)
462 Added function png_set_empty_plte_permitted() to make libpng useable
463 in MNG applications.
464 Corrected the typedef for png_free_ptr in png.h (Jesse Jones).
465 Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be
466 consistent with PNG-1.2, and allow variance of 500 before complaining.
467 Added assembler code contributed by Intel in file pngvcrd.c and modified
468 makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation,
469 Gilles Vollant)
470 Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
471 Added some aliases for png_set_expand() in pngrtran.c, namely
472 png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()
473 (Greg Roelofs, in "PNG: The Definitive Guide").
474 Added makefile.beo for BEOS on X86, contributed by Sander Stok.
475
476Version 1.0.3b [August 26, 1999]
477 Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
478 Changed leading blanks to tabs in all makefiles.
479 Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.
480 Made alternate versions of png_set_expand() in pngrtran.c, namely
481 png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha
482 (Greg Roelofs, in "PNG: The Definitive Guide"). Deleted the 1.0.3a aliases.
483 Relocated start of 'extern "C"' block in png.h so it doesn't include pngconf.h
484 Revised calculation of num_blocks in pngmem.c to avoid a potentially
485 negative shift distance, whose results are undefined in the C language.
486 Added a check in pngset.c to prevent writing multiple tIME chunks.
487 Added a check in pngwrite.c to detect invalid small window_bits sizes.
488
489Version 1.0.3d [September 4, 1999]
490 Fixed type casting of igamma in pngrutil.c
491 Added new png_expand functions to scripts/pngdef.pas and pngos2.def
492 Added a demo read_user_transform_fn that examines the row filters in pngtest.c
493
494Version 1.0.4 [September 24, 1999]
495 Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
496 Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
497 Made several minor corrections to pngtest.c
498 Renamed the makefiles with longer but more user friendly extensions.
499 Copied the PNG copyright and license to a separate LICENSE file.
500 Revised documentation, png.h, and example.c to remove reference to
501 "viewing_gamma" which no longer appears in the PNG specification.
502 Revised pngvcrd.c to use MMX code for interlacing only on the final pass.
503 Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a
504 Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX
505 assembler code) and makefile.vcwin32 (doesn't).
506 Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
507 Added a copy of pngnow.png to the distribution.
508
509Version 1.0.4a [September 25, 1999]
510 Increase max_pixel_depth in pngrutil.c if a user transform needs it.
511 Changed several division operations to right-shifts in pngvcrd.c
512
513Version 1.0.4b [September 30, 1999]
514 Added parentheses in line 3732 of pngvcrd.c
515 Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
516
517Version 1.0.4c [October 1, 1999]
518 Added a "png_check_version" function in png.c and pngtest.c that will generate
519 a helpful compiler error if an old png.h is found in the search path.
520 Changed type of png_user_transform_depth|channels from int to png_byte.
521
522Version 1.0.4d [October 6, 1999]
523 Changed 0.45 to 0.45455 in png_set_sRGB()
524 Removed unused PLTE entries from pngnow.png
525 Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
526
527Version 1.0.4e [October 10, 1999]
528 Fixed sign error in pngvcrd.c (Greg Roelofs)
529 Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
530
531Version 1.0.4f [October 15, 1999]
532 Surrounded example.c code with #if 0 .. #endif to prevent people from
533 inadvertently trying to compile it.
534 Changed png_get_header_version() from a function to a macro in png.h
535 Added type casting mostly in pngrtran.c and pngwtran.c
536 Removed some pointless "ptr = NULL" in pngmem.c
537 Added a "contrib" directory containing the source code from Greg's book.
538
539Version 1.0.5 [October 15, 1999]
540 Minor editing of the INSTALL and README files.
541
542Version 1.0.5a [October 23, 1999]
543 Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)
544 Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)
545 Further optimization and bugfix of pngvcrd.c
546 Revised pngset.c so that it does not allocate or free memory in the user's
547 text_ptr structure. Instead, it makes its own copy.
548 Created separate write_end_info_struct in pngtest.c for a more severe test.
549 Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.
550
551Version 1.0.5b [November 23, 1999]
552 Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and
553 PNG_FLAG_WROTE_tIME from flags to mode.
554 Added png_write_info_before_PLTE() function.
555 Fixed some typecasting in contrib/gregbook/*.c
556 Updated scripts/makevms.com and added makevms.com to contrib/gregbook
557 and contrib/pngminus (Martin Zinser)
558
559Version 1.0.5c [November 26, 1999]
560 Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr.
561 Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to
562 accommodate making DLL's: Moved usr_png_ver from global variable to function
563 png_get_header_ver() in png.c. Moved png_sig to png_sig_bytes in png.c and
564 eliminated use of png_sig in pngwutil.c. Moved the various png_CHNK arrays
565 into pngtypes.h. Eliminated use of global png_pass arrays. Declared the
566 png_CHNK and png_pass arrays to be "const". Made the global arrays
567 available to applications (although none are used in libpng itself) when
568 PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined.
569 Removed some extraneous "-I" from contrib/pngminus/makefile.std
570 Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.
571 Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3
572
573Version 1.0.5d [November 29, 1999]
574 Add type cast (png_const_charp) two places in png.c
575 Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.
576 Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available
577 to applications a macro "PNG_USE_LOCAL_ARRAYS".
578 comment out (with #ifdef) all the new declarations when
579 PNG_USE_GLOBAL_ARRAYS is defined.
580 Added PNG_EXPORT_VAR macro to accommodate making DLL's.
581
582Version 1.0.5e [November 30, 1999]
583 Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text
584 structure; refactored the inflate/deflate support to make adding new chunks
585 with trailing compressed parts easier in the future, and added new functions
586 png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP,
587 png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond).
588 NOTE: Applications that write text chunks MUST define png_text->lang
589 before calling png_set_text(). It must be set to NULL if you want to
590 write tEXt or zTXt chunks. If you want your application to be able to
591 run with older versions of libpng, use
592
593 #ifdef PNG_iTXt_SUPPORTED
594 png_text[i].lang = NULL;
595 #endif
596
597 Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned
598 offsets (Eric S. Raymond).
599 Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into
600 PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED
601 macros, leaving the separate macros also available.
602 Removed comments on #endifs at the end of many short, non-nested #if-blocks.
603
604Version 1.0.5f [December 6, 1999]
605 Changed makefile.solaris to issue a warning about potential problems when
606 the ucb "ld" is in the path ahead of the ccs "ld".
607 Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3.
608 Added sCAL chunk support (Eric S. Raymond).
609
610Version 1.0.5g [December 7, 1999]
611 Fixed "png_free_spallettes" typo in png.h
612 Added code to handle new chunks in pngpread.c
613 Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block
614 Added "translated_key" to png_text structure and png_write_iTXt().
615 Added code in pngwrite.c to work around a newly discovered zlib bug.
616
617Version 1.0.5h [December 10, 1999]
618 NOTE: regarding the note for version 1.0.5e, the following must also
619 be included in your code:
620 png_text[i].translated_key = NULL;
621 Unknown chunk handling is now supported.
622 Option to eliminate all floating point support was added. Some new
623 fixed-point functions such as png_set_gAMA_fixed() were added.
624 Expanded tabs and removed trailing blanks in source files.
625
626Version 1.0.5i [December 13, 1999]
627 Added some type casts to silence compiler warnings.
628 Renamed "png_free_spalette" to "png_free_spalettes" for consistency.
629 Removed leading blanks from a #define in pngvcrd.c
630 Added some parameters to the new png_set_keep_unknown_chunks() function.
631 Added a test for up->location != 0 in the first instance of writing
632 unknown chunks in pngwrite.c
633 Changed "num" to "i" in png_free_spalettes() and png_free_unknowns() to
634 prevent recursion.
635 Added png_free_hIST() function.
636 Various patches to fix bugs in the sCAL and integer cHRM processing,
637 and to add some convenience macros for use with sCAL.
638
639Version 1.0.5j [December 21, 1999]
640 Changed "unit" parameter of png_write_sCAL from png_byte to int, to work
641 around buggy compilers.
642 Added new type "png_fixed_point" for integers that hold float*100000 values
643 Restored backward compatibility of tEXt/zTXt chunk processing:
644 Restored the first four members of png_text to the same order as v.1.0.5d.
645 Added members "lang_key" and "itxt_length" to png_text struct. Set
646 text_length=0 when "text" contains iTXt data. Use the "compression"
647 member to distinguish among tEXt/zTXt/iTXt types. Added
648 PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros.
649 The "Note" above, about backward incompatibility of libpng-1.0.5e, no
650 longer applies.
651 Fixed png_read|write_iTXt() to read|write parameters in the right order,
652 and to write the iTXt chunk after IDAT if it appears in the end_ptr.
653 Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs)
654 Reversed the order of trying to write floating-point and fixed-point gAMA.
655
656Version 1.0.5k [December 27, 1999]
657 Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))"
658 Added png_handle_as_unknown() function (Glenn)
659 Added png_free_chunk_list() function and chunk_list and num_chunk_list members
660 of png_ptr.
661 Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE.
662 Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings
663 about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored)
664 Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR).
665 Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is.
666 Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP().
667
668Version 1.0.5l [January 1, 2000]
669 Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr()
670 for setting a callback function to handle unknown chunks and for
671 retrieving the associated user pointer (Glenn).
672
673Version 1.0.5m [January 7, 2000]
674 Added high-level functions png_read_png(), png_write_png(), png_free_pixels().
675
676Version 1.0.5n [January 9, 2000]
677 Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its
678 own memory for info_ptr->palette. This makes it safe for the calling
679 application to free its copy of the palette any time after it calls
680 png_set_PLTE().
681
682Version 1.0.5o [January 20, 2000]
683 Cosmetic changes only (removed some trailing blanks and TABs)
684
685Version 1.0.5p [January 31, 2000]
686 Renamed pngdll.mak to makefile.bd32
687 Cosmetic changes in pngtest.c
688
689Version 1.0.5q [February 5, 2000]
690 Relocated the makefile.solaris warning about PATH problems.
691 Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)
692 Revised makefile.gcmmx
693 Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros
694
695Version 1.0.5r [February 7, 2000]
696 Removed superfluous prototype for png_get_itxt from png.h
697 Fixed a bug in pngrtran.c that improperly expanded the background color.
698 Return *num_text=0 from png_get_text() when appropriate, and fix documentation
699 of png_get_text() in libpng.txt/libpng.3.
700
701Version 1.0.5s [February 18, 2000]
702 Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the
703 new error handler that's planned for the next libpng release, and changed
704 example.c, pngtest.c, and contrib programs to use this macro.
705 Revised some of the DLL-export macros in pngconf.h (Greg Roelofs)
706 Fixed a bug in png_read_png() that caused it to fail to expand some images
707 that it should have expanded.
708 Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions
709 in pngget.c
710 Changed the allocation of palette, history, and trans arrays back to
711 the version 1.0.5 method (linking instead of copying) which restores
712 backward compatibility with version 1.0.5. Added some remarks about
713 that in example.c. Added "free_me" member to info_ptr and png_ptr
714 and added png_free_data() function.
715 Updated makefile.linux and makefile.gccmmx to make directories conditionally.
716 Made cosmetic changes to pngasmrd.h
717 Added png_set_rows() and png_get_rows(), for use with png_read|write_png().
718 Modified png_read_png() to allocate info_ptr->row_pointers only if it
719 hasn't already been allocated.
720
721Version 1.0.5t [March 4, 2000]
722 Changed png_jmp_env() migration aiding macro to png_jmpbuf().
723 Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c
724 Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when
725 PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b
726 Files in contrib/gregbook were revised to use png_jmpbuf() and to select
727 a 24-bit visual if one is available, and to allow abbreviated options.
728 Files in contrib/pngminus were revised to use the png_jmpbuf() macro.
729 Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s
730
731Version 1.0.5u [March 5, 2000]
732 Simplified the code that detects old png.h in png.c and pngtest.c
733 Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp)
734 Increased precision of rgb_to_gray calculations from 8 to 15 bits and
735 added png_set_rgb_to_gray_fixed() function.
736 Added makefile.bc32 (32-bit Borland C++, C mode)
737
738Version 1.0.5v [March 11, 2000]
739 Added some parentheses to the png_jmpbuf macro definition.
740 Updated references to the zlib home page, which has moved to freesoftware.com.
741 Corrected bugs in documentation regarding png_read_row() and png_write_row().
742 Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt.
743 Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3,
744 revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin)
745
746Version 1.0.6 [March 20, 2000]
747 Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c
748 Added makefile.sggcc (SGI IRIX with gcc)
749
750Version 1.0.6d [April 7, 2000]
751 Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
752 Added data_length parameter to png_decompress_chunk() function
753 Revised documentation to remove reference to abandoned png_free_chnk functions
754 Fixed an error in png_rgb_to_gray_fixed()
755 Revised example.c, usage of png_destroy_write_struct().
756 Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
757 Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c
758 Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
759
760Version 1.0.6e [April 9, 2000]
761 Added png_data_freer() function.
762 In the code that checks for over-length tRNS chunks, added check of
763 info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
764 Minor revisions of libpng.txt/libpng.3.
765 Check for existing data and free it if the free_me flag is set, in png_set_*()
766 and png_handle_*().
767 Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED
768 is defined.
769 Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
770 and mentioned the purposes of the two macros in libpng.txt/libpng.3.
771
772Version 1.0.6f [April 14, 2000]
773 Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data.
774 Add checks in png_set_text() for NULL members of the input text structure.
775 Revised libpng.txt/libpng.3.
776 Removed superfluous prototype for png_set_iTXt from png.h
777 Removed "else" from pngread.c, after png_error(), and changed "0" to "length".
778 Changed several png_errors about malformed ancillary chunks to png_warnings.
779
780Version 1.0.6g [April 24, 2000]
781 Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined.
782 Relocated paragraph about png_set_background() in libpng.3/libpng.txt
783 and other revisions (Matthias Benckmann)
784 Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and
785 png_ptr members to restore binary compatibility with libpng-1.0.5
786 (breaks compatibility with libpng-1.0.6).
787
788Version 1.0.6h [April 24, 2000]
789 Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds
790 libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h)
791 This is a temporary change for test purposes.
792
793Version 1.0.6i [May 2, 2000]
794 Rearranged some members at the end of png_info and png_struct, to put
795 unknown_chunks_num and free_me within the original size of the png_structs
796 and free_me, png_read_user_fn, and png_free_fn within the original png_info,
797 because some old applications allocate the structs directly instead of
798 using png_create_*().
799 Added documentation of user memory functions in libpng.txt/libpng.3
800 Modified png_read_png so that it will use user_allocated row_pointers
801 if present, unless free_me directs that it be freed, and added description
802 of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3.
803 Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version
804 1.00) members of png_struct and png_info, to regain binary compatibility
805 when you define this macro. Capabilities lost in this event
806 are user transforms (new in version 1.0.0),the user transform pointer
807 (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT,
808 the high-level interface, and unknown chunks support (all new in 1.0.6).
809 This was necessary because of old applications that allocate the structs
810 directly as authors were instructed to do in libpng-0.88 and earlier,
811 instead of using png_create_*().
812 Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which
813 can be used to detect codes that directly allocate the structs, and
814 code to check these modes in png_read_init() and png_write_init() and
815 generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED
816 was not defined.
817 Added makefile.intel and updated makefile.watcom (Pawel Mrochen)
818
819Version 1.0.6j [May 3, 2000]
820 Overloaded png_read_init() and png_write_init() with macros that convert
821 calls to png_read_init_2() or png_write_init_2() that check the version
822 and structure sizes.
823
824Version 1.0.7beta11 [May 7, 2000]
825 Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes
826 which are no longer used.
827 Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is
828 defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED
829 is defined.
830 Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory
831 overrun when old applications fill the info_ptr->text structure directly.
832 Added PNGAPI macro, and added it to the definitions of all exported functions.
833 Relocated version macro definitions ahead of the includes of zlib.h and
834 pngconf.h in png.h.
835
836Version 1.0.7beta12 [May 12, 2000]
837 Revised pngset.c to avoid a problem with expanding the png_debug macro.
838 Deleted some extraneous defines from pngconf.h
839 Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined.
840 Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined.
841 Added png_access_version_number() function.
842 Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data().
843 Expanded libpng.3/libpng.txt information about png_data_freer().
844
845Version 1.0.7beta14 [May 17, 2000] (beta13 was not published)
846 Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as
847 warnings instead of errors, as pngrutil.c does.
848 Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png()
849 will actually write IDATs.
850 Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32.
851 Make png_free_data() ignore its final parameter except when freeing data
852 that can have multiple instances (text, sPLT, unknowns).
853 Fixed a new bug in png_set_rows().
854 Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5.
855 Added png_set_invalid() function.
856 Fixed incorrect illustrations of png_destroy_write_struct() in example.c.
857
858Version 1.0.7beta15 [May 30, 2000]
859 Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce
860 fewer error messages.
861 Rearranged checks for Z_OK to check the most likely path first in pngpread.c
862 and pngwutil.c.
863 Added checks in pngtest.c for png_create_*() returning NULL, and mentioned
864 in libpng.txt/libpng.3 the need for applications to check this.
865 Changed names of png_default_*() functions in pngtest to pngtest_*().
866 Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32.
867 Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c
868 Set each pointer to NULL after freeing it in png_free_data().
869 Worked around a problem in pngconf.h; AIX's strings.h defines an "index"
870 macro that conflicts with libpng's png_color_16.index. (Dimitri
871 Papadapoulos)
872 Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux).
873
874Version 1.0.7beta16 [June 4, 2000]
875 Revised the workaround of AIX string.h "index" bug.
876 Added a check for overlength PLTE chunk in pngrutil.c.
877 Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer
878 indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler.
879 Added a warning in png_decompress_chunk() when it runs out of data, e.g.
880 when it tries to read an erroneous PhotoShop iCCP chunk.
881 Added PNG_USE_DLL macro.
882 Revised the copyright/disclaimer/license notice.
883 Added contrib/msvctest directory
884
885Version 1.0.7rc1 [June 9, 2000]
886 Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA (0x0400 not 0x0200)
887 Added contrib/visupng directory (Willem van Schaik)
888
889Version 1.0.7beta18 [June 23, 2000]
890 Revised PNGAPI definition, and pngvcrd.c to work with __GCC__
891 and do not redefine PNGAPI if it is passed in via a compiler directive.
892 Revised visupng/PngFile.c to remove returns from within the Try block.
893 Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros.
894 Updated contrib/visupng/cexcept.h to version 1.0.0.
895 Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks.
896
897Version 1.0.7rc2 [June 28, 2000]
898 Updated license to include disclaimers required by UCITA.
899 Fixed "DJBPP" typo in pnggccrd.c introduced in beta18.
900
901Version 1.0.7 [July 1, 2000]
902 Revised the definition of "trans_values" in libpng.3/libpng.txt
903
904Version 1.0.8beta1 [July 8, 2000]
905 Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks.
906 Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and
907 pngwutil.c.
908 Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h.
909 Removed unused "#include <assert.h>" from png.c
910 Added WindowsCE support.
911 Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment.
912
913Version 1.0.8beta2 [July 10, 2000]
914 Added project files to the wince directory and made further revisions
915 of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE.
916
917Version 1.0.8beta3 [July 11, 2000]
918 Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS()
919 for indexed-color input files to avoid potential double-freeing trans array
920 under some unusual conditions; problem was introduced in version 1.0.6f.
921 Further revisions to pngtest.c and files in the wince subdirectory.
922
923Version 1.0.8beta4 [July 14, 2000]
924 Added the files pngbar.png and pngbar.jpg to the distribution.
925 Added makefile.cygwin, and cygwin support in pngconf.h
926 Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory)
927
928Version 1.0.8rc1 [July 16, 2000]
929 Revised png_debug() macros and statements to eliminate compiler warnings.
930
931Version 1.0.8 [July 24, 2000]
932 Added png_flush() in pngwrite.c, after png_write_IEND().
933 Updated makefile.hpux to build a shared library.
934
935Version 1.0.9beta1 [November 10, 2000]
936 Fixed typo in scripts/makefile.hpux
937 Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser)
938 Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser)
939 Changed "cdrom.com" in documentation to "libpng.org"
940 Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg).
941 Changed type of "params" from voidp to png_voidp in png_read|write_png().
942 Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h.
943 Revised the 3 instances of WRITEFILE in pngtest.c.
944 Relocated "msvc" and "wince" project subdirectories into "dll" subdirectory.
945 Updated png.rc in dll/msvc project
946 Revised makefile.dec to define and use LIBPATH and INCPATH
947 Increased size of global png_libpng_ver[] array from 12 to 18 chars.
948 Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const.
949 Removed duplicate png_crc_finish() from png_handle_bKGD() function.
950 Added a warning when application calls png_read_update_info() multiple times.
951 Revised makefile.cygwin
952 Fixed bugs in iCCP support in pngrutil.c and pngwutil.c.
953 Replaced png_set_empty_plte_permitted() with png_permit_mng_features().
954
955Version 1.0.9beta2 [November 19, 2000]
956 Renamed the "dll" subdirectory "projects".
957 Added borland project files to "projects" subdirectory.
958 Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate.
959 Add error message in png_set_compression_buffer_size() when malloc fails.
960
961Version 1.0.9beta3 [November 23, 2000]
962 Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project.
963 Removed the png_flush() in pngwrite.c that crashes some applications
964 that don't set png_output_flush_fn.
965 Added makefile.macosx and makefile.aix to scripts directory.
966
967Version 1.0.9beta4 [December 1, 2000]
968 Change png_chunk_warning to png_warning in png_check_keyword().
969 Increased the first part of msg buffer from 16 to 18 in png_chunk_error().
970
971Version 1.0.9beta5 [December 15, 2000]
972 Added support for filter method 64 (for PNG datastreams embedded in MNG).
973
974Version 1.0.9beta6 [December 18, 2000]
975 Revised png_set_filter() to accept filter method 64 when appropriate.
976 Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to
977 help prevent applications from using MNG features in PNG datastreams.
978 Added png_permit_mng_features() function.
979 Revised libpng.3/libpng.txt. Changed "filter type" to "filter method".
980
981Version 1.0.9rc1 [December 23, 2000]
982 Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c
983 Fixed error handling of unknown compression type in png_decompress_chunk().
984 In pngconf.h, define __cdecl when _MSC_VER is defined.
985
986Version 1.0.9beta7 [December 28, 2000]
987 Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places.
988 Revised memory management in png_set_hIST and png_handle_hIST in a backward
989 compatible manner. PLTE and tRNS were revised similarly.
990 Revised the iCCP chunk reader to ignore trailing garbage.
991
992Version 1.0.9beta8 [January 12, 2001]
993 Moved pngasmrd.h into pngconf.h.
994 Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop.
995
996Version 1.0.9beta9 [January 15, 2001]
997 Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to
998 wince and msvc project module definition files.
999 Minor revision of makefile.cygwin.
1000 Fixed bug with progressive reading of narrow interlaced images in pngpread.c
1001
1002Version 1.0.9beta10 [January 16, 2001]
1003 Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined.
1004 Fixed "png_mmx_supported" typo in project definition files.
1005
1006Version 1.0.9beta11 [January 19, 2001]
1007 Updated makefile.sgi to make shared library.
1008 Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED
1009 by default, for the benefit of DLL forward compatibility. These will
1010 be re-enabled in version 1.2.0.
1011
1012Version 1.0.9rc2 [January 22, 2001]
1013 Revised cygwin support.
1014
1015Version 1.0.9 [January 31, 2001]
1016 Added check of cygwin's ALL_STATIC in pngconf.h
1017 Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos.
1018
1019Version 1.0.10beta1 [March 14, 2001]
1020 Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc.
1021 Reformatted libpng.3 to eliminate bad line breaks.
1022 Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c
1023 Added prototype for png_mmx_support() near the top of pnggccrd.c
1024 Moved some error checking from png_handle_IHDR to png_set_IHDR.
1025 Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros.
1026 Revised png_mmx_support() function in pnggccrd.c
1027 Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c
1028 Fixed memory leak in contrib/visupng/PngFile.c
1029 Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version)
1030 Added warnings when retrieving or setting gamma=0.
1031 Increased the first part of msg buffer from 16 to 18 in png_chunk_warning().
1032
1033Version 1.0.10rc1 [March 23, 2001]
1034 Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy,
1035 and png_strlen.
1036 Revised png_mmx_supported() function in pnggccrd.c to return proper value.
1037 Fixed bug in progressive reading (pngpread.c) with small images (height < 8).
1038
1039Version 1.0.10 [March 30, 2001]
1040 Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin
1041 Added beos project files (Chris Herborth)
1042
1043Version 1.0.11beta1 [April 3, 2001]
1044 Added type casts on several png_malloc() calls (Dimitri Papadapoulos).
1045 Removed a no-longer needed AIX work-around from pngconf.h
1046 Changed several "//" single-line comments to C-style in pnggccrd.c
1047
1048Version 1.0.11beta2 [April 11, 2001]
1049 Removed PNGAPI from several functions whose prototypes did not have PNGAPI.
1050 Updated scripts/pngos2.def
1051
1052Version 1.0.11beta3 [April 14, 2001]
1053 Added checking the results of many instances of png_malloc() for NULL
1054
1055Version 1.0.11beta4 [April 20, 2001]
1056 Undid the changes from version 1.0.11beta3. Added a check for NULL return
1057 from user's malloc_fn().
1058 Removed some useless type casts of the NULL pointer.
1059 Added makefile.netbsd
1060
1061Version 1.0.11 [April 27, 2001]
1062 Revised makefile.netbsd
1063
1064Version 1.0.12beta1 [May 14, 2001]
1065 Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot)
1066 Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h
1067 Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings.
1068 Eliminated the png_error about apps using png_read|write_init(). Instead,
1069 libpng will reallocate the png_struct and info_struct if they are too small.
1070 This retains future binary compatibility for old applications written for
1071 libpng-0.88 and earlier.
1072
1073Version 1.2.0beta1 [May 6, 2001]
1074 Bumped DLLNUM to 2.
1075 Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED
1076 by default.
1077 Added runtime selection of MMX features.
1078 Added png_set_strip_error_numbers function and related macros.
1079
1080Version 1.2.0beta2 [May 7, 2001]
1081 Finished merging 1.2.0beta1 with version 1.0.11
1082 Added a check for attempts to read or write PLTE in grayscale PNG datastreams.
1083
1084Version 1.2.0beta3 [May 17, 2001]
1085 Enabled user memory function by default.
1086 Modified png_create_struct so it passes user mem_ptr to user memory allocator.
1087 Increased png_mng_features flag from png_byte to png_uint_32.
1088 Bumped shared-library (so-number) and dll-number to 3.
1089
1090Version 1.2.0beta4 [June 23, 2001]
1091 Check for missing profile length field in iCCP chunk and free chunk_data
1092 in case of truncated iCCP chunk.
1093 Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc
1094 Bumped dll-number from 2 to 3 in makefile.cygwin
1095 Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly
1096 if user attempts to run it on an 8-bit display.
1097 Updated contrib/gregbook
1098 Use png_malloc instead of png_zalloc to allocate palette in pngset.c
1099 Updated makefile.ibmc
1100 Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes
1101 of png_write_oFFS width and height from png_uint_32 to png_int_32.
1102 Updated example.c
1103 Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
1104
1105Version 1.2.0beta5 [August 8, 2001]
1106 Revised contrib/gregbook
1107 Revised makefile.gcmmx
1108 Revised pnggccrd.c to conditionally compile some thread-unsafe code only
1109 when PNG_THREAD_UNSAFE_OK is defined.
1110 Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with
1111 value exceeding 2^bit_depth-1
1112 Revised makefile.sgi and makefile.sggcc
1113 Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
1114 Removed restriction that do_invert_mono only operate on 1-bit opaque files
1115
1116Version 1.2.0 [September 1, 2001]
1117 Changed a png_warning() to png_debug() in pnggccrd.c
1118 Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC().
1119
1120Version 1.2.1beta1 [October 19, 2001]
1121 Revised makefile.std in contrib/pngminus
1122 Include background_1 in png_struct regardless of gamma support.
1123 Revised makefile.netbsd and makefile.macosx, added makefile.darwin.
1124 Revised example.c to provide more details about using row_callback().
1125
1126Version 1.2.1beta2 [October 25, 2001]
1127 Added type cast to each NULL appearing in a function call, except for
1128 WINCE functions.
1129 Added makefile.so9.
1130
1131Version 1.2.1beta3 [October 27, 2001]
1132 Removed type casts from all NULLs.
1133 Simplified png_create_struct_2().
1134
1135Version 1.2.1beta4 [November 7, 2001]
1136 Revised png_create_info_struct() and png_creat_struct_2().
1137 Added error message if png_write_info() was omitted.
1138 Type cast NULLs appearing in function calls when _NO_PROTO or
1139 PNG_TYPECAST_NULL is defined.
1140
1141Version 1.2.1rc1 [November 24, 2001]
1142 Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL
1143 is defined.
1144 Changed typecast of "size" argument to png_size_t in pngmem.c calls to
1145 the user malloc_fn, to agree with the prototype in png.h
1146 Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev)
1147 Updated makefile.sgi to recognize LIBPATH and INCPATH.
1148 Updated various makefiles so "make clean" does not remove previous major
1149 version of the shared library.
1150
1151Version 1.2.1rc2 [December 4, 2001]
1152 Always allocate 256-entry internal palette, hist, and trans arrays, to
1153 avoid out-of-bounds memory reference caused by invalid PNG datastreams.
1154 Added a check for prefix_length > data_length in iCCP chunk handler.
1155
1156Version 1.2.1 [December 7, 2001]
1157 None.
1158
1159Version 1.2.2beta1 [February 22, 2002]
1160 Fixed a bug with reading the length of iCCP profiles (Larry Reeves).
1161 Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate
1162 libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h
1163 Revised makefile.darwin to remove "-undefined suppress" option.
1164 Added checks for gamma and chromaticity values over 21474.83, which exceed
1165 the limit for PNG unsigned 32-bit integers when encoded.
1166 Revised calls to png_create_read_struct() and png_create_write_struct()
1167 for simpler debugging.
1168 Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK)
1169
1170Version 1.2.2beta2 [February 23, 2002]
1171 Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths.
1172 Check for invalid image dimensions in png_get_IHDR.
1173 Added missing "fi;" in the install target of the SGI makefiles.
1174 Added install-static to all makefiles that make shared libraries.
1175 Always do gamma compensation when image is partially transparent.
1176
1177Version 1.2.2beta3 [March 7, 2002]
1178 Compute background.gray and background_1.gray even when color_type is RGB
1179 in case image gets reduced to gray later.
1180 Modified shared-library makefiles to install pkgconfig/libpngNN.pc.
1181 Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown
1182 Removed unused png_write_destroy_info prototype from png.h
1183 Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case
1184 Added install-shared target to all makefiles that make shared libraries.
1185 Stopped a double free of palette, hist, and trans when not using free_me.
1186 Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64.
1187
1188Version 1.2.2beta4 [March 8, 2002]
1189 Compute background.gray and background_1.gray even when color_type is RGB
1190 in case image gets reduced to gray later (Jason Summers).
1191 Relocated a misplaced /bin/rm in the "install-shared" makefile targets
1192 Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library.
1193
1194Version 1.2.2beta5 [March 26, 2002]
1195 Added missing PNGAPI to several function definitions.
1196 Check for invalid bit_depth or color_type in png_get_IHDR(), and
1197 check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen).
1198 Revised iTXt support to accept NULL for lang and lang_key.
1199 Compute gamma for color components of background even when color_type is gray.
1200 Changed "()" to "{}" in scripts/libpng.pc.in.
1201 Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN
1202 Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so
1203
1204Version 1.2.2beta6 [March 31, 2002]
1205
1206Version 1.0.13beta1 [March 31, 2002]
1207 Prevent png_zalloc() from trying to memset memory that it failed to acquire.
1208 Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate).
1209 Ensure that the right function (user or default) is used to free the
1210 png_struct after an error in png_create_read_struct_2().
1211
1212Version 1.2.2rc1 [April 7, 2002]
1213
1214Version 1.0.13rc1 [April 7, 2002]
1215 Save the ebx register in pnggccrd.c (Sami Farin)
1216 Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner).
1217 Updated makefiles to put headers in include/libpng and remove old include/*.h.
1218
1219Version 1.2.2 [April 15, 2002]
1220
1221Version 1.0.13 [April 15, 2002]
1222 Revised description of png_set_filter() in libpng.3/libpng.txt.
1223 Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd
1224
1225Version 1.0.13patch01 [April 17, 2002]
1226
1227Version 1.2.2patch01 [April 17, 2002]
1228 Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and
1229 makefile.sggcc
1230 Fixed VER -> PNGVER typo in makefile.macosx and added install-static to
1231 install
1232 Added install: target to makefile.32sunu and makefile.64sunu
1233
1234Version 1.0.13patch03 [April 18, 2002]
1235
1236Version 1.2.2patch03 [April 18, 2002]
1237 Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng
1238 subdirectory to libpngNN subdirectory without the full pathname.
1239 Moved generation of libpng.pc from "install" to "all" in 15 makefiles.
1240
1241Version 1.2.3rc1 [April 28, 2002]
1242 Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos).
1243 Added $(DESTDIR) feature to 24 makefiles (Tim Mooney)
1244 Fixed bug with $prefix, should be $(prefix) in makefile.hpux.
1245 Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin
1246 Added a link from libpngNN.pc to libpng.pc in 15 makefiles.
1247 Added links from include/libpngNN/*.h to include/*.h in 24 makefiles.
1248 Revised makefile.darwin to make relative links without full pathname.
1249 Added setjmp() at the end of png_create_*_struct_2() in case user forgets
1250 to put one in their application.
1251 Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and
1252 removed them from module definition files.
1253
1254Version 1.2.3rc2 [May 1, 2002]
1255 Fixed bug in reporting number of channels in pngget.c and pngset.c,
1256 that was introduced in version 1.2.2beta5.
1257 Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(),
1258 png_default_flush(), and png_push_fill_buffer() and included them in
1259 module definition files.
1260 Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles.
1261
1262Version 1.2.3rc3 [May 1, 2002]
1263 Revised prototype for png_default_flush()
1264 Remove old libpng.pc and libpngNN.pc before installing new ones.
1265
1266Version 1.2.3rc4 [May 2, 2002]
1267 Typos in *.def files (png_default_read|write -> png_default_read|write_data)
1268 In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc
1269 Added libpng-config and libpngNN-config and modified makefiles to install
1270 them.
1271 Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles
1272 Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp
1273
1274Version 1.2.3rc5 [May 11, 2002]
1275 Changed "error" and "message" in prototypes to "error_message" and
1276 "warning_message" to avoid namespace conflict.
1277 Revised 15 makefiles to build libpng-config from libpng-config-*.in
1278 Once more restored png_zalloc and png_zfree to regular nonexported form.
1279 Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer
1280 to nonexported form, but with PNGAPI, and removed them from module def
1281 files.
1282
1283Version 1.2.3rc6 [May 14, 2002]
1284 Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c
1285 Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp.
1286 Removed leftover libpng-config "sed" script from four makefiles.
1287 Revised libpng-config creating script in 16 makefiles.
1288
1289Version 1.2.3 [May 22, 2002]
1290 Revised libpng-config target in makefile.cygwin.
1291 Removed description of png_set_mem_fn() from documentation.
1292 Revised makefile.freebsd.
1293 Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR).
1294 Revised projects/msvc/README.txt
1295 Changed -lpng to -lpngNN in LDFLAGS in several makefiles.
1296
1297Version 1.2.4beta1 [May 24, 2002]
1298 Added libpng.pc and libpng-config to "all:" target in 16 makefiles.
1299 Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH)
1300 Added missing "\" before closing double quote in makefile.gcmmx.
1301 Plugged various memory leaks; added png_malloc_warn() and png_set_text_2()
1302 functions.
1303
1304Version 1.2.4beta2 [June 25, 2002]
1305 Plugged memory leak of png_ptr->current_text (Matt Holgate).
1306 Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison)
1307 Added -soname to the loader flags in makefile.dec, makefile.sgi, and
1308 makefile.sggcc.
1309 Added "test-installed" target to makefile.linux, makefile.gcmmx,
1310 makefile.sgi, and makefile.sggcc.
1311
1312Version 1.2.4beta3 [June 28, 2002]
1313 Plugged memory leak of row_buf in pngtest.c when there is a png_error().
1314 Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data.
1315 Added "test-installed" target to makefile.32sunu, makefile.64sunu,
1316 makefile.beos, makefile.darwin, makefile.dec, makefile.macosx,
1317 makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9.
1318
1319Version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002]
1320 Added "test-installed" target to makefile.cygwin and makefile.sco.
1321 Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro.
1322
1323Version 1.2.4 and 1.0.14 [July 8, 2002]
1324 Changed png_warning() to png_error() when width is too large to process.
1325
1326Version 1.2.4patch01 [July 20, 2002]
1327 Revised makefile.cygwin to use DLL number 12 instead of 13.
1328
1329Version 1.2.5beta1 [August 6, 2002]
1330 Added code to contrib/gregbook/readpng2.c to ignore unused chunks.
1331 Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11)
1332 Removed some stray *.o files from contrib/gregbook.
1333 Changed png_error() to png_warning() about "Too much data" in pngpread.c
1334 and about "Extra compressed data" in pngrutil.c.
1335 Prevent png_ptr->pass from exceeding 7 in png_push_finish_row().
1336 Updated makefile.hpgcc
1337 Updated png.c and pnggccrd.c handling of return from png_mmx_support()
1338
1339Version 1.2.5beta2 [August 15, 2002]
1340 Only issue png_warning() about "Too much data" in pngpread.c when avail_in
1341 is nonzero.
1342 Updated makefiles to install a separate libpng.so.3 with its own rpath.
1343
1344Version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002]
1345 Revised makefiles to not remove previous minor versions of shared libraries.
1346
1347Version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002]
1348 Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared
1349 library loader directive.
1350 Added missing "$OBJSDLL" line to makefile.gcmmx.
1351 Added missing "; fi" to makefile.32sunu.
1352
1353Version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002]
1354 Revised libpng-config script.
1355
1356Version 1.2.5 and 1.0.15 [October 3, 2002]
1357 Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux,
1358 and makefile.aix.
1359 Relocated two misplaced PNGAPI lines in pngtest.c
1360
1361Version 1.2.6beta1 [October 22, 2002]
1362 Commented out warning about uninitialized mmx_support in pnggccrd.c.
1363 Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h.
1364 Relocated two more misplaced PNGAPI lines in pngtest.c
1365 Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams,
1366 introduced in version 1.0.2.
1367 Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu.
1368
1369Version 1.2.6beta2 [November 1, 2002]
1370 Added libpng-config "--ldopts" output.
1371 Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)"
1372 in makefiles.
1373
1374Version 1.2.6beta3 [July 18, 2004]
1375 Reverted makefile changes from version 1.2.6beta2 and some of the changes
1376 from version 1.2.6beta1; these will be postponed until version 1.2.7.
1377 Version 1.2.6 is going to be a simple bugfix release.
1378 Changed the one instance of "ln -sf" to "ln -f -s" in each Sun makefile.
1379 Fixed potential overrun in pngerror.c by using strncpy instead of memcpy.
1380 Added "#!/bin/sh" at the top of configure, for recognition of the
1381 'x' flag under Cygwin (Cosmin).
1382 Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin).
1383 Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin).
1384 Fixed the special memory handler for Borland C under DOS, in pngmem.c
1385 (Cosmin).
1386 Removed some spurious assignments in pngrutil.c (Cosmin).
1387 Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings
1388 on 16-bit platforms (Cosmin).
1389 Enclosed shift op expressions in parentheses, to silence warnings (Cosmin).
1390 Used proper type png_fixed_point, to avoid problems on 16-bit platforms,
1391 in png_handle_sRGB() (Cosmin).
1392 Added compression_type to png_struct, and optimized the window size
1393 inside the deflate stream (Cosmin).
1394 Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin).
1395 Fixed handling of unknown chunks that come after IDAT (Cosmin).
1396 Allowed png_error() and png_warning() to work even if png_ptr == NULL
1397 (Cosmin).
1398 Replaced row_info->rowbytes with row_bytes in png_write_find_filter()
1399 (Cosmin).
1400 Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre).
1401 Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded
1402 values in png.c (Simon-Pierre, Cosmin).
1403 Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre).
1404 Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc
1405 (Simon-Pierre).
1406 Moved the definition of PNG_HEADER_VERSION_STRING near the definitions
1407 of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin).
1408 Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin).
1409 Updated scripts/makefile.vc(a)win32 (Cosmin).
1410 Updated the MSVC project (Simon-Pierre, Cosmin).
1411 Updated the Borland C++ Builder project (Cosmin).
1412 Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin).
1413 Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin).
1414 Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin).
1415 Added extra guard around inclusion of Turbo C memory headers, in pngconf.h
1416 (Cosmin).
1417 Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to
1418 projects/cbuilder5/ (Cosmin).
1419 Moved projects/visualc6/png32ms.def to scripts/pngw32.def,
1420 and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin).
1421 Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin).
1422 Changed line endings to DOS style in cbuilder5 and visualc6 files, even
1423 in the tar.* distributions (Cosmin).
1424 Updated contrib/visupng/VisualPng.dsp (Cosmin).
1425 Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin).
1426 Added a separate distribution with "configure" and supporting files (Junichi).
1427
1428Version 1.2.6beta4 [July 28, 2004]
1429 Added user ability to change png_size_t via a PNG_SIZE_T macro.
1430 Added png_sizeof() and png_convert_size() functions.
1431 Added PNG_SIZE_MAX (maximum value of a png_size_t variable.
1432 Added check in png_malloc_default() for (size_t)size != (png_uint_32)size
1433 which would indicate an overflow.
1434 Changed sPLT failure action from png_error to png_warning and abandon chunk.
1435 Changed sCAL and iCCP failures from png_error to png_warning and abandon.
1436 Added png_get_uint_31(png_ptr, buf) function.
1437 Added PNG_UINT_32_MAX macro.
1438 Renamed PNG_MAX_UINT to PNG_UINT_31_MAX.
1439 Made png_zalloc() issue a png_warning and return NULL on potential
1440 overflow.
1441 Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x
1442 Revised "clobber list" in pnggccrd.c so it will compile under gcc-3.4.
1443 Revised Borland portion of png_malloc() to return NULL or issue
1444 png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK.
1445 Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove
1446 sequential read support.
1447 Added some "#if PNG_WRITE_SUPPORTED" blocks.
1448 Added #ifdef to remove some redundancy in png_malloc_default().
1449 Use png_malloc instead of png_zalloc to allocate the pallete.
1450
1451Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]
1452 Fixed buffer overflow vulnerability in png_handle_tRNS()
1453 Fixed integer arithmetic overflow vulnerability in png_read_png().
1454 Fixed some harmless bugs in png_handle_sBIT, etc, that would cause
1455 duplicate chunk types to go undetected.
1456 Fixed some timestamps in the -config version
1457 Rearranged order of processing of color types in png_handle_tRNS().
1458 Added ROWBYTES macro to calculate rowbytes without integer overflow.
1459 Updated makefile.darwin and removed makefile.macosx from scripts directory.
1460 Imposed default one million column, one-million row limits on the image
1461 dimensions, and added png_set_user_limits() function to override them.
1462 Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro.
1463 Fixed wrong cast of returns from png_get_user_width|height_max().
1464 Changed some "keep the compiler happy" from empty statements to returns,
1465 Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution
1466
1467Version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004]
1468 Revised makefile.darwin and makefile.solaris. Removed makefile.macosx.
1469 Revised pngtest's png_debug_malloc() to use png_malloc() instead of
1470 png_malloc_default() which is not supposed to be exported.
1471 Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in
1472 pngpread.c. Bug was introduced in 1.2.6rc1.
1473 Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1.
1474 Fixed old bug in RGB to Gray transformation.
1475 Fixed problem with 64-bit compilers by casting arguments to abs()
1476 to png_int_32.
1477 Changed "ln -sf" to "ln -f -s" in three makefiles (solaris, sco, so9).
1478 Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin)
1479 Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles.
1480 Added code to update the row_info->colortype in png_do_read_filler() (MSB).
1481
1482Version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004]
1483 Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid
1484 trouble with some 64-bit compilers. Created PNG_OUT_OF_RANGE() macro.
1485 Revised documentation of png_set_keep_unknown_chunks().
1486 Check handle_as_unknown status in pngpread.c, as in pngread.c previously.
1487 Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h
1488 Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c
1489
1490Version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004]
1491 Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of
1492 "pinfo" was out of place).
1493
1494Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004]
1495 Moved "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED
1496 section of png.h where they were inadvertently placed in version rc3.
1497
1498Version 1.2.6 and 1.0.16 [August 15, 2004]
1499 Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1.
1500
1501Version 1.2.7beta1 [August 26, 2004]
1502 Removed unused pngasmrd.h file.
1503 Removed references to uu.net for archived files. Added references to
1504 PNG Spec (second edition) and the PNG ISO/IEC Standard.
1505 Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR.
1506 Fixed bug with "optimized window size" in the IDAT datastream, that
1507 causes libpng to write PNG files with incorrect zlib header bytes.
1508
1509Version 1.2.7beta2 [August 28, 2004]
1510 Fixed bug with sCAL chunk and big-endian machines (David Munro).
1511 Undid new code added in 1.2.6rc2 to update the color_type in
1512 png_set_filler().
1513 Added png_set_add_alpha() that updates color type.
1514
1515Version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004]
1516 Revised png_set_strip_filler() to not remove alpha if color_type has alpha.
1517
1518Version 1.2.7 and 1.0.17 [September 12, 2004]
1519 Added makefile.hp64
1520 Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin
1521
1522Version 1.2.8beta1 [November 1, 2004]
1523 Fixed bug in png_text_compress() that would fail to complete a large block.
1524 Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during
1525 strip alpha operation in png_do_strip_filler().
1526 Added PNG_1_2_X definition in pngconf.h
1527 Use #ifdef to comment out png_info_init in png.c and png_read_init in
1528 pngread.c (as of 1.3.0)
1529
1530Version 1.2.8beta2 [November 2, 2004]
1531 Reduce color_type to a nonalpha type after strip alpha operation in
1532 png_do_strip_filler().
1533
1534Version 1.2.8beta3 [November 3, 2004]
1535 Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM
1536
1537Version 1.2.8beta4 [November 12, 2004]
1538 Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin).
1539 Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin).
1540 Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection
1541 of data type in deflate (Cosmin).
1542 Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of
1543 PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.
1544
1545Version 1.2.8beta5 [November 20, 2004]
1546 Use png_ptr->flags instead of png_ptr->transformations to pass
1547 PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI
1548 compatibility.
1549 Revised handling of SPECIALBUILD, PRIVATEBUILD,
1550 PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.
1551
1552Version 1.2.8rc1 [November 24, 2004]
1553 Moved handling of BUILD macros from pngconf.h to png.h
1554 Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently
1555 omitted from beta5.
1556 Revised scripts/pngw32.rc
1557 Despammed mailing addresses by masking "@" with "at".
1558 Inadvertently installed a supposedly faster test version of pngrutil.c
1559
1560Version 1.2.8rc2 [November 26, 2004]
1561 Added two missing "\" in png.h
1562 Change tests in pngread.c and pngpread.c to
1563 if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
1564 png_do_read_transformations(png_ptr);
1565
1566Version 1.2.8rc3 [November 28, 2004]
1567 Reverted pngrutil.c to version libpng-1.2.8beta5.
1568 Added scripts/makefile.elf with supporting code in pngconf.h for symbol
1569 versioning (John Bowler).
1570
1571Version 1.2.8rc4 [November 29, 2004]
1572 Added projects/visualc7 (Simon-pierre).
1573
1574Version 1.2.8rc5 [November 29, 2004]
1575 Fixed new typo in scripts/pngw32.rc
1576
1577Version 1.2.8 [December 3, 2004]
1578 Removed projects/visualc7, added projects/visualc71.
1579
1580Version 1.2.9beta1 [February 21, 2006]
1581 Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints
1582 Revised man page and libpng.txt to make it clear that one should not call
1583 png_read_end or png_write_end after png_read_png or png_write_png.
1584 Updated references to png-mng-implement mailing list.
1585 Fixed an incorrect typecast in pngrutil.c
1586 Added PNG_NO_READ_SUPPORTED conditional for making a write-only library.
1587 Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional.
1588 Optimized alpha-inversion loops in pngwtran.c
1589 Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c
1590 Make sure num_trans is <= 256 before copying data in png_set_tRNS().
1591 Make sure num_palette is <= 256 before copying data in png_set_PLTE().
1592 Interchanged order of write_swap_alpha and write_invert_alpha transforms.
1593 Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin).
1594 Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin).
1595 Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin).
1596 Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16,
1597 png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin).
1598 Added type cast (png_byte) in png_write_sCAL() (Cosmin).
1599 Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin).
1600 Default iTXt support was inadvertently enabled.
1601
1602Version 1.2.9beta2 [February 21, 2006]
1603 Check for png_rgb_to_gray and png_gray_to_rgb read transformations before
1604 checking for png_read_dither in pngrtran.c
1605 Revised checking of chromaticity limits to accommodate extended RGB
1606 colorspace (John Denker).
1607 Changed line endings in some of the project files to CRLF, even in the
1608 "Unix" tar distributions (Cosmin).
1609 Made png_get_int_32 and png_save_int_32 always available (Cosmin).
1610 Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def
1611 with the newly exported functions.
1612 Eliminated distributions without the "configure" script.
1613 Updated INSTALL instructions.
1614
1615Version 1.2.9beta3 [February 24, 2006]
1616 Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp
1617 Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler)
1618 Removed reference to pngasmrd.h from Makefile.am
1619 Renamed CHANGES to ChangeLog.
1620 Renamed LICENSE to COPYING.
1621 Renamed ANNOUNCE to NEWS.
1622 Created AUTHORS file.
1623
1624Version 1.2.9beta4 [March 3, 2006]
1625 Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac
1626 Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING.
1627 Removed newline from the end of some error and warning messages.
1628 Removed test for sqrt() from configure.ac and configure.
1629 Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix).
1630 Disabled default iTXt support that was inadvertently enabled in
1631 libpng-1.2.9beta1.
1632 Added "OS2" to list of systems that don't need underscores, in pnggccrd.c
1633 Removed libpng version and date from *.c files.
1634
1635Version 1.2.9beta5 [March 4, 2006]
1636 Removed trailing blanks from source files.
1637 Put version and date of latest change in each source file, and changed
1638 copyright year accordingly.
1639 More cleanup of configure.ac, Makefile.am, and associated scripts.
1640 Restored scripts/makefile.elf which was inadvertently deleted.
1641
1642Version 1.2.9beta6 [March 6, 2006]
1643 Fixed typo (RELEASE) in configuration files.
1644
1645Version 1.2.9beta7 [March 7, 2006]
1646 Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am
1647 Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s()
1648 in png.h.
1649 Updated makefile.elf as suggested by debian.
1650 Made cosmetic changes to some makefiles, adding LN_SF and other macros.
1651 Made some makefiles accept "exec_prefix".
1652
1653Version 1.2.9beta8 [March 9, 2006]
1654 Fixed some "#if defined (..." which should be "#if defined(..."
1655 Bug introduced in libpng-1.2.8.
1656 Fixed inconsistency in definition of png_default_read_data()
1657 Restored blank that was lost from makefile.sggcc "clean" target in beta7.
1658 Revised calculation of "current" and "major" for irix in ltmain.sh
1659 Changed "mkdir" to "MKDIR_P" in some makefiles.
1660 Separated PNG_EXPAND and PNG_EXPAND_tRNS.
1661 Added png_set_expand_gray_1_2_4_to_8() and deprecated
1662 png_set_gray_1_2_4_to_8() which also expands tRNS to alpha.
1663
1664Version 1.2.9beta9 [March 10, 2006]
1665 Include "config.h" in pngconf.h when available.
1666 Added some checks for NULL png_ptr or NULL info_ptr (timeless)
1667
1668Version 1.2.9beta10 [March 20, 2006]
1669 Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin)
1670 Made pnggccrd.c PIC-compliant (Christian Aichinger).
1671 Added makefile.mingw (Wolfgang Glas).
1672 Revised pngconf.h MMX checking.
1673
1674Version 1.2.9beta11 [March 22, 2006]
1675 Fixed out-of-order declaration in pngwrite.c that was introduced in beta9
1676 Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros.
1677
1678Version 1.2.9rc1 [March 31, 2006]
1679 Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin).
1680 Removed nonsensical assertion check from pngtest.c (Cosmin).
1681
1682Version 1.2.9 [April 14, 2006]
1683 Revised makefile.beos and added "none" selector in ltmain.sh
1684
1685Version 1.2.10beta1 [April 15, 2006]
1686 Renamed "config.h" to "png_conf.h" and revised Makefile.am to add
1687 -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h
1688 to include png_conf.h only when PNG_BUILDING_LIBPNG is defined.
1689
1690Version 1.2.10beta2 [April 15, 2006]
1691 Manually updated Makefile.in and configure. Changed png_conf.h.in
1692 back to config.h.
1693
1694Version 1.2.10beta3 [April 15, 2006]
1695 Change png_conf.h back to config.h in pngconf.h.
1696
1697Version 1.2.10beta4 [April 16, 2006]
1698 Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*.
1699
1700Version 1.2.10beta5 [April 16, 2006]
1701 Added a configure check for compiling assembler code in pnggccrd.c
1702
1703Version 1.2.10beta6 [April 17, 2006]
1704 Revised the configure check for pnggccrd.c
1705 Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@
1706 Added @LIBPNG_DEFINES@ to arguments when building libpng.sym
1707
1708Version 1.2.10beta7 [April 18, 2006]
1709 Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles.
1710
1711Version 1.2.10rc1 [April 19, 2006]
1712 Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD
1713 Fixed "LN_FS" typo in makefile.sco and makefile.solaris.
1714
1715Version 1.2.10rc2 [April 20, 2006]
1716 Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE
1717 in configure.ac and configure
1718 Made the configure warning about versioned symbols less arrogant.
1719
1720Version 1.2.10rc3 [April 21, 2006]
1721 Added a note in libpng.txt that png_set_sig_bytes(8) can be used when
1722 writing an embedded PNG without the 8-byte signature.
1723 Revised makefiles and configure to avoid making links to libpng.so.*
1724
1725Version 1.2.10 [April 23, 2006]
1726 Reverted configure to "rc2" state.
1727
1728Version 1.2.11beta1 [May 31, 2006]
1729 scripts/libpng.pc.in contained "configure" style version info and would
1730 not work with makefiles.
1731 The shared-library makefiles were linking to libpng.so.0 instead of
1732 libpng.so.3 compatibility as the library.
1733
1734Version 1.2.11beta2 [June 2, 2006]
1735 Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
1736 buffer overflow.
1737 Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb)
1738
1739Version 1.2.11beta3 [June 5, 2006]
1740 Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin).
1741 Removed the accidental leftover Makefile.in~ (Cosmin).
1742 Avoided potential buffer overflow and optimized buffer in
1743 png_write_sCAL(), png_write_sCAL_s() (Cosmin).
1744 Removed the include directories and libraries from CFLAGS and LDFLAGS
1745 in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin).
1746
1747Version 1.2.11beta4 [June 6, 2006]
1748 Allow zero-length IDAT chunks after the entire zlib datastream, but not
1749 after another intervening chunk type.
1750
1751Version 1.0.19rc1, 1.2.11rc1 [June 13, 2006]
1752 Deleted extraneous square brackets from [config.h] in configure.ac
1753
1754Version 1.0.19rc2, 1.2.11rc2 [June 14, 2006]
1755 Added prototypes for PNG_INCH_CONVERSIONS functions to png.h
1756 Revised INSTALL and autogen.sh
1757 Fixed typo in several makefiles (-W1 should be -Wl)
1758 Added typedef for png_int_32 and png_uint_32 on 64-bit systems.
1759
1760Version 1.0.19rc3, 1.2.11rc3 [June 15, 2006]
1761 Removed the new typedefs for 64-bit systems (delay until version 1.4.0)
1762 Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid
1763 reading out of bounds.
1764
1765Version 1.0.19rc4, 1.2.11rc4 [June 15, 2006]
1766 Really removed the new typedefs for 64-bit systems.
1767
1768Version 1.0.19rc5, 1.2.11rc5 [June 22, 2006]
1769 Removed png_sig_bytes entry from scripts/pngw32.def
1770
1771Version 1.0.19, 1.2.11 [June 26, 2006]
1772 None.
1773
1774Version 1.0.20, 1.2.12 [June 27, 2006]
1775 Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
1776 buffer overflow.
1777
1778Version 1.2.13beta1 [October 2, 2006]
1779 Removed AC_FUNC_MALLOC from configure.ac
1780 Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h
1781 Change "logical" to "bitwise" throughout documentation.
1782 Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244)
1783
1784Version 1.0.21, 1.2.13 [November 14, 2006]
1785 Fix potential buffer overflow in sPLT chunk handler.
1786 Fix Makefile.am to not try to link to noexistent files.
1787 Check all exported functions for NULL png_ptr.
1788
1789Version 1.2.14beta1 [November 17, 2006]
1790 Relocated three misplaced tests for NULL png_ptr.
1791 Built Makefile.in with automake-1.9.6 instead of 1.9.2.
1792 Build configure with autoconf-2.60 instead of 2.59
1793
1794Version 1.2.14beta2 [November 17, 2006]
1795 Added some typecasts in png_zalloc().
1796
1797Version 1.2.14rc1 [November 20, 2006]
1798 Changed "strtod" to "png_strtod" in pngrutil.c
1799
1800Version 1.0.22, 1.2.14 [November 27, 2006]
1801 Added missing "$(srcdir)" in Makefile.am and Makefile.in
1802
1803Version 1.2.15beta1 [December 3, 2006]
1804 Generated configure with autoconf-2.61 instead of 2.60
1805 Revised configure.ac to update libpng.pc and libpng-config.
1806
1807Version 1.2.15beta2 [December 3, 2006]
1808 Always export MMX asm functions, just stubs if not building pnggccrd.c
1809
1810Version 1.2.15beta3 [December 4, 2006]
1811 Add "png_bytep" typecast to profile while calculating length in pngwutil.c
1812
1813Version 1.2.15beta4 [December 7, 2006]
1814 Added scripts/CMakeLists.txt
1815 Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta
1816
1817Version 1.2.15beta5 [December 7, 2006]
1818 Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c
1819 Revised scripts/CMakeLists.txt
1820
1821Version 1.2.15beta6 [December 13, 2006]
1822 Revised scripts/CMakeLists.txt and configure.ac
1823
1824Version 1.2.15rc1 [December 18, 2006]
1825 Revised scripts/CMakeLists.txt
1826
1827Version 1.2.15rc2 [December 21, 2006]
1828 Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
1829 Added scripts/makefile.nommx
1830
1831Version 1.2.15rc3 [December 25, 2006]
1832 Fixed shared library numbering error that was introduced in 1.2.15beta6.
1833
1834Version 1.2.15rc4 [December 27, 2006]
1835 Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set.
1836
1837Version 1.2.15rc5 [December 31, 2006]
1838 Revised handling of rgb_to_gray.
1839
1840Version 1.2.15 [January 5, 2007]
1841 Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.
1842
1843Version 1.2.16beta1 [January 6, 2007]
1844 Fix bugs in makefile.nommx
1845
1846Version 1.2.16beta2 [January 16, 2007]
1847 Revised scripts/CMakeLists.txt
1848
1849Version 1.2.16 [January 31, 2007]
1850 No changes.
1851
1852Version 1.2.17beta1 [March 6, 2007]
1853 Revised scripts/CMakeLists.txt to install both shared and static libraries.
1854 Deleted a redundant line from pngset.c.
1855
1856Version 1.2.17beta2 [April 26, 2007]
1857 Relocated misplaced test for png_ptr == NULL in pngpread.c
1858 Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN
1859 flags.
1860 Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_*
1861 Added pngerror() when write_IHDR fails in deflateInit2().
1862 Added "const" to some array declarations.
1863 Mention examples of libpng usage in the libpng*.txt and libpng.3 documents.
1864
1865Version 1.2.17rc1 [May 4, 2007]
1866 No changes.
1867
1868Version 1.2.17rc2 [May 8, 2007]
1869 Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications
1870 calling set_unknown_chunk_location() need them.
1871 Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in
1872 png_set_expand_gray_1_2_4_to_8().
1873 Added png_ptr->unknown_chunk to hold working unknown chunk data, so it
1874 can be free'ed in case of error. Revised unknown chunk handling in
1875 pngrutil.c and pngpread.c to use this structure.
1876
1877Version 1.2.17rc3 [May 8, 2007]
1878 Revised symbol-handling in configure script.
1879
1880Version 1.2.17rc4 [May 10, 2007]
1881 Revised unknown chunk handling to avoid storing unknown critical chunks.
1882
1883Version 1.0.25 [May 15, 2007]
1884Version 1.2.17 [May 15, 2007]
1885 Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
1886 to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664)
1887
1888Version 1.0.26 [May 15, 2007]
1889Version 1.2.18 [May 15, 2007]
1890 Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script
1891
1892Version 1.2.19beta1 [May 18, 2007]
1893 Changed "const static" to "static PNG_CONST" everywhere, mostly undoing
1894 change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST"
1895 Changed some handling of unused parameters, to avoid compiler warnings.
1896 "if (unused == NULL) return;" becomes "unused = unused".
1897
1898Version 1.2.19beta2 [May 18, 2007]
1899 Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier)
1900
1901Version 1.2.19beta3 [May 19, 2007]
1902 Add some "png_byte" typecasts in png_check_keyword() and write new_key
1903 instead of key in zTXt chunk (Kevin Ryde).
1904
1905Version 1.2.19beta4 [May 21, 2007]
1906 Add png_snprintf() function and use it in place of sprint() for improved
1907 defense against buffer overflows.
1908
1909Version 1.2.19beta5 [May 21, 2007]
1910 Fixed png_handle_tRNS() to only use the valid bits of tRNS value.
1911 Changed handling of more unused parameters, to avoid compiler warnings.
1912 Removed some PNG_CONST in pngwutil.c to avoid compiler warnings.
1913
1914Version 1.2.19beta6 [May 22, 2007]
1915 Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c
1916 Added a special "_MSC_VER" case that defines png_snprintf to _snprintf
1917
1918Version 1.2.19beta7 [May 22, 2007]
1919 Squelched png_squelch_warnings() in pnggccrd.c and added
1920 an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused
1921 the warnings that png_squelch_warnings was squelching.
1922
1923Version 1.2.19beta8 [May 22, 2007]
1924 Removed __MMX__ from test in pngconf.h.
1925
1926Version 1.2.19beta9 [May 23, 2007]
1927 Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro.
1928 Revised png_squelch_warnings() so it might work.
1929 Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86.
1930
1931Version 1.2.19beta10 [May 24, 2007]
1932 Resquelched png_squelch_warnings(), use "__attribute__((used))" instead.
1933
1934Version 1.4.0beta1 [April 20, 2006]
1935 Enabled iTXt support (changes png_struct, thus requires so-number change).
1936 Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED
1937 Eliminated PNG_1_0_X and PNG_1_2_X macros.
1938 Removed deprecated functions png_read_init, png_write_init, png_info_init,
1939 png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and
1940 removed the deprecated macro PNG_MAX_UINT.
1941 Moved "PNG_INTERNAL" parts of png.h and pngconf.h into pngintrn.h
1942 Removed many WIN32_WCE #ifdefs (Cosmin).
1943 Reduced dependency on C-runtime library when on Windows (Simon-Pierre)
1944 Replaced sprintf() with png_sprintf() (Simon-Pierre)
1945
1946Version 1.4.0beta2 [April 20, 2006]
1947 Revised makefiles and configure to avoid making links to libpng.so.*
1948 Moved some leftover MMX-related defines from pngconf.h to pngintrn.h
1949 Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def
1950
1951Version 1.4.0beta3 [May 10, 2006]
1952 Updated scripts/pngw32.def to comment out MMX functions.
1953 Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros.
1954 Scripts/libpng.pc.in contained "configure" style version info and would
1955 not work with makefiles.
1956 Revised pngconf.h and added pngconf.h.in, so makefiles and configure can
1957 pass defines to libpng and applications.
1958
1959Version 1.4.0beta4 [May 11, 2006]
1960 Revised configure.ac, Makefile.am, and many of the makefiles to write
1961 their defines in pngconf.h.
1962
1963Version 1.4.0beta5 [May 15, 2006]
1964 Added a missing semicolon in Makefile.am and Makefile.in
1965 Deleted extraneous square brackets from configure.ac
1966
1967Version 1.4.0beta6 [June 2, 2006]
1968 Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
1969 buffer overflow.
1970 Changed sonum from 0 to 1.
1971 Removed unused prototype for png_check_sig() from png.h
1972
1973Version 1.4.0beta7 [June 16, 2006]
1974 Exported png_write_sig (Cosmin).
1975 Optimized buffer in png_handle_cHRM() (Cosmin).
1976 Set pHYs = 2835 x 2835 pixels per meter, and added
1977 sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin).
1978 Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error().
1979 Added typedef for png_int_32 and png_uint_32 on 64-bit systems.
1980 Added "(unsigned long)" typecast on png_uint_32 variables in printf lists.
1981
1982Version 1.4.0beta8 [June 22, 2006]
1983 Added demonstration of user chunk support in pngtest.c, to support the
1984 public sTER chunk and a private vpAg chunk.
1985
1986Version 1.4.0beta9 [July 3, 2006]
1987 Removed ordinals from scripts/pngw32.def and removed png_info_int and
1988 png_set_gray_1_2_4_to_8 entries.
1989 Inline call of png_get_uint_32() in png_get_uint_31().
1990 Use png_get_uint_31() to get vpAg width and height in pngtest.c
1991 Removed WINCE and Netware projects.
1992 Removed standalone Y2KINFO file.
1993
1994Version 1.4.0beta10 [July 12, 2006]
1995 Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and
1996 some makefiles, because it was not working reliably. Instead, distribute
1997 pngconf.h.in along with pngconf.h and cause configure and some of the
1998 makefiles to update pngconf.h from pngconf.h.in.
1999 Added pngconf.h to DEPENDENCIES in Makefile.am
2000
2001Version 1.4.0beta11 [August 19, 2006]
2002 Removed AC_FUNC_MALLOC from configure.ac.
2003 Added a warning when writing iCCP profile with mismatched profile length.
2004 Patched pnggccrd.c to assemble on x86_64 platforms.
2005 Moved chunk header reading into a separate function png_read_chunk_header()
2006 in pngrutil.c. The chunk header (len+sig) is now serialized in a single
2007 operation (Cosmin).
2008 Implemented support for I/O states. Added png_ptr member io_state, and
2009 functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
2010 (Cosmin).
2011 Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin).
2012 Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin).
2013 Removed the include directories and libraries from CFLAGS and LDFLAGS
2014 in scripts/makefile.gcc (Cosmin).
2015 Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin).
2016 Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin).
2017 Added pngintrn.h to the Visual C++ projects (Cosmin).
2018 Removed scripts/list (Cosmin).
2019 Updated copyright year in scripts/pngwin.def (Cosmin).
2020 Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin).
2021 Disallowed the user to redefine png_size_t, and enforced a consistent use
2022 of png_size_t across libpng (Cosmin).
2023 Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends
2024 to png_size_t (Cosmin).
2025 Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin).
2026 Removed some unnecessary type casts (Cosmin).
2027 Changed prototype of png_get_compression_buffer_size() and
2028 png_set_compression_buffer_size() to work with png_size_t instead of
2029 png_uint_32 (Cosmin).
2030 Removed png_memcpy_check() and png_memset_check() (Cosmin).
2031 Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin).
2032 Clarified that png_zalloc() does not clear the allocated memory,
2033 and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin).
2034 Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in
2035 pngconf.h, and used it in all memory allocation functions (Cosmin).
2036 Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file
2037 mentioning that the symbols declared in that file are private, and
2038 updated the scripts and the Visual C++ projects accordingly (Cosmin).
2039 Removed circular references between pngconf.h and pngconf.h.in in
2040 scripts/makefile.vc*win32 (Cosmin).
2041 Removing trailing '.' from the warning and error messages (Cosmin).
2042 Added pngdefs.h that is built by makefile or configure, instead of
2043 pngconf.h.in (Glenn).
2044 Detect and fix attempt to write wrong iCCP profile length.
2045
2046Version 1.4.0beta12 [October 19, 2006]
2047 Changed "logical" to "bitwise" in the documentation.
2048 Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h
2049 Add a typecast to stifle compiler warning in pngrutil.c
2050
2051Version 1.4.0beta13 [November 10, 2006]
2052 Fix potential buffer overflow in sPLT chunk handler.
2053 Fix Makefile.am to not try to link to noexistent files.
2054
2055Version 1.4.0beta14 [November 15, 2006]
2056 Check all exported functions for NULL png_ptr.
2057
2058Version 1.4.0beta15 [November 17, 2006]
2059 Relocated two misplaced tests for NULL png_ptr.
2060 Built Makefile.in with automake-1.9.6 instead of 1.9.2.
2061 Build configure with autoconf-2.60 instead of 2.59
2062 Add "install: all" in Makefile.am so "configure; make install" will work.
2063
2064Version 1.4.0beta16 [November 17, 2006]
2065 Added a typecast in png_zalloc().
2066
2067Version 1.4.0beta17 [December 4, 2006]
2068 Changed "new_key[79] = '\0';" to "(*new_key)[79] = '\0';" in pngwutil.c
2069 Add "png_bytep" typecast to profile while calculating length in pngwutil.c
2070
2071Version 1.4.0beta18 [December 7, 2006]
2072 Added scripts/CMakeLists.txt
2073
2074Version 1.4.0beta19 [May 16, 2007]
2075 Revised scripts/CMakeLists.txt
2076 Rebuilt configure and Makefile.in with newer tools.
2077 Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
2078 Added scripts/makefile.nommx
2079
2080Version 1.4.0beta20 [July 9, 2008]
2081 Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications
2082 calling set_unknown_chunk_location() need them.
2083 Moved several macro definitions from pngpriv.h to pngconf.h
2084 Merge with changes to the 1.2.X branch, as of 1.2.30beta04.
2085 Deleted all use of the MMX assembler code and Intel-licensed optimizations.
2086 Revised makefile.mingw
2087
2088Version 1.4.0beta21 [July 21, 2008]
2089 Moved local array "chunkdata" from pngrutil.c to the png_struct, so
2090 it will be freed by png_read_destroy() in case of a read error (Kurt
2091 Christensen).
2092
2093Version 1.4.0beta22 [July 21, 2008]
2094 Change "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking.
2095
2096Version 1.4.0beta23 [July 22, 2008]
2097 Change "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in
2098 png_decompress_chunk().
2099
2100Version 1.4.0beta24 [July 25, 2008]
2101 Change all remaining "chunkdata" to "png_ptr->chunkdata" in
2102 png_decompress_chunk(), and remove "chunkdata" from parameter list.
2103 Put a call to png_check_chunk_name() in png_read_chunk_header().
2104 Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte.
2105 Removed two calls to png_check_chunk_name() occuring later in the process.
2106 Define PNG_NO_ERROR_NUMBERS by default in pngconf.h
2107
2108Version 1.4.0beta25 [July 30, 2008]
2109 Added a call to png_check_chunk_name() in pngpread.c
2110 Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte.
2111 Added png_push_have_buffer() function to pngpread.c
2112 Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros.
2113 Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS.
2114 Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code.
2115 Synced contrib directory and configure files with libpng-1.2.30beta06.
2116 Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles)
2117 Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c
2118
2119Version 1.4.0beta26 [August 4, 2008]
2120 Removed png_push_have_buffer() function in pngpread.c. It increased the
2121 compiled library size slightly.
2122 Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta)
2123 Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings.
2124 Updated contrib/visupng/cexcept.h to version 2.0.1
2125 Added PNG_LITERAL_CHARACTER macros for #, [, and ].
2126
2127Version 1.4.0beta27 [August 5, 2008]
2128 Revised usage of PNG_LITERAL_SHARP in pngerror.c.
2129 Moved newline character from individual png_debug messages into the
2130 png_debug macros.
2131 Allow user to #define their own png_debug, png_debug1, and png_debug2.
2132
2133Version 1.4.0beta28 [August 5, 2008]
2134 Revised usage of PNG_LITERAL_SHARP in pngerror.c.
2135 Added PNG_STRING_NEWLINE macro
2136
2137Version 1.4.0beta29 [August 9, 2008]
2138 Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers.
2139 Added PNG_STRING_COPYRIGHT macro.
2140 Added non-ISO versions of png_debug macros.
2141
2142Version 1.4.0beta30 [August 14, 2008]
2143 Added premultiplied alpha feature (Volker Wiendl).
2144
2145Version 1.4.0beta31 [August 18, 2008]
2146 Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c
2147 Removed extra crc check at the end of png_handle_cHRM(). Bug introduced
2148 in libpng-1.4.0beta20.
2149
2150Version 1.4.0beta32 [August 19, 2008]
2151 Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call.
2152 Revised PNG_NO_STDIO version of png_write_flush()
2153
2154Version 1.4.0beta33 [August 20, 2008]
2155 Added png_get|set_chunk_cache_max() to limit the total number of sPLT,
2156 text, and unknown chunks that can be stored.
2157
2158Version 1.4.0beta34 [September 6, 2008]
2159 Shortened tIME_string to 29 bytes in pngtest.c
2160 Fixed off-by-one error introduced in png_push_read_zTXt() function in
2161 libpng-1.2.30beta04/pngpread.c (Harald van Dijk)
2162
2163Version 1.4.0beta35 [October 6, 2008]
2164 Changed "trans_values" to "trans_color".
2165 Changed so-number from 0 to 14. Some OS do not like 0.
2166 Revised makefile.darwin to fix shared library numbering.
2167 Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8()
2168 in example.c (debian bug report)
2169
2170Version 1.4.0beta36 [October 25, 2008]
2171 Sync with tEXt vulnerability fix in libpng-1.2.33rc02.
2172
2173Version 1.4.0beta37 [November 13, 2008]
2174 Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c,
2175 and pngwrite.c
2176
2177Version 1.4.0beta38 [November 22, 2008]
2178 Added check for zero-area RGB cHRM triangle in png_check_cHRM() and
2179 png_check_cHRM_fixed().
2180
2181Version 1.4.0beta39 [November 23, 2008]
2182 Revised png_warning() to write its message on standard output by default
2183 when warning_fn is NULL.
2184
2185Version 1.4.0beta40 [November 24, 2008]
2186 Eliminated png_check_cHRM(). Instead, always use png_check_cHRM_fixed().
2187 In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant
2188 check for all-zero coordinates that is detected by the triangle check.
2189
2190Version 1.4.0beta41 [November 26, 2008]
2191 Fixed string vs pointer-to-string error in png_check_keyword().
2192 Rearranged test expressions in png_check_cHRM_fixed() to avoid internal
2193 overflows.
2194 Added PNG_NO_CHECK_cHRM conditional.
2195
2196Version 1.4.0beta42, 43 [December 1, 2008]
2197 Merge png_debug with version 1.2.34beta04.
2198
2199Version 1.4.0beta44 [December 6, 2008]
2200 Removed redundant check for key==NULL before calling png_check_keyword()
2201 to ensure that new_key gets initialized and removed extra warning
2202 (Merge with version 1.2.34beta05 -- Arvan Pritchard).
2203
2204Version 1.4.0beta45 [December 9, 2008]
2205 In png_write_png(), respect the placement of the filler bytes in an earlier
2206 call to png_set_filler() (Jim Barry).
2207
2208Version 1.4.0beta46 [December 10, 2008]
2209 Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and
2210 PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated
2211 PNG_TRANSFORM_STRIP_FILLER (Jim Barry).
2212
2213Version 1.4.0beta47 [December 15, 2008]
2214 Support for dithering was disabled by default, because it has never
2215 been well tested and doesn't work very well. The code has not
2216 been removed, however, and can be enabled by building libpng with
2217 PNG_READ_DITHER_SUPPORTED defined.
2218
2219Version 1.4.0beta48 [February 14, 2009]
2220 Added new exported function png_calloc().
2221 Combined several instances of png_malloc(); png_memset() into png_calloc().
2222 Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24
2223 but was never defined.
2224
2225Version 1.4.0beta49 [February 28, 2009]
2226 Added png_fileno() macro to pngconf.h, used in pngwio.c
2227 Corrected order of #ifdef's in png_debug definition in png.h
2228 Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments
2229 for pcal_params.
2230 Fixed order of #ifdef directives in the png_debug defines in png.h
2231 (bug introduced in libpng-1.2.34/1.4.0beta29).
2232 Revised comments in png_set_read_fn() and png_set_write_fn().
2233
2234Version 1.4.0beta50 [March 18, 2009]
2235 Use png_calloc() instead of png_malloc() to allocate big_row_buf when
2236 reading an interlaced file, to avoid a possible UMR.
2237 Undid revision of PNG_NO_STDIO version of png_write_flush(). Users
2238 having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined
2239 or supply their own flush_fn() replacement.
2240 Revised libpng*.txt and png.h documentation about use of png_write_flush()
2241 and png_set_write_fn().
2242 Removed fflush() from pngtest.c.
2243 Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
2244
2245Version 1.4.0beta51 [March 21, 2009]
2246 Removed new png_fileno() macro from pngconf.h .
2247
2248Version 1.4.0beta52 [March 27, 2009]
2249 Relocated png_do_chop() ahead of building gamma tables in pngrtran.c
2250 This avoids building 16-bit gamma tables unnecessarily.
2251 Removed fflush() from pngtest.c.
2252 Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
2253 Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt
2254
2255Version 1.4.0beta53 [April 1, 2009]
2256 Removed some remaining MMX macros from pngpriv.h
2257 Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles)
2258
2259Version 1.4.0beta54 [April 13, 2009]
2260 Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow
2261 application code writers to bypass the check for multiple inclusion
2262 of setjmp.h when they know that it is safe to ignore the situation.
2263 Eliminated internal use of setjmp() in pngread.c and pngwrite.c
2264 Reordered ancillary chunks in pngtest.png to be the same as what
2265 pngtest now produces, and made some cosmetic changes to pngtest output.
2266 Eliminated deprecated png_read_init_3() and png_write_init_3() functions.
2267
2268Version 1.4.0beta55 [April 15, 2009]
2269 Simplified error handling in pngread.c and pngwrite.c by putting
2270 the new png_read_cleanup() and png_write_cleanup() functions inline.
2271
2272Version 1.4.0beta56 [April 25, 2009]
2273 Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress
2274 "shadowed declaration" warning from gcc-4.3.3.
2275 Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration"
2276 warning about a global "gamma" variable in math.h on some platforms.
2277
2278Version 1.4.0beta57 [May 2, 2009]
2279 Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24
2280 but was never defined (again).
2281 Rebuilt configure scripts with autoconf-2.63 instead of 2.62
2282 Removed pngprefs.h and MMX from makefiles
2283
2284Version 1.4.0beta58 [May 14, 2009]
2285 Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced
2286 in beta57).
2287 Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri)
2288
2289Version 1.4.0beta59 [May 15, 2009]
2290 Reformated sources in libpng style (3-space intentation, comment format)
2291 Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG)
2292 Added sections about the git repository and our coding style to the
2293 documentation
2294 Relocated misplaced #endif in pngwrite.c, sCAL chunk handler.
2295
2296Version 1.4.0beta60 [May 19, 2009]
2297 Conditionally compile png_read_finish_row() which is not used by
2298 progressive readers.
2299 Added contrib/pngminim/preader to demonstrate building minimal progressive
2300 decoder, based on contrib/gregbook with embedded libpng and zlib.
2301
2302Version 1.4.0beta61 [May 20, 2009]
2303 In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there
2304 is only one makefile in those directories, and revised the README files
2305 accordingly.
2306 More reformatting of comments, mostly to capitalize sentences.
2307
2308Version 1.4.0beta62 [June 2, 2009]
2309 Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h
2310 and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h
2311 Reformatted several remaining "else statement" into two lines.
2312 Added a section to the libpng documentation about using png_get_io_ptr()
2313 in configure scripts to detect the presence of libpng.
2314
2315Version 1.4.0beta63 [June 15, 2009]
2316 Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR()
2317 multiple times and to specify the sample order in the tRNS chunk,
2318 because the ISO PNG specification has a typo in the tRNS table.
2319 Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to
2320 PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism
2321 available for ignoring known chunks even when not saving unknown chunks.
2322 Adopted preference for consistent use of "#ifdef" and "#ifndef" versus
2323 "#if defined()" and "if !defined()" where possible.
2324
2325Version 1.4.0beta64 [June 24, 2009]
2326 Eliminated PNG_LEGACY_SUPPORTED code.
2327 Moved the various unknown chunk macro definitions outside of the
2328 PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks.
2329
2330Version 1.4.0beta65 [June 26, 2009]
2331 Added a reference to the libpng license in each file.
2332
2333Version 1.4.0beta66 [June 27, 2009]
2334 Refer to the libpng license instead of the libpng license in each file.
2335
2336Version 1.4.0beta67 [July 6, 2009]
2337 Relocated INVERT_ALPHA within png_read_png() and png_write_png().
2338 Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB.
2339 Added an "xcode" project to the projects directory (Alam Arias).
2340
2341Version 1.4.0beta68 [July 19, 2009]
2342 Avoid some tests in filter selection in pngwutil.c
2343
2344Version 1.4.0beta69 [July 25, 2009]
2345 Simplified the new filter-selection test. This runs faster in the
2346 common "PNG_ALL_FILTERS" and PNG_FILTER_NONE cases.
2347 Removed extraneous declaration from the new call to png_read_gray_to_rgb()
2348 (bug introduced in libpng-1.4.0beta67).
2349 Fixed up xcode project (Alam Arias)
2350 Added a prototype for png_64bit_product() in png.c
2351
2352Version 1.4.0beta70 [July 27, 2009]
2353 Avoid a possible NULL dereference in debug build, in png_set_text_2().
2354 (bug introduced in libpng-0.95, discovered by Evan Rouault)
2355
2356Version 1.4.0beta71 [July 29, 2009]
2357 Rebuilt configure scripts with autoconf-2.64.
2358
2359Version 1.4.0beta72 [August 1, 2009]
2360 Replaced *.tar.lzma with *.tar.xz in distribution. Get the xz codec
2361 from <http://tukaani.org/xz>.
2362
2363Version 1.4.0beta73 [August 1, 2009]
2364 Reject attempt to write iCCP chunk with negative embedded profile length
2365 (JD Chen) (CVE-2009-5063).
2366
2367Version 1.4.0beta74 [August 8, 2009]
2368 Changed png_ptr and info_ptr member "trans" to "trans_alpha".
2369
2370Version 1.4.0beta75 [August 21, 2009]
2371 Removed an extra png_debug() recently added to png_write_find_filter().
2372 Fixed incorrect #ifdef in pngset.c regarding unknown chunk support.
2373
2374Version 1.4.0beta76 [August 22, 2009]
2375 Moved an incorrectly located test in png_read_row() in pngread.c
2376
2377Version 1.4.0beta77 [August 27, 2009]
2378 Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt,
2379 and the "noconfig" files from the distribution.
2380 Moved CMakeLists.txt from scripts into the main libpng directory.
2381 Various bugfixes and improvements to CMakeLists.txt (Philip Lowman)
2382
2383Version 1.4.0beta78 [August 31, 2009]
2384 Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h
2385 Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros.
2386 Use png_malloc plus a loop instead of png_calloc() to initialize
2387 row_pointers in png_read_png().
2388
2389Version 1.4.0beta79 [September 1, 2009]
2390 Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays.
2391 Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc().
2392
2393Version 1.4.0beta80 [September 17, 2009]
2394 Removed scripts/libpng.icc
2395 Changed typecast of filler from png_byte to png_uint_16 in png_set_filler().
2396 (Dennis Gustafsson)
2397 Fixed typo introduced in beta78 in pngtest.c ("#if def " should be "#ifdef ")
2398
2399Version 1.4.0beta81 [September 23, 2009]
2400 Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h
2401 Expanded TAB characters in pngrtran.c
2402 Removed PNG_CONST from all "PNG_CONST PNG_CHNK" declarations to avoid
2403 compiler complaints about doubly declaring things "const".
2404 Changed all "#if [!]defined(X)" to "if[n]def X" where possible.
2405 Eliminated unused png_ptr->row_buf_size
2406
2407Version 1.4.0beta82 [September 25, 2009]
2408 Moved redundant IHDR checking into new png_check_IHDR() in png.c
2409 and report all errors found in the IHDR data.
2410 Eliminated useless call to png_check_cHRM() from pngset.c
2411
2412Version 1.4.0beta83 [September 25, 2009]
2413 Revised png_check_IHDR() to eliminate bogus complaint about filter_type.
2414
2415Version 1.4.0beta84 [September 30, 2009]
2416 Fixed some inconsistent indentation in pngconf.h
2417 Revised png_check_IHDR() to add a test for width variable less than 32-bit.
2418
2419Version 1.4.0beta85 [October 1, 2009]
2420 Revised png_check_IHDR() again, to check info_ptr members instead of
2421 the contents of the returned parameters.
2422
2423Version 1.4.0beta86 [October 9, 2009]
2424 Updated the "xcode" project (Alam Arias).
2425 Eliminated a shadowed declaration of "pp" in png_handle_sPLT().
2426
2427Version 1.4.0rc01 [October 19, 2009]
2428 Trivial cosmetic changes.
2429
2430Version 1.4.0beta87 [October 30, 2009]
2431 Moved version 1.4.0 back into beta.
2432
2433Version 1.4.0beta88 [October 30, 2009]
2434 Revised libpng*.txt section about differences between 1.2.x and 1.4.0
2435 because most of the new features have now been ported back to 1.2.41
2436
2437Version 1.4.0beta89 [November 1, 2009]
2438 More bugfixes and improvements to CMakeLists.txt (Philip Lowman)
2439 Removed a harmless extra png_set_invert_alpha() from pngwrite.c
2440 Apply png_user_chunk_cache_max within png_decompress_chunk().
2441 Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate.
2442
2443Version 1.4.0beta90 [November 2, 2009]
2444 Removed all remaining WIN32_WCE #ifdefs except those involving the
2445 time.h "tm" structure
2446
2447Version 1.4.0beta91 [November 3, 2009]
2448 Updated scripts/pngw32.def and projects/wince/png32ce.def
2449 Copied projects/wince/png32ce.def to the scripts directory.
2450 Added scripts/makefile.wce
2451 Patched ltmain.sh for wince support.
2452 Added PNG_CONVERT_tIME_SUPPORTED macro.
2453
2454Version 1.4.0beta92 [November 4, 2009]
2455 Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED
2456 Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED
2457 Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead
2458 of differences from 1.2.41 to 1.4.0)
2459
2460Version 1.4.0beta93 [November 7, 2009]
2461 Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and
2462 PNG_ALLOCATED macros to detect deprecated direct access to the
2463 png_struct or info_struct members and other deprecated usage in
2464 applications (John Bowler).
2465 Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS,
2466 to prevent warnings about direct access to png structs by libpng
2467 functions while building libpng. They need to be tested, especially
2468 those using compilers other than gcc.
2469 Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG".
2470 They should work but still need to be updated to remove
2471 references to pnggccrd.c or pngvcrd.c and ASM building.
2472 Added README.txt to the beos, cbuilder5, netware, and xcode projects warning
2473 that they need to be updated, to remove references to pnggccrd.c and
2474 pngvcrd.c and to depend on pngpriv.h
2475 Removed three direct references to read_info_ptr members in pngtest.c
2476 that were detected by the new PNG_DEPSTRUCT macro.
2477 Moved the png_debug macro definitions and the png_read_destroy(),
2478 png_write_destroy() and png_far_to_near() prototypes from png.h
2479 to pngpriv.h (John Bowler)
2480 Moved the synopsis lines for png_read_destroy(), png_write_destroy()
2481 png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3.
2482
2483Version 1.4.0beta94 [November 9, 2009]
2484 Removed the obsolete, unused pnggccrd.c and pngvcrd.c files.
2485 Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions.
2486 Removed dependency of pngtest.o on pngpriv.h in the makefiles.
2487 Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined.
2488
2489Version 1.4.0beta95 [November 10, 2009]
2490 Changed png_check_sig() to !png_sig_cmp() in contrib programs.
2491 Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile
2492 Changed png_check_sig() to !png_sig_cmp() in contrib programs.
2493 Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c
2494 Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c
2495 Added dependency on pngpriv.h in contrib/pngminim/*/makefile
2496
2497Version 1.4.0beta96 [November 12, 2009]
2498 Renamed scripts/makefile.wce to scripts/makefile.cegcc
2499 Revised Makefile.am to use libpng.sys while building libpng.so
2500 so that only PNG_EXPORT functions are exported.
2501 Removed the deprecated png_check_sig() function/macro.
2502 Removed recently removed function names from scripts/*.def
2503 Revised pngtest.png to put chunks in the same order written by pngtest
2504 (evidently the same change made in libpng-1.0beta54 was lost).
2505 Added PNG_PRIVATE macro definition in pngconf.h for possible future use.
2506
2507Version 1.4.0beta97 [November 13, 2009]
2508 Restored pngtest.png to the libpng-1.4.0beta7 version.
2509 Removed projects/beos and netware.txt; no one seems to be supporting them.
2510 Revised Makefile.in
2511
2512Version 1.4.0beta98 [November 13, 2009]
2513 Added the "xcode" project to zip distributions,
2514 Fixed a typo in scripts/pngwin.def introduced in beta97.
2515
2516Version 1.4.0beta99 [November 14, 2009]
2517 Moved libpng-config.in and libpng.pc-configure.in out of the scripts
2518 directory, to libpng-config.in and libpng-pc.in, respectively, and
2519 modified Makefile.am and configure.ac accordingly. Now "configure"
2520 needs nothing from the "scripts" directory.
2521 Avoid redefining PNG_CONST in pngconf.h
2522
2523Version 1.4.0beta100 [November 14, 2009]
2524 Removed ASM builds from projects/visualc6 and projects/visualc71
2525 Removed scripts/makefile.nommx and makefile.vcawin32
2526 Revised CMakeLists.txt to account for new location of libpng-config.in
2527 and libpng-pc.in
2528 Updated INSTALL to reflect removal and relocation of files.
2529
2530Version 1.4.0beta101 [November 14, 2009]
2531 Restored the binary files (*.jpg, *.png, some project files) that were
2532 accidentally deleted from the zip and 7z distributions when the xcode
2533 project was added.
2534
2535Version 1.4.0beta102 [November 18, 2009]
2536 Added libpng-config.in and libpng-pc.in to the zip and 7z distributions.
2537 Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100.
2538 Moved descriptions of makefiles and other scripts out of INSTALL into
2539 scripts/README.txt
2540 Updated the copyright year in scripts/pngwin.rc from 2006 to 2009.
2541
2542Version 1.4.0beta103 [November 21, 2009]
2543 Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt
2544 Align row_buf on 16-byte boundary in memory.
2545 Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call
2546 to png_flush() after png_write_IEND(). See 1.4.0beta32, 1.4.0beta50
2547 changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES. Someone
2548 needs this feature.
2549 Make the 'png_jmpbuf' macro expand to a call that records the correct
2550 longjmp function as well as returning a pointer to the setjmp
2551 jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'.
2552 (John Bowler)
2553
2554Version 1.4.0beta104 [November 22, 2009]
2555 Removed png_longjmp_ptr from scripts/*.def and libpng.3
2556 Rebuilt configure scripts with autoconf-2.65
2557
2558Version 1.4.0beta105 [November 25, 2009]
2559 Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535()
2560 to accomplish alpha premultiplication when
2561 PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined.
2562 Changed "/255" to "/255.0" in background calculations to make it clear
2563 that the 255 is used as a double.
2564
2565Version 1.4.0beta106 [November 27, 2009]
2566 Removed premultiplied alpha feature.
2567
2568Version 1.4.0beta107 [December 4, 2009]
2569 Updated README
2570 Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files.
2571 Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects.
2572 Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco
2573 to put png.h and pngconf.h in $prefix/include, like the other scripts,
2574 instead of in $prefix/include/libpng. Also revised makefile.sco
2575 to put them in $prefix/include/libpng15 instead of in
2576 $prefix/include/libpng/libpng15.
2577
2578Version 1.4.0beta108 [December 11, 2009]
2579 Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile
2580 Relocated png_do_chop() to its original position in pngrtran.c; the
2581 change in version 1.2.41beta08 caused transparency to be handled wrong
2582 in some 16-bit datastreams (Yusaku Sugai).
2583
2584Version 1.4.0beta109 [December 13, 2009]
2585 Added "bit_depth" parameter to the private png_build_gamma_table() function.
2586 Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the
2587 PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit
2588 tables.
2589
2590Version 1.4.0rc02 [December 20, 2009]
2591 Declared png_cleanup_needed "volatile" in pngread.c and pngwrite.c
2592
2593Version 1.4.0rc03 [December 22, 2009]
2594 Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt
2595 (revising the change in 1.4.0beta99)
2596
2597Version 1.4.0rc04 [December 25, 2009]
2598 Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2599 in pngset.c to be consistent with other changes in version 1.2.38.
2600
2601Version 1.4.0rc05 [December 25, 2009]
2602 Changed "libpng-pc.in" to "libpng.pc.in" in configure.ac, configure, and
2603 Makefile.in to be consistent with changes in libpng-1.4.0rc03
2604
2605Version 1.4.0rc06 [December 29, 2009]
2606 Reverted the gamma_table changes from libpng-1.4.0beta109.
2607 Fixed some indentation errors.
2608
2609Version 1.4.0rc07 [January 1, 2010]
2610 Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences.
2611 Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c
2612 Update copyright year to 2010.
2613
2614Version 1.4.0rc08 [January 2, 2010]
2615 Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr
2616 in pngtest.c
2617
2618Version 1.4.0 [January 3, 2010]
2619 No changes.
2620
2621Version 1.4.1beta01 [January 8, 2010]
2622 Updated CMakeLists.txt for consistent indentation and to avoid an
2623 unclosed if-statement warning (Philip Lowman).
2624 Revised Makefile.am and Makefile.in to remove references to Y2KINFO,
2625 KNOWNBUG, and libpng.la (Robert Schwebel).
2626 Revised the makefiles to install the same files and symbolic
2627 links as configure, except for libpng.la and libpng14.la.
2628 Make png_set|get_compression_buffer_size() available even when
2629 PNG_WRITE_SUPPORTED is not enabled.
2630 Revised Makefile.am and Makefile.in to simplify their maintenance.
2631 Revised scripts/makefile.linux to install a link to libpng14.so.14.1
2632
2633Version 1.4.1beta02 [January 9, 2010]
2634 Revised the rest of the makefiles to install a link to libpng14.so.14.1
2635
2636Version 1.4.1beta03 [January 10, 2010]
2637 Removed png_set_premultiply_alpha() from scripts/*.def
2638
2639Version 1.4.1rc01 [January 16, 2010]
2640 No changes.
2641
2642Version 1.4.1beta04 [January 23, 2010]
2643 Revised png_decompress_chunk() to improve speed and memory usage when
2644 decoding large chunks.
2645 Added png_set|get_chunk_malloc_max() functions.
2646
2647Version 1.4.1beta05 [January 26, 2010]
2648 Relocated "int k" declaration in pngtest.c to minimize its scope.
2649
2650Version 1.4.1beta06 [January 28, 2010]
2651 Revised png_decompress_chunk() to use a two-pass method suggested by
2652 John Bowler.
2653
2654Version 1.4.1beta07 [February 6, 2010]
2655 Folded some long lines in the source files.
2656 Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX,
2657 and a PNG_USER_LIMITS_SUPPORTED flag.
2658 Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as
2659 png_ptr->png_user_chunk_malloc_max.
2660 Revised png_push_save_buffer() to do fewer but larger png_malloc() calls.
2661
2662Version 1.4.1beta08 [February 6, 2010]
2663 Minor cleanup and updating of dates and copyright year.
2664
2665Version 1.5.0beta01 [February 7, 2010]
2666 Moved declaration of png_struct into private pngstruct.h and png_info
2667 into pnginfo.h
2668
2669Version 1.4.1beta09 and 1.5.0beta02 [February 7, 2010]
2670 Reverted to original png_push_save_buffer() code.
2671
2672Version 1.4.1beta10 and 1.5.0beta03 [February 8, 2010]
2673 Return allocated "old_buffer" in png_push_save_buffer() before
2674 calling png_error(), to avoid a potential memory leak.
2675 Updated configure script to use SO number 15.
2676
2677Version 1.5.0beta04 [February 9, 2010]
2678 Removed malformed "incomplete struct declaration" of png_info from png.h
2679
2680Version 1.5.0beta05 [February 12, 2010]
2681 Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the
2682 linewrapping that it entailed.
2683 Revised comments in pngstruct.h and pnginfo.h and added pointers to
2684 the libpng license.
2685 Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES
2686 Removed the cbuilder5 project, which has not been updated to 1.4.0.
2687
2688Version 1.4.1beta12 and 1.5.0beta06 [February 14, 2010]
2689 Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke
2690 Nishikawa)
2691
2692Version 1.5.0beta07 [omitted]
2693
2694Version 1.5.0beta08 [February 19, 2010]
2695 Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED
2696 wherever png_snprintf() is used to construct error and warning messages.
2697 Noted in scripts/makefile.mingw that it expects to be run under MSYS.
2698 Removed obsolete unused MMX-querying support from contrib/gregbook
2699 Added exported png_longjmp() function.
2700 Removed the AIX redefinition of jmpbuf in png.h
2701 Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt
2702 when building on AIX.
2703
2704Version 1.5.0beta09 [February 19, 2010]
2705 Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt.
2706 Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h
2707
2708Version 1.5.0beta10 [February 25, 2010]
2709 Removed unused gzio.c from contrib/pngminim gather and makefile scripts
2710 Removed replacement error handlers from contrib/gregbook. Because of
2711 the new png_longjmp() function they are no longer needed.
2712
2713Version 1.5.0beta11 [March 6, 2010]
2714 Removed checking for already-included setjmp.h from pngconf.h
2715 Fixed inconsistent indentations and made numerous cosmetic changes.
2716 Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5
2717
2718Version 1.5.0beta12 [March 9, 2010]
2719 Moved "#include png.h" inside pngpriv.h and removed "#include png.h" from
2720 the source files, along with "#define PNG_EXPOSE_INTERNAL_STRUCTURES"
2721 and "#define PNG_NO_PEDANTIC_WARNINGS" (John Bowler).
2722 Created new pngdebug.h and moved debug definitions there.
2723
2724Version 1.5.0beta13 [March 10, 2010]
2725 Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice.
2726 Revise the "#ifdef" blocks in png_inflate() so it will compile when neither
2727 PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
2728 is defined.
2729 Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3
2730 Moved the 'config.h' support from pngconf.h to pngpriv.h
2731 Removed PNGAPI from the png_longjmp_ptr typedef.
2732 Eliminated dependence of pngtest.c on the private pngdebug.h file.
2733 Make all png_debug macros into *unterminated* statements or
2734 expressions (i.e. a trailing ';' must always be added) and correct
2735 the format statements in various png_debug messages.
2736
2737Version 1.5.0beta14 [March 14, 2010]
2738 Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c
2739 Revised Makefile.am to account for recent additions and replacements.
2740 Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and
2741 added ordinal numbers to the Windows DEF file and corrected the duplicated
2742 ordinal numbers on CE symbols that are commented out.
2743 Added back in export symbols that can be present in the Windows build but
2744 are disabled by default.
2745 PNG_EXPORT changed to include an 'ordinal' field for DEF file generation.
2746 PNG_CALLBACK added to make callback definitions uniform. PNGAPI split
2747 into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks),
2748 and appropriate changes made to all files. Cygwin builds re-hinged to
2749 allow procedure call standard changes and to remove the need for the DEF
2750 file (fixes build on Cygwin).
2751 Enabled 'attribute' warnings that are relevant to library APIs and callbacks.
2752 Changed rules for generation of the various symbol files and added a new
2753 rule for a DEF file (which is also added to the distribution).
2754 Updated the symbol file generation to stop it adding spurious spaces
2755 to EOL (coming from preprocessor macro expansion). Added a facility
2756 to join tokens in the output and rewrite *.dfn to use this.
2757 Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71
2758 and removed scripts/makefile.cygwin.
2759 Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built.
2760 Removed the include of sys/types.h - apparently unnecessary now on the
2761 platforms on which it happened (all but Mac OS and RISC OS).
2762 Moved the Mac OS test into pngpriv.h (the only place it is used.)
2763
2764Version 1.5.0beta15 [March 17, 2010]
2765 Added symbols.chk target to Makefile.am to validate the symbols in png.h
2766 against the new DEF file scripts/symbols.def.
2767 Changed the default DEF file back to pngwin.def.
2768 Removed makefile.mingw.
2769 Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN
2770
2771Version 1.5.0beta16 [April 1, 2010]
2772 Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that
2773 fields are initialized in all configurations. The READ/WRITE
2774 macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as
2775 before to disable code to actually read or write iTXt chunks
2776 and iTXt_SUPPORTED can be used to detect presence of either
2777 read or write support (but it is probably better to check for
2778 the one actually required - read or write.)
2779 Combined multiple png_warning() calls for a single error.
2780 Restored the macro definition of png_check_sig().
2781
2782Version 1.5.0beta17 [April 17, 2010]
2783 Added some "(long)" typecasts to printf calls in png_handle_cHRM().
2784 Documented the fact that png_set_dither() was disabled since libpng-1.4.0.
2785 Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect
2786 more accurately what it actually does. At the same time, renamed
2787 the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to
2788 PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS.
2789 Added some "(long)" typecasts to printf calls in png_handle_cHRM().
2790 Freeze build-time only configuration in the build.
2791 In all prior versions of libpng most configuration options
2792 controlled by compiler #defines had to be repeated by the
2793 application code that used libpng. This patch changes this
2794 so that compilation options that can only be changed at build
2795 time are frozen in the build. Options that are compiler
2796 dependent (and those that are system dependent) are evaluated
2797 each time - pngconf.h holds these. Options that can be changed
2798 per-file in the application are in png.h. Frozen options are
2799 in the new installed header file pnglibconf.h (John Bowler)
2800 Removed the xcode project because it has not been updated to work
2801 with libpng-1.5.0.
2802 Removed the ability to include optional pngusr.h
2803
2804Version 1.5.0beta18 [April 17, 2010]
2805 Restored the ability to include optional pngusr.h
2806 Moved replacements for png_error() and png_warning() from the
2807 contrib/pngminim project to pngerror.c, for use when warnings or
2808 errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid
2809 storing unneeded error/warning text.
2810 Updated contrib/pngminim project to work with the new pnglibconf.h
2811 Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space.
2812
2813Version 1.5.0beta19 [April 24, 2010]
2814 Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the functions
2815 to read and write ints to be disabled independently of PNG_USE_READ_MACROS,
2816 which allows libpng to be built with the functions even though the default
2817 is to use the macros - this allows applications to choose at app build
2818 time whether or not to use macros (previously impossible because the
2819 functions weren't in the default build.)
2820 Changed Windows calling convention back to __cdecl for API functions.
2821 For Windows/x86 platforms only:
2822 __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses
2823 __cdecl throughout (both API functions and callbacks) on Windows/x86
2824 platforms.
2825 Replaced visualc6 and visualc71 projects with new vstudio project
2826 Relaxed the overly-restrictive permissions of some files.
2827
2828Version 1.5.0beta20 [April 24, 2010]
2829 Relaxed more overly-restrictive permissions of some files.
2830
2831Version 1.5.0beta21 [April 27, 2010]
2832 Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new
2833 vstudio project files, and some trivial editing of some files in the
2834 scripts directory.
2835 Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in
2836 contrib/pngminim/decoder/pngusr.h to make a smaller decoder application.
2837
2838Version 1.5.0beta22 [April 28, 2010]
2839 Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS
2840 because it has a macro equivalent.
2841 Improved the options.awk script; added an "everything off" option.
2842 Revised contrib/pngminim to use the "everything off" option in pngusr.dfa.
2843
2844Version 1.5.0beta23 [April 29, 2010]
2845 Corrected PNG_REMOVED macro to take five arguments.
2846 The macro was documented with two arguments (name,ordinal), however
2847 the symbol checking .dfn files assumed five arguments. The five
2848 argument form seems more useful so it is changed to that.
2849 Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2850 in gregbook/readpng2.c
2851 Corrected protection of png_get_user_transform_ptr. The API declaration in
2852 png.h is removed if both READ and WRITE USER_TRANSFORM are turned off
2853 but was left defined in pngtrans.c
2854 Added logunsupported=1 to cause pnglibconf.h to document disabled options.
2855 This makes the installed pnglibconf.h more readable but causes no
2856 other change. The intention is that users of libpng will find it
2857 easier to understand if an API they need is missing.
2858 Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined.
2859 Removed dummy_inflate.c from contrib/pngminim/encoder
2860 Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile.
2861
2862Version 1.5.0beta24 [May 7, 2010]
2863 Use bitwise "&" instead of arithmetic mod in pngrutil.c calculation of the
2864 offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf.
2865 Added more blank lines for readability.
2866
2867Version 1.5.0beta25 [June 18, 2010]
2868 In pngpread.c: png_push_have_row() add check for new_row > height
2869 Removed the now-redundant check for out-of-bounds new_row from example.c
2870
2871Version 1.5.0beta26 [June 18, 2010]
2872 In pngpread.c: png_push_process_row() add check for too many rows.
2873
2874Version 1.5.0beta27 [June 18, 2010]
2875 Removed the check added in beta25 as it is now redundant.
2876
2877Version 1.5.0beta28 [June 20, 2010]
2878 Rewrote png_process_IDAT_data to consistently treat extra data as warnings
2879 and handle end conditions more cleanly.
2880 Removed the new (beta26) check in png_push_process_row().
2881
2882Version 1.5.0beta29 [June 21, 2010]
2883 Revised scripts/options.awk to work on Sunos (but still doesn't work)
2884 Added comment to options.awk and contrib/pngminim/*/makefile to try nawk.
2885
2886Version 1.5.0beta30 [June 22, 2010]
2887 Stop memory leak when reading a malformed sCAL chunk.
2888
2889Version 1.5.0beta31 [June 26, 2010]
2890 Revised pngpread.c patch of beta28 to avoid an endless loop.
2891 Removed some trailing blanks.
2892
2893Version 1.5.0beta32 [June 26, 2010]
2894 Removed leftover scripts/options.patch and scripts/options.rej
2895
2896Version 1.5.0beta33 [July 6, 3010]
2897 Made FIXED and FLOATING options consistent in the APIs they enable and
2898 disable. Corrected scripts/options.awk to handle both command line
2899 options and options specified in the .dfa files.
2900 Changed char *msg to PNG_CONST char *msg in pngrutil.c
2901 Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or
2902 floating point APIs, but not both.
2903 Reversed patch to remove error handler when the jmp_buf is stored in the
2904 main program structure, not the png_struct.
2905 The error handler is needed because the default handler in libpng will
2906 always use the jmp_buf in the library control structure; this is never
2907 set. The gregbook code is a useful example because, even though it
2908 uses setjmp/longjmp, it shows how error handling can be implemented
2909 using control mechanisms not directly supported by libpng. The
2910 technique will work correctly with mechanisms such as Microsoft
2911 Structure Exceptions or C++ exceptions (compiler willing - note that gcc
2912 does not by default support interworking of C and C++ error handling.)
2913 Reverted changes to call png_longjmp in contrib/gregbook where it is not
2914 appropriate. If mainprog->jmpbuf is used by setjmp, then png_longjmp
2915 cannot be used.
2916 Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans)
2917 Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {')
2918
2919Version 1.5.0beta34 [July 12, 2010]
2920 Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h
2921
2922Version 1.5.0beta35 [July 24, 2010]
2923 Removed some newly-added TAB characters.
2924 Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2
2925 Moved the definition of png_snprintf() outside of the enclosing
2926 #ifdef blocks in pngconf.h
2927
2928Version 1.5.0beta36 [July 29, 2010]
2929 Patches by John Bowler:
2930 Fixed point APIs are now supported throughout (no missing APIs).
2931 Internal fixed point arithmetic support exists for all internal floating
2932 point operations.
2933 sCAL validates the floating point strings it is passed.
2934 Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2
2935 Two new APIs exist to get the number of passes without turning on the
2936 PNG_INTERLACE transform and to get the number of rows in the current
2937 pass.
2938 A new test program, pngvalid.c, validates the gamma code.
2939 Errors in the 16-bit gamma correction (overflows) have been corrected.
2940 cHRM chunk testing is done consistently (previously the floating point
2941 API bypassed it, because the test really didn't work on FP, now the test
2942 is performed on the actual values to be stored in the PNG file so it
2943 works in the FP case too.)
2944 Most floating point APIs now simply call the fixed point APIs after
2945 converting the values to the fixed point form used in the PNG file.
2946 The standard headers no longer include zlib.h, which is currently only
2947 required for pngstruct.h and can therefore be internal.
2948 Revised png_get_int_32 to undo the PNG two's complement representation of
2949 negative numbers.
2950
2951Version 1.5.0beta37 [July 30, 2010]
2952 Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid
2953 a compiler warning.
2954 Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png
2955
2956Version 1.5.0beta38 [July 31, 2010]
2957 Implemented remaining "_fixed" functions.
2958 Corrected a number of recently introduced warnings mostly resulting from
2959 safe but uncast assignments to shorter integers. Also added a zlib
2960 VStudio release library project because the latest zlib Official Windows
2961 build does not include such a thing.
2962 Revised png_get_int_16() to be similar to png_get_int_32().
2963 Restored projects/visualc71.
2964
2965Version 1.5.0beta39 [August 2, 2010]
2966 VisualC/GCC warning fixes, VisualC build fixes
2967 The changes include support for function attributes in VC in addition to
2968 those already present in GCC - necessary because without these some
2969 warnings are unavoidable. Fixes include signed/unsigned fixes in
2970 pngvalid and checks with gcc -Wall -Wextra -Wunused.
2971 VC requires function attributes on function definitions as well as
2972 declarations, PNG_FUNCTION has been added to enable this and the
2973 relevant function definitions changed.
2974
2975Version 1.5.0beta40 [August 6, 2010]
2976 Correct use of _WINDOWS_ in pngconf.h
2977 Removed png_mem_ #defines; they are no longer used.
2978 Added the sRGB chunk to pngtest.png
2979
2980Version 1.5.0beta41 [August 11, 2010]
2981 Added the cHRM chunk to pngtest.png
2982 Don't try to use version-script with cygwin/mingw.
2983 Revised contrib/gregbook to work under cygwin/mingw.
2984
2985Version 1.5.0beta42 [August 18, 2010]
2986 Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov)
2987 Made all API functions that have const arguments and constant string
2988 literal pointers declare them (John Bowler).
2989
2990Version 1.5.0beta43 [August 20, 2010]
2991 Removed spurious tabs, shorten long lines (no source change)
2992 Also added scripts/chkfmt to validate the format of all the files that can
2993 reasonably be validated (it is suggested to run "make distclean" before
2994 checking, because some machine generated files have long lines.)
2995 Reformatted the CHANGES file to be more consistent throughout.
2996 Made changes to address various issues identified by GCC, mostly
2997 signed/unsigned and shortening problems on assignment but also a few
2998 difficult to optimize (for GCC) loops.
2999 Fixed non-GCC fixed point builds. In png.c a declaration was misplaced
3000 in an earlier update. Fixed to declare the auto variables at the head.
3001 Use cexcept.h in pngvalid.c.
3002
3003Version 1.5.0beta44 [August 24, 2010]
3004 Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for
3005 installing libpng in /usr/lib64 (Funda Wang).
3006 Revised CMakeLists.txt to put the man pages in share/man/man* not man/man*
3007 Revised CMakeLists.txt to make symlinks instead of copies when installing.
3008 Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman)
3009 Implemented memory checks within pngvalid
3010 Reformatted/rearranged pngvalid.c to assist use of progressive reader.
3011 Check interlaced images in pngvalid
3012 Clarified pngusr.h comments in pnglibconf.dfa
3013 Simplified the pngvalid error-handling code now that cexcept.h is in place.
3014 Implemented progressive reader in pngvalid.c for standard tests
3015 Implemented progressive read in pngvalid.c gamma tests
3016 Turn on progressive reader in pngvalid.c by default and tidy code.
3017
3018Version 1.5.0beta45 [August 26, 2010]
3019 Added an explicit make step to projects/vstudio for pnglibconf.h
3020 Also corrected zlib.vcxproj into which Visual Studio had introduced
3021 what it calls an "authoring error". The change to make pnglibconf.h
3022 simply copies the file; in the future it may actually generate the
3023 file from scripts/pnglibconf.dfa as the other build systems do.
3024 Changed pngvalid to work when floating point APIs are disabled
3025 Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt
3026 Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX
3027 in pngpriv.h in case the user neglected to define them in their pngusr.h
3028
3029Version 1.5.0beta46 [August 28, 2010]
3030 Added new private header files to libpng_sources in CMakeLists.txt
3031 Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options.
3032 Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project.
3033
3034Version 1.5.0beta47 [September 11, 2010]
3035 Fixed a number of problems with 64-bit compilation reported by Visual
3036 Studio 2010 (John Bowler).
3037
3038Version 1.5.0beta48 [October 4, 2010]
3039 Updated CMakeLists.txt (Philip Lowman).
3040 Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER,
3041 $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE
3042 Fixed problem with symbols creation in Makefile.am which was assuming that
3043 all versions of ccp write to standard output by default (Martin Banky). The
3044 bug was introduced in libpng-1.2.9beta5.
3045 Removed unused mkinstalldirs.
3046
3047Version 1.5.0beta49 [October 8, 2010]
3048 Undid Makefile.am revision of 1.5.0beta48.
3049
3050Version 1.5.0beta50 [October 14, 2010]
3051 Revised Makefile.in to account for mkinstalldirs being removed.
3052 Added some "(unsigned long)" typecasts in printf statements in pngvalid.c.
3053 Suppressed a compiler warning in png_handle_sPLT().
3054 Check for out-of-range text compression mode in png_set_text().
3055
3056Version 1.5.0beta51 [October 15, 2010]
3057 Changed embedded dates to "(PENDING RELEASE) in beta releases (and future
3058 rc releases) to minimize the difference between releases.
3059
3060Version 1.5.0beta52 [October 16, 2010]
3061 Restored some of the embedded dates (in png.h, png.c, documentation, etc.)
3062
3063Version 1.5.0beta53 [October 18, 2010]
3064 Updated INSTALL to mention using "make maintainer-clean" and to remove
3065 obsolete statement about a custom ltmain.sh
3066 Disabled "color-tests" by default in Makefile.am so it will work with
3067 automake versions earlier than 1.11.1
3068 Use document name "libpng-manual.txt" instead of "libpng-<version>.txt"
3069 to simplify version differences.
3070 Removed obsolete remarks about setjmp handling from INSTALL.
3071 Revised and renamed the typedef in png.h and png.c that was designed
3072 to catch library and header mismatch.
3073
3074Version 1.5.0beta54 [November 10, 2010]
3075 Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks.
3076 Used a consistent structure for the pngget.c functions.
3077
3078Version 1.5.0beta55 [November 21, 2010]
3079 Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
3080 Moved reading of file signature into png_read_sig (Cosmin)
3081 Fixed atomicity of chunk header serialization (Cosmin)
3082 Added test for io_state in pngtest.c (Cosmin)
3083 Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts.
3084 Changes to remove gcc warnings (John Bowler)
3085 Certain optional gcc warning flags resulted in warnings in libpng code.
3086 With these changes only -Wconversion and -Wcast-qual cannot be turned on.
3087 Changes are trivial rearrangements of code. -Wconversion is not possible
3088 for pngrutil.c (because of the widespread use of += et al on variables
3089 smaller than (int) or (unsigned int)) and -Wcast-qual is not possible
3090 with pngwio.c and pngwutil.c because the 'write' callback and zlib
3091 compression both fail to declare their input buffers with 'const'.
3092
3093Version 1.5.0beta56 [December 7, 2010]
3094 Added the private PNG_UNUSED() macro definition in pngpriv.h.
3095 Added some commentary about PNG_EXPORT in png.h and pngconf.h
3096 Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the
3097 objective of simplifying and improving the cosmetic appearance of png.h.
3098 Fixed some incorrect "=" macro names in pnglibconf.dfa
3099 Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt
3100
3101Version 1.5.0beta57 [December 9, 2010]
3102 Documented the pngvalid gamma error summary with additional comments and
3103 print statements.
3104 Improved missing symbol handling in checksym.awk; symbols missing in both
3105 the old and new files can now be optionally ignored, treated as errors
3106 or warnings.
3107 Removed references to pngvcrd.c and pnggccrd.c from the vstudio project.
3108 Updated "libpng14" to "libpng15" in the visualc71 project.
3109 Enabled the strip16 tests in pngvalid.`
3110 Don't display test results (except PASS/FAIL) when running "make test".
3111 Instead put them in pngtest-log.txt
3112 Added "--with-zprefix=<string>" to configure.ac
3113 Updated the prebuilt configuration files to autoconf version 2.68
3114
3115Version 1.5.0beta58 [December 19, 2010]
3116 Fixed interlace image handling and add test cases (John Bowler)
3117 Fixed the clean rule in Makefile.am to remove pngtest-log.txt
3118 Made minor changes to work around warnings in gcc 3.4
3119
3120Version 1.5.0rc01 [December 27, 2010]
3121 No changes.
3122
3123Version 1.5.0rc02 [December 27, 2010]
3124 Eliminated references to the scripts/*.def files in project/visualc71.
3125
3126Version 1.5.0rc03 [December 28, 2010]
3127 Eliminated scripts/*.def and revised Makefile.am accordingly
3128
3129Version 1.5.0rc04 [December 29, 2010]
3130 Fixed bug in background transformation handling in pngrtran.c (it was
3131 looking for the flag in png_ptr->transformations instead of in
3132 png_ptr->flags) (David Raymond).
3133
3134Version 1.5.0rc05 [December 31, 2010]
3135 Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin)
3136
3137Version 1.5.0rc06 [January 4, 2011]
3138 Changed the new configure option "zprefix=string" to "zlib-prefix=string"
3139
3140Version 1.5.0rc07 [January 4, 2011]
3141 Updated copyright year.
3142
3143Version 1.5.0 [January 6, 2011]
3144 No changes.
3145
3146version 1.5.1beta01 [January 8, 2011]
3147 Added description of png_set_crc_action() to the manual.
3148 Added a note in the manual that the type of the iCCP profile was changed
3149 from png_charpp to png_bytepp in png_get_iCCP(). This change happened
3150 in version 1.5.0beta36 but is not noted in the CHANGES. Similarly,
3151 it was changed from png_charpp to png_const_bytepp in png_set_iCCP().
3152 Ensure that png_rgb_to_gray ignores palette mapped images, if libpng
3153 internally happens to call it with one, and fixed a failure to handle
3154 palette mapped images correctly. This fixes CVE-2690.
3155
3156Version 1.5.1beta02 [January 14, 2011]
3157 Fixed a bug in handling of interlaced images (bero at arklinux.org).
3158 Updated CMakeLists.txt (Clifford Yapp)
3159
3160Version 1.5.1beta03 [January 14, 2011]
3161 Fixed typecasting of some png_debug() statements (Cosmin)
3162
3163Version 1.5.1beta04 [January 16, 2011]
3164 Updated documentation of png_set|get_tRNS() (Thomas Klausner).
3165 Mentioned in the documentation that applications must #include "zlib.h"
3166 if they need access to anything in zlib.h, and that a number of
3167 macros such as png_memset() are no longer accessible by applications.
3168 Corrected pngvalid gamma test "sample" function to access all of the color
3169 samples of each pixel, instead of sampling the red channel three times.
3170 Prefixed variable names index, div, exp, gamma with "png_" to avoid "shadow"
3171 warnings, and (mistakenly) changed png_exp() to exp().
3172
3173Version 1.5.1beta05 [January 16, 2011]
3174 Changed variable names png_index, png_div, png_exp, and png_gamma to
3175 char_index, divisor, exp_b10, and gamma_val, respectively, and
3176 changed exp() back to png_exp().
3177
3178Version 1.5.1beta06 [January 20, 2011]
3179 Prevent png_push_crc_skip() from hanging while reading an unknown chunk
3180 or an over-large compressed zTXt chunk with the progressive reader.
3181 Eliminated more GCC "shadow" warnings.
3182 Revised png_fixed() in png.c to avoid compiler warning about reaching the
3183 end without returning anything.
3184
3185Version 1.5.1beta07 [January 22, 2011]
3186 In the manual, describe the png_get_IHDR() arguments in the correct order.
3187 Added const_png_structp and const_png_infop types, and used them in
3188 prototypes for most png_get_*() functions.
3189
3190Version 1.5.1beta08 [January 23, 2011]
3191 Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name()
3192 Added synopses for the IO_STATE functions and other missing synopses
3193 to the manual. Removed the synopses from libpngpf.3 because they
3194 were out of date and no longer useful. Better information can be
3195 obtained by reading the prototypes and comments in pngpriv.h
3196 Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build
3197 Added a make macro DFNCPP that is a CPP that will accept the tokens in
3198 a .dfn file and adds configure stuff to test for such a CPP. ./configure
3199 should fail if one is not available.
3200 Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace.
3201 Added png_get_current_row_number and png_get_current_pass_number for the
3202 benefit of the user transform callback.
3203 Added png_process_data_pause and png_process_data_skip for the benefit of
3204 progressive readers that need to stop data processing or want to optimize
3205 skipping of unread data (e.g., if the reader marks a chunk to be skipped.)
3206
3207Version 1.5.1beta09 [January 24, 2011]
3208 Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error.
3209 pngvalid contains tests of transforms, which tests are currently disabled
3210 because they are incompletely tested. gray_to_rgb was failing to expand
3211 the bit depth for smaller bit depth images; this seems to be a long
3212 standing error and resulted, apparently, in invalid output
3213 (CVE-2011-0408, CERT VU#643140). The documentation did not accurately
3214 describe what libpng really does when converting RGB to gray.
3215
3216Version 1.5.1beta10 [January 27, 2010]
3217 Fixed incorrect examples of callback prototypes in the manual, that were
3218 introduced in libpng-1.0.0.
3219 In addition the order of the png_get_uint macros with respect to the
3220 relevant function definitions has been reversed. This helps the
3221 preprocessing of the symbol files be more robust. Furthermore, the
3222 symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when
3223 the library may actually be built with PNG_USE_READ_MACROS; this stops
3224 the read macros interfering with the symbol file format.
3225 Made the manual, synopses, and function prototypes use the function
3226 argument names file_gamma, int_file_gamma, and srgb_intent consistently.
3227
3228Version 1.5.1beta11 [January 28, 2011]
3229 Changed PNG_UNUSED from "param=param;" to "{if(param){}}".
3230 Corrected local variable type in new API png_process_data_skip()
3231 The type was self-evidently incorrect but only causes problems on 64-bit
3232 architectures.
3233 Added transform tests to pngvalid and simplified the arguments.
3234
3235Version 1.5.1rc01 [January 29, 2011]
3236 No changes.
3237
3238Version 1.5.1rc02 [January 31, 2011]
3239 Added a request in the manual that applications do not use "png_" or
3240 "PNG_" to begin any of their own symbols.
3241 Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h
3242
3243Version 1.5.1 [February 3, 2011]
3244 No changes.
3245
3246Version 1.5.2beta01 [February 13, 2011]
3247 More -Wshadow fixes for older gcc compilers. Older gcc versions apparently
3248 check formal parameters names in function declarations (as well as
3249 definitions) to see if they match a name in the global namespace.
3250 Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the
3251 old VisualC++ preprocessor.
3252 Turned on interlace handling in png_read_png().
3253 Fixed gcc pendantic warnings.
3254 Handle longjmp in Cygwin.
3255 Fixed png_get_current_row_number() in the interlaced case.
3256 Cleaned up ALPHA flags and transformations.
3257 Implemented expansion to 16 bits.
3258
3259Version 1.5.2beta02 [February 19, 2011]
3260 Fixed mistake in the descriptions of user read_transform and write_transform
3261 function prototypes in the manual. The row_info struct is png_row_infop.
3262 Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior.
3263 Corrected png_get_current_row_number documentation
3264 Fixed the read/write row callback documentation.
3265 This documents the current behavior, where the callback is called after
3266 every row with information pertaining to the next row.
3267
3268Version 1.5.2beta03 [March 3, 2011]
3269 Fixed scripts/makefile.vcwin32
3270 Updated contrib/pngsuite/README to add the word "modify".
3271 Define PNG_ALLOCATED to blank when _MSC_VER<1300.
3272
3273Version 1.5.2rc01 [March 19, 2011]
3274 Define remaining attributes to blank when MSC_VER<1300.
3275 ifdef out mask arrays in pngread.c when interlacing is not supported.
3276
3277Version 1.5.2rc02 [March 22, 2011]
3278 Added a hint to try CPP=/bin/cpp if "cpp -E" fails in scripts/pnglibconf.mak
3279 and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed "strip"
3280 from the makefiles.
3281 Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail
3282 to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill)
3283
3284Version 1.5.2rc03 [March 24, 2011]
3285 Don't include standard header files in png.h while building the symbol table,
3286 to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro).
3287
3288Version 1.5.2 [March 31, 2011]
3289 No changes.
3290
3291Version 1.5.3beta01 [April 1, 2011]
3292 Re-initialize the zlib compressor before compressing non-IDAT chunks.
3293 Added API functions (png_set_text_compression_level() and four others) to
3294 set parameters for zlib compression of non-IDAT chunks.
3295
3296Version 1.5.3beta02 [April 3, 2011]
3297 Updated scripts/symbols.def with new API functions.
3298 Only compile the new zlib re-initializing code when text or iCCP is
3299 supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro.
3300 Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03).
3301 Optimize the zlib CMF byte in non-IDAT compressed chunks
3302
3303Version 1.5.3beta03 [April 16, 2011]
3304 Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have
3305 snprintf, and the "__STRICT_ANSI__" detects that condition more reliably
3306 than __STDC__ (John Bowler).
3307 Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells
3308 the compiler that a user supplied callback (the error handler) does not
3309 return, yet there is no guarantee in practice that the application code
3310 will correctly implement the error handler because the compiler only
3311 issues a warning if there is a mistake (John Bowler).
3312 Removed the no-longer-used PNG_DEPSTRUCT macro.
3313 Updated the zlib version to 1.2.5 in the VStudio project.
3314 Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in
3315 pngwutil.c (John Bowler).
3316 Fixed bug with stripping the filler or alpha channel when writing, that
3317 was introduced in libpng-1.5.2beta01 (bug report by Andrew Church).
3318
3319Version 1.5.3beta04 [April 27, 2011]
3320 Updated pngtest.png with the new zlib CMF optimization.
3321 Cleaned up conditional compilation code and of background/gamma handling
3322 Internal changes only except a new option to avoid compiling the
3323 png_build_grayscale_palette API (which is not used at all internally.)
3324 The main change is to move the transform tests (READ_TRANSFORMS,
3325 WRITE_TRANSFORMS) up one level to the caller of the APIs. This avoids
3326 calls to spurious functions if all transforms are disabled and slightly
3327 simplifies those functions. Pngvalid modified to handle this.
3328 A minor change is to stop the strip_16 and expand_16 interfaces from
3329 disabling each other; this allows the future alpha premultiplication
3330 code to use 16-bit intermediate values while still producing 8-bit output.
3331 png_do_background and png_do_gamma have been simplified to take a single
3332 pointer to the png_struct rather than pointers to every item required
3333 from the png_struct. This makes no practical difference to the internal
3334 code.
3335 A serious bug in the pngvalid internal routine 'standard_display_init' has
3336 been fixed - this failed to initialize the red channel and accidentally
3337 initialized the alpha channel twice.
3338 Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to
3339 avoid a possible clash with the png_jmpbuf macro on some platforms.
3340
3341Version 1.5.3beta05 [May 6, 2011]
3342 Added the "_POSIX_SOURCE" feature test macro to ensure libpng sees the
3343 correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and
3344 pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs.
3345 Removed png_snprintf and added formatted warning messages. This change adds
3346 internal APIs to allow png_warning messages to have parameters without
3347 requiring the host OS to implement snprintf. As a side effect the
3348 dependency of the tIME-supporting RFC1132 code on stdio is removed and
3349 PNG_NO_WARNINGS does actually work now.
3350 Pass "" instead of '\0' to png_default_error() in png_err(). This mistake
3351 was introduced in libpng-1.2.20beta01. This fixes CVE-2011-2691.
3352 Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte
3353 optimization configureable.
3354 IDAT compression failed if preceded by a compressed text chunk (bug
3355 introduced in libpng-1.5.3beta01-02). This was because the attempt to
3356 reset the zlib stream in png_write_IDAT happened after the first IDAT
3357 chunk had been deflated - much too late. In this change internal
3358 functions were added to claim/release the z_stream and, hopefully, make
3359 the code more robust. Also deflateEnd checking is added - previously
3360 libpng would ignore an error at the end of the stream.
3361
3362Version 1.5.3beta06 [May 8, 2011]
3363 Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt
3364 Implemented premultiplied alpha support: png_set_alpha_mode API
3365
3366Version 1.5.3beta07 [May 11, 2011]
3367 Added expand_16 support to the high level interface.
3368 Added named value and 'flag' gamma support to png_set_gamma. Made a minor
3369 change from the previous (unreleased) ABI/API to hide the exact value used
3370 for Macs - it's not a good idea to embed this in the ABI!
3371 Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT
3372 from pngpriv.h to png.h because they must be visible to applications
3373 that call png_set_unknown_chunks().
3374 Check for up->location !PNG_AFTER_IDAT when writing unknown chunks
3375 before IDAT.
3376
3377Version 1.5.3beta08 [May 16, 2011]
3378 Improved "pngvalid --speed" to exclude more of pngvalid from the time.
3379 Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt
3380 The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative
3381 parameters are supplied by the caller), while in the absence of cHRM
3382 sRGB/Rec 709 values are still used. This introduced a divide-by-zero
3383 bug in png_handle_cHRM().
3384 The bKGD chunk no longer overwrites the background value set by
3385 png_set_background(), allowing the latter to be used before the file
3386 header is read. It never performed any useful function to override
3387 the default anyway.
3388 Added memory overwrite and palette image checks to pngvalid.c
3389 Previously palette image code was poorly checked. Since the transformation
3390 code has a special palette path in most cases this was a severe weakness.
3391 Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When
3392 expanding an indexed image, always expand to RGBA if transparency is
3393 present.
3394
3395Version 1.5.3beta09 [May 17, 2011]
3396 Reversed earlier 1.5.3 change of transformation order; move png_expand_16
3397 back where it was. The change doesn't work because it requires 16-bit
3398 gamma tables when the code only generates 8-bit ones. This fails
3399 silently; the libpng code just doesn't do any gamma correction. Moving
3400 the tests back leaves the old, inaccurate, 8-bit gamma calculations, but
3401 these are clearly better than none!
3402
3403Version 1.5.3beta10 [May 20, 2011]
3404
3405 png_set_background() and png_expand_16() did not work together correctly.
3406 This problem is present in 1.5.2; if png_set_background is called with
3407 need_expand false and the matching 16 bit color libpng erroneously just
3408 treats it as an 8-bit color because of where png_do_expand_16 is in the
3409 transform list. This simple fix reduces the supplied colour to 8-bits,
3410 so it gets smashed, but this is better than the current behavior.
3411 Added tests for expand16, more fixes for palette image tests to pngvalid.
3412 Corrects the code for palette image tests and disables attempts to
3413 validate palette colors.
3414
3415Version 1.5.3rc01 [June 3, 2011]
3416 No changes.
3417
3418Version 1.5.3rc02 [June 8, 2011]
3419 Fixed uninitialized memory read in png_format_buffer() (Bug report by
3420 Frank Busse, CVE-2011-2501, related to CVE-2004-0421).
3421
3422Version 1.5.3beta11 [June 11, 2011]
3423 Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692.
3424 Added sCAL to pngtest.png
3425 Revised documentation about png_set_user_limits() to say that it also affects
3426 png writing.
3427 Revised handling of png_set_user_limits() so that it can increase the
3428 limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only
3429 reduce it.
3430 Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is
3431 wrong (high by one) 25% of the time. Dividing by 257 with rounding is
3432 wrong in 128 out of 65536 cases. Getting the right answer all the time
3433 without division is easy.
3434 Added "_SUPPORTED" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro.
3435 Added projects/owatcom, an IDE project for OpenWatcom to replace
3436 scripts/makefile.watcom. This project works with OpenWatcom 1.9. The
3437 IDE autogenerates appropriate makefiles (libpng.mk) for batch processing.
3438 The project is configurable, unlike the Visual Studio project, so long
3439 as the developer has an awk.
3440 Changed png_set_gAMA to limit the gamma value range so that the inverse
3441 of the stored value cannot overflow the fixed point representation,
3442 and changed other things OpenWatcom warns about.
3443 Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows
3444 pngvalid to build when ALPHA_MODE is not supported, which is required if
3445 it is to build on libpng 1.4.
3446 Removed string/memory macros that are no longer used and are not
3447 necessarily fully supportable, particularly png_strncpy and png_snprintf.
3448 Added log option to pngvalid.c and attempted to improve gamma messages.
3449
3450Version 1.5.3 [omitted]
3451 People found the presence of a beta release following an rc release
3452 to be confusing; therefore we bump the version to libpng-1.5.4beta01
3453 and there will be no libpng-1.5.3 release.
3454
3455Version 1.5.4beta01 [June 14, 2011]
3456 Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
3457 to get the same (inaccurate) output as libpng-1.5.2 and earlier.
3458 Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE
3459 outside of an unknown-chunk block in png.h because they are also
3460 needed for other uses.
3461
3462Version 1.5.4beta02 [June 14, 2011]
3463 Fixed and clarified LEGACY 16-to-8 scaling code.
3464 Added png_set_chop_16() API, to match inaccurate results from previous
3465 libpng versions.
3466 Removed the ACCURATE and LEGACY options (they are no longer useable)
3467 Use the old scaling method for background if png_set_chop_16() was
3468 called.
3469 Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED
3470
3471Version 1.5.4beta03 [June 15, 2011]
3472 Fixed a problem in png_do_expand_palette() exposed by optimization in
3473 1.5.3beta06
3474 Also removed a spurious and confusing "trans" member ("trans") from png_info.
3475 The palette expand optimization prevented expansion to an intermediate RGBA
3476 form if tRNS was present but alpha was marked to be stripped; this exposed
3477 a check for tRNS in png_do_expand_palette() which is inconsistent with the
3478 code elsewhere in libpng.
3479 Correction to the expand_16 code; removed extra instance of
3480 png_set_scale_16_to_8 from pngpriv.h
3481
3482Version 1.5.4beta04 [June 16, 2011]
3483 Added a missing "#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif" in pngrtran.c
3484 Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms.
3485 Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again. If this is
3486 not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built.
3487 Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8
3488
3489Version 1.5.4beta05 [June 16, 2011]
3490 Renamed png_set_strip_16() to png_set_scale_16() and renamed
3491 png_set_chop_16() to png_set_strip(16) in an attempt to minimize the
3492 behavior changes between libpng14 and libpng15.
3493
3494Version 1.5.4beta06 [June 18, 2011]
3495 Fixed new bug that was causing both strip_16 and scale_16 to be applied.
3496
3497Version 1.5.4beta07 [June 19, 2011]
3498 Fixed pngvalid, simplified macros, added checking for 0 in sCAL.
3499 The ACCURATE scale macro is no longer defined in 1.5 - call the
3500 png_scale_16_to_8 API. Made sure that PNG_READ_16_TO_8 is still defined
3501 if the png_strip_16_to_8 API is present. png_check_fp_number now
3502 maintains some state so that positive, negative and zero values are
3503 identified. sCAL uses these to be strictly spec conformant.
3504
3505Version 1.5.4beta08 [June 23, 2011]
3506 Fixed pngvalid if ACCURATE_SCALE is defined.
3507 Updated scripts/pnglibconf.h.prebuilt.
3508
3509Version 1.5.4rc01 [June 30, 2011]
3510 Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400.
3511
3512Version 1.5.4 [July 7, 2011]
3513 No changes.
3514
3515Version 1.5.5beta01 [July 13, 2011]
3516 Fixed some typos and made other minor changes in the manual.
3517 Updated contrib/pngminus/makefile.std (Samuli Souminen)
3518
3519Version 1.5.5beta02 [July 14, 2011]
3520 Revised Makefile.am and Makefile.in to look in the right directory for
3521 pnglibconf.h.prebuilt
3522
3523Version 1.5.5beta03 [July 27, 2011]
3524 Enabled compilation with g++ compiler. This compiler does not recognize
3525 the file extension, so it always compiles with C++ rules. Made minor
3526 changes to pngrutil.c to cast results where C++ expects it but C does not.
3527 Minor editing of libpng.3 and libpng-manual.txt.
3528
3529Version 1.5.5beta04 [July 29, 2011]
3530 Revised CMakeLists.txt (Clifford Yapp)
3531 Updated commentary about the png_rgb_to_gray() default coefficients
3532 in the manual and in pngrtran.c
3533
3534Version 1.5.5beta05 [August 17, 2011]
3535 Prevent unexpected API exports from non-libpng DLLs on Windows. The "_DLL"
3536 is removed from the test of whether a DLL is being built (this erroneously
3537 caused the libpng APIs to be marked as DLL exports in static builds under
3538 Microsoft Visual Studio). Almost all of the libpng building configuration
3539 is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in
3540 pngconf.h, though, so that it is colocated with the import definition (it
3541 is no longer used anywhere in the installed headers). The VStudio project
3542 definitions have been cleaned up: "_USRDLL" has been removed from the
3543 static library builds (this was incorrect), and PNG_USE_DLL has been added
3544 to pngvalid to test the functionality (pngtest does not supply it,
3545 deliberately). The spurious "_EXPORTS" has been removed from the
3546 libpng build (all these errors were a result of copy/paste between project
3547 configurations.)
3548 Added new types and internal functions for CIE RGB end point handling to
3549 pngpriv.h (functions yet to be implemented).
3550
3551Version 1.5.5beta06 [August 26, 2011]
3552 Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt
3553 (Clifford Yap)
3554 Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler):
3555 The rgb_to_gray code had errors when combined with gamma correction.
3556 Some pixels were treated as true grey when they weren't and such pixels
3557 and true grey ones were not gamma corrected (the original value of the
3558 red component was used instead). APIs to get and set cHRM using color
3559 space end points have been added and the rgb_to_gray code that defaults
3560 based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT
3561 VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected.
3562 A considerable number of tests has been added to pngvalid for the
3563 rgb_to_gray transform.
3564 Arithmetic errors in rgb_to_gray whereby the calculated gray value was
3565 truncated to the bit depth rather than rounded have been fixed except in
3566 the 8-bit non-gamma-corrected case (where consistency seems more important
3567 than correctness.) The code still has considerable inaccuracies in the
3568 8-bit case because 8-bit linear arithmetic is used.
3569
3570Version 1.5.5beta07 [September 7, 2011]
3571 Added "$(ARCH)" option to makefile.darwin
3572 Added SunOS support to configure.ac and Makefile.am
3573 Changed png_chunk_benign_error() to png_warning() in png.c, in
3574 png_XYZ_from_xy_checked().
3575
3576Version 1.5.5beta08 [September 10, 2011]
3577 Fixed 64-bit compilation errors (gcc). The errors fixed relate
3578 to conditions where types that are 32 bits in the GCC 32-bit
3579 world (uLong and png_size_t) become 64 bits in the 64-bit
3580 world. This produces potential truncation errors which the
3581 compiler correctly flags.
3582 Relocated new HAVE_SOLARIS_LD definition in configure.ac
3583 Constant changes for 64-bit compatibility (removal of L suffixes). The
3584 16-bit cases still use "L" as we don't have a 16-bit test system.
3585
3586Version 1.5.5rc01 [September 15, 2011]
3587 Removed "L" suffixes in pngpriv.h
3588
3589Version 1.5.5 [September 22, 2011]
3590 No changes.
3591
3592Version 1.5.6beta01 [September 22, 2011]
3593 Fixed some 64-bit type conversion warnings in pngrtran.c
3594 Moved row_info from png_struct to a local variable.
3595 The various interlace mask arrays have been made into arrays of
3596 bytes and made PNG_CONST and static (previously some arrays were
3597 marked PNG_CONST and some weren't).
3598 Additional checks have been added to the transform code to validate the
3599 pixel depths after the transforms on both read and write.
3600 Removed some redundant code from pngwrite.c, in png_destroy_write_struct().
3601 Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4].
3602 This removes the need to allocate temporary strings for chunk names on
3603 the stack in the read/write code. Unknown chunk handling still uses the
3604 string form because this is exposed in the API.
3605
3606Version 1.5.6beta02 [September 26, 2011]
3607 Added a note in the manual the png_read_update_info() must be called only
3608 once with a particular info_ptr.
3609 Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro.
3610
3611Version 1.5.6beta03 [September 28, 2011]
3612 Revised test-pngtest.sh to report FAIL when pngtest fails.
3613 Added "--strict" option to pngtest, to report FAIL when the failure is
3614 only because the resulting valid files are different.
3615 Revised CMakeLists.txt to work with mingw and removed some material from
3616 CMakeLists.txt that is no longer useful in libpng-1.5.
3617
3618Version 1.5.6beta04 [October 5, 2011]
3619 Fixed typo in Makefile.in and Makefile.am ("-M Wl" should be "-M -Wl")."
3620
3621Version 1.5.6beta05 [October 12, 2011]
3622 Speed up png_combine_row() for interlaced images. This reduces the generality
3623 of the code, allowing it to be optimized for Adam7 interlace. The masks
3624 passed to png_combine_row() are now generated internally, avoiding
3625 some code duplication and localizing the interlace handling somewhat.
3626 Align png_struct::row_buf - previously it was always unaligned, caused by
3627 a bug in the code that attempted to align it; the code needs to subtract
3628 one from the pointer to take account of the filter byte prepended to
3629 each row.
3630 Optimized png_combine_row() when rows are aligned. This gains a small
3631 percentage for 16-bit and 32-bit pixels in the typical case where the
3632 output row buffers are appropriately aligned. The optimization was not
3633 previously possible because the png_struct buffer was always misaligned.
3634 Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01.
3635
3636Version 1.5.6beta06 [October 17, 2011]
3637 Removed two redundant tests for unitialized row.
3638 Fixed a relatively harmless memory overwrite in compressed text writing
3639 with a 1 byte zlib buffer.
3640 Add ability to call png_read_update_info multiple times to pngvalid.c.
3641 Fixes for multiple calls to png_read_update_info. These fixes attend to
3642 most of the errors revealed in pngvalid, however doing the gamma work
3643 twice results in inaccuracies that can't be easily fixed. There is now
3644 a warning in the code if this is going to happen.
3645 Turned on multiple png_read_update_info in pngvalid transform tests.
3646 Prevent libpng from overwriting unused bits at the end of the image when
3647 it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would
3648 overwrite the partial byte at the end of each row if the row width was not
3649 an exact multiple of 8 bits and the image is not interlaced.
3650
3651Version 1.5.6beta07 [October 21, 2011]
3652 Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row
3653 (Mans Rullgard).
3654
3655Version 1.5.6rc01 [October 26, 2011]
3656 Changed misleading "Missing PLTE before cHRM" warning to "Out of place cHRM"
3657
3658Version 1.5.6rc02 [October 27, 2011]
3659 Added LSR() macro to defend against buggy compilers that evaluate non-taken
3660 code branches and complain about out-of-range shifts.
3661
3662Version 1.5.6rc03 [October 28, 2011]
3663 Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro.
3664 Fixed compiler warnings with Intel and MSYS compilers. The logical shift
3665 fix for Microsoft Visual C is required by other compilers, so this
3666 enables that fix for all compilers when using compile-time constants.
3667 Under MSYS 'byte' is a name declared in a system header file, so we
3668 changed the name of a local variable to avoid the warnings that result.
3669 Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h
3670
3671Version 1.5.6 [November 3, 2011]
3672 No changes.
3673
3674Version 1.5.7beta01 [November 4, 2011]
3675 Added support for ARM processor (Mans Rullgard)
3676 Fixed bug in pngvalid on early allocation failure; fixed type cast in
3677 pngmem.c; pngvalid would attempt to call png_error() if the allocation
3678 of a png_struct or png_info failed. This would probably have led to a
3679 crash. The pngmem.c implementation of png_malloc() included a cast
3680 to png_size_t which would fail on large allocations on 16-bit systems.
3681 Fix for the preprocessor of the Intel C compiler. The preprocessor
3682 splits adjacent @ signs with a space; this changes the concatentation
3683 token from @-@-@ to PNG_JOIN; that should work with all compiler
3684 preprocessors.
3685 Paeth filter speed improvements from work by Siarhei Siamashka. This
3686 changes the 'Paeth' reconstruction function to improve the GCC code
3687 generation on x86. The changes are only part of the suggested ones;
3688 just the changes that definitely improve speed and remain simple.
3689 The changes also slightly increase the clarity of the code.
3690
3691Version 1.5.7beta02 [November 11, 2011]
3692 Check compression_type parameter in png_get_iCCP and remove spurious
3693 casts. The compression_type parameter is always assigned to, so must
3694 be non-NULL. The cast of the profile length potentially truncated the
3695 value unnecessarily on a 16-bit int system, so the cast of the (byte)
3696 compression type to (int) is specified by ANSI-C anyway.
3697 Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left
3698 the sBIT fields in the test pixel as 0, which resulted in a floating
3699 point division by zero which was irrelevant but causes systems where
3700 FP exceptions cause a crash. Added code to pngvalid to turn on FP
3701 exceptions if the appropriate glibc support is there to ensure this is
3702 tested in the future.
3703 Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the
3704 new PNG_JOIN macro.
3705 Added versioning to pnglibconf.h comments.
3706 Simplified read/write API initial version; basic read/write tested on
3707 a variety of images, limited documentation (in the header file.)
3708 Installed more accurate linear to sRGB conversion tables. The slightly
3709 modified tables reduce the number of 16-bit values that
3710 convert to an off-by-one 8-bit value. The "makesRGB.c" code that was used
3711 to generate the tables is now in a contrib/sRGBtables sub-directory.
3712
3713Version 1.5.7beta03 [November 17, 2011]
3714 Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c
3715 Added run-time detection of NEON support.
3716 Added contrib/libtests; includes simplified API test and timing test and
3717 a color conversion utility for rapid checking of failed 'pngstest' results.
3718 Multiple transform bug fixes plus a work-round for double gamma correction.
3719 libpng does not support more than one transform that requires linear data
3720 at once - if this is tried typically the results is double gamma
3721 correction. Since the simplified APIs can need rgb to gray combined with
3722 a compose operation it is necessary to do one of these outside the main
3723 libpng transform code. This check-in also contains fixes to various bugs
3724 in the simplified APIs themselves and to some bugs in compose and rgb to
3725 gray (on palette) itself.
3726 Fixes for C++ compilation using g++ When libpng source is compiled
3727 using g++. The compiler imposes C++ rules on the C source; thus it
3728 is desireable to make the source work with either C or C++ rules
3729 without throwing away useful error information. This change adds
3730 png_voidcast to allow C semantic (void*) cases or the corresponding
3731 C++ static_cast operation, as appropriate.
3732 Added --noexecstack to assembler file compilation. GCC does not set
3733 this on assembler compilation, even though it does on C compilation.
3734 This creates security issues if assembler code is enabled; the
3735 work-around is to set it by default in the flags for $(CCAS)
3736 Work around compilers that don't support declaration of const data. Some
3737 compilers fault 'extern const' data declarations (because the data is
3738 not initialized); this turns on const-ness only for compilers where
3739 this is known to work.
3740
3741Version 1.5.7beta04 [November 17, 2011]
3742 Since the gcc driver does not recognize the --noexecstack flag, we must
3743 use the -Wa prefix to have it passed through to the assembler.
3744 Also removed a duplicate setting of this flag.
3745 Added files that were omitted from the libpng-1.5.7beta03 zip distribution.
3746
3747Version 1.5.7beta05 [November 25, 2011]
3748 Removed "zTXt" from warning in generic chunk decompression function.
3749 Validate time settings passed to pngset() and png_convert_to_rfc1123()
3750 (Frank Busse).
3751 Added MINGW support to CMakeLists.txt
3752 Reject invalid compression flag or method when reading the iTXt chunk.
3753 Backed out 'simplified' API changes. The API seems too complex and there
3754 is a lack of consensus or enthusiasm for the proposals. The API also
3755 reveals significant bugs inside libpng (double gamma correction and the
3756 known bug of being unable to retrieve a corrected palette). It seems
3757 better to wait until the bugs, at least, are corrected.
3758 Moved pngvalid.c into contrib/libtests
3759 Rebuilt Makefile.in, configure, etc., with autoconf-2.68
3760
3761Version 1.5.7rc01 [December 1, 2011]
3762 Replaced an "#if" with "#ifdef" in pngrtran.c
3763 Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else)
3764
3765Version 1.5.7rc02 [December 5, 2011]
3766 Revised project files and contrib/pngvalid/pngvalid.c to account for
3767 the relocation of pngvalid into contrib/libtests.
3768 Revised pngconf.h to use " __declspec(restrict)" only when MSC_VER >= 1400,
3769 as in libpng-1.5.4.
3770 Put CRLF line endings in the owatcom project files.
3771
3772Version 1.5.7rc03 [December 7, 2011]
3773 Updated CMakeLists.txt to account for the relocation of pngvalid.c
3774
3775Version 1.5.7 [December 15, 2011]
3776 Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings
3777 reported by earlier versions.
3778
3779Version 1.5.8beta01 [January 15, 2011]
3780 Removed '#include config.h"' from contrib/libtests/pngvalid.c. It's not
3781 needed and causes trouble for VPATH building.
3782 Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper
3783 location in configure.ac (Gilles Espinasse).
3784 Fix bug in pngerror.c: some long warnings were being improperly truncated
3785 (CVE-2011-3464, bug introduced in libpng-1.5.3beta05).
3786
3787Version 1.5.8rc01 [January 21, 2012]
3788 No changes.
3789
3790Version 1.5.8rc02 [January 25, 2012]
3791 Fixed Min/GW uninstall to remove libpng.dll.a
3792 Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt
3793
3794Version 1.5.8 [February 1, 2012]
3795 No changes.
3796
3797Version 1.5.9beta01 [February 3, 2012]
3798 Rebuilt configure scripts in the tar distributions.
3799
3800Version 1.5.9beta02 [February 16, 2012]
3801 Removed two unused definitions from scripts/pnglibconf.h.prebuilt
3802 Removed some unused arrays (with #ifdef) from png_read_push_finish_row().
3803 Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h
3804
3805Version 1.5.9rc01 [February 17, 2012]
3806 Fixed CVE-2011-3026 buffer overrun bug. Deal more correctly with the test
3807 on iCCP chunk length. Also removed spurious casts that may hide problems
3808 on 16-bit systems.
3809
3810Version 1.5.9 [February 18, 2012]
3811 No changes.
3812
3813Send comments/corrections/commendations to png-mng-implement at lists.sf.net
3814(subscription required; visit
3815https://lists.sourceforge.net/lists/listinfo/png-mng-implement
3816to subscribe)
3817or to glennrp at users.sourceforge.net
3818
3819Glenn R-P
3820#endif
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/CMakeLists.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/CMakeLists.txt
new file mode 100644
index 0000000..e9a421a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/CMakeLists.txt
@@ -0,0 +1,348 @@
1# CMakeLists.txt
2
3# Copyright (C) 2007-2011 Glenn Randers-Pehrson
4
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9cmake_minimum_required(VERSION 2.4.4)
10set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
11
12if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
13 if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
14 # workaround CMake 2.4.x bug
15 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
16 "Choose the type of build, options are:
17 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
18 Debug
19 Release
20 RelWithDebInfo
21 MinSizeRel.")
22 else()
23 set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
24 "Choose the type of build, options are:
25 None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
26 Debug
27 Release
28 RelWithDebInfo
29 MinSizeRel.")
30 endif()
31endif()
32
33project(libpng C)
34enable_testing()
35
36set(PNGLIB_MAJOR 1)
37set(PNGLIB_MINOR 5)
38set(PNGLIB_RELEASE 9)
39set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
40set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
41
42# needed packages
43find_package(ZLIB REQUIRED)
44include_directories(${ZLIB_INCLUDE_DIR})
45
46if(NOT WIN32)
47 find_library(M_LIBRARY
48 NAMES m
49 PATHS /usr/lib /usr/local/lib
50 )
51 if(NOT M_LIBRARY)
52 message(STATUS
53 "math library 'libm' not found - floating point support disabled")
54 endif()
55else()
56 # not needed on windows
57 set(M_LIBRARY "")
58endif()
59
60# COMMAND LINE OPTIONS
61if(DEFINED PNG_SHARED)
62 option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
63else()
64 option(PNG_SHARED "Build shared lib" ON)
65endif()
66if(DEFINED PNG_STATIC)
67 option(PNG_STATIC "Build static lib" ${PNG_STATIC})
68else()
69 option(PNG_STATIC "Build static lib" ON)
70endif()
71
72option(PNG_TESTS "Build libpng tests" YES)
73
74# Many more configuration options could be added here
75option(PNG_DEBUG "Build with debug output" NO)
76option(PNGARG "Disable ANSI-C prototypes" NO)
77
78# SET LIBNAME
79set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
80
81# to distinguish between debug and release lib
82set(CMAKE_DEBUG_POSTFIX "d")
83
84# Use the prebuilt pnglibconf.h file from the scripts folder
85# TODO: fix this by building with awk; without this no cmake build can be
86# configured directly (to do so indirectly use your local awk to build a
87# pnglibconf.h in the build directory.)
88configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
89 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
90include_directories(${CMAKE_CURRENT_BINARY_DIR})
91
92# OUR SOURCES
93set(libpng_public_hdrs
94 png.h
95 pngconf.h
96 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
97)
98set(libpng_sources
99 ${libpng_public_hdrs}
100 pngdebug.h
101 pnginfo.h
102 pngpriv.h
103 pngstruct.h
104 png.c
105 pngerror.c
106 pngget.c
107 pngmem.c
108 pngpread.c
109 pngread.c
110 pngrio.c
111 pngrtran.c
112 pngrutil.c
113 pngset.c
114 pngtrans.c
115 pngwio.c
116 pngwrite.c
117 pngwtran.c
118 pngwutil.c
119)
120set(pngtest_sources
121 pngtest.c
122)
123set(pngvalid_sources
124 contrib/libtests/pngvalid.c
125)
126# SOME NEEDED DEFINITIONS
127
128add_definitions(-DPNG_CONFIGURE_LIBPNG)
129
130if(MSVC)
131 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
132endif(MSVC)
133
134if(PNG_DEBUG)
135 add_definitions(-DPNG_DEBUG)
136endif()
137
138# NOW BUILD OUR TARGET
139include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
140
141if(PNG_SHARED)
142 add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
143 if(MSVC)
144 # msvc does not append 'lib' - do it here to have consistent name
145 set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
146 set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
147 endif()
148 target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
149endif()
150
151if(PNG_STATIC)
152# does not work without changing name
153 set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
154 add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
155 if(MSVC)
156 # msvc does not append 'lib' - do it here to have consistent name
157 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
158 endif()
159 target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
160endif()
161
162if(PNG_SHARED AND WIN32)
163 set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
164endif()
165
166if(PNG_TESTS AND PNG_SHARED)
167 # does not work with msvc due to png_lib_ver issue
168 add_executable(pngtest ${pngtest_sources})
169 target_link_libraries(pngtest ${PNG_LIB_NAME})
170 add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
171 #
172 add_executable(pngvalid ${pngvalid_sources})
173 target_link_libraries(pngvalid ${PNG_LIB_NAME})
174 add_test(pngvalid ./pngvalid)
175endif()
176
177# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set
178IF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
179 IF(WIN32)
180 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "bin")
181 ELSE(WIN32)
182 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
183 ENDIF(WIN32)
184ENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
185
186# Set a variable with CMake code which:
187# Creates a symlink from src to dest (if possible) or alternatively
188# copies if different.
189macro(CREATE_SYMLINK SRC_FILE DEST_FILE)
190 FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
191 if(WIN32 AND NOT CYGWIN AND NOT MINGW)
192 ADD_CUSTOM_COMMAND(
193 OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
194 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}
195 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}
196 DEPENDS ${PNG_LIB_NAME} ${PNG_LIB_NAME_STATIC}
197 )
198 ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})
199 else(WIN32 AND NOT CYGWIN AND NOT MINGW)
200 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
201 execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${SRC_FILE} ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
202 endif(WIN32 AND NOT CYGWIN AND NOT MINGW)
203endmacro()
204
205# libpng is a library so default to 'lib'
206if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
207 set(CMAKE_INSTALL_LIBDIR lib)
208endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
209
210# CREATE PKGCONFIG FILES
211# we use the same files like ./configure, so we have to set its vars
212# Only do this on Windows for Cygwin - the files don't make much sense outside
213# a UNIX look alike
214if(NOT WIN32 OR CYGWIN OR MINGW)
215 set(prefix ${CMAKE_INSTALL_PREFIX})
216 set(exec_prefix ${CMAKE_INSTALL_PREFIX})
217 set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
218 set(includedir ${CMAKE_INSTALL_PREFIX}/include)
219 set(LIBS "-lz -lm")
220 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
221 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
222 CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc)
223
224 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
225 ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
226 CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config)
227endif(NOT WIN32 OR CYGWIN OR MINGW)
228
229# SET UP LINKS
230if(PNG_SHARED)
231 set_target_properties(${PNG_LIB_NAME} PROPERTIES
232# VERSION 15.${PNGLIB_RELEASE}.1.5.9
233 VERSION 15.${PNGLIB_RELEASE}.0
234 SOVERSION 15
235 CLEAN_DIRECT_OUTPUT 1)
236endif()
237if(PNG_STATIC)
238 # MSVC doesn't use a different file extension for shared vs. static
239 # libs. We are able to change OUTPUT_NAME to remove the _static
240 # for all other platforms.
241 if(NOT MSVC)
242 set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
243 OUTPUT_NAME ${PNG_LIB_NAME}
244 CLEAN_DIRECT_OUTPUT 1)
245 endif()
246endif()
247
248# If CMake > 2.4.x, we set a variable used below to export
249# targets to an export file.
250# TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
251if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
252 set(PNG_EXPORT_RULE EXPORT libpng)
253elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
254 set(PNG_EXPORT_RULE EXPORT libpng)
255endif()
256
257# INSTALL
258if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
259 if(PNG_SHARED)
260 install(TARGETS ${PNG_LIB_NAME}
261 ${PNG_EXPORT_RULE}
262 RUNTIME DESTINATION bin
263 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
264 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
265
266 # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
267 if(CYGWIN OR MINGW)
268 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
269 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
270 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
271 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
272 DESTINATION ${CMAKE_INSTALL_LIBDIR})
273 endif(CYGWIN OR MINGW)
274
275 if(NOT WIN32)
276 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME} LOCATION_${CMAKE_BUILD_TYPE})
277 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
278 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
279 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
280 DESTINATION ${CMAKE_INSTALL_LIBDIR})
281 endif(NOT WIN32)
282 endif(PNG_SHARED)
283
284 if(PNG_STATIC)
285 install(TARGETS ${PNG_LIB_NAME_STATIC}
286 ${PNG_EXPORT_RULE}
287 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
288 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
289 if(NOT WIN32 OR CYGWIN OR MINGW)
290 get_target_property(BUILD_TARGET_LOCATION ${PNG_LIB_NAME_STATIC} LOCATION_${CMAKE_BUILD_TYPE})
291 get_filename_component(BUILD_TARGET_FILE ${BUILD_TARGET_LOCATION} NAME)
292 CREATE_SYMLINK(${BUILD_TARGET_FILE} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
293 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
294 DESTINATION ${CMAKE_INSTALL_LIBDIR})
295 endif(NOT WIN32 OR CYGWIN OR MINGW)
296 endif()
297endif()
298
299if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
300 install(FILES ${libpng_public_hdrs} DESTINATION include)
301 install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME})
302endif()
303if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
304 if(NOT WIN32 OR CYGWIN OR MINGW)
305 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
306 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
307 DESTINATION bin)
308 endif(NOT WIN32 OR CYGWIN OR MINGW)
309endif()
310
311if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
312 # Install man pages
313 if(NOT PNG_MAN_DIR)
314 set(PNG_MAN_DIR "share/man")
315 endif()
316 install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
317 install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
318 # Install pkg-config files
319 if(NOT WIN32 OR CYGWIN OR MINGW)
320 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
321 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
322 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
323 DESTINATION bin)
324 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
325 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
326 install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
327 DESTINATION bin)
328 endif(NOT WIN32 OR CYGWIN OR MINGW)
329endif()
330
331# On versions of CMake that support it, create an export file CMake
332# users can include() to import our targets
333if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
334 install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
335endif()
336
337# what's with libpng-$VER%.txt and all the extra files?
338
339# UNINSTALL
340# do we need this?
341
342# DIST
343# do we need this?
344
345# to create msvc import lib for mingw compiled shared lib
346# pexports libpng.dll > libpng.def
347# lib /def:libpng.def /machine:x86
348
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/INSTALL b/libraries/irrlicht-1.8/source/Irrlicht/libpng/INSTALL
new file mode 100644
index 0000000..c2d6c9e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/INSTALL
@@ -0,0 +1,135 @@
1
2Installing libpng
3
4On Unix/Linux and similar systems, you can simply type
5
6 ./configure [--prefix=/path]
7 make check
8 make install
9
10and ignore the rest of this document.
11
12If configure does not work on your system and you have a reasonably
13up-to-date set of tools, running ./autogen.sh before running ./configure
14may fix the problem. You can also run the individual commands in
15autogen.sh with the --force option, if supported by your version of
16the tools. To be really sure that you aren't using any of the included
17pre-built scripts, you can do this:
18
19 ./configure --enable-maintainer-mode
20 make maintainer-clean
21 ./autogen.sh
22 ./configure [--prefix=/path] [other options]
23 make
24 make install
25 make check
26
27Instead, you can use one of the custom-built makefiles in the
28"scripts" directory
29
30 cp scripts/makefile.system makefile
31 make test
32 make install
33
34The files that are presently available in the scripts directory
35are listed and described in scripts/README.txt.
36
37Or you can use one of the "projects" in the "projects" directory.
38
39Before installing libpng, you must first install zlib, if it
40is not already on your system. zlib can usually be found
41wherever you got libpng. zlib can be placed in another directory,
42at the same level as libpng.
43
44If you want to use "cmake" (see www.cmake.org), type
45
46 cmake . -DCMAKE_INSTALL_PREFIX=/path
47 make
48 make install
49
50If your system already has a preinstalled zlib you will still need
51to have access to the zlib.h and zconf.h include files that
52correspond to the version of zlib that's installed.
53
54You can rename the directories that you downloaded (they
55might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.5"
56or "zlib125") so that you have directories called "zlib" and "libpng".
57
58Your directory structure should look like this:
59
60 .. (the parent directory)
61 libpng (this directory)
62 INSTALL (this file)
63 README
64 *.h
65 *.c
66 CMakeLists.txt => "cmake" script
67 configuration files:
68 configure.ac, configure, Makefile.am, Makefile.in,
69 autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in,
70 libpng-config.in, aclocal.m4, config.h.in, config.sub,
71 depcomp, install-sh, mkinstalldirs, test-pngtest.sh
72 contrib
73 gregbook
74 pngminim
75 pngminus
76 pngsuite
77 visupng
78 projects
79 visualc71
80 vstudio
81 scripts
82 makefile.*
83 *.def (module definition files)
84 etc.
85 pngtest.png
86 etc.
87 zlib
88 README
89 *.h
90 *.c
91 contrib
92 etc.
93
94If the line endings in the files look funny, you may wish to get the other
95distribution of libpng. It is available in both tar.gz (UNIX style line
96endings) and zip (DOS style line endings) formats.
97
98If you are building libpng with MSVC, you can enter the
99libpng projects\visualc6 or visualc71 directory and follow the instructions
100in README.txt.
101
102Otherwise enter the zlib directory and follow the instructions in zlib/README,
103then come back here and run "configure" or choose the appropriate
104makefile.sys in the scripts directory.
105
106Copy the file (or files) that you need from the
107scripts directory into this directory, for example
108
109 MSDOS example: copy scripts\makefile.msc makefile
110 UNIX example: cp scripts/makefile.std makefile
111
112Read the makefile to see if you need to change any source or
113target directories to match your preferences.
114
115Then read pnglibconf.dfa to see if you want to make any configuration
116changes.
117
118Then just run "make" which will create the libpng library in
119this directory and "make test" which will run a quick test that reads
120the "pngtest.png" file and writes a "pngout.png" file that should be
121identical to it. Look for "9782 zero samples" in the output of the
122test. For more confidence, you can run another test by typing
123"pngtest pngnow.png" and looking for "289 zero samples" in the output.
124Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare
125your output with the result shown in contrib/pngsuite/README.
126
127Most of the makefiles will allow you to run "make install" to
128put the library in its final resting place (if you want to
129do that, run "make install" in the zlib directory first if necessary).
130Some also allow you to run "make test-installed" after you have
131run "make install".
132
133Further information can be found in the README and libpng-manual.txt
134files, in the individual makefiles, in png.h, and the manual pages
135libpng.3 and png.5.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/LICENSE b/libraries/irrlicht-1.8/source/Irrlicht/libpng/LICENSE
new file mode 100644
index 0000000..0c92740
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/LICENSE
@@ -0,0 +1,111 @@
1
2This copy of the libpng notices is provided for your convenience. In case of
3any discrepancy between this copy and the notices in the file png.h that is
4included in the libpng distribution, the latter shall prevail.
5
6COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
7
8If you modify libpng you may insert additional notices immediately following
9this sentence.
10
11This code is released under the libpng license.
12
13libpng versions 1.2.6, August 15, 2004, through 1.5.9, February 18, 2012, are
14Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
15distributed according to the same disclaimer and license as libpng-1.2.5
16with the following individual added to the list of Contributing Authors
17
18 Cosmin Truta
19
20libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
21Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
22distributed according to the same disclaimer and license as libpng-1.0.6
23with the following individuals added to the list of Contributing Authors
24
25 Simon-Pierre Cadieux
26 Eric S. Raymond
27 Gilles Vollant
28
29and with the following additions to the disclaimer:
30
31 There is no warranty against interference with your enjoyment of the
32 library or against infringement. There is no warranty that our
33 efforts or the library will fulfill any of your particular purposes
34 or needs. This library is provided with all faults, and the entire
35 risk of satisfactory quality, performance, accuracy, and effort is with
36 the user.
37
38libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
39Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
40distributed according to the same disclaimer and license as libpng-0.96,
41with the following individuals added to the list of Contributing Authors:
42
43 Tom Lane
44 Glenn Randers-Pehrson
45 Willem van Schaik
46
47libpng versions 0.89, June 1996, through 0.96, May 1997, are
48Copyright (c) 1996, 1997 Andreas Dilger
49Distributed according to the same disclaimer and license as libpng-0.88,
50with the following individuals added to the list of Contributing Authors:
51
52 John Bowler
53 Kevin Bracey
54 Sam Bushell
55 Magnus Holmgren
56 Greg Roelofs
57 Tom Tanner
58
59libpng versions 0.5, May 1995, through 0.88, January 1996, are
60Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
61
62For the purposes of this copyright and license, "Contributing Authors"
63is defined as the following set of individuals:
64
65 Andreas Dilger
66 Dave Martindale
67 Guy Eric Schalnat
68 Paul Schmidt
69 Tim Wegner
70
71The PNG Reference Library is supplied "AS IS". The Contributing Authors
72and Group 42, Inc. disclaim all warranties, expressed or implied,
73including, without limitation, the warranties of merchantability and of
74fitness for any purpose. The Contributing Authors and Group 42, Inc.
75assume no liability for direct, indirect, incidental, special, exemplary,
76or consequential damages, which may result from the use of the PNG
77Reference Library, even if advised of the possibility of such damage.
78
79Permission is hereby granted to use, copy, modify, and distribute this
80source code, or portions hereof, for any purpose, without fee, subject
81to the following restrictions:
82
831. The origin of this source code must not be misrepresented.
84
852. Altered versions must be plainly marked as such and must not
86 be misrepresented as being the original source.
87
883. This Copyright notice may not be removed or altered from any
89 source or altered source distribution.
90
91The Contributing Authors and Group 42, Inc. specifically permit, without
92fee, and encourage the use of this source code as a component to
93supporting the PNG file format in commercial products. If you use this
94source code in a product, acknowledgment is not required but would be
95appreciated.
96
97
98A "png_get_copyright" function is available, for convenient use in "about"
99boxes and the like:
100
101 printf("%s",png_get_copyright(NULL));
102
103Also, the PNG logo (in PNG format, of course) is supplied in the
104files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
105
106Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
107certification mark of the Open Source Initiative.
108
109Glenn Randers-Pehrson
110glennrp at users.sourceforge.net
111February 18, 2012
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/README
new file mode 100644
index 0000000..c648a5a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/README
@@ -0,0 +1,202 @@
1README for libpng version 1.5.9 - February 18, 2012 (shared library 15.0)
2See the note about version numbers near the top of png.h
3
4See INSTALL for instructions on how to install libpng.
5
6Libpng comes in several distribution formats. Get libpng-*.tar.gz,
7libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings
8in the text files, or lpng*.zip if you want DOS-style line endings.
9
10Version 0.89 was the first official release of libpng. Don't let the
11fact that it's the first release fool you. The libpng library has been in
12extensive use and testing since mid-1995. By late 1997 it had
13finally gotten to the stage where there hadn't been significant
14changes to the API in some time, and people have a bad feeling about
15libraries with versions < 1.0. Version 1.0.0 was released in
16March 1998.
17
18****
19Note that some of the changes to the png_info structure render this
20version of the library binary incompatible with libpng-0.89 or
21earlier versions if you are using a shared library. The type of the
22"filler" parameter for png_set_filler() has changed from png_byte to
23png_uint_32, which will affect shared-library applications that use
24this function.
25
26To avoid problems with changes to the internals of png_info_struct,
27new APIs have been made available in 0.95 to avoid direct application
28access to info_ptr. These functions are the png_set_<chunk> and
29png_get_<chunk> functions. These functions should be used when
30accessing/storing the info_struct data, rather than manipulating it
31directly, to avoid such problems in the future.
32
33It is important to note that the APIs do not make current programs
34that access the info struct directly incompatible with the new
35library. However, it is strongly suggested that new programs use
36the new APIs (as shown in example.c and pngtest.c), and older programs
37be converted to the new format, to facilitate upgrades in the future.
38****
39
40Additions since 0.90 include the ability to compile libpng as a
41Windows DLL, and new APIs for accessing data in the info struct.
42Experimental functions include the ability to set weighting and cost
43factors for row filter selection, direct reads of integers from buffers
44on big-endian processors that support misaligned data access, faster
45methods of doing alpha composition, and more accurate 16->8 bit color
46conversion.
47
48The additions since 0.89 include the ability to read from a PNG stream
49which has had some (or all) of the signature bytes read by the calling
50application. This also allows the reading of embedded PNG streams that
51do not have the PNG file signature. As well, it is now possible to set
52the library action on the detection of chunk CRC errors. It is possible
53to set different actions based on whether the CRC error occurred in a
54critical or an ancillary chunk.
55
56The changes made to the library, and bugs fixed are based on discussions
57on the PNG-implement mailing list and not on material submitted
58privately to Guy, Andreas, or Glenn. They will forward any good
59suggestions to the list.
60
61For a detailed description on using libpng, read libpng-manual.txt. For
62examples of libpng in a program, see example.c and pngtest.c. For usage
63information and restrictions (what little they are) on libpng, see
64png.h. For a description on using zlib (the compression library used by
65libpng) and zlib's restrictions, see zlib.h
66
67I have included a general makefile, as well as several machine and
68compiler specific ones, but you may have to modify one for your own needs.
69
70You should use zlib 1.0.4 or later to run this, but it MAY work with
71versions as old as zlib 0.95. Even so, there are bugs in older zlib
72versions which can cause the output of invalid compression streams for
73some images. You will definitely need zlib 1.0.4 or later if you are
74taking advantage of the MS-DOS "far" structure allocation for the small
75and medium memory models. You should also note that zlib is a
76compression library that is useful for more things than just PNG files.
77You can use zlib as a drop-in replacement for fread() and fwrite() if
78you are so inclined.
79
80zlib should be available at the same place that libpng is, or at.
81ftp://ftp.info-zip.org/pub/infozip/zlib
82
83You may also want a copy of the PNG specification. It is available
84as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
85these at http://www.libpng.org/pub/png/documents/
86
87This code is currently being archived at libpng.sf.net in the
88[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
89at GO GRAPHSUP. If you can't find it in any of those places,
90e-mail me, and I'll help you find it.
91
92If you have any code changes, requests, problems, etc., please e-mail
93them to me. Also, I'd appreciate any make files or project files,
94and any modifications you needed to make to get libpng to compile,
95along with a #define variable to tell what compiler/system you are on.
96If you needed to add transformations to libpng, or wish libpng would
97provide the image in a different way, drop me a note (and code, if
98possible), so I can consider supporting the transformation.
99Finally, if you get any warning messages when compiling libpng
100(note: not zlib), and they are easy to fix, I'd appreciate the
101fix. Please mention "libpng" somewhere in the subject line. Thanks.
102
103This release was created and will be supported by myself (of course
104based in a large way on Guy's and Andreas' earlier work), and the PNG
105development group.
106
107Send comments/corrections/commendations to png-mng-implement at
108lists.sourceforge.net (subscription required; visit
109https://lists.sourceforge.net/lists/listinfo/png-mng-implement
110to subscribe) or to glennrp at users.sourceforge.net
111
112You can't reach Guy, the original libpng author, at the addresses
113given in previous versions of this document. He and Andreas will
114read mail addressed to the png-implement list, however.
115
116Please do not send general questions about PNG. Send them to
117png-mng-misc at lists.sf.net (subscription required; visit
118https://lists.sourceforge.net/lists/listinfo/png-mng-misc to
119subscribe). If you have a question about something
120in the PNG specification that is related to using libpng, send it
121to me. Send me any questions that start with "I was using libpng,
122and ...". If in doubt, send questions to me. I'll bounce them
123to others, if necessary.
124
125Please do not send suggestions on how to change PNG. We have
126been discussing PNG for sixteen years now, and it is official and
127finished. If you have suggestions for libpng, however, I'll
128gladly listen. Even if your suggestion is not used immediately,
129it may be used later.
130
131Files in this distribution:
132
133 ANNOUNCE => Announcement of this version, with recent changes
134 CHANGES => Description of changes between libpng versions
135 KNOWNBUG => List of known bugs and deficiencies
136 LICENSE => License to use and redistribute libpng
137 README => This file
138 TODO => Things not implemented in the current library
139 Y2KINFO => Statement of Y2K compliance
140 example.c => Example code for using libpng functions
141 libpng.3 => manual page for libpng (includes libpng-manual.txt)
142 libpng-manual.txt => Description of libpng and its functions
143 libpngpf.3 => manual page for libpng's private functions
144 png.5 => manual page for the PNG format
145 png.c => Basic interface functions common to library
146 png.h => Library function and interface declarations (public)
147 pngpriv.h => Library function and interface declarations (private)
148 pngconf.h => System specific library configuration (public)
149 pngstruct.h => png_struct declaration (private)
150 pnginfo.h => png_info struct declaration (private)
151 pngdebug.h => debugging macros (private)
152 pngerror.c => Error/warning message I/O functions
153 pngget.c => Functions for retrieving info from struct
154 pngmem.c => Memory handling functions
155 pngbar.png => PNG logo, 88x31
156 pngnow.png => PNG logo, 98x31
157 pngpread.c => Progressive reading functions
158 pngread.c => Read data/helper high-level functions
159 pngrio.c => Lowest-level data read I/O functions
160 pngrtran.c => Read data transformation functions
161 pngrutil.c => Read data utility functions
162 pngset.c => Functions for storing data into the info_struct
163 pngtest.c => Library test program
164 pngtest.png => Library test sample image
165 pngtrans.c => Common data transformation functions
166 pngwio.c => Lowest-level write I/O functions
167 pngwrite.c => High-level write functions
168 pngwtran.c => Write data transformations
169 pngwutil.c => Write utility functions
170 contrib => Contributions
171 gregbook => source code for PNG reading and writing, from
172 Greg Roelofs' "PNG: The Definitive Guide",
173 O'Reilly, 1999
174 msvctest => Builds and runs pngtest using a MSVC workspace
175 pngminus => Simple pnm2png and png2pnm programs
176 pngsuite => Test images
177 visupng => Contains a MSVC workspace for VisualPng
178 projects => Contains project files and workspaces for
179 building a DLL
180 cbuilder5 => Contains a Borland workspace for building
181 libpng and zlib
182 visualc6 => Contains a Microsoft Visual C++ (MSVC)
183 workspace for building libpng and zlib
184 visualc71 => Contains a Microsoft Visual C++ (MSVC)
185 workspace for building libpng and zlib
186 xcode => Contains an Apple xcode
187 workspace for building libpng and zlib
188 scripts => Directory containing scripts for building libpng:
189 (see scripts/README.txt for the list of scripts)
190
191Good luck, and happy coding.
192
193-Glenn Randers-Pehrson (current maintainer, since 1998)
194 Internet: glennrp at users.sourceforge.net
195
196-Andreas Eric Dilger (former maintainer, 1996-1997)
197 Internet: adilger at enel.ucalgary.ca
198 Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
199
200-Guy Eric Schalnat (original author and former maintainer, 1995-1996)
201 (formerly of Group 42, Inc)
202 Internet: gschal at infinet.com
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/TODO b/libraries/irrlicht-1.8/source/Irrlicht/libpng/TODO
new file mode 100644
index 0000000..b1660a4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/TODO
@@ -0,0 +1,27 @@
1/*
2TODO - list of things to do for libpng:
3
4Final bug fixes.
5Better C++ wrapper/full C++ implementation?
6Fix problem with C++ and EXTERN "C".
7cHRM transformation.
8Remove setjmp/longjmp usage in favor of returning error codes.
9Add "grayscale->palette" transformation and "palette->grayscale" detection.
10Improved dithering.
11Multi-lingual error and warning message support.
12Complete sRGB transformation (presently it simply uses gamma=0.45455).
13Man pages for function calls.
14Better documentation.
15Better filter selection
16 (counting huffman bits/precompression? filter inertia? filter costs?).
17Histogram creation.
18Text conversion between different code pages (Latin-1 -> Mac and DOS).
19Avoid building gamma tables whenever possible.
20Use greater precision when changing to linear gamma for compositing against
21 background and doing rgb-to-gray transformation.
22Investigate pre-incremented loop counters and other loop constructions.
23Add interpolated method of handling interlacing.
24Switch to the simpler zlib (zlib/libpng) license if legally possible.
25Extend pngvalid.c to validate more of the libpng transformations.
26
27*/
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/configure b/libraries/irrlicht-1.8/source/Irrlicht/libpng/configure
new file mode 100644
index 0000000..9da0f74
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/configure
@@ -0,0 +1,19 @@
1
2echo "
3 There is no \"configure\" script in this distribution of
4 libpng-1.5.9.
5
6 Instead, please copy the appropriate makefile for your system from the
7 \"scripts\" directory. Read the INSTALL file for more details.
8
9 Update, July 2004: you can get a \"configure\" based distribution
10 from the libpng distribution sites. Download the file
11 libpng-1.5.9.tar.gz, libpng-1.5.9.tar.xz, or libpng-1.5.9.tar.bz2
12
13 If the line endings in the files look funny, which is likely to be the
14 case if you were trying to run \"configure\" on a Linux machine, you may
15 wish to get the other distribution of libpng. It is available in both
16 tar.gz/tar.xz (UNIX style line endings) and .7z/.zip (DOS style line
17 endings) formats.
18"
19
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/README.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/README.txt
new file mode 100644
index 0000000..7e9b7d0
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/README.txt
@@ -0,0 +1,4 @@
1
2This "contrib" directory contains contributions which are not necessarily under
3the libpng license, although all are open source. They are not part of
4libpng proper and are not used for building the library.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING
new file mode 100644
index 0000000..c2d382b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING
@@ -0,0 +1,340 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) <year> <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
310
311Also add information on how to contact you by electronic and paper mail.
312
313If the program is interactive, make it output a short notice like this
314when it starts in an interactive mode:
315
316 Gnomovision version 69, Copyright (C) year name of author
317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 This is free software, and you are welcome to redistribute it
319 under certain conditions; type `show c' for details.
320
321The hypothetical commands `show w' and `show c' should show the appropriate
322parts of the General Public License. Of course, the commands you use may
323be called something other than `show w' and `show c'; they could even be
324mouse-clicks or menu items--whatever suits your program.
325
326You should also get your employer (if you work as a programmer) or your
327school, if any, to sign a "copyright disclaimer" for the program, if
328necessary. Here is a sample; alter the names:
329
330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
333 <signature of Ty Coon>, 1 April 1989
334 Ty Coon, President of Vice
335
336This General Public License does not permit incorporating your program into
337proprietary programs. If your program is a subroutine library, you may
338consider it more useful to permit linking proprietary applications with the
339library. If this is what you want to do, use the GNU Library General
340Public License instead of this License.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE
new file mode 100644
index 0000000..40a0c8e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE
@@ -0,0 +1,50 @@
1 ---------------------------------------------------------------------------
2
3 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
4
5 This software is provided "as is," without warranty of any kind,
6 express or implied. In no event shall the author or contributors
7 be held liable for any damages arising in any way from the use of
8 this software.
9
10 The contents of this file are DUAL-LICENSED. You may modify and/or
11 redistribute this software according to the terms of one of the
12 following two licenses (at your option):
13
14
15 LICENSE 1 ("BSD-like with advertising clause"):
16
17 Permission is granted to anyone to use this software for any purpose,
18 including commercial applications, and to alter it and redistribute
19 it freely, subject to the following restrictions:
20
21 1. Redistributions of source code must retain the above copyright
22 notice, disclaimer, and this list of conditions.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, disclaimer, and this list of conditions in the documenta-
25 tion and/or other materials provided with the distribution.
26 3. All advertising materials mentioning features or use of this
27 software must display the following acknowledgment:
28
29 This product includes software developed by Greg Roelofs
30 and contributors for the book, "PNG: The Definitive Guide,"
31 published by O'Reilly and Associates.
32
33
34 LICENSE 2 (GNU GPL v2 or later):
35
36 This program is free software; you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation; either version 2 of the License, or
39 (at your option) any later version.
40
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
45
46 You should have received a copy of the GNU General Public License
47 along with this program; if not, write to the Free Software Foundation,
48 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49
50 ---------------------------------------------------------------------------
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32
new file mode 100644
index 0000000..a736556
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32
@@ -0,0 +1,130 @@
1# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a DOS-prompt window via:
12#
13# make -f Makefile.mingw32
14#
15# This makefile assumes libpng and zlib have already been built or downloaded
16# and are in subdirectories at the same level as the current subdirectory
17# (as indicated by the PNGDIR and ZDIR macros below). It makes no assumptions
18# at all about the mingw32 installation tree (W32DIR). Edit as appropriate.
19#
20# Note that the names of the dynamic and static libpng and zlib libraries
21# used below may change in later releases of the libraries. This makefile
22# builds both statically and dynamically linked executables by default.
23# (You need only one set, but for testing it can be handy to have both.)
24
25
26# macros --------------------------------------------------------------------
27
28#PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds
29PNGDIR = ../libpng-win32
30PNGINC = -I$(PNGDIR)
31PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked
32PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
33
34#ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds
35ZDIR = ../zlib-win32
36ZINC = -I$(ZDIR)
37ZLIBd = $(ZDIR)/libzdll.a
38ZLIBs = $(ZDIR)/libz.a
39
40# change this to be the path where mingw32 installs its stuff:
41W32DIR =
42#W32DIR = /usr/local/cross-tools/i386-mingw32msvc
43W32INC = -I$(W32DIR)/include
44W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a
45
46CC = gcc
47#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation
48LD = $(CC)
49RM = rm -f
50CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS)
51# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
52# [-ansi, -pedantic and -W can also be used]
53LDFLAGS = $(MINGW_LDFLAGS)
54O = .o
55E = .exe
56
57INCS = $(PNGINC) $(ZINC) $(W32INC)
58RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm
59RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm
60WLIBSd = $(PNGLIBd) $(ZLIBd)
61WLIBSs = $(PNGLIBs) $(ZLIBs)
62
63RPNG = rpng-win
64RPNG2 = rpng2-win
65WPNG = wpng
66
67ROBJSd = $(RPNG)$(O) readpng.pic$(O)
68ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O)
69WOBJSd = $(WPNG)$(O) writepng.pic$(O)
70
71RPNGs = $(RPNG)-static
72RPNG2s = $(RPNG2)-static
73WPNGs = $(WPNG)-static
74
75ROBJSs = $(RPNG)$(O) readpng$(O)
76ROBJS2s = $(RPNG2)$(O) readpng2$(O)
77WOBJSs = $(WPNG)$(O) writepng$(O)
78
79STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
80DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
81
82EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
83
84
85# implicit make rules -------------------------------------------------------
86
87.c$(O):
88 $(CC) -c $(CFLAGS) $<
89
90%.pic$(O): %.c
91 $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
92
93
94# dependencies --------------------------------------------------------------
95
96all: $(EXES)
97
98$(RPNGs)$(E): $(ROBJSs)
99 $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs)
100
101$(RPNG)$(E): $(ROBJSd)
102 $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd)
103
104$(RPNG2s)$(E): $(ROBJS2s)
105 $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs)
106
107$(RPNG2)$(E): $(ROBJS2d)
108 $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd)
109
110$(WPNGs)$(E): $(WOBJSs)
111 $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs)
112
113$(WPNG)$(E): $(WOBJSd)
114 $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd)
115
116$(RPNG)$(O): $(RPNG).c readpng.h
117$(RPNG2)$(O): $(RPNG2).c readpng2.h
118$(WPNG)$(O): $(WPNG).c writepng.h
119
120readpng$(O) readpng.pic$(O): readpng.c readpng.h
121readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h
122writepng$(O) writepng.pic$(O): writepng.c writepng.h
123
124
125# maintenance ---------------------------------------------------------------
126
127clean:
128 $(RM) $(EXES)
129 $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs)
130 $(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi
new file mode 100644
index 0000000..8773a00
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi
@@ -0,0 +1,104 @@
1# Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make.
2# Greg Roelofs
3# Last modified: 7 March 2002
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Buy some for friends
8# and family, too. (Not that this is a blatant plug or anything.)
9#
10# Invoke this makefile from a shell prompt in the usual way; for example:
11#
12# make -f Makefile.sgi
13#
14# This makefile assumes libpng and zlib have already been built or downloaded
15# and are both installed in /usr/local/{include,lib} (as indicated by the
16# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of
17# the PNGINC, PNGLIB, ZINC and ZLIB lines.
18#
19# This makefile builds dynamically linked executables (against libpng and zlib,
20# that is), but that can be changed by uncommenting the appropriate PNGLIB and
21# ZLIB lines.
22
23
24# macros --------------------------------------------------------------------
25
26PNGINC = -I/usr/local/include/libpng15
27PNGLIB = -L/usr/local/lib -lpng15 # dynamically linked against libpng
28#PNGLIB = /usr/local/lib/libpng15.a # statically linked against libpng
29# or:
30#PNGINC = -I../..
31#PNGLIB = -L../.. -lpng
32#PNGLIB = ../../libpng.a
33
34ZINC = -I/usr/local/include
35ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib
36#ZLIB = /usr/local/lib/libz.a # statically linked against zlib
37#ZINC = -I../zlib
38#ZLIB = -L../zlib -lz
39#ZLIB = ../../../zlib/libz.a
40
41XINC = -I/usr/include/X11 # old-style, stock X distributions
42XLIB = -L/usr/lib/X11 -lX11
43#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
44#XLIB = -L/usr/openwin/lib -lX11
45#XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.)
46#XLIB = -L/usr/X11R6/lib -lX11
47
48INCS = $(PNGINC) $(ZINC) $(XINC)
49RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
50WLIBS = $(PNGLIB) $(ZLIB)
51
52CC = cc
53LD = cc
54RM = rm -f
55# ABI must be the same as that used to build libpng.
56ABI=
57CFLAGS = $(ABI) -O -fullwarn $(INCS)
58LDFLAGS = $(ABI)
59O = .o
60E =
61
62RPNG = rpng-x
63RPNG2 = rpng2-x
64WPNG = wpng
65
66ROBJS = $(RPNG)$(O) readpng$(O)
67ROBJS2 = $(RPNG2)$(O) readpng2$(O)
68WOBJS = $(WPNG)$(O) writepng$(O)
69
70EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
71
72
73# implicit make rules -------------------------------------------------------
74
75.c$(O):
76 $(CC) -c $(CFLAGS) $<
77
78
79# dependencies --------------------------------------------------------------
80
81all: $(EXES)
82
83$(RPNG)$(E): $(ROBJS)
84 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)
85
86$(RPNG2)$(E): $(ROBJS2)
87 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)
88
89$(WPNG)$(E): $(WOBJS)
90 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)
91
92$(RPNG)$(O): $(RPNG).c readpng.h
93$(RPNG2)$(O): $(RPNG2).c readpng2.h
94$(WPNG)$(O): $(WPNG).c writepng.h
95
96readpng$(O): readpng.c readpng.h
97readpng2$(O): readpng2.c readpng2.h
98writepng$(O): writepng.c writepng.h
99
100
101# maintenance ---------------------------------------------------------------
102
103clean:
104 $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx
new file mode 100644
index 0000000..3bffc2f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx
@@ -0,0 +1,132 @@
1# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a shell prompt in the usual way; for example:
12#
13# make -f Makefile.unx
14#
15# This makefile assumes libpng and zlib have already been built or downloaded
16# and are installed in /usr/local/{include,lib} or as otherwise indicated by
17# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of
18# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.
19#
20# This makefile builds both dynamically and statically linked executables
21# (against libpng and zlib, that is), but that can be changed by modifying
22# the "EXES =" line. (You need only one set, but for testing it can be handy
23# to have both.)
24
25
26# macros --------------------------------------------------------------------
27
28#PNGDIR = /usr/local/lib
29#PNGINC = -I/usr/local/include/libpng15
30#PNGLIBd = -L$(PNGDIR) -lpng15 # dynamically linked, installed libpng
31#PNGLIBs = $(PNGDIR)/libpng15.a # statically linked, installed libpng
32# or:
33PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds
34#PNGDIR = ../libpng
35PNGINC = -I$(PNGDIR)
36PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng15 # dynamically linked
37PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
38
39ZDIR = /usr/local/lib
40#ZDIR = /usr/lib64
41ZINC = -I/usr/local/include
42ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib
43ZLIBs = $(ZDIR)/libz.a # statically linked against zlib
44# or:
45#ZDIR = ../zlib
46#ZINC = -I$(ZDIR)
47#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing
48#ZLIBs = $(ZDIR)/libz.a
49
50#XINC = -I/usr/include # old-style, stock X distributions
51#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX)
52#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
53#XLIB = -L/usr/openwin/lib -lX11
54XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.)
55XLIB = -L/usr/X11R6/lib -lX11
56#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64
57
58INCS = $(PNGINC) $(ZINC) $(XINC)
59RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
60RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
61WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
62WLIBSs = $(PNGLIBs) $(ZLIBs)
63
64CC = gcc
65LD = gcc
66RM = rm -f
67CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP
68# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
69# [-ansi, -pedantic and -W can also be used]
70LDFLAGS =
71O = .o
72E =
73
74RPNG = rpng-x
75RPNG2 = rpng2-x
76WPNG = wpng
77
78RPNGs = $(RPNG)-static
79RPNG2s = $(RPNG2)-static
80WPNGs = $(WPNG)-static
81
82ROBJS = $(RPNG)$(O) readpng$(O)
83ROBJS2 = $(RPNG2)$(O) readpng2$(O)
84WOBJS = $(WPNG)$(O) writepng$(O)
85
86STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
87DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
88
89EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
90
91
92# implicit make rules -------------------------------------------------------
93
94.c$(O):
95 $(CC) -c $(CFLAGS) $<
96
97
98# dependencies --------------------------------------------------------------
99
100all: $(EXES)
101
102$(RPNGs)$(E): $(ROBJS)
103 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)
104
105$(RPNG)$(E): $(ROBJS)
106 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)
107
108$(RPNG2s)$(E): $(ROBJS2)
109 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)
110
111$(RPNG2)$(E): $(ROBJS2)
112 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)
113
114$(WPNGs)$(E): $(WOBJS)
115 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)
116
117$(WPNG)$(E): $(WOBJS)
118 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)
119
120$(RPNG)$(O): $(RPNG).c readpng.h
121$(RPNG2)$(O): $(RPNG2).c readpng2.h
122$(WPNG)$(O): $(WPNG).c writepng.h
123
124readpng$(O): readpng.c readpng.h
125readpng2$(O): readpng2.c readpng2.h
126writepng$(O): writepng.c writepng.h
127
128
129# maintenance ---------------------------------------------------------------
130
131clean:
132 $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32
new file mode 100644
index 0000000..eced083
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32
@@ -0,0 +1,113 @@
1# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a DOS prompt window via:
12#
13# %devstudio%\vc\bin\vcvars32.bat
14# nmake -nologo -f Makefile.w32
15#
16# where %devstudio% is the installation directory for MSVC / DevStudio. If
17# you get "environment out of space" errors, create a desktop shortcut with
18# "c:\windows\command.com /e:4096" as the program command line and set the
19# working directory to this directory. Then double-click to open the new
20# DOS-prompt window with a bigger environment and retry the commands above.
21#
22# This makefile assumes libpng and zlib have already been built or downloaded
23# and are in subdirectories at the same level as the current subdirectory
24# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate.
25#
26# Note that the names of the dynamic and static libpng and zlib libraries
27# used below may change in later releases of the libraries. This makefile
28# builds statically linked executables, but that can be changed by uncom-
29# menting the appropriate PNGLIB and ZLIB lines.
30
31!include <ntwin32.mak>
32
33
34# macros --------------------------------------------------------------------
35
36PNGPATH = ../libpng
37PNGINC = -I$(PNGPATH)
38#PNGLIB = $(PNGPATH)/pngdll.lib
39PNGLIB = $(PNGPATH)/libpng.lib
40
41ZPATH = ../zlib
42ZINC = -I$(ZPATH)
43#ZLIB = $(ZPATH)/zlibdll.lib
44ZLIB = $(ZPATH)/zlibstat.lib
45
46WINLIBS = -defaultlib:user32.lib gdi32.lib
47# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]
48
49INCS = $(PNGINC) $(ZINC)
50RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)
51WLIBS = $(PNGLIB) $(ZLIB)
52
53CC = cl
54LD = link
55RM = del
56CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
57# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")]
58# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
59O = .obj
60E = .exe
61
62RLDFLAGS = -nologo -subsystem:windows
63WLDFLAGS = -nologo
64
65RPNG = rpng-win
66RPNG2 = rpng2-win
67WPNG = wpng
68
69ROBJS = $(RPNG)$(O) readpng$(O)
70ROBJS2 = $(RPNG2)$(O) readpng2$(O)
71WOBJS = $(WPNG)$(O) writepng$(O)
72
73EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
74
75
76# implicit make rules -------------------------------------------------------
77
78.c$(O):
79 $(CC) -c $(CFLAGS) $<
80
81
82# dependencies --------------------------------------------------------------
83
84all: $(EXES)
85
86$(RPNG)$(E): $(ROBJS)
87 $(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)
88
89$(RPNG2)$(E): $(ROBJS2)
90 $(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)
91
92$(WPNG)$(E): $(WOBJS)
93 $(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)
94
95$(RPNG)$(O): $(RPNG).c readpng.h
96$(RPNG2)$(O): $(RPNG2).c readpng2.h
97$(WPNG)$(O): $(WPNG).c writepng.h
98
99readpng$(O): readpng.c readpng.h
100readpng2$(O): readpng2.c readpng2.h
101writepng$(O): writepng.c writepng.h
102
103
104# maintenance ---------------------------------------------------------------
105
106clean:
107# ideally we could just do this:
108# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
109# ...but the Windows "DEL" command is none too bright, so:
110 $(RM) r*$(E)
111 $(RM) w*$(E)
112 $(RM) r*$(O)
113 $(RM) w*$(O)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README
new file mode 100644
index 0000000..791fec8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README
@@ -0,0 +1,186 @@
1 ===========================
2 PNG: The Definitive Guide
3 ===========================
4
5 Source Code
6
7Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free,
8cross-platform demo programs that show how to use the libpng reference
9library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is
10a very simple example that that shows how a standard file-viewer might use
11libpng, while the second is designed to process streaming data and shows
12how a web browser might be written. wpng is a simple command-line program
13that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets
14of PBMPLUS/NetPBM) and converts them to PNG.
15
16The source code for all three demo programs currently compiles under
17Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
18zinser@decus.de, for making the necessary changes for OpenVMS and for
19providing an appropriate build script.) Build instructions can be found
20below.
21
22Files:
23
24 README this file
25 LICENSE terms of distribution and reuse (BSD-like or GNU GPL)
26 COPYING GNU General Public License (GPL)
27
28 Makefile.unx Unix makefile
29 Makefile.w32 Windows (MSVC) makefile
30 makevms.com OpenVMS build script
31
32 rpng-win.c Windows front end for the basic viewer
33 rpng-x.c X Window System (Unix, OpenVMS) front end
34 readpng.c generic back end for the basic viewer
35 readpng.h header file for the basic viewer
36
37 rpng2-win.c Windows front end for the progressive viewer
38 rpng2-x.c X front end for the progressive viewer
39 readpng2.c generic back end for the progressive viewer
40 readpng2.h header file for the progressive viewer
41
42 wpng.c generic (text) front end for the converter
43 writepng.c generic back end for the converter
44 writepng.h header file for the converter
45
46 toucan.png transparent PNG for testing (by Stefan Schneider)
47
48Note that, although the programs are designed to be functional, their
49primary purpose is to illustrate how to use libpng to add PNG support to
50other programs. As such, their user interfaces are crude and definitely
51are not intended for everyday use.
52
53Please see http://www.libpng.org/pub/png/pngbook.html for further infor-
54mation and links to the latest version of the source code, and Chapters
5513-15 of the book for detailed discussion of the three programs.
56
57Greg Roelofs
58http://pobox.com/~newt/greg_contact.html
5916 March 2008
60
61
62BUILD INSTRUCTIONS
63
64 - Prerequisites (in order of compilation):
65
66 - zlib http://zlib.net/
67 - libpng http://www.libpng.org/pub/png/libpng.html
68 - pngbook http://www.libpng.org/pub/png/book/sources.html
69
70 The pngbook demo programs are explicitly designed to demonstrate proper
71 coding techniques for using the libpng reference library. As a result,
72 you need to download and build both zlib (on which libpng depends) and
73 libpng. A common build setup is to place the zlib, libpng and pngbook
74 subdirectory trees ("folders") in the same parent directory. Then the
75 libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]),
76 and similarly for the pngbook build.
77
78 Note that all three packages are designed to be built from a command
79 line by default; those who wish to use a graphical or other integrated
80 development environments are on their own.
81
82
83 - Unix:
84
85 Unpack the latest pngbook sources (which should correspond to this
86 README file) into a directory and change into that directory.
87
88 Copy Makefile.unx to Makefile and edit the PNG* and Z* variables
89 appropriately (possibly also the X* variables if necessary).
90
91 make
92
93 There is no "install" target, so copy the three executables somewhere
94 in your path or run them from the current directory. All three will
95 print a basic usage screen when run without any command-line arguments;
96 see the book for more details.
97
98
99 - Windows:
100
101 Unpack the latest pngbook sources (which should correspond to this
102 README file) into a folder, open a "DOS shell" or "command prompt"
103 or equivalent command-line window, and cd into the folder where you
104 unpacked the source code.
105
106 For MSVC, set up the necessary environment variables by invoking
107
108 %devstudio%\vc\bin\vcvars32.bat
109
110 where where %devstudio% is the installation directory for MSVC /
111 DevStudio. If you get "environment out of space" errors under 95/98,
112 create a desktop shortcut with "c:\windows\command.com /e:4096" as
113 the program command line and set the working directory to the pngbook
114 directory. Then double-click to open the new DOS-prompt window with
115 a bigger environment and retry the commands above.
116
117 Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables
118 appropriately (possibly also the "INC" and "LIB" variables if needed).
119 Note that the names of the dynamic and static libpng and zlib libraries
120 used in the makefile may change in later releases of the libraries.
121 Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.
122 This makefile therefore builds statically linked executables, but if
123 the DLL problems ever get fixed, uncommenting the appropriate PNGLIB
124 and ZLIB lines will build dynamically linked executables instead.
125
126 Do the build by typing
127
128 nmake
129
130 The result should be three executables: rpng-win.exe, rpng2-win.exe,
131 and wpng.exe. Copy them somewhere in your PATH or run them from the
132 current folder. Like the Unix versions, the two windowed programs
133 (rpng and rpng2) now display a usage screen in a console window when
134 invoked without command-line arguments; this is new behavior as of
135 the June 2001 release. Note that the programs use the Unix-style "-"
136 character to specify options, instead of the more common DOS/Windows
137 "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not
138 "rpng2-win /bgpat 4 foo.png")
139
140
141 - OpenVMS:
142
143 Unpack the pngbook sources into a subdirectory and change into that
144 subdirectory.
145
146 Edit makevms.com appropriately, specifically the zpath and pngpath
147 variables.
148
149 @makevms
150
151 To run the programs, they probably first need to be set up as "foreign
152 symbols," with "disk" and "dir" set appropriately:
153
154 $ rpng == "$disk:[dir]rpng-x.exe"
155 $ rpng2 == "$disk:[dir]rpng2-x.exe"
156 $ wpng == "$disk:[dir]wpng.exe"
157
158 All three will print a basic usage screen when run without any command-
159 line arguments; see the book for more details. Note that the options
160 style is Unix-like, i.e., preceded by "-" rather than "/".
161
162
163RUNNING THE PROGRAMS: (VERY) BRIEF INTRO
164
165 rpng is a simple PNG viewer that can display transparent PNGs with a
166 specified background color; for example,
167
168 rpng -bgcolor \#ff0000 toucan.png
169
170 would display the image with a red background. rpng2 is a progressive
171 viewer that simulates a web browser in some respects; it can display
172 images against either a background color or a dynamically generated
173 background image. For example:
174
175 rpng2 -bgpat 16 toucan.png
176
177 wpng is a purely command-line image converter from binary PBMPLUS/NetPBM
178 format (.pgm or .ppm) to PNG; for example,
179
180 wpng -time < toucan-notrans.ppm > toucan-notrans.png
181
182 would convert the specified PPM file (using redirection) to PNG, auto-
183 matically setting the PNG modification-time chunk.
184
185 All options can be abbreviated to the shortest unique value; for example,
186 "-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com
new file mode 100644
index 0000000..29a5727
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com
@@ -0,0 +1,132 @@
1$!------------------------------------------------------------------------------
2$! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS
3$!
4$! Script created by Martin Zinser for libpng; modified by Greg Roelofs
5$! for standalone pngbook source distribution.
6$!
7$!
8$! Set locations where zlib and libpng sources live.
9$!
10$ zpath = ""
11$ pngpath = ""
12$!
13$ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]"
14$ if f$search("[--]png.h").nes."" then pngpath = "[--]"
15$!
16$ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]"
17$ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]"
18$!
19$ if zpath .eqs. ""
20$ then
21$ write sys$output "zlib include not found. Exiting..."
22$ exit 2
23$ endif
24$!
25$ if pngpath .eqs. ""
26$ then
27$ write sys$output "libpng include not found. Exiting..."
28$ exit 2
29$ endif
30$!
31$! Look for the compiler used.
32$!
33$ ccopt="/include=(''zpath',''pngpath')"
34$ if f$getsyi("HW_MODEL").ge.1024
35$ then
36$ ccopt = "/prefix=all"+ccopt
37$ comp = "__decc__=1"
38$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
39$ else
40$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
41$ then
42$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
43$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
44$ then
45$ comp = "__gcc__=1"
46$ CC :== GCC
47$ else
48$ comp = "__vaxc__=1"
49$ endif
50$ else
51$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
52$ ccopt = "/decc/prefix=all"+ccopt
53$ comp = "__decc__=1"
54$ endif
55$ endif
56$ open/write lopt lib.opt
57$ write lopt "''pngpath'libpng.olb/lib"
58$ write lopt "''zpath'libz.olb/lib"
59$ close lopt
60$ open/write xopt x11.opt
61$ write xopt "sys$library:decw$xlibshr.exe/share"
62$ close xopt
63$!
64$! Build 'em.
65$!
66$ write sys$output "Compiling PNG book programs ..."
67$ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" -
68 readpng.c readpng.h
69$ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" -
70 readpng2.c readpng2.h
71$ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" -
72 writepng.c writepng.h
73$ write sys$output "Building rpng-x..."
74$ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" -
75 rpng-x.c readpng.h
76$ call make rpng-x.exe -
77 "LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" -
78 rpng-x.obj readpng.obj
79$ write sys$output "Building rpng2-x..."
80$ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" -
81 rpng2-x.c readpng2.h
82$ call make rpng2-x.exe -
83 "LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" -
84 rpng2-x.obj readpng2.obj
85$ write sys$output "Building wpng..."
86$ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" -
87 wpng.c writepng.h
88$ call make wpng.exe -
89 "LINK wpng,writepng,lib.opt/opt" -
90 wpng.obj writepng.obj
91$ exit
92$!
93$!
94$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
95$ V = 'F$Verify(0)
96$! P1 = What we are trying to make
97$! P2 = Command to make it
98$! P3 - P8 What it depends on
99$
100$ If F$Search(P1) .Eqs. "" Then Goto Makeit
101$ Time = F$CvTime(F$File(P1,"RDT"))
102$arg=3
103$Loop:
104$ Argument = P'arg
105$ If Argument .Eqs. "" Then Goto Exit
106$ El=0
107$Loop2:
108$ File = F$Element(El," ",Argument)
109$ If File .Eqs. " " Then Goto Endl
110$ AFile = ""
111$Loop3:
112$ OFile = AFile
113$ AFile = F$Search(File)
114$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
115$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
116$ Goto Loop3
117$NextEL:
118$ El = El + 1
119$ Goto Loop2
120$EndL:
121$ arg=arg+1
122$ If arg .Le. 8 Then Goto Loop
123$ Goto Exit
124$
125$Makeit:
126$ VV=F$VERIFY(0)
127$ write sys$output P2
128$ 'P2
129$ VV='F$Verify(VV)
130$Exit:
131$ If V Then Set Verify
132$ENDSUBROUTINE
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c
new file mode 100644
index 0000000..27a2f11
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c
@@ -0,0 +1,311 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readpng.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#include <stdio.h>
57#include <stdlib.h>
58
59#include "png.h" /* libpng header; includes zlib.h */
60#include "readpng.h" /* typedefs, common macros, public prototypes */
61
62/* future versions of libpng will provide this macro: */
63#ifndef png_jmpbuf
64# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
65#endif
66
67
68static png_structp png_ptr = NULL;
69static png_infop info_ptr = NULL;
70
71png_uint_32 width, height;
72int bit_depth, color_type;
73uch *image_data = NULL;
74
75
76void readpng_version_info(void)
77{
78 fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
79 PNG_LIBPNG_VER_STRING, png_libpng_ver);
80 fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
81 ZLIB_VERSION, zlib_version);
82}
83
84
85/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
86
87int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
88{
89 uch sig[8];
90
91
92 /* first do a quick check that the file really is a PNG image; could
93 * have used slightly more general png_sig_cmp() function instead */
94
95 fread(sig, 1, 8, infile);
96 if (png_sig_cmp(sig, 0, 8))
97 return 1; /* bad signature */
98
99
100 /* could pass pointers to user-defined error handlers instead of NULLs: */
101
102 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
103 if (!png_ptr)
104 return 4; /* out of memory */
105
106 info_ptr = png_create_info_struct(png_ptr);
107 if (!info_ptr) {
108 png_destroy_read_struct(&png_ptr, NULL, NULL);
109 return 4; /* out of memory */
110 }
111
112
113 /* we could create a second info struct here (end_info), but it's only
114 * useful if we want to keep pre- and post-IDAT chunk info separated
115 * (mainly for PNG-aware image editors and converters) */
116
117
118 /* setjmp() must be called in every function that calls a PNG-reading
119 * libpng function */
120
121 if (setjmp(png_jmpbuf(png_ptr))) {
122 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
123 return 2;
124 }
125
126
127 png_init_io(png_ptr, infile);
128 png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */
129
130 png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
131
132
133 /* alternatively, could make separate calls to png_get_image_width(),
134 * etc., but want bit_depth and color_type for later [don't care about
135 * compression_type and filter_type => NULLs] */
136
137 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
138 NULL, NULL, NULL);
139 *pWidth = width;
140 *pHeight = height;
141
142
143 /* OK, that's all we need for now; return happy */
144
145 return 0;
146}
147
148
149
150
151/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
152 * scales values to 8-bit if necessary */
153
154int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
155{
156 png_color_16p pBackground;
157
158
159 /* setjmp() must be called in every function that calls a PNG-reading
160 * libpng function */
161
162 if (setjmp(png_jmpbuf(png_ptr))) {
163 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
164 return 2;
165 }
166
167
168 if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
169 return 1;
170
171 /* it is not obvious from the libpng documentation, but this function
172 * takes a pointer to a pointer, and it always returns valid red, green
173 * and blue values, regardless of color_type: */
174
175 png_get_bKGD(png_ptr, info_ptr, &pBackground);
176
177
178 /* however, it always returns the raw bKGD data, regardless of any
179 * bit-depth transformations, so check depth and adjust if necessary */
180
181 if (bit_depth == 16) {
182 *red = pBackground->red >> 8;
183 *green = pBackground->green >> 8;
184 *blue = pBackground->blue >> 8;
185 } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
186 if (bit_depth == 1)
187 *red = *green = *blue = pBackground->gray? 255 : 0;
188 else if (bit_depth == 2)
189 *red = *green = *blue = (255/3) * pBackground->gray;
190 else /* bit_depth == 4 */
191 *red = *green = *blue = (255/15) * pBackground->gray;
192 } else {
193 *red = (uch)pBackground->red;
194 *green = (uch)pBackground->green;
195 *blue = (uch)pBackground->blue;
196 }
197
198 return 0;
199}
200
201
202
203
204/* display_exponent == LUT_exponent * CRT_exponent */
205
206uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
207{
208 double gamma;
209 png_uint_32 i, rowbytes;
210 png_bytepp row_pointers = NULL;
211
212
213 /* setjmp() must be called in every function that calls a PNG-reading
214 * libpng function */
215
216 if (setjmp(png_jmpbuf(png_ptr))) {
217 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
218 return NULL;
219 }
220
221
222 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
223 * transparency chunks to full alpha channel; strip 16-bit-per-sample
224 * images to 8 bits per sample; and convert grayscale to RGB[A] */
225
226 if (color_type == PNG_COLOR_TYPE_PALETTE)
227 png_set_expand(png_ptr);
228 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
229 png_set_expand(png_ptr);
230 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
231 png_set_expand(png_ptr);
232#ifdef PNG_READ_16_TO_8_SUPPORTED
233 if (bit_depth == 16)
234# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
235 png_set_scale_16(png_ptr);
236# else
237 png_set_strip_16(png_ptr);
238# endif
239#endif
240 if (color_type == PNG_COLOR_TYPE_GRAY ||
241 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
242 png_set_gray_to_rgb(png_ptr);
243
244
245 /* unlike the example in the libpng documentation, we have *no* idea where
246 * this file may have come from--so if it doesn't have a file gamma, don't
247 * do any correction ("do no harm") */
248
249 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
250 png_set_gamma(png_ptr, display_exponent, gamma);
251
252
253 /* all transformations have been registered; now update info_ptr data,
254 * get rowbytes and channels, and allocate image memory */
255
256 png_read_update_info(png_ptr, info_ptr);
257
258 *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
259 *pChannels = (int)png_get_channels(png_ptr, info_ptr);
260
261 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
262 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
263 return NULL;
264 }
265 if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
266 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
267 free(image_data);
268 image_data = NULL;
269 return NULL;
270 }
271
272 Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n",
273 *pChannels, rowbytes, height));
274
275
276 /* set the individual row_pointers to point at the correct offsets */
277
278 for (i = 0; i < height; ++i)
279 row_pointers[i] = image_data + i*rowbytes;
280
281
282 /* now we can go ahead and just read the whole image */
283
284 png_read_image(png_ptr, row_pointers);
285
286
287 /* and we're done! (png_read_end() can be omitted if no processing of
288 * post-IDAT text/time/etc. is desired) */
289
290 free(row_pointers);
291 row_pointers = NULL;
292
293 png_read_end(png_ptr, NULL);
294
295 return image_data;
296}
297
298
299void readpng_cleanup(int free_image_data)
300{
301 if (free_image_data && image_data) {
302 free(image_data);
303 image_data = NULL;
304 }
305
306 if (png_ptr && info_ptr) {
307 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
308 png_ptr = NULL;
309 info_ptr = NULL;
310 }
311}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h
new file mode 100644
index 0000000..ec6b483
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h
@@ -0,0 +1,88 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readpng.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72typedef unsigned char uch;
73typedef unsigned short ush;
74typedef unsigned long ulg;
75
76
77/* prototypes for public functions in readpng.c */
78
79void readpng_version_info(void);
80
81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);
82
83int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);
84
85uch *readpng_get_image(double display_exponent, int *pChannels,
86 ulg *pRowbytes);
87
88void readpng_cleanup(int free_image_data);
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c
new file mode 100644
index 0000000..3bbd2ec
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c
@@ -0,0 +1,511 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program readpng2.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56
57#include <stdlib.h> /* for exit() prototype */
58#include <setjmp.h>
59
60#include <zlib.h>
61#include "png.h" /* libpng header from the local directory */
62#include "readpng2.h" /* typedefs, common macros, public prototypes */
63
64
65/* local prototypes */
66
67static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
68static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
69 png_uint_32 row_num, int pass);
70static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
71static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
72
73
74
75
76void readpng2_version_info(void)
77{
78 fprintf(stderr, " Compiled with libpng %s; using libpng %s\n",
79 PNG_LIBPNG_VER_STRING, png_libpng_ver);
80
81 fprintf(stderr, " and with zlib %s; using zlib %s.\n",
82 ZLIB_VERSION, zlib_version);
83}
84
85
86
87
88int readpng2_check_sig(uch *sig, int num)
89{
90 return !png_sig_cmp(sig, 0, num);
91}
92
93
94
95
96/* returns 0 for success, 2 for libpng problem, 4 for out of memory */
97
98int readpng2_init(mainprog_info *mainprog_ptr)
99{
100 png_structp png_ptr; /* note: temporary variables! */
101 png_infop info_ptr;
102
103
104 /* could also replace libpng warning-handler (final NULL), but no need: */
105
106 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
107 readpng2_error_handler, NULL);
108 if (!png_ptr)
109 return 4; /* out of memory */
110
111 info_ptr = png_create_info_struct(png_ptr);
112 if (!info_ptr) {
113 png_destroy_read_struct(&png_ptr, NULL, NULL);
114 return 4; /* out of memory */
115 }
116
117
118 /* we could create a second info struct here (end_info), but it's only
119 * useful if we want to keep pre- and post-IDAT chunk info separated
120 * (mainly for PNG-aware image editors and converters) */
121
122
123 /* setjmp() must be called in every function that calls a PNG-reading
124 * libpng function, unless an alternate error handler was installed--
125 * but compatible error handlers must either use longjmp() themselves
126 * (as in this program) or exit immediately, so here we are: */
127
128 if (setjmp(mainprog_ptr->jmpbuf)) {
129 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
130 return 2;
131 }
132
133
134#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
135 /* prepare the reader to ignore all recognized chunks whose data won't be
136 * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
137 * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
138 {
139 /* These byte strings were copied from png.h. If a future libpng
140 * version recognizes more chunks, add them to this list. If a
141 * future version of readpng2.c recognizes more chunks, delete them
142 * from this list. */
143 static /* const */ png_byte chunks_to_ignore[] = {
144 99, 72, 82, 77, '\0', /* cHRM */
145 104, 73, 83, 84, '\0', /* hIST */
146 105, 67, 67, 80, '\0', /* iCCP */
147 105, 84, 88, 116, '\0', /* iTXt */
148 111, 70, 70, 115, '\0', /* oFFs */
149 112, 67, 65, 76, '\0', /* pCAL */
150 112, 72, 89, 115, '\0', /* pHYs */
151 115, 66, 73, 84, '\0', /* sBIT */
152 115, 67, 65, 76, '\0', /* sCAL */
153 115, 80, 76, 84, '\0', /* sPLT */
154 115, 84, 69, 82, '\0', /* sTER */
155 116, 69, 88, 116, '\0', /* tEXt */
156 116, 73, 77, 69, '\0', /* tIME */
157 122, 84, 88, 116, '\0' /* zTXt */
158 };
159
160 png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
161 chunks_to_ignore, sizeof(chunks_to_ignore)/5);
162 }
163#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */
164
165
166 /* instead of doing png_init_io() here, now we set up our callback
167 * functions for progressive decoding */
168
169 png_set_progressive_read_fn(png_ptr, mainprog_ptr,
170 readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
171
172
173 /* make sure we save our pointers for use in readpng2_decode_data() */
174
175 mainprog_ptr->png_ptr = png_ptr;
176 mainprog_ptr->info_ptr = info_ptr;
177
178
179 /* and that's all there is to initialization */
180
181 return 0;
182}
183
184
185
186
187/* returns 0 for success, 2 for libpng (longjmp) problem */
188
189int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
190{
191 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
192 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
193
194
195 /* setjmp() must be called in every function that calls a PNG-reading
196 * libpng function */
197
198 if (setjmp(mainprog_ptr->jmpbuf)) {
199 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
200 mainprog_ptr->png_ptr = NULL;
201 mainprog_ptr->info_ptr = NULL;
202 return 2;
203 }
204
205
206 /* hand off the next chunk of input data to libpng for decoding */
207
208 png_process_data(png_ptr, info_ptr, rawbuf, length);
209
210 return 0;
211}
212
213
214
215
216static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
217{
218 mainprog_info *mainprog_ptr;
219 int color_type, bit_depth;
220 png_uint_32 width, height;
221#ifdef PNG_FLOATING_POINT_SUPPORTED
222 double gamma;
223#else
224 png_fixed_point gamma;
225#endif
226
227
228 /* setjmp() doesn't make sense here, because we'd either have to exit(),
229 * longjmp() ourselves, or return control to libpng, which doesn't want
230 * to see us again. By not doing anything here, libpng will instead jump
231 * to readpng2_decode_data(), which can return an error value to the main
232 * program. */
233
234
235 /* retrieve the pointer to our special-purpose struct, using the png_ptr
236 * that libpng passed back to us (i.e., not a global this time--there's
237 * no real difference for a single image, but for a multithreaded browser
238 * decoding several PNG images at the same time, one needs to avoid mixing
239 * up different images' structs) */
240
241 mainprog_ptr = png_get_progressive_ptr(png_ptr);
242
243 if (mainprog_ptr == NULL) { /* we be hosed */
244 fprintf(stderr,
245 "readpng2 error: main struct not recoverable in info_callback.\n");
246 fflush(stderr);
247 return;
248 /*
249 * Alternatively, we could call our error-handler just like libpng
250 * does, which would effectively terminate the program. Since this
251 * can only happen if png_ptr gets redirected somewhere odd or the
252 * main PNG struct gets wiped, we're probably toast anyway. (If
253 * png_ptr itself is NULL, we would not have been called.)
254 */
255 }
256
257
258 /* this is just like in the non-progressive case */
259
260 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
261 NULL, NULL, NULL);
262 mainprog_ptr->width = (ulg)width;
263 mainprog_ptr->height = (ulg)height;
264
265
266 /* since we know we've read all of the PNG file's "header" (i.e., up
267 * to IDAT), we can check for a background color here */
268
269 if (mainprog_ptr->need_bgcolor &&
270 png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
271 {
272 png_color_16p pBackground;
273
274 /* it is not obvious from the libpng documentation, but this function
275 * takes a pointer to a pointer, and it always returns valid red,
276 * green and blue values, regardless of color_type: */
277 png_get_bKGD(png_ptr, info_ptr, &pBackground);
278
279 /* however, it always returns the raw bKGD data, regardless of any
280 * bit-depth transformations, so check depth and adjust if necessary */
281 if (bit_depth == 16) {
282 mainprog_ptr->bg_red = pBackground->red >> 8;
283 mainprog_ptr->bg_green = pBackground->green >> 8;
284 mainprog_ptr->bg_blue = pBackground->blue >> 8;
285 } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
286 if (bit_depth == 1)
287 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
288 mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
289 else if (bit_depth == 2)
290 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
291 mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
292 else /* bit_depth == 4 */
293 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
294 mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
295 } else {
296 mainprog_ptr->bg_red = (uch)pBackground->red;
297 mainprog_ptr->bg_green = (uch)pBackground->green;
298 mainprog_ptr->bg_blue = (uch)pBackground->blue;
299 }
300 }
301
302
303 /* as before, let libpng expand palette images to RGB, low-bit-depth
304 * grayscale images to 8 bits, transparency chunks to full alpha channel;
305 * strip 16-bit-per-sample images to 8 bits per sample; and convert
306 * grayscale to RGB[A] */
307
308 if (color_type == PNG_COLOR_TYPE_PALETTE)
309 png_set_expand(png_ptr);
310 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
311 png_set_expand(png_ptr);
312 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
313 png_set_expand(png_ptr);
314#ifdef PNG_READ_16_TO_8_SUPPORTED
315 if (bit_depth == 16)
316# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
317 png_set_scale_16(png_ptr);
318# else
319 png_set_strip_16(png_ptr);
320# endif
321#endif
322 if (color_type == PNG_COLOR_TYPE_GRAY ||
323 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
324 png_set_gray_to_rgb(png_ptr);
325
326
327 /* Unlike the basic viewer, which was designed to operate on local files,
328 * this program is intended to simulate a web browser--even though we
329 * actually read from a local file, too. But because we are pretending
330 * that most of the images originate on the Internet, we follow the recom-
331 * mendation of the sRGB proposal and treat unlabelled images (no gAMA
332 * chunk) as existing in the sRGB color space. That is, we assume that
333 * such images have a file gamma of 0.45455, which corresponds to a PC-like
334 * display system. This change in assumptions will have no effect on a
335 * PC-like system, but on a Mac, SGI, NeXT or other system with a non-
336 * identity lookup table, it will darken unlabelled images, which effec-
337 * tively favors images from PC-like systems over those originating on
338 * the local platform. Note that mainprog_ptr->display_exponent is the
339 * "gamma" value for the entire display system, i.e., the product of
340 * LUT_exponent and CRT_exponent. */
341
342#ifdef PNG_FLOATING_POINT_SUPPORTED
343 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
344 png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
345 else
346 png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);
347#else
348 if (png_get_gAMA_fixed(png_ptr, info_ptr, &gamma))
349 png_set_gamma_fixed(png_ptr,
350 (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), gamma);
351 else
352 png_set_gamma_fixed(png_ptr,
353 (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), 45455);
354#endif
355
356 /* we'll let libpng expand interlaced images, too */
357
358 mainprog_ptr->passes = png_set_interlace_handling(png_ptr);
359
360
361 /* all transformations have been registered; now update info_ptr data and
362 * then get rowbytes and channels */
363
364 png_read_update_info(png_ptr, info_ptr);
365
366 mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);
367 mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);
368
369
370 /* Call the main program to allocate memory for the image buffer and
371 * initialize windows and whatnot. (The old-style function-pointer
372 * invocation is used for compatibility with a few supposedly ANSI
373 * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */
374
375 (*mainprog_ptr->mainprog_init)();
376
377
378 /* and that takes care of initialization */
379
380 return;
381}
382
383
384
385
386
387static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
388 png_uint_32 row_num, int pass)
389{
390 mainprog_info *mainprog_ptr;
391
392
393 /* first check whether the row differs from the previous pass; if not,
394 * nothing to combine or display */
395
396 if (!new_row)
397 return;
398
399
400 /* retrieve the pointer to our special-purpose struct so we can access
401 * the old rows and image-display callback function */
402
403 mainprog_ptr = png_get_progressive_ptr(png_ptr);
404
405
406 /* save the pass number for optional use by the front end */
407
408 mainprog_ptr->pass = pass;
409
410
411 /* have libpng either combine the new row data with the existing row data
412 * from previous passes (if interlaced) or else just copy the new row
413 * into the main program's image buffer */
414
415 png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
416 new_row);
417
418
419 /* finally, call the display routine in the main program with the number
420 * of the row we just updated */
421
422 (*mainprog_ptr->mainprog_display_row)(row_num);
423
424
425 /* and we're ready for more */
426
427 return;
428}
429
430
431
432
433
434static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
435{
436 mainprog_info *mainprog_ptr;
437
438
439 /* retrieve the pointer to our special-purpose struct */
440
441 mainprog_ptr = png_get_progressive_ptr(png_ptr);
442
443
444 /* let the main program know that it should flush any buffered image
445 * data to the display now and set a "done" flag or whatever, but note
446 * that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
447 * NOT call readpng2_cleanup() either here or in the finish_display()
448 * routine; wait until control returns to the main program via
449 * readpng2_decode_data() */
450
451 (*mainprog_ptr->mainprog_finish_display)();
452
453
454 /* all done */
455
456 return;
457}
458
459
460
461
462
463void readpng2_cleanup(mainprog_info *mainprog_ptr)
464{
465 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
466 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
467
468 if (png_ptr && info_ptr)
469 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
470
471 mainprog_ptr->png_ptr = NULL;
472 mainprog_ptr->info_ptr = NULL;
473}
474
475
476
477
478
479static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
480{
481 mainprog_info *mainprog_ptr;
482
483 /* This function, aside from the extra step of retrieving the "error
484 * pointer" (below) and the fact that it exists within the application
485 * rather than within libpng, is essentially identical to libpng's
486 * default error handler. The second point is critical: since both
487 * setjmp() and longjmp() are called from the same code, they are
488 * guaranteed to have compatible notions of how big a jmp_buf is,
489 * regardless of whether _BSD_SOURCE or anything else has (or has not)
490 * been defined. */
491
492 fprintf(stderr, "readpng2 libpng error: %s\n", msg);
493 fflush(stderr);
494
495 mainprog_ptr = png_get_error_ptr(png_ptr);
496 if (mainprog_ptr == NULL) { /* we are completely hosed now */
497 fprintf(stderr,
498 "readpng2 severe error: jmpbuf not recoverable; terminating.\n");
499 fflush(stderr);
500 exit(99);
501 }
502
503 /* Now we have our data structure we can use the information in it
504 * to return control to our own higher level code (all the points
505 * where 'setjmp' is called in this file.) This will work with other
506 * error handling mechanisms as well - libpng always calls png_error
507 * when it can proceed no further, thus, so long as the error handler
508 * is intercepted, application code can do its own error recovery.
509 */
510 longjmp(mainprog_ptr->jmpbuf, 1);
511}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h
new file mode 100644
index 0000000..7a59263
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h
@@ -0,0 +1,116 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program readpng2.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72enum rpng2_states {
73 kPreInit = 0,
74 kWindowInit,
75 kDone
76};
77
78typedef unsigned char uch;
79typedef unsigned short ush;
80typedef unsigned long ulg;
81
82typedef struct _mainprog_info {
83 double display_exponent;
84 ulg width;
85 ulg height;
86 void *png_ptr;
87 void *info_ptr;
88 void (*mainprog_init)(void);
89 void (*mainprog_display_row)(ulg row_num);
90 void (*mainprog_finish_display)(void);
91 uch *image_data;
92 uch **row_pointers;
93 jmp_buf jmpbuf;
94 int passes; /* not used */
95 int pass;
96 int rowbytes;
97 int channels;
98 int need_bgcolor;
99 int state;
100 uch bg_red;
101 uch bg_green;
102 uch bg_blue;
103} mainprog_info;
104
105
106/* prototypes for public functions in readpng2.c */
107
108void readpng2_version_info(void);
109
110int readpng2_check_sig(uch *sig, int num);
111
112int readpng2_init(mainprog_info *mainprog_ptr);
113
114int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);
115
116void readpng2_cleanup(mainprog_info *mainprog_ptr);
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
new file mode 100644
index 0000000..1ba2092
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
@@ -0,0 +1,179 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readppm.c
4
5 ---------------------------------------------------------------------------
6
7 This is a special-purpose replacement for readpng.c that allows binary
8 PPM files to be used in place of PNG images.
9
10 ---------------------------------------------------------------------------
11
12 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
13
14 This software is provided "as is," without warranty of any kind,
15 express or implied. In no event shall the author or contributors
16 be held liable for any damages arising in any way from the use of
17 this software.
18
19 The contents of this file are DUAL-LICENSED. You may modify and/or
20 redistribute this software according to the terms of one of the
21 following two licenses (at your option):
22
23
24 LICENSE 1 ("BSD-like with advertising clause"):
25
26 Permission is granted to anyone to use this software for any purpose,
27 including commercial applications, and to alter it and redistribute
28 it freely, subject to the following restrictions:
29
30 1. Redistributions of source code must retain the above copyright
31 notice, disclaimer, and this list of conditions.
32 2. Redistributions in binary form must reproduce the above copyright
33 notice, disclaimer, and this list of conditions in the documenta-
34 tion and/or other materials provided with the distribution.
35 3. All advertising materials mentioning features or use of this
36 software must display the following acknowledgment:
37
38 This product includes software developed by Greg Roelofs
39 and contributors for the book, "PNG: The Definitive Guide,"
40 published by O'Reilly and Associates.
41
42
43 LICENSE 2 (GNU GPL v2 or later):
44
45 This program is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License as published by
47 the Free Software Foundation; either version 2 of the License, or
48 (at your option) any later version.
49
50 This program is distributed in the hope that it will be useful,
51 but WITHOUT ANY WARRANTY; without even the implied warranty of
52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 GNU General Public License for more details.
54
55 You should have received a copy of the GNU General Public License
56 along with this program; if not, write to the Free Software Foundation,
57 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
58
59 ---------------------------------------------------------------------------*/
60
61#include <stdio.h>
62#include <stdlib.h>
63
64#include "readpng.h" /* typedefs, common macros, public prototypes */
65
66
67ulg width, height;
68int bit_depth, color_type, channels;
69uch *image_data = NULL;
70FILE *saved_infile;
71
72
73void readpng_version_info()
74{
75 fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n");
76}
77
78
79/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
80
81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
82{
83 static uch ppmline[256];
84 int maxval;
85
86
87 saved_infile = infile;
88
89 fgets(ppmline, 256, infile);
90 if (ppmline[0] != 'P' || ppmline[1] != '6') {
91 fprintf(stderr, "ERROR: not a PPM file\n");
92 return 1;
93 }
94 /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */
95 if (ppmline[1] == '6') {
96 color_type = 2;
97 channels = 3;
98 } else if (ppmline[1] == '8') {
99 color_type = 6;
100 channels = 4;
101 } else /* if (ppmline[1] == '5') */ {
102 color_type = 0;
103 channels = 1;
104 }
105
106 do {
107 fgets(ppmline, 256, infile);
108 } while (ppmline[0] == '#');
109 sscanf(ppmline, "%lu %lu", &width, &height);
110
111 do {
112 fgets(ppmline, 256, infile);
113 } while (ppmline[0] == '#');
114 sscanf(ppmline, "%d", &maxval);
115 if (maxval != 255) {
116 fprintf(stderr, "ERROR: maxval = %d\n", maxval);
117 return 2;
118 }
119 bit_depth = 8;
120
121 *pWidth = width;
122 *pHeight = height;
123
124 return 0;
125}
126
127
128
129
130/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
131 * scales values to 8-bit if necessary */
132
133int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
134{
135 return 1;
136}
137
138
139
140
141/* display_exponent == LUT_exponent * CRT_exponent */
142
143uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
144{
145 ulg rowbytes;
146
147
148 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
149 * transparency chunks to full alpha channel; strip 16-bit-per-sample
150 * images to 8 bits per sample; and convert grayscale to RGB[A] */
151
152 /* GRR WARNING: grayscale needs to be expanded and channels reset! */
153
154 *pRowbytes = rowbytes = channels*width;
155 *pChannels = channels;
156
157 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
158 return NULL;
159 }
160
161 Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
162
163
164 /* now we can go ahead and just read the whole image */
165
166 fread(image_data, 1L, rowbytes*height, saved_infile);
167
168
169 return image_data;
170}
171
172
173void readpng_cleanup(int free_image_data)
174{
175 if (free_image_data && image_data) {
176 free(image_data);
177 image_data = NULL;
178 }
179}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c
new file mode 100644
index 0000000..1c22282
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c
@@ -0,0 +1,728 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program rpng-win.c
4
5 This program decodes and displays PNG images, with gamma correction and
6 optionally with a user-specified background color (in case the image has
7 transparency). It is very nearly the most basic PNG viewer possible.
8 This version is for 32-bit Windows; it may compile under 16-bit Windows
9 with a little tweaking (or maybe not).
10
11 to do:
12 - handle quoted command-line args (especially filenames with spaces)
13 - have minimum window width: oh well
14 - use %.1023s to simplify truncation of title-bar string?
15
16 ---------------------------------------------------------------------------
17
18 Changelog:
19 - 1.00: initial public release
20 - 1.01: modified to allow abbreviated options; fixed long/ulong mis-
21 match; switched to png_jmpbuf() macro
22 - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed
23 command-line parsing bug
24 - 1.10: enabled "message window"/console (thanks to David Geldreich)
25 - 2.00: dual-licensed (added GNU GPL)
26 - 2.01: fixed improper display of usage screen on PNG error(s)
27
28 ---------------------------------------------------------------------------
29
30 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
31
32 This software is provided "as is," without warranty of any kind,
33 express or implied. In no event shall the author or contributors
34 be held liable for any damages arising in any way from the use of
35 this software.
36
37 The contents of this file are DUAL-LICENSED. You may modify and/or
38 redistribute this software according to the terms of one of the
39 following two licenses (at your option):
40
41
42 LICENSE 1 ("BSD-like with advertising clause"):
43
44 Permission is granted to anyone to use this software for any purpose,
45 including commercial applications, and to alter it and redistribute
46 it freely, subject to the following restrictions:
47
48 1. Redistributions of source code must retain the above copyright
49 notice, disclaimer, and this list of conditions.
50 2. Redistributions in binary form must reproduce the above copyright
51 notice, disclaimer, and this list of conditions in the documenta-
52 tion and/or other materials provided with the distribution.
53 3. All advertising materials mentioning features or use of this
54 software must display the following acknowledgment:
55
56 This product includes software developed by Greg Roelofs
57 and contributors for the book, "PNG: The Definitive Guide,"
58 published by O'Reilly and Associates.
59
60
61 LICENSE 2 (GNU GPL v2 or later):
62
63 This program is free software; you can redistribute it and/or modify
64 it under the terms of the GNU General Public License as published by
65 the Free Software Foundation; either version 2 of the License, or
66 (at your option) any later version.
67
68 This program is distributed in the hope that it will be useful,
69 but WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71 GNU General Public License for more details.
72
73 You should have received a copy of the GNU General Public License
74 along with this program; if not, write to the Free Software Foundation,
75 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
76
77 ---------------------------------------------------------------------------*/
78
79#define PROGNAME "rpng-win"
80#define LONGNAME "Simple PNG Viewer for Windows"
81#define VERSION "2.01 of 16 March 2008"
82
83#include <stdio.h>
84#include <stdlib.h>
85#include <string.h>
86#include <time.h>
87#include <windows.h>
88#ifdef __CYGWIN__
89/* getch replacement. Turns out, we don't really need this,
90 * but leave it here if we ever enable any of the uses of
91 * _getch in the main code
92 */
93#include <unistd.h>
94#include <termio.h>
95#include <sys/ioctl.h>
96int repl_getch( void )
97{
98 char ch;
99 int fd = fileno(stdin);
100 struct termio old_tty, new_tty;
101
102 ioctl(fd, TCGETA, &old_tty);
103 new_tty = old_tty;
104 new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);
105 ioctl(fd, TCSETA, &new_tty);
106 fread(&ch, 1, sizeof(ch), stdin);
107 ioctl(fd, TCSETA, &old_tty);
108
109 return ch;
110}
111#define _getch repl_getch
112#else
113#include <conio.h> /* only for _getch() */
114#endif
115
116/* #define DEBUG : this enables the Trace() macros */
117
118#include "readpng.h" /* typedefs, common macros, readpng prototypes */
119
120
121/* could just include png.h, but this macro is the only thing we need
122 * (name and typedefs changed to local versions); note that side effects
123 * only happen with alpha (which could easily be avoided with
124 * "ush acopy = (alpha);") */
125
126#define alpha_composite(composite, fg, alpha, bg) { \
127 ush temp = ((ush)(fg)*(ush)(alpha) + \
128 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
129 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
130}
131
132
133/* local prototypes */
134static int rpng_win_create_window(HINSTANCE hInst, int showmode);
135static int rpng_win_display_image(void);
136static void rpng_win_cleanup(void);
137LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM);
138
139
140static char titlebar[1024];
141static char *progname = PROGNAME;
142static char *appname = LONGNAME;
143static char *filename;
144static FILE *infile;
145
146static char *bgstr;
147static uch bg_red=0, bg_green=0, bg_blue=0;
148
149static double display_exponent;
150
151static ulg image_width, image_height, image_rowbytes;
152static int image_channels;
153static uch *image_data;
154
155/* Windows-specific variables */
156static ulg wimage_rowbytes;
157static uch *dib;
158static uch *wimage_data;
159static BITMAPINFOHEADER *bmih;
160
161static HWND global_hwnd;
162
163
164
165
166int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
167{
168 char *args[1024]; /* arbitrary limit, but should suffice */
169 char *p, *q, **argv = args;
170 int argc = 0;
171 int rc, alen, flen;
172 int error = 0;
173 int have_bg = FALSE;
174 double LUT_exponent; /* just the lookup table */
175 double CRT_exponent = 2.2; /* just the monitor */
176 double default_display_exponent; /* whole display system */
177 MSG msg;
178
179
180 filename = (char *)NULL;
181
182#ifndef __CYGWIN__
183 /* First reenable console output, which normally goes to the bit bucket
184 * for windowed apps. Closing the console window will terminate the
185 * app. Thanks to David.Geldreich@realviz.com for supplying the magical
186 * incantation. */
187
188 AllocConsole();
189 freopen("CONOUT$", "a", stderr);
190 freopen("CONOUT$", "a", stdout);
191#endif
192
193
194 /* Next set the default value for our display-system exponent, i.e.,
195 * the product of the CRT exponent and the exponent corresponding to
196 * the frame-buffer's lookup table (LUT), if any. This is not an
197 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
198 * ones), but it should cover 99% of the current possibilities. And
199 * yes, these ifdefs are completely wasted in a Windows program... */
200
201#if defined(NeXT)
202 LUT_exponent = 1.0 / 2.2;
203 /*
204 if (some_next_function_that_returns_gamma(&next_gamma))
205 LUT_exponent = 1.0 / next_gamma;
206 */
207#elif defined(sgi)
208 LUT_exponent = 1.0 / 1.7;
209 /* there doesn't seem to be any documented function to get the
210 * "gamma" value, so we do it the hard way */
211 infile = fopen("/etc/config/system.glGammaVal", "r");
212 if (infile) {
213 double sgi_gamma;
214
215 fgets(tmpline, 80, infile);
216 fclose(infile);
217 sgi_gamma = atof(tmpline);
218 if (sgi_gamma > 0.0)
219 LUT_exponent = 1.0 / sgi_gamma;
220 }
221#elif defined(Macintosh)
222 LUT_exponent = 1.8 / 2.61;
223 /*
224 if (some_mac_function_that_returns_gamma(&mac_gamma))
225 LUT_exponent = mac_gamma / 2.61;
226 */
227#else
228 LUT_exponent = 1.0; /* assume no LUT: most PCs */
229#endif
230
231 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
232 default_display_exponent = LUT_exponent * CRT_exponent;
233
234
235 /* If the user has set the SCREEN_GAMMA environment variable as suggested
236 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
237 * use the default value we just calculated. Either way, the user may
238 * override this via a command-line option. */
239
240 if ((p = getenv("SCREEN_GAMMA")) != NULL)
241 display_exponent = atof(p);
242 else
243 display_exponent = default_display_exponent;
244
245
246 /* Windows really hates command lines, so we have to set up our own argv.
247 * Note that we do NOT bother with quoted arguments here, so don't use
248 * filenames with spaces in 'em! */
249
250 argv[argc++] = PROGNAME;
251 p = cmd;
252 for (;;) {
253 if (*p == ' ')
254 while (*++p == ' ')
255 ;
256 /* now p points at the first non-space after some spaces */
257 if (*p == '\0')
258 break; /* nothing after the spaces: done */
259 argv[argc++] = q = p;
260 while (*q && *q != ' ')
261 ++q;
262 /* now q points at a space or the end of the string */
263 if (*q == '\0')
264 break; /* last argv already terminated; quit */
265 *q = '\0'; /* change space to terminator */
266 p = q + 1;
267 }
268 argv[argc] = NULL; /* terminate the argv array itself */
269
270
271 /* Now parse the command line for options and the PNG filename. */
272
273 while (*++argv && !error) {
274 if (!strncmp(*argv, "-gamma", 2)) {
275 if (!*++argv)
276 ++error;
277 else {
278 display_exponent = atof(*argv);
279 if (display_exponent <= 0.0)
280 ++error;
281 }
282 } else if (!strncmp(*argv, "-bgcolor", 2)) {
283 if (!*++argv)
284 ++error;
285 else {
286 bgstr = *argv;
287 if (strlen(bgstr) != 7 || bgstr[0] != '#')
288 ++error;
289 else
290 have_bg = TRUE;
291 }
292 } else {
293 if (**argv != '-') {
294 filename = *argv;
295 if (argv[1]) /* shouldn't be any more args after filename */
296 ++error;
297 } else
298 ++error; /* not expecting any other options */
299 }
300 }
301
302 if (!filename)
303 ++error;
304
305
306 /* print usage screen if any errors up to this point */
307
308 if (error) {
309#ifndef __CYGWIN__
310 int ch;
311#endif
312
313 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
314 readpng_version_info();
315 fprintf(stderr, "\n"
316 "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n"
317 " exp \ttransfer-function exponent (``gamma'') of the display\n"
318 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
319 "\t\t to the product of the lookup-table exponent (varies)\n"
320 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
321 " bg \tdesired background color in 7-character hex RGB format\n"
322 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
323 "\t\t used with transparent images\n"
324 "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
325#ifndef __CYGWIN__
326 "Press Q or Esc to quit this usage screen.\n"
327#endif
328 "\n", PROGNAME, default_display_exponent);
329#ifndef __CYGWIN__
330 do
331 ch = _getch();
332 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
333#endif
334 exit(1);
335 }
336
337
338 if (!(infile = fopen(filename, "rb"))) {
339 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
340 ++error;
341 } else {
342 if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
343 switch (rc) {
344 case 1:
345 fprintf(stderr, PROGNAME
346 ": [%s] is not a PNG file: incorrect signature\n",
347 filename);
348 break;
349 case 2:
350 fprintf(stderr, PROGNAME
351 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
352 break;
353 case 4:
354 fprintf(stderr, PROGNAME ": insufficient memory\n");
355 break;
356 default:
357 fprintf(stderr, PROGNAME
358 ": unknown readpng_init() error\n");
359 break;
360 }
361 ++error;
362 }
363 if (error)
364 fclose(infile);
365 }
366
367
368 if (error) {
369#ifndef __CYGWIN__
370 int ch;
371#endif
372
373 fprintf(stderr, PROGNAME ": aborting.\n");
374#ifndef __CYGWIN__
375 do
376 ch = _getch();
377 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
378#endif
379 exit(2);
380 } else {
381 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
382#ifndef __CYGWIN__
383 fprintf(stderr,
384 "\n [console window: closing this window will terminate %s]\n\n",
385 PROGNAME);
386#endif
387 }
388
389
390 /* set the title-bar string, but make sure buffer doesn't overflow */
391
392 alen = strlen(appname);
393 flen = strlen(filename);
394 if (alen + flen + 3 > 1023)
395 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
396 else
397 sprintf(titlebar, "%s: %s", appname, filename);
398
399
400 /* if the user didn't specify a background color on the command line,
401 * check for one in the PNG file--if not, the initialized values of 0
402 * (black) will be used */
403
404 if (have_bg) {
405 unsigned r, g, b; /* this approach quiets compiler warnings */
406
407 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
408 bg_red = (uch)r;
409 bg_green = (uch)g;
410 bg_blue = (uch)b;
411 } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
412 readpng_cleanup(TRUE);
413 fprintf(stderr, PROGNAME
414 ": libpng error while checking for background color\n");
415 exit(2);
416 }
417
418
419 /* do the basic Windows initialization stuff, make the window and fill it
420 * with the background color */
421
422 if (rpng_win_create_window(hInst, showmode))
423 exit(2);
424
425
426 /* decode the image, all at once */
427
428 Trace((stderr, "calling readpng_get_image()\n"))
429 image_data = readpng_get_image(display_exponent, &image_channels,
430 &image_rowbytes);
431 Trace((stderr, "done with readpng_get_image()\n"))
432
433
434 /* done with PNG file, so clean up to minimize memory usage (but do NOT
435 * nuke image_data!) */
436
437 readpng_cleanup(FALSE);
438 fclose(infile);
439
440 if (!image_data) {
441 fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
442 exit(3);
443 }
444
445
446 /* display image (composite with background if requested) */
447
448 Trace((stderr, "calling rpng_win_display_image()\n"))
449 if (rpng_win_display_image()) {
450 free(image_data);
451 exit(4);
452 }
453 Trace((stderr, "done with rpng_win_display_image()\n"))
454
455
456 /* wait for the user to tell us when to quit */
457
458 printf(
459#ifndef __CYGWIN__
460 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"
461#else
462 "Done. Press mouse button 1 (within image window) to quit.\n"
463#endif
464 );
465 fflush(stdout);
466
467 while (GetMessage(&msg, NULL, 0, 0)) {
468 TranslateMessage(&msg);
469 DispatchMessage(&msg);
470 }
471
472
473 /* OK, we're done: clean up all image and Windows resources and go away */
474
475 rpng_win_cleanup();
476
477 return msg.wParam;
478}
479
480
481
482
483
484static int rpng_win_create_window(HINSTANCE hInst, int showmode)
485{
486 uch *dest;
487 int extra_width, extra_height;
488 ulg i, j;
489 WNDCLASSEX wndclass;
490
491
492/*---------------------------------------------------------------------------
493 Allocate memory for the display-specific version of the image (round up
494 to multiple of 4 for Windows DIB).
495 ---------------------------------------------------------------------------*/
496
497 wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;
498
499 if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
500 wimage_rowbytes*image_height)))
501 {
502 return 4; /* fail */
503 }
504
505/*---------------------------------------------------------------------------
506 Initialize the DIB. Negative height means to use top-down BMP ordering
507 (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
508 implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
509 directly => wimage_data begins immediately after BMP header.
510 ---------------------------------------------------------------------------*/
511
512 memset(dib, 0, sizeof(BITMAPINFOHEADER));
513 bmih = (BITMAPINFOHEADER *)dib;
514 bmih->biSize = sizeof(BITMAPINFOHEADER);
515 bmih->biWidth = image_width;
516 bmih->biHeight = -((long)image_height);
517 bmih->biPlanes = 1;
518 bmih->biBitCount = 24;
519 bmih->biCompression = 0;
520 wimage_data = dib + sizeof(BITMAPINFOHEADER);
521
522/*---------------------------------------------------------------------------
523 Fill in background color (black by default); data are in BGR order.
524 ---------------------------------------------------------------------------*/
525
526 for (j = 0; j < image_height; ++j) {
527 dest = wimage_data + j*wimage_rowbytes;
528 for (i = image_width; i > 0; --i) {
529 *dest++ = bg_blue;
530 *dest++ = bg_green;
531 *dest++ = bg_red;
532 }
533 }
534
535/*---------------------------------------------------------------------------
536 Set the window parameters.
537 ---------------------------------------------------------------------------*/
538
539 memset(&wndclass, 0, sizeof(wndclass));
540
541 wndclass.cbSize = sizeof(wndclass);
542 wndclass.style = CS_HREDRAW | CS_VREDRAW;
543 wndclass.lpfnWndProc = rpng_win_wndproc;
544 wndclass.hInstance = hInst;
545 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
546 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
547 wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
548 wndclass.lpszMenuName = NULL;
549 wndclass.lpszClassName = progname;
550 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
551
552 RegisterClassEx(&wndclass);
553
554/*---------------------------------------------------------------------------
555 Finally, create the window.
556 ---------------------------------------------------------------------------*/
557
558 extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
559 GetSystemMetrics(SM_CXDLGFRAME));
560 extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
561 GetSystemMetrics(SM_CYDLGFRAME)) +
562 GetSystemMetrics(SM_CYCAPTION);
563
564 global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
565 CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width,
566 image_height+extra_height, NULL, NULL, hInst, NULL);
567
568 ShowWindow(global_hwnd, showmode);
569 UpdateWindow(global_hwnd);
570
571 return 0;
572
573} /* end function rpng_win_create_window() */
574
575
576
577
578
579static int rpng_win_display_image()
580{
581 uch *src, *dest;
582 uch r, g, b, a;
583 ulg i, row, lastrow;
584 RECT rect;
585
586
587 Trace((stderr, "beginning display loop (image_channels == %d)\n",
588 image_channels))
589 Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n",
590 image_width, image_rowbytes, wimage_rowbytes))
591
592
593/*---------------------------------------------------------------------------
594 Blast image data to buffer. This whole routine takes place before the
595 message loop begins, so there's no real point in any pseudo-progressive
596 display...
597 ---------------------------------------------------------------------------*/
598
599 for (lastrow = row = 0; row < image_height; ++row) {
600 src = image_data + row*image_rowbytes;
601 dest = wimage_data + row*wimage_rowbytes;
602 if (image_channels == 3) {
603 for (i = image_width; i > 0; --i) {
604 r = *src++;
605 g = *src++;
606 b = *src++;
607 *dest++ = b;
608 *dest++ = g; /* note reverse order */
609 *dest++ = r;
610 }
611 } else /* if (image_channels == 4) */ {
612 for (i = image_width; i > 0; --i) {
613 r = *src++;
614 g = *src++;
615 b = *src++;
616 a = *src++;
617 if (a == 255) {
618 *dest++ = b;
619 *dest++ = g;
620 *dest++ = r;
621 } else if (a == 0) {
622 *dest++ = bg_blue;
623 *dest++ = bg_green;
624 *dest++ = bg_red;
625 } else {
626 /* this macro (copied from png.h) composites the
627 * foreground and background values and puts the
628 * result into the first argument; there are no
629 * side effects with the first argument */
630 alpha_composite(*dest++, b, a, bg_blue);
631 alpha_composite(*dest++, g, a, bg_green);
632 alpha_composite(*dest++, r, a, bg_red);
633 }
634 }
635 }
636 /* display after every 16 lines */
637 if (((row+1) & 0xf) == 0) {
638 rect.left = 0L;
639 rect.top = (LONG)lastrow;
640 rect.right = (LONG)image_width; /* possibly off by one? */
641 rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */
642 InvalidateRect(global_hwnd, &rect, FALSE);
643 UpdateWindow(global_hwnd); /* similar to XFlush() */
644 lastrow = row + 1;
645 }
646 }
647
648 Trace((stderr, "calling final image-flush routine\n"))
649 if (lastrow < image_height) {
650 rect.left = 0L;
651 rect.top = (LONG)lastrow;
652 rect.right = (LONG)image_width; /* possibly off by one? */
653 rect.bottom = (LONG)image_height; /* possibly off by one? */
654 InvalidateRect(global_hwnd, &rect, FALSE);
655 UpdateWindow(global_hwnd); /* similar to XFlush() */
656 }
657
658/*
659 last param determines whether or not background is wiped before paint
660 InvalidateRect(global_hwnd, NULL, TRUE);
661 UpdateWindow(global_hwnd);
662 */
663
664 return 0;
665}
666
667
668
669
670
671static void rpng_win_cleanup()
672{
673 if (image_data) {
674 free(image_data);
675 image_data = NULL;
676 }
677
678 if (dib) {
679 free(dib);
680 dib = NULL;
681 }
682}
683
684
685
686
687
688LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
689{
690 HDC hdc;
691 PAINTSTRUCT ps;
692 int rc;
693
694 switch (iMsg) {
695 case WM_CREATE:
696 /* one-time processing here, if any */
697 return 0;
698
699 case WM_PAINT:
700 hdc = BeginPaint(hwnd, &ps);
701 /* dest */
702 rc = StretchDIBits(hdc, 0, 0, image_width, image_height,
703 /* source */
704 0, 0, image_width, image_height,
705 wimage_data, (BITMAPINFO *)bmih,
706 /* iUsage: no clue */
707 0, SRCCOPY);
708 EndPaint(hwnd, &ps);
709 return 0;
710
711 /* wait for the user to tell us when to quit */
712 case WM_CHAR:
713 switch (wP) { /* only need one, so ignore repeat count */
714 case 'q':
715 case 'Q':
716 case 0x1B: /* Esc key */
717 PostQuitMessage(0);
718 }
719 return 0;
720
721 case WM_LBUTTONDOWN: /* another way of quitting */
722 case WM_DESTROY:
723 PostQuitMessage(0);
724 return 0;
725 }
726
727 return DefWindowProc(hwnd, iMsg, wP, lP);
728}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c
new file mode 100644
index 0000000..fc8be88
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c
@@ -0,0 +1,904 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program rpng-x.c
4
5 This program decodes and displays PNG images, with gamma correction and
6 optionally with a user-specified background color (in case the image has
7 transparency). It is very nearly the most basic PNG viewer possible.
8 This version is for the X Window System (tested by author under Unix and
9 by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking).
10
11 to do:
12 - 8-bit (colormapped) X support
13 - use %.1023s to simplify truncation of title-bar string?
14
15 ---------------------------------------------------------------------------
16
17 Changelog:
18 - 1.01: initial public release
19 - 1.02: modified to allow abbreviated options; fixed long/ulong mis-
20 match; switched to png_jmpbuf() macro
21 - 1.10: added support for non-default visuals; fixed X pixel-conversion
22 - 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed
23 command-line parsing bug
24 - 1.12: fixed some small X memory leaks (thanks to François Petitjean)
25 - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche)
26 - 1.14: added support for X resources (thanks to Gerhard Niklasch)
27 - 2.00: dual-licensed (added GNU GPL)
28 - 2.01: fixed improper display of usage screen on PNG error(s)
29
30 ---------------------------------------------------------------------------
31
32 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
33
34 This software is provided "as is," without warranty of any kind,
35 express or implied. In no event shall the author or contributors
36 be held liable for any damages arising in any way from the use of
37 this software.
38
39 The contents of this file are DUAL-LICENSED. You may modify and/or
40 redistribute this software according to the terms of one of the
41 following two licenses (at your option):
42
43
44 LICENSE 1 ("BSD-like with advertising clause"):
45
46 Permission is granted to anyone to use this software for any purpose,
47 including commercial applications, and to alter it and redistribute
48 it freely, subject to the following restrictions:
49
50 1. Redistributions of source code must retain the above copyright
51 notice, disclaimer, and this list of conditions.
52 2. Redistributions in binary form must reproduce the above copyright
53 notice, disclaimer, and this list of conditions in the documenta-
54 tion and/or other materials provided with the distribution.
55 3. All advertising materials mentioning features or use of this
56 software must display the following acknowledgment:
57
58 This product includes software developed by Greg Roelofs
59 and contributors for the book, "PNG: The Definitive Guide,"
60 published by O'Reilly and Associates.
61
62
63 LICENSE 2 (GNU GPL v2 or later):
64
65 This program is free software; you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
67 the Free Software Foundation; either version 2 of the License, or
68 (at your option) any later version.
69
70 This program is distributed in the hope that it will be useful,
71 but WITHOUT ANY WARRANTY; without even the implied warranty of
72 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 GNU General Public License for more details.
74
75 You should have received a copy of the GNU General Public License
76 along with this program; if not, write to the Free Software Foundation,
77 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
78
79 ---------------------------------------------------------------------------*/
80
81#define PROGNAME "rpng-x"
82#define LONGNAME "Simple PNG Viewer for X"
83#define VERSION "2.01 of 16 March 2008"
84#define RESNAME "rpng" /* our X resource application name */
85#define RESCLASS "Rpng" /* our X resource class name */
86
87#include <stdio.h>
88#include <stdlib.h>
89#include <string.h>
90#include <time.h>
91#include <X11/Xlib.h>
92#include <X11/Xutil.h>
93#include <X11/Xos.h>
94#include <X11/keysym.h>
95
96/* #define DEBUG : this enables the Trace() macros */
97
98#include "readpng.h" /* typedefs, common macros, readpng prototypes */
99
100
101/* could just include png.h, but this macro is the only thing we need
102 * (name and typedefs changed to local versions); note that side effects
103 * only happen with alpha (which could easily be avoided with
104 * "ush acopy = (alpha);") */
105
106#define alpha_composite(composite, fg, alpha, bg) { \
107 ush temp = ((ush)(fg)*(ush)(alpha) + \
108 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
109 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
110}
111
112
113/* local prototypes */
114static int rpng_x_create_window(void);
115static int rpng_x_display_image(void);
116static void rpng_x_cleanup(void);
117static int rpng_x_msb(ulg u32val);
118
119
120static char titlebar[1024], *window_name = titlebar;
121static char *appname = LONGNAME;
122static char *icon_name = PROGNAME;
123static char *res_name = RESNAME;
124static char *res_class = RESCLASS;
125static char *filename;
126static FILE *infile;
127
128static char *bgstr;
129static uch bg_red=0, bg_green=0, bg_blue=0;
130
131static double display_exponent;
132
133static ulg image_width, image_height, image_rowbytes;
134static int image_channels;
135static uch *image_data;
136
137/* X-specific variables */
138static char *displayname;
139static XImage *ximage;
140static Display *display;
141static int depth;
142static Visual *visual;
143static XVisualInfo *visual_list;
144static int RShift, GShift, BShift;
145static ulg RMask, GMask, BMask;
146static Window window;
147static GC gc;
148static Colormap colormap;
149
150static int have_nondefault_visual = FALSE;
151static int have_colormap = FALSE;
152static int have_window = FALSE;
153static int have_gc = FALSE;
154/*
155ulg numcolors=0, pixels[256];
156ush reds[256], greens[256], blues[256];
157 */
158
159
160
161
162int main(int argc, char **argv)
163{
164#ifdef sgi
165 char tmpline[80];
166#endif
167 char *p;
168 int rc, alen, flen;
169 int error = 0;
170 int have_bg = FALSE;
171 double LUT_exponent; /* just the lookup table */
172 double CRT_exponent = 2.2; /* just the monitor */
173 double default_display_exponent; /* whole display system */
174 XEvent e;
175 KeySym k;
176
177
178 displayname = (char *)NULL;
179 filename = (char *)NULL;
180
181
182 /* First set the default value for our display-system exponent, i.e.,
183 * the product of the CRT exponent and the exponent corresponding to
184 * the frame-buffer's lookup table (LUT), if any. This is not an
185 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
186 * ones), but it should cover 99% of the current possibilities. */
187
188#if defined(NeXT)
189 LUT_exponent = 1.0 / 2.2;
190 /*
191 if (some_next_function_that_returns_gamma(&next_gamma))
192 LUT_exponent = 1.0 / next_gamma;
193 */
194#elif defined(sgi)
195 LUT_exponent = 1.0 / 1.7;
196 /* there doesn't seem to be any documented function to get the
197 * "gamma" value, so we do it the hard way */
198 infile = fopen("/etc/config/system.glGammaVal", "r");
199 if (infile) {
200 double sgi_gamma;
201
202 fgets(tmpline, 80, infile);
203 fclose(infile);
204 sgi_gamma = atof(tmpline);
205 if (sgi_gamma > 0.0)
206 LUT_exponent = 1.0 / sgi_gamma;
207 }
208#elif defined(Macintosh)
209 LUT_exponent = 1.8 / 2.61;
210 /*
211 if (some_mac_function_that_returns_gamma(&mac_gamma))
212 LUT_exponent = mac_gamma / 2.61;
213 */
214#else
215 LUT_exponent = 1.0; /* assume no LUT: most PCs */
216#endif
217
218 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
219 default_display_exponent = LUT_exponent * CRT_exponent;
220
221
222 /* If the user has set the SCREEN_GAMMA environment variable as suggested
223 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
224 * use the default value we just calculated. Either way, the user may
225 * override this via a command-line option. */
226
227 if ((p = getenv("SCREEN_GAMMA")) != NULL)
228 display_exponent = atof(p);
229 else
230 display_exponent = default_display_exponent;
231
232
233 /* Now parse the command line for options and the PNG filename. */
234
235 while (*++argv && !error) {
236 if (!strncmp(*argv, "-display", 2)) {
237 if (!*++argv)
238 ++error;
239 else
240 displayname = *argv;
241 } else if (!strncmp(*argv, "-gamma", 2)) {
242 if (!*++argv)
243 ++error;
244 else {
245 display_exponent = atof(*argv);
246 if (display_exponent <= 0.0)
247 ++error;
248 }
249 } else if (!strncmp(*argv, "-bgcolor", 2)) {
250 if (!*++argv)
251 ++error;
252 else {
253 bgstr = *argv;
254 if (strlen(bgstr) != 7 || bgstr[0] != '#')
255 ++error;
256 else
257 have_bg = TRUE;
258 }
259 } else {
260 if (**argv != '-') {
261 filename = *argv;
262 if (argv[1]) /* shouldn't be any more args after filename */
263 ++error;
264 } else
265 ++error; /* not expecting any other options */
266 }
267 }
268
269 if (!filename)
270 ++error;
271
272
273 /* print usage screen if any errors up to this point */
274
275 if (error) {
276 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
277 readpng_version_info();
278 fprintf(stderr, "\n"
279 "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n"
280 " xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
281 " exp \ttransfer-function exponent (``gamma'') of the display\n"
282 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
283 "\t\t to the product of the lookup-table exponent (varies)\n"
284 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
285 " bg \tdesired background color in 7-character hex RGB format\n"
286 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
287 "\t\t used with transparent images\n"
288 "\nPress Q, Esc or mouse button 1 (within image window, after image\n"
289 "is displayed) to quit.\n"
290 "\n", PROGNAME, default_display_exponent);
291 exit(1);
292 }
293
294
295 if (!(infile = fopen(filename, "rb"))) {
296 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
297 ++error;
298 } else {
299 if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
300 switch (rc) {
301 case 1:
302 fprintf(stderr, PROGNAME
303 ": [%s] is not a PNG file: incorrect signature\n",
304 filename);
305 break;
306 case 2:
307 fprintf(stderr, PROGNAME
308 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
309 break;
310 case 4:
311 fprintf(stderr, PROGNAME ": insufficient memory\n");
312 break;
313 default:
314 fprintf(stderr, PROGNAME
315 ": unknown readpng_init() error\n");
316 break;
317 }
318 ++error;
319 } else {
320 display = XOpenDisplay(displayname);
321 if (!display) {
322 readpng_cleanup(TRUE);
323 fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
324 displayname? displayname : "default");
325 ++error;
326 }
327 }
328 if (error)
329 fclose(infile);
330 }
331
332
333 if (error) {
334 fprintf(stderr, PROGNAME ": aborting.\n");
335 exit(2);
336 }
337
338
339 /* set the title-bar string, but make sure buffer doesn't overflow */
340
341 alen = strlen(appname);
342 flen = strlen(filename);
343 if (alen + flen + 3 > 1023)
344 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
345 else
346 sprintf(titlebar, "%s: %s", appname, filename);
347
348
349 /* if the user didn't specify a background color on the command line,
350 * check for one in the PNG file--if not, the initialized values of 0
351 * (black) will be used */
352
353 if (have_bg) {
354 unsigned r, g, b; /* this approach quiets compiler warnings */
355
356 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
357 bg_red = (uch)r;
358 bg_green = (uch)g;
359 bg_blue = (uch)b;
360 } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
361 readpng_cleanup(TRUE);
362 fprintf(stderr, PROGNAME
363 ": libpng error while checking for background color\n");
364 exit(2);
365 }
366
367
368 /* do the basic X initialization stuff, make the window and fill it
369 * with the background color */
370
371 if (rpng_x_create_window())
372 exit(2);
373
374
375 /* decode the image, all at once */
376
377 Trace((stderr, "calling readpng_get_image()\n"))
378 image_data = readpng_get_image(display_exponent, &image_channels,
379 &image_rowbytes);
380 Trace((stderr, "done with readpng_get_image()\n"))
381
382
383 /* done with PNG file, so clean up to minimize memory usage (but do NOT
384 * nuke image_data!) */
385
386 readpng_cleanup(FALSE);
387 fclose(infile);
388
389 if (!image_data) {
390 fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
391 exit(3);
392 }
393
394
395 /* display image (composite with background if requested) */
396
397 Trace((stderr, "calling rpng_x_display_image()\n"))
398 if (rpng_x_display_image()) {
399 free(image_data);
400 exit(4);
401 }
402 Trace((stderr, "done with rpng_x_display_image()\n"))
403
404
405 /* wait for the user to tell us when to quit */
406
407 printf(
408 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
409 fflush(stdout);
410
411 do
412 XNextEvent(display, &e);
413 while (!(e.type == ButtonPress && e.xbutton.button == Button1) &&
414 !(e.type == KeyPress && /* v--- or 1 for shifted keys */
415 ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) ));
416
417
418 /* OK, we're done: clean up all image and X resources and go away */
419
420 rpng_x_cleanup();
421
422 return 0;
423}
424
425
426
427
428
429static int rpng_x_create_window(void)
430{
431 uch *xdata;
432 int need_colormap = FALSE;
433 int screen, pad;
434 ulg bg_pixel = 0L;
435 ulg attrmask;
436 Window root;
437 XEvent e;
438 XGCValues gcvalues;
439 XSetWindowAttributes attr;
440 XTextProperty windowName, *pWindowName = &windowName;
441 XTextProperty iconName, *pIconName = &iconName;
442 XVisualInfo visual_info;
443 XSizeHints *size_hints;
444 XWMHints *wm_hints;
445 XClassHint *class_hints;
446
447
448 screen = DefaultScreen(display);
449 depth = DisplayPlanes(display, screen);
450 root = RootWindow(display, screen);
451
452#ifdef DEBUG
453 XSynchronize(display, True);
454#endif
455
456#if 0
457/* GRR: add 8-bit support */
458 if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) {
459 fprintf(stderr,
460 "screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n",
461 depth);
462 return 2;
463 }
464
465 XMatchVisualInfo(display, screen, depth,
466 (depth == 8)? PseudoColor : TrueColor, &visual_info);
467 visual = visual_info.visual;
468#else
469 if (depth != 16 && depth != 24 && depth != 32) {
470 int visuals_matched = 0;
471
472 Trace((stderr, "default depth is %d: checking other visuals\n",
473 depth))
474
475 /* 24-bit first */
476 visual_info.screen = screen;
477 visual_info.depth = 24;
478 visual_list = XGetVisualInfo(display,
479 VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
480 if (visuals_matched == 0) {
481/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
482 fprintf(stderr, "default screen depth %d not supported, and no"
483 " 24-bit visuals found\n", depth);
484 return 2;
485 }
486 Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
487 visuals_matched))
488 visual = visual_list[0].visual;
489 depth = visual_list[0].depth;
490/*
491 colormap_size = visual_list[0].colormap_size;
492 visual_class = visual->class;
493 visualID = XVisualIDFromVisual(visual);
494 */
495 have_nondefault_visual = TRUE;
496 need_colormap = TRUE;
497 } else {
498 XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
499 visual = visual_info.visual;
500 }
501#endif
502
503 RMask = visual->red_mask;
504 GMask = visual->green_mask;
505 BMask = visual->blue_mask;
506
507/* GRR: add/check 8-bit support */
508 if (depth == 8 || need_colormap) {
509 colormap = XCreateColormap(display, root, visual, AllocNone);
510 if (!colormap) {
511 fprintf(stderr, "XCreateColormap() failed\n");
512 return 2;
513 }
514 have_colormap = TRUE;
515 }
516 if (depth == 15 || depth == 16) {
517 RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */
518 GShift = 15 - rpng_x_msb(GMask);
519 BShift = 15 - rpng_x_msb(BMask);
520 } else if (depth > 16) {
521#define NO_24BIT_MASKS
522#ifdef NO_24BIT_MASKS
523 RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */
524 GShift = rpng_x_msb(GMask) - 7;
525 BShift = rpng_x_msb(BMask) - 7;
526#else
527 RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */
528 GShift = 7 - rpng_x_msb(GMask);
529 BShift = 7 - rpng_x_msb(BMask);
530#endif
531 }
532 if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
533 fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n");
534 return 2;
535 }
536
537/*---------------------------------------------------------------------------
538 Finally, create the window.
539 ---------------------------------------------------------------------------*/
540
541 attr.backing_store = Always;
542 attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
543 attrmask = CWBackingStore | CWEventMask;
544 if (have_nondefault_visual) {
545 attr.colormap = colormap;
546 attr.background_pixel = 0;
547 attr.border_pixel = 1;
548 attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
549 }
550
551 window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0,
552 depth, InputOutput, visual, attrmask, &attr);
553
554 if (window == None) {
555 fprintf(stderr, "XCreateWindow() failed\n");
556 return 2;
557 } else
558 have_window = TRUE;
559
560 if (depth == 8)
561 XSetWindowColormap(display, window, colormap);
562
563 if (!XStringListToTextProperty(&window_name, 1, pWindowName))
564 pWindowName = NULL;
565 if (!XStringListToTextProperty(&icon_name, 1, pIconName))
566 pIconName = NULL;
567
568 /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */
569
570 if ((size_hints = XAllocSizeHints()) != NULL) {
571 /* window will not be resizable */
572 size_hints->flags = PMinSize | PMaxSize;
573 size_hints->min_width = size_hints->max_width = (int)image_width;
574 size_hints->min_height = size_hints->max_height = (int)image_height;
575 }
576
577 if ((wm_hints = XAllocWMHints()) != NULL) {
578 wm_hints->initial_state = NormalState;
579 wm_hints->input = True;
580 /* wm_hints->icon_pixmap = icon_pixmap; */
581 wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
582 }
583
584 if ((class_hints = XAllocClassHint()) != NULL) {
585 class_hints->res_name = res_name;
586 class_hints->res_class = res_class;
587 }
588
589 XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
590 size_hints, wm_hints, class_hints);
591
592 /* various properties and hints no longer needed; free memory */
593 if (pWindowName)
594 XFree(pWindowName->value);
595 if (pIconName)
596 XFree(pIconName->value);
597 if (size_hints)
598 XFree(size_hints);
599 if (wm_hints)
600 XFree(wm_hints);
601 if (class_hints)
602 XFree(class_hints);
603
604 XMapWindow(display, window);
605
606 gc = XCreateGC(display, window, 0, &gcvalues);
607 have_gc = TRUE;
608
609/*---------------------------------------------------------------------------
610 Fill window with the specified background color.
611 ---------------------------------------------------------------------------*/
612
613 if (depth == 24 || depth == 32) {
614 bg_pixel = ((ulg)bg_red << RShift) |
615 ((ulg)bg_green << GShift) |
616 ((ulg)bg_blue << BShift);
617 } else if (depth == 16) {
618 bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) |
619 ((((ulg)bg_green << 8) >> GShift) & GMask) |
620 ((((ulg)bg_blue << 8) >> BShift) & BMask);
621 } else /* depth == 8 */ {
622
623 /* GRR: add 8-bit support */
624
625 }
626
627 XSetForeground(display, gc, bg_pixel);
628 XFillRectangle(display, window, gc, 0, 0, image_width, image_height);
629
630/*---------------------------------------------------------------------------
631 Wait for first Expose event to do any drawing, then flush.
632 ---------------------------------------------------------------------------*/
633
634 do
635 XNextEvent(display, &e);
636 while (e.type != Expose || e.xexpose.count);
637
638 XFlush(display);
639
640/*---------------------------------------------------------------------------
641 Allocate memory for the X- and display-specific version of the image.
642 ---------------------------------------------------------------------------*/
643
644 if (depth == 24 || depth == 32) {
645 xdata = (uch *)malloc(4*image_width*image_height);
646 pad = 32;
647 } else if (depth == 16) {
648 xdata = (uch *)malloc(2*image_width*image_height);
649 pad = 16;
650 } else /* depth == 8 */ {
651 xdata = (uch *)malloc(image_width*image_height);
652 pad = 8;
653 }
654
655 if (!xdata) {
656 fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
657 return 4;
658 }
659
660 ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
661 (char *)xdata, image_width, image_height, pad, 0);
662
663 if (!ximage) {
664 fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
665 free(xdata);
666 return 3;
667 }
668
669 /* to avoid testing the byte order every pixel (or doubling the size of
670 * the drawing routine with a giant if-test), we arbitrarily set the byte
671 * order to MSBFirst and let Xlib worry about inverting things on little-
672 * endian machines (like Linux/x86, old VAXen, etc.)--this is not the most
673 * efficient approach (the giant if-test would be better), but in the
674 * interest of clarity, we take the easy way out... */
675
676 ximage->byte_order = MSBFirst;
677
678 return 0;
679
680} /* end function rpng_x_create_window() */
681
682
683
684
685
686static int rpng_x_display_image(void)
687{
688 uch *src;
689 char *dest;
690 uch r, g, b, a;
691 ulg i, row, lastrow = 0;
692 ulg pixel;
693 int ximage_rowbytes = ximage->bytes_per_line;
694/* int bpp = ximage->bits_per_pixel; */
695
696
697 Trace((stderr, "beginning display loop (image_channels == %d)\n",
698 image_channels))
699 Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n",
700 image_width, image_rowbytes, ximage_rowbytes))
701 Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
702 Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
703 "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
704
705 if (depth == 24 || depth == 32) {
706 ulg red, green, blue;
707
708 for (lastrow = row = 0; row < image_height; ++row) {
709 src = image_data + row*image_rowbytes;
710 dest = ximage->data + row*ximage_rowbytes;
711 if (image_channels == 3) {
712 for (i = image_width; i > 0; --i) {
713 red = *src++;
714 green = *src++;
715 blue = *src++;
716#ifdef NO_24BIT_MASKS
717 pixel = (red << RShift) |
718 (green << GShift) |
719 (blue << BShift);
720 /* recall that we set ximage->byte_order = MSBFirst above */
721 /* GRR BUG: this assumes bpp == 32, but may be 24: */
722 *dest++ = (char)((pixel >> 24) & 0xff);
723 *dest++ = (char)((pixel >> 16) & 0xff);
724 *dest++ = (char)((pixel >> 8) & 0xff);
725 *dest++ = (char)( pixel & 0xff);
726#else
727 red = (RShift < 0)? red << (-RShift) : red >> RShift;
728 green = (GShift < 0)? green << (-GShift) : green >> GShift;
729 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
730 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
731 /* recall that we set ximage->byte_order = MSBFirst above */
732 *dest++ = (char)((pixel >> 24) & 0xff);
733 *dest++ = (char)((pixel >> 16) & 0xff);
734 *dest++ = (char)((pixel >> 8) & 0xff);
735 *dest++ = (char)( pixel & 0xff);
736#endif
737 }
738 } else /* if (image_channels == 4) */ {
739 for (i = image_width; i > 0; --i) {
740 r = *src++;
741 g = *src++;
742 b = *src++;
743 a = *src++;
744 if (a == 255) {
745 red = r;
746 green = g;
747 blue = b;
748 } else if (a == 0) {
749 red = bg_red;
750 green = bg_green;
751 blue = bg_blue;
752 } else {
753 /* this macro (from png.h) composites the foreground
754 * and background values and puts the result into the
755 * first argument */
756 alpha_composite(red, r, a, bg_red);
757 alpha_composite(green, g, a, bg_green);
758 alpha_composite(blue, b, a, bg_blue);
759 }
760 pixel = (red << RShift) |
761 (green << GShift) |
762 (blue << BShift);
763 /* recall that we set ximage->byte_order = MSBFirst above */
764 *dest++ = (char)((pixel >> 24) & 0xff);
765 *dest++ = (char)((pixel >> 16) & 0xff);
766 *dest++ = (char)((pixel >> 8) & 0xff);
767 *dest++ = (char)( pixel & 0xff);
768 }
769 }
770 /* display after every 16 lines */
771 if (((row+1) & 0xf) == 0) {
772 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
773 (int)lastrow, image_width, 16);
774 XFlush(display);
775 lastrow = row + 1;
776 }
777 }
778
779 } else if (depth == 16) {
780 ush red, green, blue;
781
782 for (lastrow = row = 0; row < image_height; ++row) {
783 src = image_data + row*image_rowbytes;
784 dest = ximage->data + row*ximage_rowbytes;
785 if (image_channels == 3) {
786 for (i = image_width; i > 0; --i) {
787 red = ((ush)(*src) << 8);
788 ++src;
789 green = ((ush)(*src) << 8);
790 ++src;
791 blue = ((ush)(*src) << 8);
792 ++src;
793 pixel = ((red >> RShift) & RMask) |
794 ((green >> GShift) & GMask) |
795 ((blue >> BShift) & BMask);
796 /* recall that we set ximage->byte_order = MSBFirst above */
797 *dest++ = (char)((pixel >> 8) & 0xff);
798 *dest++ = (char)( pixel & 0xff);
799 }
800 } else /* if (image_channels == 4) */ {
801 for (i = image_width; i > 0; --i) {
802 r = *src++;
803 g = *src++;
804 b = *src++;
805 a = *src++;
806 if (a == 255) {
807 red = ((ush)r << 8);
808 green = ((ush)g << 8);
809 blue = ((ush)b << 8);
810 } else if (a == 0) {
811 red = ((ush)bg_red << 8);
812 green = ((ush)bg_green << 8);
813 blue = ((ush)bg_blue << 8);
814 } else {
815 /* this macro (from png.h) composites the foreground
816 * and background values and puts the result back into
817 * the first argument (== fg byte here: safe) */
818 alpha_composite(r, r, a, bg_red);
819 alpha_composite(g, g, a, bg_green);
820 alpha_composite(b, b, a, bg_blue);
821 red = ((ush)r << 8);
822 green = ((ush)g << 8);
823 blue = ((ush)b << 8);
824 }
825 pixel = ((red >> RShift) & RMask) |
826 ((green >> GShift) & GMask) |
827 ((blue >> BShift) & BMask);
828 /* recall that we set ximage->byte_order = MSBFirst above */
829 *dest++ = (char)((pixel >> 8) & 0xff);
830 *dest++ = (char)( pixel & 0xff);
831 }
832 }
833 /* display after every 16 lines */
834 if (((row+1) & 0xf) == 0) {
835 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
836 (int)lastrow, image_width, 16);
837 XFlush(display);
838 lastrow = row + 1;
839 }
840 }
841
842 } else /* depth == 8 */ {
843
844 /* GRR: add 8-bit support */
845
846 }
847
848 Trace((stderr, "calling final XPutImage()\n"))
849 if (lastrow < image_height) {
850 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
851 (int)lastrow, image_width, image_height-lastrow);
852 XFlush(display);
853 }
854
855 return 0;
856}
857
858
859
860
861static void rpng_x_cleanup(void)
862{
863 if (image_data) {
864 free(image_data);
865 image_data = NULL;
866 }
867
868 if (ximage) {
869 if (ximage->data) {
870 free(ximage->data); /* we allocated it, so we free it */
871 ximage->data = (char *)NULL; /* instead of XDestroyImage() */
872 }
873 XDestroyImage(ximage);
874 ximage = NULL;
875 }
876
877 if (have_gc)
878 XFreeGC(display, gc);
879
880 if (have_window)
881 XDestroyWindow(display, window);
882
883 if (have_colormap)
884 XFreeColormap(display, colormap);
885
886 if (have_nondefault_visual)
887 XFree(visual_list);
888}
889
890
891
892
893
894static int rpng_x_msb(ulg u32val)
895{
896 int i;
897
898 for (i = 31; i >= 0; --i) {
899 if (u32val & 0x80000000L)
900 break;
901 u32val <<= 1;
902 }
903 return i;
904}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c
new file mode 100644
index 0000000..2303b58
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c
@@ -0,0 +1,1253 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program rpng2-win.c
4
5 This program decodes and displays PNG files progressively, as if it were
6 a web browser (though the front end is only set up to read from files).
7 It supports gamma correction, user-specified background colors, and user-
8 specified background patterns (for transparent images). This version is
9 for 32-bit Windows; it may compile under 16-bit Windows with a little
10 tweaking (or maybe not). Thanks to Adam Costello and Pieter S. van der
11 Meulen for the "diamond" and "radial waves" patterns, respectively.
12
13 to do (someday, maybe):
14 - handle quoted command-line args (especially filenames with spaces)
15 - finish resizable checkerboard-gradient (sizes 4-128?)
16 - use %.1023s to simplify truncation of title-bar string?
17 - have minimum window width: oh well
18
19 ---------------------------------------------------------------------------
20
21 Changelog:
22 - 1.01: initial public release
23 - 1.02: fixed cut-and-paste error in usage screen (oops...)
24 - 1.03: modified to allow abbreviated options
25 - 1.04: removed bogus extra argument from usage fprintf() [Glenn R-P?];
26 fixed command-line parsing bug
27 - 1.10: enabled "message window"/console (thanks to David Geldreich)
28 - 1.20: added runtime MMX-enabling/disabling and new -mmx* options
29 - 1.21: made minor tweak to usage screen to fit within 25-line console
30 - 1.22: added AMD64/EM64T support (__x86_64__)
31 - 2.00: dual-licensed (added GNU GPL)
32 - 2.01: fixed 64-bit typo in readpng2.c
33 - 2.02: fixed improper display of usage screen on PNG error(s); fixed
34 unexpected-EOF and file-read-error cases
35 - 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options
36
37 ---------------------------------------------------------------------------
38
39 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
40
41 This software is provided "as is," without warranty of any kind,
42 express or implied. In no event shall the author or contributors
43 be held liable for any damages arising in any way from the use of
44 this software.
45
46 The contents of this file are DUAL-LICENSED. You may modify and/or
47 redistribute this software according to the terms of one of the
48 following two licenses (at your option):
49
50
51 LICENSE 1 ("BSD-like with advertising clause"):
52
53 Permission is granted to anyone to use this software for any purpose,
54 including commercial applications, and to alter it and redistribute
55 it freely, subject to the following restrictions:
56
57 1. Redistributions of source code must retain the above copyright
58 notice, disclaimer, and this list of conditions.
59 2. Redistributions in binary form must reproduce the above copyright
60 notice, disclaimer, and this list of conditions in the documenta-
61 tion and/or other materials provided with the distribution.
62 3. All advertising materials mentioning features or use of this
63 software must display the following acknowledgment:
64
65 This product includes software developed by Greg Roelofs
66 and contributors for the book, "PNG: The Definitive Guide,"
67 published by O'Reilly and Associates.
68
69
70 LICENSE 2 (GNU GPL v2 or later):
71
72 This program is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2 of the License, or
75 (at your option) any later version.
76
77 This program is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80 GNU General Public License for more details.
81
82 You should have received a copy of the GNU General Public License
83 along with this program; if not, write to the Free Software Foundation,
84 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
85
86 ---------------------------------------------------------------------------*/
87
88#define PROGNAME "rpng2-win"
89#define LONGNAME "Progressive PNG Viewer for Windows"
90#define VERSION "2.02 of 16 March 2008"
91
92#include <stdio.h>
93#include <stdlib.h>
94#include <string.h>
95#include <setjmp.h> /* for jmpbuf declaration in readpng2.h */
96#include <time.h>
97#include <math.h> /* only for PvdM background code */
98#include <windows.h>
99#ifdef __CYGWIN__
100/* getch replacement. Turns out, we don't really need this,
101 * but leave it here if we ever enable any of the uses of
102 * _getch in the main code
103 */
104#include <unistd.h>
105#include <termio.h>
106#include <sys/ioctl.h>
107int repl_getch( void )
108{
109 char ch;
110 int fd = fileno(stdin);
111 struct termio old_tty, new_tty;
112
113 ioctl(fd, TCGETA, &old_tty);
114 new_tty = old_tty;
115 new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);
116 ioctl(fd, TCSETA, &new_tty);
117 fread(&ch, 1, sizeof(ch), stdin);
118 ioctl(fd, TCSETA, &old_tty);
119
120 return ch;
121}
122#define _getch repl_getch
123#else
124#include <conio.h> /* only for _getch() */
125#endif
126
127/* all for PvdM background code: */
128#ifndef PI
129# define PI 3.141592653589793238
130#endif
131#define PI_2 (PI*0.5)
132#define INV_PI_360 (360.0 / PI)
133#define MAX(a,b) (a>b?a:b)
134#define MIN(a,b) (a<b?a:b)
135#define CLIP(a,min,max) MAX(min,MIN((a),max))
136#define ABS(a) ((a)<0?-(a):(a))
137#define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */
138#define ROUNDF(f) ((int)(f + 0.5))
139
140#define rgb1_max bg_freq
141#define rgb1_min bg_gray
142#define rgb2_max bg_bsat
143#define rgb2_min bg_brot
144
145/* #define DEBUG */ /* this enables the Trace() macros */
146
147#include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */
148
149
150/* could just include png.h, but this macro is the only thing we need
151 * (name and typedefs changed to local versions); note that side effects
152 * only happen with alpha (which could easily be avoided with
153 * "ush acopy = (alpha);") */
154
155#define alpha_composite(composite, fg, alpha, bg) { \
156 ush temp = ((ush)(fg)*(ush)(alpha) + \
157 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
158 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
159}
160
161
162#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this
163 * block size corresponds roughly to a download
164 * speed 10% faster than theoretical 33.6K maximum
165 * (assuming 8 data bits, 1 stop bit and no other
166 * overhead) */
167
168/* local prototypes */
169static void rpng2_win_init(void);
170static int rpng2_win_create_window(void);
171static int rpng2_win_load_bg_image(void);
172static void rpng2_win_display_row(ulg row);
173static void rpng2_win_finish_display(void);
174static void rpng2_win_cleanup(void);
175LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM);
176
177
178static char titlebar[1024];
179static char *progname = PROGNAME;
180static char *appname = LONGNAME;
181static char *filename;
182static FILE *infile;
183
184static mainprog_info rpng2_info;
185
186static uch inbuf[INBUFSIZE];
187static int incount;
188
189static int pat = 6; /* must be less than num_bgpat */
190static int bg_image = 0;
191static int bgscale = 16;
192static ulg bg_rowbytes;
193static uch *bg_data;
194
195static struct rgb_color {
196 uch r, g, b;
197} rgb[] = {
198 { 0, 0, 0}, /* 0: black */
199 {255, 255, 255}, /* 1: white */
200 {173, 132, 57}, /* 2: tan */
201 { 64, 132, 0}, /* 3: medium green */
202 {189, 117, 1}, /* 4: gold */
203 {253, 249, 1}, /* 5: yellow */
204 { 0, 0, 255}, /* 6: blue */
205 { 0, 0, 120}, /* 7: medium blue */
206 {255, 0, 255}, /* 8: magenta */
207 { 64, 0, 64}, /* 9: dark magenta */
208 {255, 0, 0}, /* 10: red */
209 { 64, 0, 0}, /* 11: dark red */
210 {255, 127, 0}, /* 12: orange */
211 {192, 96, 0}, /* 13: darker orange */
212 { 24, 60, 0}, /* 14: dark green-yellow */
213 { 85, 125, 200} /* 15: ice blue */
214};
215/* not used for now, but should be for error-checking:
216static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);
217 */
218
219/*
220 This whole struct is a fairly cheesy way to keep the number of
221 command-line options to a minimum. The radial-waves background
222 type is a particularly poor fit to the integer elements of the
223 struct...but a few macros and a little fixed-point math will do
224 wonders for ya.
225
226 type bits:
227 F E D C B A 9 8 7 6 5 4 3 2 1 0
228 | | | | |
229 | | +-+-+-- 0 = sharp-edged checkerboard
230 | | 1 = soft diamonds
231 | | 2 = radial waves
232 | | 3-7 = undefined
233 | +-- gradient #2 inverted?
234 +-- alternating columns inverted?
235 */
236static struct background_pattern {
237 ush type;
238 int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */
239 int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/
240} bg[] = {
241 {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */
242 {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */
243 {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */
244 {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */
245 {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */
246 {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */
247 {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */
248 {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */
249 {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */
250 {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */
251 {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */
252 {1, 3,0, 0,0}, /* diamonds: medium green vs. black */
253 {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */
254 {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */
255 {2, 16, 256, 100, 250}, /* radial: very tight spiral */
256 {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */
257};
258static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);
259
260
261/* Windows-specific global variables (could go in struct, but messy...) */
262static ulg wimage_rowbytes;
263static uch *dib;
264static uch *wimage_data;
265static BITMAPINFOHEADER *bmih;
266
267static HWND global_hwnd;
268static HINSTANCE global_hInst;
269static int global_showmode;
270
271
272
273
274int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
275{
276 char *args[1024]; /* arbitrary limit, but should suffice */
277 char **argv = args;
278 char *p, *q, *bgstr = NULL;
279 int argc = 0;
280 int rc, alen, flen;
281 int error = 0;
282 int timing = FALSE;
283 int have_bg = FALSE;
284 double LUT_exponent; /* just the lookup table */
285 double CRT_exponent = 2.2; /* just the monitor */
286 double default_display_exponent; /* whole display system */
287 MSG msg;
288
289
290 /* First initialize a few things, just to be sure--memset takes care of
291 * default background color (black), booleans (FALSE), pointers (NULL),
292 * etc. */
293
294 global_hInst = hInst;
295 global_showmode = showmode;
296 filename = (char *)NULL;
297 memset(&rpng2_info, 0, sizeof(mainprog_info));
298
299#ifndef __CYGWIN__
300 /* Next reenable console output, which normally goes to the bit bucket
301 * for windowed apps. Closing the console window will terminate the
302 * app. Thanks to David.Geldreich@realviz.com for supplying the magical
303 * incantation. */
304
305 AllocConsole();
306 freopen("CONOUT$", "a", stderr);
307 freopen("CONOUT$", "a", stdout);
308#endif
309
310 /* Set the default value for our display-system exponent, i.e., the
311 * product of the CRT exponent and the exponent corresponding to
312 * the frame-buffer's lookup table (LUT), if any. This is not an
313 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
314 * ones), but it should cover 99% of the current possibilities. And
315 * yes, these ifdefs are completely wasted in a Windows program... */
316
317#if defined(NeXT)
318 /* third-party utilities can modify the default LUT exponent */
319 LUT_exponent = 1.0 / 2.2;
320 /*
321 if (some_next_function_that_returns_gamma(&next_gamma))
322 LUT_exponent = 1.0 / next_gamma;
323 */
324#elif defined(sgi)
325 LUT_exponent = 1.0 / 1.7;
326 /* there doesn't seem to be any documented function to
327 * get the "gamma" value, so we do it the hard way */
328 infile = fopen("/etc/config/system.glGammaVal", "r");
329 if (infile) {
330 double sgi_gamma;
331
332 fgets(tmpline, 80, infile);
333 fclose(infile);
334 sgi_gamma = atof(tmpline);
335 if (sgi_gamma > 0.0)
336 LUT_exponent = 1.0 / sgi_gamma;
337 }
338#elif defined(Macintosh)
339 LUT_exponent = 1.8 / 2.61;
340 /*
341 if (some_mac_function_that_returns_gamma(&mac_gamma))
342 LUT_exponent = mac_gamma / 2.61;
343 */
344#else
345 LUT_exponent = 1.0; /* assume no LUT: most PCs */
346#endif
347
348 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
349 default_display_exponent = LUT_exponent * CRT_exponent;
350
351
352 /* If the user has set the SCREEN_GAMMA environment variable as suggested
353 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
354 * use the default value we just calculated. Either way, the user may
355 * override this via a command-line option. */
356
357 if ((p = getenv("SCREEN_GAMMA")) != NULL)
358 rpng2_info.display_exponent = atof(p);
359 else
360 rpng2_info.display_exponent = default_display_exponent;
361
362
363 /* Windows really hates command lines, so we have to set up our own argv.
364 * Note that we do NOT bother with quoted arguments here, so don't use
365 * filenames with spaces in 'em! */
366
367 argv[argc++] = PROGNAME;
368 p = cmd;
369 for (;;) {
370 if (*p == ' ')
371 while (*++p == ' ')
372 ;
373 /* now p points at the first non-space after some spaces */
374 if (*p == '\0')
375 break; /* nothing after the spaces: done */
376 argv[argc++] = q = p;
377 while (*q && *q != ' ')
378 ++q;
379 /* now q points at a space or the end of the string */
380 if (*q == '\0')
381 break; /* last argv already terminated; quit */
382 *q = '\0'; /* change space to terminator */
383 p = q + 1;
384 }
385 argv[argc] = NULL; /* terminate the argv array itself */
386
387
388 /* Now parse the command line for options and the PNG filename. */
389
390 while (*++argv && !error) {
391 if (!strncmp(*argv, "-gamma", 2)) {
392 if (!*++argv)
393 ++error;
394 else {
395 rpng2_info.display_exponent = atof(*argv);
396 if (rpng2_info.display_exponent <= 0.0)
397 ++error;
398 }
399 } else if (!strncmp(*argv, "-bgcolor", 4)) {
400 if (!*++argv)
401 ++error;
402 else {
403 bgstr = *argv;
404 if (strlen(bgstr) != 7 || bgstr[0] != '#')
405 ++error;
406 else {
407 have_bg = TRUE;
408 bg_image = FALSE;
409 }
410 }
411 } else if (!strncmp(*argv, "-bgpat", 4)) {
412 if (!*++argv)
413 ++error;
414 else {
415 pat = atoi(*argv) - 1;
416 if (pat < 0 || pat >= num_bgpat)
417 ++error;
418 else {
419 bg_image = TRUE;
420 have_bg = FALSE;
421 }
422 }
423 } else if (!strncmp(*argv, "-timing", 2)) {
424 timing = TRUE;
425 } else {
426 if (**argv != '-') {
427 filename = *argv;
428 if (argv[1]) /* shouldn't be any more args after filename */
429 ++error;
430 } else
431 ++error; /* not expecting any other options */
432 }
433 }
434
435 if (!filename)
436 ++error;
437
438
439 /* print usage screen if any errors up to this point */
440
441 if (error) {
442#ifndef __CYGWIN__
443 int ch;
444#endif
445
446 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
447 readpng2_version_info();
448 fprintf(stderr, "\n"
449 "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n"
450 " %*s file.png\n\n"
451 " exp \ttransfer-function exponent (``gamma'') of the display\n"
452 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
453 "\t\t to the product of the lookup-table exponent (varies)\n"
454 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
455 " bg \tdesired background color in 7-character hex RGB format\n"
456 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
457 "\t\t used with transparent images; overrides -bgpat option\n"
458 " pat \tdesired background pattern number (1-%d); used with\n"
459 "\t\t transparent images; overrides -bgcolor option\n"
460 " -timing\tenables delay for every block read, to simulate modem\n"
461 "\t\t download of image (~36 Kbps)\n"
462 "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
463#ifndef __CYGWIN__
464 "Press Q or Esc to quit this usage screen. ",
465#else
466 ,
467#endif
468 PROGNAME,
469#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \
470 !(defined(__CYGWIN__) || defined(__MINGW32__))
471 (int)strlen(PROGNAME), " ",
472#endif
473 (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat);
474 fflush(stderr);
475#ifndef __CYGWIN__
476 do
477 ch = _getch();
478 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
479#endif
480 exit(1);
481 }
482
483
484 if (!(infile = fopen(filename, "rb"))) {
485 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
486 ++error;
487 } else {
488 incount = fread(inbuf, 1, INBUFSIZE, infile);
489 if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {
490 fprintf(stderr, PROGNAME
491 ": [%s] is not a PNG file: incorrect signature\n",
492 filename);
493 ++error;
494 } else if ((rc = readpng2_init(&rpng2_info)) != 0) {
495 switch (rc) {
496 case 2:
497 fprintf(stderr, PROGNAME
498 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
499 break;
500 case 4:
501 fprintf(stderr, PROGNAME ": insufficient memory\n");
502 break;
503 default:
504 fprintf(stderr, PROGNAME
505 ": unknown readpng2_init() error\n");
506 break;
507 }
508 ++error;
509 }
510 if (error)
511 fclose(infile);
512 }
513
514
515 if (error) {
516#ifndef __CYGWIN__
517 int ch;
518#endif
519
520 fprintf(stderr, PROGNAME ": aborting.\n");
521#ifndef __CYGWIN__
522 do
523 ch = _getch();
524 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
525#endif
526 exit(2);
527 } else {
528 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
529#ifndef __CYGWIN__
530 fprintf(stderr,
531 "\n [console window: closing this window will terminate %s]\n\n",
532 PROGNAME);
533#endif
534 fflush(stderr);
535 }
536
537
538 /* set the title-bar string, but make sure buffer doesn't overflow */
539
540 alen = strlen(appname);
541 flen = strlen(filename);
542 if (alen + flen + 3 > 1023)
543 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
544 else
545 sprintf(titlebar, "%s: %s", appname, filename);
546
547
548 /* set some final rpng2_info variables before entering main data loop */
549
550 if (have_bg) {
551 unsigned r, g, b; /* this approach quiets compiler warnings */
552
553 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
554 rpng2_info.bg_red = (uch)r;
555 rpng2_info.bg_green = (uch)g;
556 rpng2_info.bg_blue = (uch)b;
557 } else
558 rpng2_info.need_bgcolor = TRUE;
559
560 rpng2_info.state = kPreInit;
561 rpng2_info.mainprog_init = rpng2_win_init;
562 rpng2_info.mainprog_display_row = rpng2_win_display_row;
563 rpng2_info.mainprog_finish_display = rpng2_win_finish_display;
564
565
566 /* OK, this is the fun part: call readpng2_decode_data() at the start of
567 * the loop to deal with our first buffer of data (read in above to verify
568 * that the file is a PNG image), then loop through the file and continue
569 * calling the same routine to handle each chunk of data. It in turn
570 * passes the data to libpng, which will invoke one or more of our call-
571 * backs as decoded data become available. We optionally call Sleep() for
572 * one second per iteration to simulate downloading the image via an analog
573 * modem. */
574
575 for (;;) {
576 Trace((stderr, "about to call readpng2_decode_data()\n"))
577 if (readpng2_decode_data(&rpng2_info, inbuf, incount))
578 ++error;
579 Trace((stderr, "done with readpng2_decode_data()\n"))
580
581 if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {
582 if (rpng2_info.state == kDone) {
583 Trace((stderr, "done decoding PNG image\n"))
584 } else if (ferror(infile)) {
585 fprintf(stderr, PROGNAME
586 ": error while reading PNG image file\n");
587 exit(3);
588 } else if (feof(infile)) {
589 fprintf(stderr, PROGNAME ": end of file reached "
590 "(unexpectedly) while reading PNG image file\n");
591 exit(3);
592 } else /* if (error) */ {
593 /* will print error message below */
594 }
595 break;
596 }
597
598 if (timing)
599 Sleep(1000L);
600
601 incount = fread(inbuf, 1, INBUFSIZE, infile);
602 }
603
604
605 /* clean up PNG stuff and report any decoding errors */
606
607 fclose(infile);
608 Trace((stderr, "about to call readpng2_cleanup()\n"))
609 readpng2_cleanup(&rpng2_info);
610
611 if (error) {
612 fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n");
613 exit(3);
614 }
615
616
617 /* wait for the user to tell us when to quit */
618
619 while (GetMessage(&msg, NULL, 0, 0)) {
620 TranslateMessage(&msg);
621 DispatchMessage(&msg);
622 }
623
624
625 /* we're done: clean up all image and Windows resources and go away */
626
627 Trace((stderr, "about to call rpng2_win_cleanup()\n"))
628 rpng2_win_cleanup();
629
630 return msg.wParam;
631}
632
633
634
635
636
637/* this function is called by readpng2_info_callback() in readpng2.c, which
638 * in turn is called by libpng after all of the pre-IDAT chunks have been
639 * read and processed--i.e., we now have enough info to finish initializing */
640
641static void rpng2_win_init()
642{
643 ulg i;
644 ulg rowbytes = rpng2_info.rowbytes;
645
646 Trace((stderr, "beginning rpng2_win_init()\n"))
647 Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes))
648 Trace((stderr, " width = %ld\n", rpng2_info.width))
649 Trace((stderr, " height = %ld\n", rpng2_info.height))
650
651 rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
652 if (!rpng2_info.image_data) {
653 readpng2_cleanup(&rpng2_info);
654 return;
655 }
656
657 rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));
658 if (!rpng2_info.row_pointers) {
659 free(rpng2_info.image_data);
660 rpng2_info.image_data = NULL;
661 readpng2_cleanup(&rpng2_info);
662 return;
663 }
664
665 for (i = 0; i < rpng2_info.height; ++i)
666 rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;
667
668/*---------------------------------------------------------------------------
669 Do the basic Windows initialization stuff, make the window, and fill it
670 with the user-specified, file-specified or default background color.
671 ---------------------------------------------------------------------------*/
672
673 if (rpng2_win_create_window()) {
674 readpng2_cleanup(&rpng2_info);
675 return;
676 }
677
678 rpng2_info.state = kWindowInit;
679}
680
681
682
683
684
685static int rpng2_win_create_window()
686{
687 uch bg_red = rpng2_info.bg_red;
688 uch bg_green = rpng2_info.bg_green;
689 uch bg_blue = rpng2_info.bg_blue;
690 uch *dest;
691 int extra_width, extra_height;
692 ulg i, j;
693 WNDCLASSEX wndclass;
694 RECT rect;
695
696
697/*---------------------------------------------------------------------------
698 Allocate memory for the display-specific version of the image (round up
699 to multiple of 4 for Windows DIB).
700 ---------------------------------------------------------------------------*/
701
702 wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2;
703
704 if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
705 wimage_rowbytes*rpng2_info.height)))
706 {
707 return 4; /* fail */
708 }
709
710/*---------------------------------------------------------------------------
711 Initialize the DIB. Negative height means to use top-down BMP ordering
712 (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
713 implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
714 directly => wimage_data begins immediately after BMP header.
715 ---------------------------------------------------------------------------*/
716
717 memset(dib, 0, sizeof(BITMAPINFOHEADER));
718 bmih = (BITMAPINFOHEADER *)dib;
719 bmih->biSize = sizeof(BITMAPINFOHEADER);
720 bmih->biWidth = rpng2_info.width;
721 bmih->biHeight = -((long)rpng2_info.height);
722 bmih->biPlanes = 1;
723 bmih->biBitCount = 24;
724 bmih->biCompression = 0;
725 wimage_data = dib + sizeof(BITMAPINFOHEADER);
726
727/*---------------------------------------------------------------------------
728 Fill window with the specified background color (default is black), but
729 defer loading faked "background image" until window is displayed (may be
730 slow to compute). Data are in BGR order.
731 ---------------------------------------------------------------------------*/
732
733 if (bg_image) { /* just fill with black for now */
734 memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height);
735 } else {
736 for (j = 0; j < rpng2_info.height; ++j) {
737 dest = wimage_data + j*wimage_rowbytes;
738 for (i = rpng2_info.width; i > 0; --i) {
739 *dest++ = bg_blue;
740 *dest++ = bg_green;
741 *dest++ = bg_red;
742 }
743 }
744 }
745
746/*---------------------------------------------------------------------------
747 Set the window parameters.
748 ---------------------------------------------------------------------------*/
749
750 memset(&wndclass, 0, sizeof(wndclass));
751
752 wndclass.cbSize = sizeof(wndclass);
753 wndclass.style = CS_HREDRAW | CS_VREDRAW;
754 wndclass.lpfnWndProc = rpng2_win_wndproc;
755 wndclass.hInstance = global_hInst;
756 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
757 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
758 wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
759 wndclass.lpszMenuName = NULL;
760 wndclass.lpszClassName = progname;
761 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
762
763 RegisterClassEx(&wndclass);
764
765/*---------------------------------------------------------------------------
766 Finally, create the window.
767 ---------------------------------------------------------------------------*/
768
769 extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
770 GetSystemMetrics(SM_CXDLGFRAME));
771 extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
772 GetSystemMetrics(SM_CYDLGFRAME)) +
773 GetSystemMetrics(SM_CYCAPTION);
774
775 global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
776 CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width,
777 rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL);
778
779 ShowWindow(global_hwnd, global_showmode);
780 UpdateWindow(global_hwnd);
781
782/*---------------------------------------------------------------------------
783 Now compute the background image and display it. If it fails (memory
784 allocation), revert to a plain background color.
785 ---------------------------------------------------------------------------*/
786
787 if (bg_image) {
788 static const char *msg = "Computing background image...";
789 int x, y, len = strlen(msg);
790 HDC hdc = GetDC(global_hwnd);
791 TEXTMETRIC tm;
792
793 GetTextMetrics(hdc, &tm);
794 x = (rpng2_info.width - len*tm.tmAveCharWidth)/2;
795 y = (rpng2_info.height - tm.tmHeight)/2;
796 SetBkMode(hdc, TRANSPARENT);
797 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
798 /* this can still begin out of bounds even if x is positive (???): */
799 TextOut(hdc, ((x < 0)? 0 : x), ((y < 0)? 0 : y), msg, len);
800 ReleaseDC(global_hwnd, hdc);
801
802 rpng2_win_load_bg_image(); /* resets bg_image if fails */
803 }
804
805 if (!bg_image) {
806 for (j = 0; j < rpng2_info.height; ++j) {
807 dest = wimage_data + j*wimage_rowbytes;
808 for (i = rpng2_info.width; i > 0; --i) {
809 *dest++ = bg_blue;
810 *dest++ = bg_green;
811 *dest++ = bg_red;
812 }
813 }
814 }
815
816 rect.left = 0L;
817 rect.top = 0L;
818 rect.right = (LONG)rpng2_info.width; /* possibly off by one? */
819 rect.bottom = (LONG)rpng2_info.height; /* possibly off by one? */
820 InvalidateRect(global_hwnd, &rect, FALSE);
821 UpdateWindow(global_hwnd); /* similar to XFlush() */
822
823 return 0;
824
825} /* end function rpng2_win_create_window() */
826
827
828
829
830
831static int rpng2_win_load_bg_image()
832{
833 uch *src, *dest;
834 uch r1, r2, g1, g2, b1, b2;
835 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
836 int k, hmax, max;
837 int xidx, yidx, yidx_max = (bgscale-1);
838 int even_odd_vert, even_odd_horiz, even_odd;
839 int invert_gradient2 = (bg[pat].type & 0x08);
840 int invert_column;
841 ulg i, row;
842
843/*---------------------------------------------------------------------------
844 Allocate buffer for fake background image to be used with transparent
845 images; if this fails, revert to plain background color.
846 ---------------------------------------------------------------------------*/
847
848 bg_rowbytes = 3 * rpng2_info.width;
849 bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);
850 if (!bg_data) {
851 fprintf(stderr, PROGNAME
852 ": unable to allocate memory for background image\n");
853 bg_image = 0;
854 return 1;
855 }
856
857/*---------------------------------------------------------------------------
858 Vertical gradients (ramps) in NxN squares, alternating direction and
859 colors (N == bgscale).
860 ---------------------------------------------------------------------------*/
861
862 if ((bg[pat].type & 0x07) == 0) {
863 uch r1_min = rgb[bg[pat].rgb1_min].r;
864 uch g1_min = rgb[bg[pat].rgb1_min].g;
865 uch b1_min = rgb[bg[pat].rgb1_min].b;
866 uch r2_min = rgb[bg[pat].rgb2_min].r;
867 uch g2_min = rgb[bg[pat].rgb2_min].g;
868 uch b2_min = rgb[bg[pat].rgb2_min].b;
869 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
870 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
871 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
872 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
873 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
874 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
875
876 for (row = 0; row < rpng2_info.height; ++row) {
877 yidx = row % bgscale;
878 even_odd_vert = (row / bgscale) & 1;
879
880 r1 = r1_min + (r1_diff * yidx) / yidx_max;
881 g1 = g1_min + (g1_diff * yidx) / yidx_max;
882 b1 = b1_min + (b1_diff * yidx) / yidx_max;
883 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
884 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
885 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
886
887 r2 = r2_min + (r2_diff * yidx) / yidx_max;
888 g2 = g2_min + (g2_diff * yidx) / yidx_max;
889 b2 = b2_min + (b2_diff * yidx) / yidx_max;
890 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
891 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
892 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
893
894 dest = bg_data + row*bg_rowbytes;
895 for (i = 0; i < rpng2_info.width; ++i) {
896 even_odd_horiz = (i / bgscale) & 1;
897 even_odd = even_odd_vert ^ even_odd_horiz;
898 invert_column =
899 (even_odd_horiz && (bg[pat].type & 0x10));
900 if (even_odd == 0) { /* gradient #1 */
901 if (invert_column) {
902 *dest++ = r1_inv;
903 *dest++ = g1_inv;
904 *dest++ = b1_inv;
905 } else {
906 *dest++ = r1;
907 *dest++ = g1;
908 *dest++ = b1;
909 }
910 } else { /* gradient #2 */
911 if ((invert_column && invert_gradient2) ||
912 (!invert_column && !invert_gradient2))
913 {
914 *dest++ = r2; /* not inverted or */
915 *dest++ = g2; /* doubly inverted */
916 *dest++ = b2;
917 } else {
918 *dest++ = r2_inv;
919 *dest++ = g2_inv; /* singly inverted */
920 *dest++ = b2_inv;
921 }
922 }
923 }
924 }
925
926/*---------------------------------------------------------------------------
927 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
928 M. Costello.
929 ---------------------------------------------------------------------------*/
930
931 } else if ((bg[pat].type & 0x07) == 1) {
932
933 hmax = (bgscale-1)/2; /* half the max weight of a color */
934 max = 2*hmax; /* the max weight of a color */
935
936 r1 = rgb[bg[pat].rgb1_max].r;
937 g1 = rgb[bg[pat].rgb1_max].g;
938 b1 = rgb[bg[pat].rgb1_max].b;
939 r2 = rgb[bg[pat].rgb2_max].r;
940 g2 = rgb[bg[pat].rgb2_max].g;
941 b2 = rgb[bg[pat].rgb2_max].b;
942
943 for (row = 0; row < rpng2_info.height; ++row) {
944 yidx = row % bgscale;
945 if (yidx > hmax)
946 yidx = bgscale-1 - yidx;
947 dest = bg_data + row*bg_rowbytes;
948 for (i = 0; i < rpng2_info.width; ++i) {
949 xidx = i % bgscale;
950 if (xidx > hmax)
951 xidx = bgscale-1 - xidx;
952 k = xidx + yidx;
953 *dest++ = (k*r1 + (max-k)*r2) / max;
954 *dest++ = (k*g1 + (max-k)*g2) / max;
955 *dest++ = (k*b1 + (max-k)*b2) / max;
956 }
957 }
958
959/*---------------------------------------------------------------------------
960 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
961 soids will equal bgscale?]. This one is slow but very cool. Code con-
962 tributed by Pieter S. van der Meulen (originally in Smalltalk).
963 ---------------------------------------------------------------------------*/
964
965 } else if ((bg[pat].type & 0x07) == 2) {
966 uch ch;
967 int ii, x, y, hw, hh, grayspot;
968 double freq, rotate, saturate, gray, intensity;
969 double angle=0.0, aoffset=0.0, maxDist, dist;
970 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
971
972 fprintf(stderr, "%s: computing radial background...",
973 PROGNAME);
974 fflush(stderr);
975
976 hh = rpng2_info.height / 2;
977 hw = rpng2_info.width / 2;
978
979 /* variables for radial waves:
980 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
981 * freq: number of color beams originating from the center
982 * grayspot: size of the graying center area (anti-alias)
983 * rotate: rotation of the beams as a function of radius
984 * saturate: saturation of beams' shape azimuthally
985 */
986 angle = CLIP(angle, 0.0, 360.0);
987 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
988 freq = MAX((double)bg[pat].bg_freq, 0.0);
989 saturate = (double)bg[pat].bg_bsat * 0.1;
990 rotate = (double)bg[pat].bg_brot * 0.1;
991 gray = 0.0;
992 intensity = 0.0;
993 maxDist = (double)((hw*hw) + (hh*hh));
994
995 for (row = 0; row < rpng2_info.height; ++row) {
996 y = row - hh;
997 dest = bg_data + row*bg_rowbytes;
998 for (i = 0; i < rpng2_info.width; ++i) {
999 x = i - hw;
1000 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1001 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1002 gray = MIN(1.0, gray);
1003 dist = (double)((x*x) + (y*y)) / maxDist;
1004 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1005 gray * saturate;
1006 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1007 hue = (angle + PI) * INV_PI_360 + aoffset;
1008 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
1009 s = MIN(MAX(s,0.0), 1.0);
1010 v = MIN(MAX(intensity,0.0), 1.0);
1011
1012 if (s == 0.0) {
1013 ch = (uch)(v * 255.0);
1014 *dest++ = ch;
1015 *dest++ = ch;
1016 *dest++ = ch;
1017 } else {
1018 if ((hue < 0.0) || (hue >= 360.0))
1019 hue -= (((int)(hue / 360.0)) * 360.0);
1020 hue /= 60.0;
1021 ii = (int)hue;
1022 f = hue - (double)ii;
1023 p = (1.0 - s) * v;
1024 q = (1.0 - (s * f)) * v;
1025 t = (1.0 - (s * (1.0 - f))) * v;
1026 if (ii == 0) { red = v; green = t; blue = p; }
1027 else if (ii == 1) { red = q; green = v; blue = p; }
1028 else if (ii == 2) { red = p; green = v; blue = t; }
1029 else if (ii == 3) { red = p; green = q; blue = v; }
1030 else if (ii == 4) { red = t; green = p; blue = v; }
1031 else if (ii == 5) { red = v; green = p; blue = q; }
1032 *dest++ = (uch)(red * 255.0);
1033 *dest++ = (uch)(green * 255.0);
1034 *dest++ = (uch)(blue * 255.0);
1035 }
1036 }
1037 }
1038 fprintf(stderr, "done.\n");
1039 fflush(stderr);
1040 }
1041
1042/*---------------------------------------------------------------------------
1043 Blast background image to display buffer before beginning PNG decode;
1044 calling function will handle invalidation and UpdateWindow() call.
1045 ---------------------------------------------------------------------------*/
1046
1047 for (row = 0; row < rpng2_info.height; ++row) {
1048 src = bg_data + row*bg_rowbytes;
1049 dest = wimage_data + row*wimage_rowbytes;
1050 for (i = rpng2_info.width; i > 0; --i) {
1051 r1 = *src++;
1052 g1 = *src++;
1053 b1 = *src++;
1054 *dest++ = b1;
1055 *dest++ = g1; /* note reverse order */
1056 *dest++ = r1;
1057 }
1058 }
1059
1060 return 0;
1061
1062} /* end function rpng2_win_load_bg_image() */
1063
1064
1065
1066
1067
1068static void rpng2_win_display_row(ulg row)
1069{
1070 uch bg_red = rpng2_info.bg_red;
1071 uch bg_green = rpng2_info.bg_green;
1072 uch bg_blue = rpng2_info.bg_blue;
1073 uch *src, *src2=NULL, *dest;
1074 uch r, g, b, a;
1075 ulg i;
1076 static int rows=0;
1077 static ulg firstrow;
1078
1079/*---------------------------------------------------------------------------
1080 rows and firstrow simply track how many rows (and which ones) have not
1081 yet been displayed; alternatively, we could call InvalidateRect() for
1082 every row and not bother with the records-keeping.
1083 ---------------------------------------------------------------------------*/
1084
1085 Trace((stderr, "beginning rpng2_win_display_row()\n"))
1086
1087 if (rows == 0)
1088 firstrow = row; /* first row not yet displayed */
1089
1090 ++rows; /* count of rows received but not yet displayed */
1091
1092/*---------------------------------------------------------------------------
1093 Aside from the use of the rpng2_info struct and the lack of an outer
1094 loop (over rows), this routine is identical to rpng_win_display_image()
1095 in the non-progressive version of the program.
1096 ---------------------------------------------------------------------------*/
1097
1098 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1099 if (bg_image)
1100 src2 = bg_data + row*bg_rowbytes;
1101 dest = wimage_data + row*wimage_rowbytes;
1102
1103 if (rpng2_info.channels == 3) {
1104 for (i = rpng2_info.width; i > 0; --i) {
1105 r = *src++;
1106 g = *src++;
1107 b = *src++;
1108 *dest++ = b;
1109 *dest++ = g; /* note reverse order */
1110 *dest++ = r;
1111 }
1112 } else /* if (rpng2_info.channels == 4) */ {
1113 for (i = rpng2_info.width; i > 0; --i) {
1114 r = *src++;
1115 g = *src++;
1116 b = *src++;
1117 a = *src++;
1118 if (bg_image) {
1119 bg_red = *src2++;
1120 bg_green = *src2++;
1121 bg_blue = *src2++;
1122 }
1123 if (a == 255) {
1124 *dest++ = b;
1125 *dest++ = g;
1126 *dest++ = r;
1127 } else if (a == 0) {
1128 *dest++ = bg_blue;
1129 *dest++ = bg_green;
1130 *dest++ = bg_red;
1131 } else {
1132 /* this macro (copied from png.h) composites the
1133 * foreground and background values and puts the
1134 * result into the first argument; there are no
1135 * side effects with the first argument */
1136 alpha_composite(*dest++, b, a, bg_blue);
1137 alpha_composite(*dest++, g, a, bg_green);
1138 alpha_composite(*dest++, r, a, bg_red);
1139 }
1140 }
1141 }
1142
1143/*---------------------------------------------------------------------------
1144 Display after every 16 rows or when on last row. (Region may include
1145 previously displayed lines due to interlacing--i.e., not contiguous.)
1146 ---------------------------------------------------------------------------*/
1147
1148 if ((rows & 0xf) == 0 || row == rpng2_info.height-1) {
1149 RECT rect;
1150
1151 rect.left = 0L;
1152 rect.top = (LONG)firstrow;
1153 rect.right = (LONG)rpng2_info.width; /* possibly off by one? */
1154 rect.bottom = (LONG)row + 1L; /* possibly off by one? */
1155 InvalidateRect(global_hwnd, &rect, FALSE);
1156 UpdateWindow(global_hwnd); /* similar to XFlush() */
1157 rows = 0;
1158 }
1159
1160} /* end function rpng2_win_display_row() */
1161
1162
1163
1164
1165
1166static void rpng2_win_finish_display()
1167{
1168 Trace((stderr, "beginning rpng2_win_finish_display()\n"))
1169
1170 /* last row has already been displayed by rpng2_win_display_row(), so
1171 * we have nothing to do here except set a flag and let the user know
1172 * that the image is done */
1173
1174 rpng2_info.state = kDone;
1175 printf(
1176#ifndef __CYGWIN__
1177 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"
1178#else
1179 "Done. Press mouse button 1 (within image window) to quit.\n"
1180#endif
1181 );
1182 fflush(stdout);
1183}
1184
1185
1186
1187
1188
1189static void rpng2_win_cleanup()
1190{
1191 if (bg_image && bg_data) {
1192 free(bg_data);
1193 bg_data = NULL;
1194 }
1195
1196 if (rpng2_info.image_data) {
1197 free(rpng2_info.image_data);
1198 rpng2_info.image_data = NULL;
1199 }
1200
1201 if (rpng2_info.row_pointers) {
1202 free(rpng2_info.row_pointers);
1203 rpng2_info.row_pointers = NULL;
1204 }
1205
1206 if (dib) {
1207 free(dib);
1208 dib = NULL;
1209 }
1210}
1211
1212
1213
1214
1215
1216LRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
1217{
1218 HDC hdc;
1219 PAINTSTRUCT ps;
1220 int rc;
1221
1222 switch (iMsg) {
1223 case WM_CREATE:
1224 /* one-time processing here, if any */
1225 return 0;
1226
1227 case WM_PAINT:
1228 hdc = BeginPaint(hwnd, &ps);
1229 rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height,
1230 0, 0, rpng2_info.width, rpng2_info.height,
1231 wimage_data, (BITMAPINFO *)bmih,
1232 0, SRCCOPY);
1233 EndPaint(hwnd, &ps);
1234 return 0;
1235
1236 /* wait for the user to tell us when to quit */
1237 case WM_CHAR:
1238 switch (wP) { /* only need one, so ignore repeat count */
1239 case 'q':
1240 case 'Q':
1241 case 0x1B: /* Esc key */
1242 PostQuitMessage(0);
1243 }
1244 return 0;
1245
1246 case WM_LBUTTONDOWN: /* another way of quitting */
1247 case WM_DESTROY:
1248 PostQuitMessage(0);
1249 return 0;
1250 }
1251
1252 return DefWindowProc(hwnd, iMsg, wP, lP);
1253}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c
new file mode 100644
index 0000000..6c687db
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c
@@ -0,0 +1,2107 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program rpng2-x.c
4
5 This program decodes and displays PNG files progressively, as if it were
6 a web browser (though the front end is only set up to read from files).
7 It supports gamma correction, user-specified background colors, and user-
8 specified background patterns (for transparent images). This version is
9 for the X Window System (tested by the author under Unix and by Martin
10 Zinser under OpenVMS; may work under OS/2 with a little tweaking).
11
12 Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond"
13 and "radial waves" patterns, respectively.
14
15 to do (someday, maybe):
16 - fix expose/redraw code: don't draw entire row if only part exposed
17 - 8-bit (colormapped) X support
18 - finish resizable checkerboard-gradient (sizes 4-128?)
19 - use %.1023s to simplify truncation of title-bar string?
20
21 ---------------------------------------------------------------------------
22
23 Changelog:
24 - 1.01: initial public release
25 - 1.02: modified to allow abbreviated options; fixed char/uchar mismatch
26 - 1.10: added support for non-default visuals; fixed X pixel-conversion
27 - 1.11: added -usleep option for demos; fixed command-line parsing bug
28 - 1.12: added -pause option for demos and testing
29 - 1.20: added runtime MMX-enabling/disabling and new -mmx* options
30 - 1.21: fixed some small X memory leaks (thanks to François Petitjean)
31 - 1.22: fixed XFreeGC() crash bug (thanks to Patrick Welche)
32 - 1.23: added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares)
33 - 1.30: added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp =
34 24; added support for X resources (thanks to Gerhard Niklasch)
35 - 1.31: added code to skip unused chunks (thanks to Glenn Randers-Pehrson)
36 - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw
37 handling
38 - 2.00: dual-licensed (added GNU GPL)
39 - 2.01: fixed 64-bit typo in readpng2.c; fixed -pause usage description
40 - 2.02: fixed improper display of usage screen on PNG error(s); fixed
41 unexpected-EOF and file-read-error cases; fixed Trace() cut-and-
42 paste bugs
43 - 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options
44
45 ---------------------------------------------------------------------------
46
47 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
48
49 This software is provided "as is," without warranty of any kind,
50 express or implied. In no event shall the author or contributors
51 be held liable for any damages arising in any way from the use of
52 this software.
53
54 The contents of this file are DUAL-LICENSED. You may modify and/or
55 redistribute this software according to the terms of one of the
56 following two licenses (at your option):
57
58
59 LICENSE 1 ("BSD-like with advertising clause"):
60
61 Permission is granted to anyone to use this software for any purpose,
62 including commercial applications, and to alter it and redistribute
63 it freely, subject to the following restrictions:
64
65 1. Redistributions of source code must retain the above copyright
66 notice, disclaimer, and this list of conditions.
67 2. Redistributions in binary form must reproduce the above copyright
68 notice, disclaimer, and this list of conditions in the documenta-
69 tion and/or other materials provided with the distribution.
70 3. All advertising materials mentioning features or use of this
71 software must display the following acknowledgment:
72
73 This product includes software developed by Greg Roelofs
74 and contributors for the book, "PNG: The Definitive Guide,"
75 published by O'Reilly and Associates.
76
77
78 LICENSE 2 (GNU GPL v2 or later):
79
80 This program is free software; you can redistribute it and/or modify
81 it under the terms of the GNU General Public License as published by
82 the Free Software Foundation; either version 2 of the License, or
83 (at your option) any later version.
84
85 This program is distributed in the hope that it will be useful,
86 but WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 GNU General Public License for more details.
89
90 You should have received a copy of the GNU General Public License
91 along with this program; if not, write to the Free Software Foundation,
92 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
93
94 ---------------------------------------------------------------------------*/
95
96#define PROGNAME "rpng2-x"
97#define LONGNAME "Progressive PNG Viewer for X"
98#define VERSION "2.03 of 25 February 2010"
99#define RESNAME "rpng2" /* our X resource application name */
100#define RESCLASS "Rpng" /* our X resource class name */
101
102#include <stdio.h>
103#include <stdlib.h>
104#include <ctype.h>
105#include <string.h>
106#include <setjmp.h> /* for jmpbuf declaration in readpng2.h */
107#include <time.h>
108#include <math.h> /* only for PvdM background code */
109#include <X11/Xlib.h>
110#include <X11/Xutil.h>
111#include <X11/Xos.h>
112#include <X11/keysym.h> /* defines XK_* macros */
113
114#ifdef VMS
115# include <unistd.h>
116#endif
117
118/* all for PvdM background code: */
119#ifndef PI
120# define PI 3.141592653589793238
121#endif
122#define PI_2 (PI*0.5)
123#define INV_PI_360 (360.0 / PI)
124#define MAX(a,b) (a>b?a:b)
125#define MIN(a,b) (a<b?a:b)
126#define CLIP(a,min,max) MAX(min,MIN((a),max))
127#define ABS(a) ((a)<0?-(a):(a))
128#define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */
129#define ROUNDF(f) ((int)(f + 0.5))
130
131#define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) || \
132 (e.type == KeyPress && /* v--- or 1 for shifted keys */ \
133 ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape)))
134
135#define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */
136
137#define rgb1_max bg_freq
138#define rgb1_min bg_gray
139#define rgb2_max bg_bsat
140#define rgb2_min bg_brot
141
142/* #define DEBUG */ /* this enables the Trace() macros */
143
144#include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */
145
146
147/* could just include png.h, but this macro is the only thing we need
148 * (name and typedefs changed to local versions); note that side effects
149 * only happen with alpha (which could easily be avoided with
150 * "ush acopy = (alpha);") */
151
152#define alpha_composite(composite, fg, alpha, bg) { \
153 ush temp = ((ush)(fg)*(ush)(alpha) + \
154 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
155 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
156}
157
158
159#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this
160 * block size corresponds roughly to a download
161 * speed 10% faster than theoretical 33.6K maximum
162 * (assuming 8 data bits, 1 stop bit and no other
163 * overhead) */
164
165/* local prototypes */
166static void rpng2_x_init (void);
167static int rpng2_x_create_window (void);
168static int rpng2_x_load_bg_image (void);
169static void rpng2_x_display_row (ulg row);
170static void rpng2_x_finish_display (void);
171static void rpng2_x_redisplay_image (ulg startcol, ulg startrow,
172 ulg width, ulg height);
173#ifdef FEATURE_LOOP
174static void rpng2_x_reload_bg_image (void);
175static int is_number (char *p);
176#endif
177static void rpng2_x_cleanup (void);
178static int rpng2_x_msb (ulg u32val);
179
180
181static char titlebar[1024], *window_name = titlebar;
182static char *appname = LONGNAME;
183static char *icon_name = PROGNAME;
184static char *res_name = RESNAME;
185static char *res_class = RESCLASS;
186static char *filename;
187static FILE *infile;
188
189static mainprog_info rpng2_info;
190
191static uch inbuf[INBUFSIZE];
192static int incount;
193
194static int pat = 6; /* must be less than num_bgpat */
195static int bg_image = 0;
196static int bgscale, bgscale_default = 16;
197static ulg bg_rowbytes;
198static uch *bg_data;
199
200int pause_after_pass = FALSE;
201int demo_timing = FALSE;
202ulg usleep_duration = 0L;
203
204static struct rgb_color {
205 uch r, g, b;
206} rgb[] = {
207 { 0, 0, 0}, /* 0: black */
208 {255, 255, 255}, /* 1: white */
209 {173, 132, 57}, /* 2: tan */
210 { 64, 132, 0}, /* 3: medium green */
211 {189, 117, 1}, /* 4: gold */
212 {253, 249, 1}, /* 5: yellow */
213 { 0, 0, 255}, /* 6: blue */
214 { 0, 0, 120}, /* 7: medium blue */
215 {255, 0, 255}, /* 8: magenta */
216 { 64, 0, 64}, /* 9: dark magenta */
217 {255, 0, 0}, /* 10: red */
218 { 64, 0, 0}, /* 11: dark red */
219 {255, 127, 0}, /* 12: orange */
220 {192, 96, 0}, /* 13: darker orange */
221 { 24, 60, 0}, /* 14: dark green-yellow */
222 { 85, 125, 200}, /* 15: ice blue */
223 {192, 192, 192} /* 16: Netscape/Mosaic gray */
224};
225/* not used for now, but should be for error-checking:
226static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);
227 */
228
229/*
230 This whole struct is a fairly cheesy way to keep the number of
231 command-line options to a minimum. The radial-waves background
232 type is a particularly poor fit to the integer elements of the
233 struct...but a few macros and a little fixed-point math will do
234 wonders for ya.
235
236 type bits:
237 F E D C B A 9 8 7 6 5 4 3 2 1 0
238 | | | | |
239 | | +-+-+-- 0 = sharp-edged checkerboard
240 | | 1 = soft diamonds
241 | | 2 = radial waves
242 | | 3-7 = undefined
243 | +-- gradient #2 inverted?
244 +-- alternating columns inverted?
245 */
246static struct background_pattern {
247 ush type;
248 int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */
249 int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/
250} bg[] = {
251 {0, 1,1, 16,16}, /* checkered: white vs. light gray (basic) */
252 {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */
253 {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */
254 {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */
255 {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */
256 {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */
257 {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */
258 {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */
259 {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */
260 {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */
261 {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */
262 {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */
263 {1, 3,0, 0,0}, /* diamonds: medium green vs. black */
264 {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */
265 {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */
266 {2, 16, 256, 100, 250}, /* radial: very tight spiral */
267 {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */
268};
269static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);
270
271
272/* X-specific variables */
273static char *displayname;
274static XImage *ximage;
275static Display *display;
276static int depth;
277static Visual *visual;
278static XVisualInfo *visual_list;
279static int RShift, GShift, BShift;
280static ulg RMask, GMask, BMask;
281static Window window;
282static GC gc;
283static Colormap colormap;
284
285static int have_nondefault_visual = FALSE;
286static int have_colormap = FALSE;
287static int have_window = FALSE;
288static int have_gc = FALSE;
289
290
291
292
293int main(int argc, char **argv)
294{
295#ifdef sgi
296 char tmpline[80];
297#endif
298 char *p, *bgstr = NULL;
299 int rc, alen, flen;
300 int error = 0;
301 int timing = FALSE;
302 int have_bg = FALSE;
303#ifdef FEATURE_LOOP
304 int loop = FALSE;
305 long loop_interval = -1; /* seconds (100,000 max) */
306#endif
307 double LUT_exponent; /* just the lookup table */
308 double CRT_exponent = 2.2; /* just the monitor */
309 double default_display_exponent; /* whole display system */
310 XEvent e;
311 KeySym k;
312
313
314 /* First initialize a few things, just to be sure--memset takes care of
315 * default background color (black), booleans (FALSE), pointers (NULL),
316 * etc. */
317
318 displayname = (char *)NULL;
319 filename = (char *)NULL;
320 memset(&rpng2_info, 0, sizeof(mainprog_info));
321
322
323 /* Set the default value for our display-system exponent, i.e., the
324 * product of the CRT exponent and the exponent corresponding to
325 * the frame-buffer's lookup table (LUT), if any. This is not an
326 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
327 * ones), but it should cover 99% of the current possibilities. */
328
329#if defined(NeXT)
330 /* third-party utilities can modify the default LUT exponent */
331 LUT_exponent = 1.0 / 2.2;
332 /*
333 if (some_next_function_that_returns_gamma(&next_gamma))
334 LUT_exponent = 1.0 / next_gamma;
335 */
336#elif defined(sgi)
337 LUT_exponent = 1.0 / 1.7;
338 /* there doesn't seem to be any documented function to
339 * get the "gamma" value, so we do it the hard way */
340 infile = fopen("/etc/config/system.glGammaVal", "r");
341 if (infile) {
342 double sgi_gamma;
343
344 fgets(tmpline, 80, infile);
345 fclose(infile);
346 sgi_gamma = atof(tmpline);
347 if (sgi_gamma > 0.0)
348 LUT_exponent = 1.0 / sgi_gamma;
349 }
350#elif defined(Macintosh)
351 LUT_exponent = 1.8 / 2.61;
352 /*
353 if (some_mac_function_that_returns_gamma(&mac_gamma))
354 LUT_exponent = mac_gamma / 2.61;
355 */
356#else
357 LUT_exponent = 1.0; /* assume no LUT: most PCs */
358#endif
359
360 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
361 default_display_exponent = LUT_exponent * CRT_exponent;
362
363
364 /* If the user has set the SCREEN_GAMMA environment variable as suggested
365 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
366 * use the default value we just calculated. Either way, the user may
367 * override this via a command-line option. */
368
369 if ((p = getenv("SCREEN_GAMMA")) != NULL)
370 rpng2_info.display_exponent = atof(p);
371 else
372 rpng2_info.display_exponent = default_display_exponent;
373
374
375 /* Now parse the command line for options and the PNG filename. */
376
377 while (*++argv && !error) {
378 if (!strncmp(*argv, "-display", 2)) {
379 if (!*++argv)
380 ++error;
381 else
382 displayname = *argv;
383 } else if (!strncmp(*argv, "-gamma", 2)) {
384 if (!*++argv)
385 ++error;
386 else {
387 rpng2_info.display_exponent = atof(*argv);
388 if (rpng2_info.display_exponent <= 0.0)
389 ++error;
390 }
391 } else if (!strncmp(*argv, "-bgcolor", 4)) {
392 if (!*++argv)
393 ++error;
394 else {
395 bgstr = *argv;
396 if (strlen(bgstr) != 7 || bgstr[0] != '#')
397 ++error;
398 else {
399 have_bg = TRUE;
400 bg_image = FALSE;
401 }
402 }
403 } else if (!strncmp(*argv, "-bgpat", 4)) {
404 if (!*++argv)
405 ++error;
406 else {
407 pat = atoi(*argv);
408 if (pat >= 0 && pat < num_bgpat) {
409 bg_image = TRUE;
410 have_bg = FALSE;
411 } else
412 ++error;
413 }
414 } else if (!strncmp(*argv, "-usleep", 2)) {
415 if (!*++argv)
416 ++error;
417 else {
418 usleep_duration = (ulg)atol(*argv);
419 demo_timing = TRUE;
420 }
421 } else if (!strncmp(*argv, "-pause", 2)) {
422 pause_after_pass = TRUE;
423 } else if (!strncmp(*argv, "-timing", 2)) {
424 timing = TRUE;
425#ifdef FEATURE_LOOP
426 } else if (!strncmp(*argv, "-loop", 2)) {
427 loop = TRUE;
428 if (!argv[1] || !is_number(argv[1]))
429 loop_interval = 2;
430 else {
431 ++argv;
432 loop_interval = atol(*argv);
433 if (loop_interval < 0)
434 loop_interval = 2;
435 else if (loop_interval > 100000) /* bit more than one day */
436 loop_interval = 100000;
437 }
438#endif
439 } else {
440 if (**argv != '-') {
441 filename = *argv;
442 if (argv[1]) /* shouldn't be any more args after filename */
443 ++error;
444 } else
445 ++error; /* not expecting any other options */
446 }
447 }
448
449 if (!filename)
450 ++error;
451
452
453 /* print usage screen if any errors up to this point */
454
455 if (error) {
456 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
457 readpng2_version_info();
458 fprintf(stderr, "\n"
459 "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n"
460#ifdef FEATURE_LOOP
461 " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n"
462#else
463 " %*s [-usleep dur | -timing] [-pause] file.png\n\n"
464#endif
465 " xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
466 " exp \ttransfer-function exponent (``gamma'') of the display\n"
467 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
468 "\t\t to the product of the lookup-table exponent (varies)\n"
469 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
470 " bg \tdesired background color in 7-character hex RGB format\n"
471 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
472 "\t\t used with transparent images; overrides -bgpat\n"
473 " pat \tdesired background pattern number (0-%d); used with\n"
474 "\t\t transparent images; overrides -bgcolor\n"
475#ifdef FEATURE_LOOP
476 " -loop\tloops through background images after initial display\n"
477 "\t\t is complete (depends on -bgpat)\n"
478 " sec \tseconds to display each background image (default = 2)\n"
479#endif
480 " dur \tduration in microseconds to wait after displaying each\n"
481 "\t\t row (for demo purposes)\n"
482 " -timing\tenables delay for every block read, to simulate modem\n"
483 "\t\t download of image (~36 Kbps)\n"
484 " -pause\tpauses after displaying each pass until mouse clicked\n"
485 "\nPress Q, Esc or mouse button 1 (within image window, after image\n"
486 "is displayed) to quit.\n"
487 "\n", PROGNAME,
488 (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1);
489 exit(1);
490 }
491
492
493 if (!(infile = fopen(filename, "rb"))) {
494 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
495 ++error;
496 } else {
497 incount = fread(inbuf, 1, INBUFSIZE, infile);
498 if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {
499 fprintf(stderr, PROGNAME
500 ": [%s] is not a PNG file: incorrect signature\n",
501 filename);
502 ++error;
503 } else if ((rc = readpng2_init(&rpng2_info)) != 0) {
504 switch (rc) {
505 case 2:
506 fprintf(stderr, PROGNAME
507 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
508 break;
509 case 4:
510 fprintf(stderr, PROGNAME ": insufficient memory\n");
511 break;
512 default:
513 fprintf(stderr, PROGNAME
514 ": unknown readpng2_init() error\n");
515 break;
516 }
517 ++error;
518 } else {
519 Trace((stderr, "about to call XOpenDisplay()\n"))
520 display = XOpenDisplay(displayname);
521 if (!display) {
522 readpng2_cleanup(&rpng2_info);
523 fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
524 displayname? displayname : "default");
525 ++error;
526 }
527 }
528 if (error)
529 fclose(infile);
530 }
531
532
533 if (error) {
534 fprintf(stderr, PROGNAME ": aborting.\n");
535 exit(2);
536 }
537
538
539 /* set the title-bar string, but make sure buffer doesn't overflow */
540
541 alen = strlen(appname);
542 flen = strlen(filename);
543 if (alen + flen + 3 > 1023)
544 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
545 else
546 sprintf(titlebar, "%s: %s", appname, filename);
547
548
549 /* set some final rpng2_info variables before entering main data loop */
550
551 if (have_bg) {
552 unsigned r, g, b; /* this approach quiets compiler warnings */
553
554 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
555 rpng2_info.bg_red = (uch)r;
556 rpng2_info.bg_green = (uch)g;
557 rpng2_info.bg_blue = (uch)b;
558 } else
559 rpng2_info.need_bgcolor = TRUE;
560
561 rpng2_info.state = kPreInit;
562 rpng2_info.mainprog_init = rpng2_x_init;
563 rpng2_info.mainprog_display_row = rpng2_x_display_row;
564 rpng2_info.mainprog_finish_display = rpng2_x_finish_display;
565
566
567 /* OK, this is the fun part: call readpng2_decode_data() at the start of
568 * the loop to deal with our first buffer of data (read in above to verify
569 * that the file is a PNG image), then loop through the file and continue
570 * calling the same routine to handle each chunk of data. It in turn
571 * passes the data to libpng, which will invoke one or more of our call-
572 * backs as decoded data become available. We optionally call sleep() for
573 * one second per iteration to simulate downloading the image via an analog
574 * modem. */
575
576 for (;;) {
577 Trace((stderr, "about to call readpng2_decode_data()\n"))
578 if (readpng2_decode_data(&rpng2_info, inbuf, incount))
579 ++error;
580 Trace((stderr, "done with readpng2_decode_data()\n"))
581
582 if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {
583 if (rpng2_info.state == kDone) {
584 Trace((stderr, "done decoding PNG image\n"))
585 } else if (ferror(infile)) {
586 fprintf(stderr, PROGNAME
587 ": error while reading PNG image file\n");
588 exit(3);
589 } else if (feof(infile)) {
590 fprintf(stderr, PROGNAME ": end of file reached "
591 "(unexpectedly) while reading PNG image file\n");
592 exit(3);
593 } else /* if (error) */ {
594 /* will print error message below */
595 }
596 break;
597 }
598
599 if (timing)
600 sleep(1);
601
602 incount = fread(inbuf, 1, INBUFSIZE, infile);
603 }
604
605
606 /* clean up PNG stuff and report any decoding errors */
607
608 fclose(infile);
609 Trace((stderr, "about to call readpng2_cleanup()\n"))
610 readpng2_cleanup(&rpng2_info);
611
612 if (error) {
613 fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n");
614 exit(3);
615 }
616
617
618#ifdef FEATURE_LOOP
619
620 if (loop && bg_image) {
621 Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n"))
622 for (;;) {
623 int i, use_sleep;
624 struct timeval now, then;
625
626 /* get current time and add loop_interval to get target time */
627 if (gettimeofday(&then, NULL) == 0) {
628 then.tv_sec += loop_interval;
629 use_sleep = FALSE;
630 } else
631 use_sleep = TRUE;
632
633 /* do quick check for a quit event but don't wait for it */
634 /* GRR BUG: should also check for Expose events and redraw... */
635 if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e))
636 if (QUIT(e,k))
637 break;
638
639 /* generate next background image */
640 if (++pat >= num_bgpat)
641 pat = 0;
642 rpng2_x_reload_bg_image();
643
644 /* wait for timeout, using whatever means are available */
645 if (use_sleep || gettimeofday(&now, NULL) != 0) {
646 for (i = loop_interval; i > 0; --i) {
647 sleep(1);
648 /* GRR BUG: also need to check for Expose (and redraw!) */
649 if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask,
650 &e) && QUIT(e,k))
651 break;
652 }
653 } else {
654 /* Y2038 BUG! */
655 if (now.tv_sec < then.tv_sec ||
656 (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec))
657 {
658 int quit = FALSE;
659 long seconds_to_go = then.tv_sec - now.tv_sec;
660 long usleep_usec;
661
662 /* basically chew up most of remaining loop-interval with
663 * calls to sleep(1) interleaved with checks for quit
664 * events, but also recalc time-to-go periodically; when
665 * done, clean up any remaining time with usleep() call
666 * (could also use SIGALRM, but signals are a pain...) */
667 while (seconds_to_go-- > 1) {
668 int seconds_done = 0;
669
670 for (i = seconds_to_go; i > 0 && !quit; --i) {
671 sleep(1);
672 /* GRR BUG: need to check for Expose and redraw */
673 if (XCheckMaskEvent(display, KeyPressMask |
674 ButtonPressMask, &e) && QUIT(e,k))
675 quit = TRUE;
676 if (++seconds_done > 1000)
677 break; /* time to redo seconds_to_go meas. */
678 }
679 if (quit)
680 break;
681
682 /* OK, more than 1000 seconds since last check:
683 * correct the time-to-go measurement for drift */
684 if (gettimeofday(&now, NULL) == 0) {
685 if (now.tv_sec >= then.tv_sec)
686 break;
687 seconds_to_go = then.tv_sec - now.tv_sec;
688 } else
689 ++seconds_to_go; /* restore what we subtracted */
690 }
691 if (quit)
692 break; /* breaks outer do-loop, skips redisplay */
693
694 /* since difference between "now" and "then" is already
695 * eaten up to within a couple of seconds, don't need to
696 * worry about overflow--but might have overshot (neg.) */
697 if (gettimeofday(&now, NULL) == 0) {
698 usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) +
699 then.tv_usec - now.tv_usec;
700 if (usleep_usec > 0)
701 usleep((ulg)usleep_usec);
702 }
703 }
704 }
705
706 /* composite image against new background and display (note that
707 * we do not take into account the time spent doing this...) */
708 rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height);
709 }
710
711 } else /* FALL THROUGH and do the normal thing */
712
713#endif /* FEATURE_LOOP */
714
715 /* wait for the user to tell us when to quit */
716
717 if (rpng2_info.state >= kWindowInit) {
718 Trace((stderr, "entering final wait-for-quit-event loop\n"))
719 do {
720 XNextEvent(display, &e);
721 if (e.type == Expose) {
722 XExposeEvent *ex = (XExposeEvent *)&e;
723 rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height);
724 }
725 } while (!QUIT(e,k));
726 } else {
727 fprintf(stderr, PROGNAME ": init callback never called: probable "
728 "libpng error while decoding PNG metadata\n");
729 exit(4);
730 }
731
732
733 /* we're done: clean up all image and X resources and go away */
734
735 Trace((stderr, "about to call rpng2_x_cleanup()\n"))
736 rpng2_x_cleanup();
737
738 return 0;
739}
740
741
742
743
744
745/* this function is called by readpng2_info_callback() in readpng2.c, which
746 * in turn is called by libpng after all of the pre-IDAT chunks have been
747 * read and processed--i.e., we now have enough info to finish initializing */
748
749static void rpng2_x_init(void)
750{
751 ulg i;
752 ulg rowbytes = rpng2_info.rowbytes;
753
754 Trace((stderr, "beginning rpng2_x_init()\n"))
755 Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes))
756 Trace((stderr, " width = %ld\n", rpng2_info.width))
757 Trace((stderr, " height = %ld\n", rpng2_info.height))
758
759 rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
760 if (!rpng2_info.image_data) {
761 readpng2_cleanup(&rpng2_info);
762 return;
763 }
764
765 rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));
766 if (!rpng2_info.row_pointers) {
767 free(rpng2_info.image_data);
768 rpng2_info.image_data = NULL;
769 readpng2_cleanup(&rpng2_info);
770 return;
771 }
772
773 for (i = 0; i < rpng2_info.height; ++i)
774 rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;
775
776
777 /* do the basic X initialization stuff, make the window, and fill it with
778 * the user-specified, file-specified or default background color or
779 * pattern */
780
781 if (rpng2_x_create_window()) {
782
783 /* GRR TEMPORARY HACK: this is fundamentally no different from cases
784 * above; libpng should call our error handler to longjmp() back to us
785 * when png_ptr goes away. If we/it segfault instead, seems like a
786 * libpng bug... */
787
788 /* we're here via libpng callback, so if window fails, clean and bail */
789 readpng2_cleanup(&rpng2_info);
790 rpng2_x_cleanup();
791 exit(2);
792 }
793
794 rpng2_info.state = kWindowInit;
795}
796
797
798
799
800
801static int rpng2_x_create_window(void)
802{
803 ulg bg_red = rpng2_info.bg_red;
804 ulg bg_green = rpng2_info.bg_green;
805 ulg bg_blue = rpng2_info.bg_blue;
806 ulg bg_pixel = 0L;
807 ulg attrmask;
808 int need_colormap = FALSE;
809 int screen, pad;
810 uch *xdata;
811 Window root;
812 XEvent e;
813 XGCValues gcvalues;
814 XSetWindowAttributes attr;
815 XTextProperty windowName, *pWindowName = &windowName;
816 XTextProperty iconName, *pIconName = &iconName;
817 XVisualInfo visual_info;
818 XSizeHints *size_hints;
819 XWMHints *wm_hints;
820 XClassHint *class_hints;
821
822
823 Trace((stderr, "beginning rpng2_x_create_window()\n"))
824
825 screen = DefaultScreen(display);
826 depth = DisplayPlanes(display, screen);
827 root = RootWindow(display, screen);
828
829#ifdef DEBUG
830 XSynchronize(display, True);
831#endif
832
833 if (depth != 16 && depth != 24 && depth != 32) {
834 int visuals_matched = 0;
835
836 Trace((stderr, "default depth is %d: checking other visuals\n",
837 depth))
838
839 /* 24-bit first */
840 visual_info.screen = screen;
841 visual_info.depth = 24;
842 visual_list = XGetVisualInfo(display,
843 VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
844 if (visuals_matched == 0) {
845/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
846 fprintf(stderr, "default screen depth %d not supported, and no"
847 " 24-bit visuals found\n", depth);
848 return 2;
849 }
850 Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
851 visuals_matched))
852 visual = visual_list[0].visual;
853 depth = visual_list[0].depth;
854/*
855 colormap_size = visual_list[0].colormap_size;
856 visual_class = visual->class;
857 visualID = XVisualIDFromVisual(visual);
858 */
859 have_nondefault_visual = TRUE;
860 need_colormap = TRUE;
861 } else {
862 XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
863 visual = visual_info.visual;
864 }
865
866 RMask = visual->red_mask;
867 GMask = visual->green_mask;
868 BMask = visual->blue_mask;
869
870/* GRR: add/check 8-bit support */
871 if (depth == 8 || need_colormap) {
872 colormap = XCreateColormap(display, root, visual, AllocNone);
873 if (!colormap) {
874 fprintf(stderr, "XCreateColormap() failed\n");
875 return 2;
876 }
877 have_colormap = TRUE;
878 if (depth == 8)
879 bg_image = FALSE; /* gradient just wastes palette entries */
880 }
881 if (depth == 15 || depth == 16) {
882 RShift = 15 - rpng2_x_msb(RMask); /* these are right-shifts */
883 GShift = 15 - rpng2_x_msb(GMask);
884 BShift = 15 - rpng2_x_msb(BMask);
885 } else if (depth > 16) {
886 RShift = rpng2_x_msb(RMask) - 7; /* these are left-shifts */
887 GShift = rpng2_x_msb(GMask) - 7;
888 BShift = rpng2_x_msb(BMask) - 7;
889 }
890 if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
891 fprintf(stderr, "rpng2 internal logic error: negative X shift(s)!\n");
892 return 2;
893 }
894
895/*---------------------------------------------------------------------------
896 Finally, create the window.
897 ---------------------------------------------------------------------------*/
898
899 attr.backing_store = Always;
900 attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
901 attrmask = CWBackingStore | CWEventMask;
902 if (have_nondefault_visual) {
903 attr.colormap = colormap;
904 attr.background_pixel = 0;
905 attr.border_pixel = 1;
906 attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
907 }
908
909 window = XCreateWindow(display, root, 0, 0, rpng2_info.width,
910 rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr);
911
912 if (window == None) {
913 fprintf(stderr, "XCreateWindow() failed\n");
914 return 2;
915 } else
916 have_window = TRUE;
917
918 if (depth == 8)
919 XSetWindowColormap(display, window, colormap);
920
921 if (!XStringListToTextProperty(&window_name, 1, pWindowName))
922 pWindowName = NULL;
923 if (!XStringListToTextProperty(&icon_name, 1, pIconName))
924 pIconName = NULL;
925
926 /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */
927
928 if ((size_hints = XAllocSizeHints()) != NULL) {
929 /* window will not be resizable */
930 size_hints->flags = PMinSize | PMaxSize;
931 size_hints->min_width = size_hints->max_width = (int)rpng2_info.width;
932 size_hints->min_height = size_hints->max_height =
933 (int)rpng2_info.height;
934 }
935
936 if ((wm_hints = XAllocWMHints()) != NULL) {
937 wm_hints->initial_state = NormalState;
938 wm_hints->input = True;
939 /* wm_hints->icon_pixmap = icon_pixmap; */
940 wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
941 }
942
943 if ((class_hints = XAllocClassHint()) != NULL) {
944 class_hints->res_name = res_name;
945 class_hints->res_class = res_class;
946 }
947
948 XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
949 size_hints, wm_hints, class_hints);
950
951 /* various properties and hints no longer needed; free memory */
952 if (pWindowName)
953 XFree(pWindowName->value);
954 if (pIconName)
955 XFree(pIconName->value);
956 if (size_hints)
957 XFree(size_hints);
958 if (wm_hints)
959 XFree(wm_hints);
960 if (class_hints)
961 XFree(class_hints);
962
963 XMapWindow(display, window);
964
965 gc = XCreateGC(display, window, 0, &gcvalues);
966 have_gc = TRUE;
967
968/*---------------------------------------------------------------------------
969 Allocate memory for the X- and display-specific version of the image.
970 ---------------------------------------------------------------------------*/
971
972 if (depth == 24 || depth == 32) {
973 xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height);
974 pad = 32;
975 } else if (depth == 16) {
976 xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height);
977 pad = 16;
978 } else /* depth == 8 */ {
979 xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height);
980 pad = 8;
981 }
982
983 if (!xdata) {
984 fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
985 return 4;
986 }
987
988 ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
989 (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0);
990
991 if (!ximage) {
992 fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
993 free(xdata);
994 return 3;
995 }
996
997 /* to avoid testing the byte order every pixel (or doubling the size of
998 * the drawing routine with a giant if-test), we arbitrarily set the byte
999 * order to MSBFirst and let Xlib worry about inverting things on little-
1000 * endian machines (e.g., Linux/x86, old VAXen, etc.)--this is not the
1001 * most efficient approach (the giant if-test would be better), but in
1002 * the interest of clarity, we'll take the easy way out... */
1003
1004 ximage->byte_order = MSBFirst;
1005
1006/*---------------------------------------------------------------------------
1007 Fill window with the specified background color (default is black) or
1008 faked "background image" (but latter is disabled if 8-bit; gradients
1009 just waste palette entries).
1010 ---------------------------------------------------------------------------*/
1011
1012 if (bg_image)
1013 rpng2_x_load_bg_image(); /* resets bg_image if fails */
1014
1015 if (!bg_image) {
1016 if (depth == 24 || depth == 32) {
1017 bg_pixel = (bg_red << RShift) |
1018 (bg_green << GShift) |
1019 (bg_blue << BShift);
1020 } else if (depth == 16) {
1021 bg_pixel = (((bg_red << 8) >> RShift) & RMask) |
1022 (((bg_green << 8) >> GShift) & GMask) |
1023 (((bg_blue << 8) >> BShift) & BMask);
1024 } else /* depth == 8 */ {
1025
1026 /* GRR: add 8-bit support */
1027
1028 }
1029 XSetForeground(display, gc, bg_pixel);
1030 XFillRectangle(display, window, gc, 0, 0, rpng2_info.width,
1031 rpng2_info.height);
1032 }
1033
1034/*---------------------------------------------------------------------------
1035 Wait for first Expose event to do any drawing, then flush and return.
1036 ---------------------------------------------------------------------------*/
1037
1038 do
1039 XNextEvent(display, &e);
1040 while (e.type != Expose || e.xexpose.count);
1041
1042 XFlush(display);
1043
1044 return 0;
1045
1046} /* end function rpng2_x_create_window() */
1047
1048
1049
1050
1051
1052static int rpng2_x_load_bg_image(void)
1053{
1054 uch *src;
1055 char *dest;
1056 uch r1, r2, g1, g2, b1, b2;
1057 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
1058 int k, hmax, max;
1059 int xidx, yidx, yidx_max;
1060 int even_odd_vert, even_odd_horiz, even_odd;
1061 int invert_gradient2 = (bg[pat].type & 0x08);
1062 int invert_column;
1063 int ximage_rowbytes = ximage->bytes_per_line;
1064 ulg i, row;
1065 ulg pixel;
1066
1067/*---------------------------------------------------------------------------
1068 Allocate buffer for fake background image to be used with transparent
1069 images; if this fails, revert to plain background color.
1070 ---------------------------------------------------------------------------*/
1071
1072 bg_rowbytes = 3 * rpng2_info.width;
1073 bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);
1074 if (!bg_data) {
1075 fprintf(stderr, PROGNAME
1076 ": unable to allocate memory for background image\n");
1077 bg_image = 0;
1078 return 1;
1079 }
1080
1081 bgscale = (pat == 0)? 8 : bgscale_default;
1082 yidx_max = bgscale - 1;
1083
1084/*---------------------------------------------------------------------------
1085 Vertical gradients (ramps) in NxN squares, alternating direction and
1086 colors (N == bgscale).
1087 ---------------------------------------------------------------------------*/
1088
1089 if ((bg[pat].type & 0x07) == 0) {
1090 uch r1_min = rgb[bg[pat].rgb1_min].r;
1091 uch g1_min = rgb[bg[pat].rgb1_min].g;
1092 uch b1_min = rgb[bg[pat].rgb1_min].b;
1093 uch r2_min = rgb[bg[pat].rgb2_min].r;
1094 uch g2_min = rgb[bg[pat].rgb2_min].g;
1095 uch b2_min = rgb[bg[pat].rgb2_min].b;
1096 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
1097 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
1098 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
1099 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
1100 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
1101 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
1102
1103 for (row = 0; row < rpng2_info.height; ++row) {
1104 yidx = (int)(row % bgscale);
1105 even_odd_vert = (int)((row / bgscale) & 1);
1106
1107 r1 = r1_min + (r1_diff * yidx) / yidx_max;
1108 g1 = g1_min + (g1_diff * yidx) / yidx_max;
1109 b1 = b1_min + (b1_diff * yidx) / yidx_max;
1110 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
1111 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
1112 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
1113
1114 r2 = r2_min + (r2_diff * yidx) / yidx_max;
1115 g2 = g2_min + (g2_diff * yidx) / yidx_max;
1116 b2 = b2_min + (b2_diff * yidx) / yidx_max;
1117 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
1118 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
1119 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
1120
1121 dest = (char *)bg_data + row*bg_rowbytes;
1122 for (i = 0; i < rpng2_info.width; ++i) {
1123 even_odd_horiz = (int)((i / bgscale) & 1);
1124 even_odd = even_odd_vert ^ even_odd_horiz;
1125 invert_column =
1126 (even_odd_horiz && (bg[pat].type & 0x10));
1127 if (even_odd == 0) { /* gradient #1 */
1128 if (invert_column) {
1129 *dest++ = r1_inv;
1130 *dest++ = g1_inv;
1131 *dest++ = b1_inv;
1132 } else {
1133 *dest++ = r1;
1134 *dest++ = g1;
1135 *dest++ = b1;
1136 }
1137 } else { /* gradient #2 */
1138 if ((invert_column && invert_gradient2) ||
1139 (!invert_column && !invert_gradient2))
1140 {
1141 *dest++ = r2; /* not inverted or */
1142 *dest++ = g2; /* doubly inverted */
1143 *dest++ = b2;
1144 } else {
1145 *dest++ = r2_inv;
1146 *dest++ = g2_inv; /* singly inverted */
1147 *dest++ = b2_inv;
1148 }
1149 }
1150 }
1151 }
1152
1153/*---------------------------------------------------------------------------
1154 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
1155 M. Costello.
1156 ---------------------------------------------------------------------------*/
1157
1158 } else if ((bg[pat].type & 0x07) == 1) {
1159
1160 hmax = (bgscale-1)/2; /* half the max weight of a color */
1161 max = 2*hmax; /* the max weight of a color */
1162
1163 r1 = rgb[bg[pat].rgb1_max].r;
1164 g1 = rgb[bg[pat].rgb1_max].g;
1165 b1 = rgb[bg[pat].rgb1_max].b;
1166 r2 = rgb[bg[pat].rgb2_max].r;
1167 g2 = rgb[bg[pat].rgb2_max].g;
1168 b2 = rgb[bg[pat].rgb2_max].b;
1169
1170 for (row = 0; row < rpng2_info.height; ++row) {
1171 yidx = (int)(row % bgscale);
1172 if (yidx > hmax)
1173 yidx = bgscale-1 - yidx;
1174 dest = (char *)bg_data + row*bg_rowbytes;
1175 for (i = 0; i < rpng2_info.width; ++i) {
1176 xidx = (int)(i % bgscale);
1177 if (xidx > hmax)
1178 xidx = bgscale-1 - xidx;
1179 k = xidx + yidx;
1180 *dest++ = (k*r1 + (max-k)*r2) / max;
1181 *dest++ = (k*g1 + (max-k)*g2) / max;
1182 *dest++ = (k*b1 + (max-k)*b2) / max;
1183 }
1184 }
1185
1186/*---------------------------------------------------------------------------
1187 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
1188 soids will equal bgscale?]. This one is slow but very cool. Code con-
1189 tributed by Pieter S. van der Meulen (originally in Smalltalk).
1190 ---------------------------------------------------------------------------*/
1191
1192 } else if ((bg[pat].type & 0x07) == 2) {
1193 uch ch;
1194 int ii, x, y, hw, hh, grayspot;
1195 double freq, rotate, saturate, gray, intensity;
1196 double angle=0.0, aoffset=0.0, maxDist, dist;
1197 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
1198
1199 fprintf(stderr, "%s: computing radial background...",
1200 PROGNAME);
1201 fflush(stderr);
1202
1203 hh = (int)(rpng2_info.height / 2);
1204 hw = (int)(rpng2_info.width / 2);
1205
1206 /* variables for radial waves:
1207 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
1208 * freq: number of color beams originating from the center
1209 * grayspot: size of the graying center area (anti-alias)
1210 * rotate: rotation of the beams as a function of radius
1211 * saturate: saturation of beams' shape azimuthally
1212 */
1213 angle = CLIP(angle, 0.0, 360.0);
1214 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
1215 freq = MAX((double)bg[pat].bg_freq, 0.0);
1216 saturate = (double)bg[pat].bg_bsat * 0.1;
1217 rotate = (double)bg[pat].bg_brot * 0.1;
1218 gray = 0.0;
1219 intensity = 0.0;
1220 maxDist = (double)((hw*hw) + (hh*hh));
1221
1222 for (row = 0; row < rpng2_info.height; ++row) {
1223 y = (int)(row - hh);
1224 dest = (char *)bg_data + row*bg_rowbytes;
1225 for (i = 0; i < rpng2_info.width; ++i) {
1226 x = (int)(i - hw);
1227 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1228 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1229 gray = MIN(1.0, gray);
1230 dist = (double)((x*x) + (y*y)) / maxDist;
1231 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1232 gray * saturate;
1233 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1234 hue = (angle + PI) * INV_PI_360 + aoffset;
1235 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
1236 s = MIN(MAX(s,0.0), 1.0);
1237 v = MIN(MAX(intensity,0.0), 1.0);
1238
1239 if (s == 0.0) {
1240 ch = (uch)(v * 255.0);
1241 *dest++ = ch;
1242 *dest++ = ch;
1243 *dest++ = ch;
1244 } else {
1245 if ((hue < 0.0) || (hue >= 360.0))
1246 hue -= (((int)(hue / 360.0)) * 360.0);
1247 hue /= 60.0;
1248 ii = (int)hue;
1249 f = hue - (double)ii;
1250 p = (1.0 - s) * v;
1251 q = (1.0 - (s * f)) * v;
1252 t = (1.0 - (s * (1.0 - f))) * v;
1253 if (ii == 0) { red = v; green = t; blue = p; }
1254 else if (ii == 1) { red = q; green = v; blue = p; }
1255 else if (ii == 2) { red = p; green = v; blue = t; }
1256 else if (ii == 3) { red = p; green = q; blue = v; }
1257 else if (ii == 4) { red = t; green = p; blue = v; }
1258 else if (ii == 5) { red = v; green = p; blue = q; }
1259 *dest++ = (uch)(red * 255.0);
1260 *dest++ = (uch)(green * 255.0);
1261 *dest++ = (uch)(blue * 255.0);
1262 }
1263 }
1264 }
1265 fprintf(stderr, "done.\n");
1266 fflush(stderr);
1267 }
1268
1269/*---------------------------------------------------------------------------
1270 Blast background image to display buffer before beginning PNG decode.
1271 ---------------------------------------------------------------------------*/
1272
1273 if (depth == 24 || depth == 32) {
1274 ulg red, green, blue;
1275 int bpp = ximage->bits_per_pixel;
1276
1277 for (row = 0; row < rpng2_info.height; ++row) {
1278 src = bg_data + row*bg_rowbytes;
1279 dest = ximage->data + row*ximage_rowbytes;
1280 if (bpp == 32) { /* slightly optimized version */
1281 for (i = rpng2_info.width; i > 0; --i) {
1282 red = *src++;
1283 green = *src++;
1284 blue = *src++;
1285 pixel = (red << RShift) |
1286 (green << GShift) |
1287 (blue << BShift);
1288 /* recall that we set ximage->byte_order = MSBFirst above */
1289 *dest++ = (char)((pixel >> 24) & 0xff);
1290 *dest++ = (char)((pixel >> 16) & 0xff);
1291 *dest++ = (char)((pixel >> 8) & 0xff);
1292 *dest++ = (char)( pixel & 0xff);
1293 }
1294 } else {
1295 for (i = rpng2_info.width; i > 0; --i) {
1296 red = *src++;
1297 green = *src++;
1298 blue = *src++;
1299 pixel = (red << RShift) |
1300 (green << GShift) |
1301 (blue << BShift);
1302 /* recall that we set ximage->byte_order = MSBFirst above */
1303 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1304 /* (probably need to use RShift, RMask, etc.) */
1305 *dest++ = (char)((pixel >> 16) & 0xff);
1306 *dest++ = (char)((pixel >> 8) & 0xff);
1307 *dest++ = (char)( pixel & 0xff);
1308 }
1309 }
1310 }
1311
1312 } else if (depth == 16) {
1313 ush red, green, blue;
1314
1315 for (row = 0; row < rpng2_info.height; ++row) {
1316 src = bg_data + row*bg_rowbytes;
1317 dest = ximage->data + row*ximage_rowbytes;
1318 for (i = rpng2_info.width; i > 0; --i) {
1319 red = ((ush)(*src) << 8); ++src;
1320 green = ((ush)(*src) << 8); ++src;
1321 blue = ((ush)(*src) << 8); ++src;
1322 pixel = ((red >> RShift) & RMask) |
1323 ((green >> GShift) & GMask) |
1324 ((blue >> BShift) & BMask);
1325 /* recall that we set ximage->byte_order = MSBFirst above */
1326 *dest++ = (char)((pixel >> 8) & 0xff);
1327 *dest++ = (char)( pixel & 0xff);
1328 }
1329 }
1330
1331 } else /* depth == 8 */ {
1332
1333 /* GRR: add 8-bit support */
1334
1335 }
1336
1337 XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width,
1338 rpng2_info.height);
1339
1340 return 0;
1341
1342} /* end function rpng2_x_load_bg_image() */
1343
1344
1345
1346
1347
1348static void rpng2_x_display_row(ulg row)
1349{
1350 uch bg_red = rpng2_info.bg_red;
1351 uch bg_green = rpng2_info.bg_green;
1352 uch bg_blue = rpng2_info.bg_blue;
1353 uch *src, *src2=NULL;
1354 char *dest;
1355 uch r, g, b, a;
1356 int ximage_rowbytes = ximage->bytes_per_line;
1357 ulg i, pixel;
1358 static int rows=0, prevpass=(-1);
1359 static ulg firstrow;
1360
1361/*---------------------------------------------------------------------------
1362 rows and firstrow simply track how many rows (and which ones) have not
1363 yet been displayed; alternatively, we could call XPutImage() for every
1364 row and not bother with the records-keeping.
1365 ---------------------------------------------------------------------------*/
1366
1367 Trace((stderr, "beginning rpng2_x_display_row()\n"))
1368
1369 if (rpng2_info.pass != prevpass) {
1370 if (pause_after_pass && rpng2_info.pass > 0) {
1371 XEvent e;
1372 KeySym k;
1373
1374 fprintf(stderr,
1375 "%s: end of pass %d of 7; click in image window to continue\n",
1376 PROGNAME, prevpass + 1);
1377 do
1378 XNextEvent(display, &e);
1379 while (!QUIT(e,k));
1380 }
1381 fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1);
1382 fflush(stderr);
1383 prevpass = rpng2_info.pass;
1384 }
1385
1386 if (rows == 0)
1387 firstrow = row; /* first row that is not yet displayed */
1388
1389 ++rows; /* count of rows received but not yet displayed */
1390
1391/*---------------------------------------------------------------------------
1392 Aside from the use of the rpng2_info struct, the lack of an outer loop
1393 (over rows) and moving the XPutImage() call outside the "if (depth)"
1394 tests, this routine is identical to rpng_x_display_image() in the non-
1395 progressive version of the program.
1396 ---------------------------------------------------------------------------*/
1397
1398 if (depth == 24 || depth == 32) {
1399 ulg red, green, blue;
1400 int bpp = ximage->bits_per_pixel;
1401
1402 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1403 if (bg_image)
1404 src2 = bg_data + row*bg_rowbytes;
1405 dest = ximage->data + row*ximage_rowbytes;
1406 if (rpng2_info.channels == 3) {
1407 for (i = rpng2_info.width; i > 0; --i) {
1408 red = *src++;
1409 green = *src++;
1410 blue = *src++;
1411 pixel = (red << RShift) |
1412 (green << GShift) |
1413 (blue << BShift);
1414 /* recall that we set ximage->byte_order = MSBFirst above */
1415 if (bpp == 32) {
1416 *dest++ = (char)((pixel >> 24) & 0xff);
1417 *dest++ = (char)((pixel >> 16) & 0xff);
1418 *dest++ = (char)((pixel >> 8) & 0xff);
1419 *dest++ = (char)( pixel & 0xff);
1420 } else {
1421 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1422 /* (probably need to use RShift, RMask, etc.) */
1423 *dest++ = (char)((pixel >> 16) & 0xff);
1424 *dest++ = (char)((pixel >> 8) & 0xff);
1425 *dest++ = (char)( pixel & 0xff);
1426 }
1427 }
1428 } else /* if (rpng2_info.channels == 4) */ {
1429 for (i = rpng2_info.width; i > 0; --i) {
1430 r = *src++;
1431 g = *src++;
1432 b = *src++;
1433 a = *src++;
1434 if (bg_image) {
1435 bg_red = *src2++;
1436 bg_green = *src2++;
1437 bg_blue = *src2++;
1438 }
1439 if (a == 255) {
1440 red = r;
1441 green = g;
1442 blue = b;
1443 } else if (a == 0) {
1444 red = bg_red;
1445 green = bg_green;
1446 blue = bg_blue;
1447 } else {
1448 /* this macro (from png.h) composites the foreground
1449 * and background values and puts the result into the
1450 * first argument */
1451 alpha_composite(red, r, a, bg_red);
1452 alpha_composite(green, g, a, bg_green);
1453 alpha_composite(blue, b, a, bg_blue);
1454 }
1455 pixel = (red << RShift) |
1456 (green << GShift) |
1457 (blue << BShift);
1458 /* recall that we set ximage->byte_order = MSBFirst above */
1459 if (bpp == 32) {
1460 *dest++ = (char)((pixel >> 24) & 0xff);
1461 *dest++ = (char)((pixel >> 16) & 0xff);
1462 *dest++ = (char)((pixel >> 8) & 0xff);
1463 *dest++ = (char)( pixel & 0xff);
1464 } else {
1465 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1466 /* (probably need to use RShift, RMask, etc.) */
1467 *dest++ = (char)((pixel >> 16) & 0xff);
1468 *dest++ = (char)((pixel >> 8) & 0xff);
1469 *dest++ = (char)( pixel & 0xff);
1470 }
1471 }
1472 }
1473
1474 } else if (depth == 16) {
1475 ush red, green, blue;
1476
1477 src = rpng2_info.row_pointers[row];
1478 if (bg_image)
1479 src2 = bg_data + row*bg_rowbytes;
1480 dest = ximage->data + row*ximage_rowbytes;
1481 if (rpng2_info.channels == 3) {
1482 for (i = rpng2_info.width; i > 0; --i) {
1483 red = ((ush)(*src) << 8);
1484 ++src;
1485 green = ((ush)(*src) << 8);
1486 ++src;
1487 blue = ((ush)(*src) << 8);
1488 ++src;
1489 pixel = ((red >> RShift) & RMask) |
1490 ((green >> GShift) & GMask) |
1491 ((blue >> BShift) & BMask);
1492 /* recall that we set ximage->byte_order = MSBFirst above */
1493 *dest++ = (char)((pixel >> 8) & 0xff);
1494 *dest++ = (char)( pixel & 0xff);
1495 }
1496 } else /* if (rpng2_info.channels == 4) */ {
1497 for (i = rpng2_info.width; i > 0; --i) {
1498 r = *src++;
1499 g = *src++;
1500 b = *src++;
1501 a = *src++;
1502 if (bg_image) {
1503 bg_red = *src2++;
1504 bg_green = *src2++;
1505 bg_blue = *src2++;
1506 }
1507 if (a == 255) {
1508 red = ((ush)r << 8);
1509 green = ((ush)g << 8);
1510 blue = ((ush)b << 8);
1511 } else if (a == 0) {
1512 red = ((ush)bg_red << 8);
1513 green = ((ush)bg_green << 8);
1514 blue = ((ush)bg_blue << 8);
1515 } else {
1516 /* this macro (from png.h) composites the foreground
1517 * and background values and puts the result back into
1518 * the first argument (== fg byte here: safe) */
1519 alpha_composite(r, r, a, bg_red);
1520 alpha_composite(g, g, a, bg_green);
1521 alpha_composite(b, b, a, bg_blue);
1522 red = ((ush)r << 8);
1523 green = ((ush)g << 8);
1524 blue = ((ush)b << 8);
1525 }
1526 pixel = ((red >> RShift) & RMask) |
1527 ((green >> GShift) & GMask) |
1528 ((blue >> BShift) & BMask);
1529 /* recall that we set ximage->byte_order = MSBFirst above */
1530 *dest++ = (char)((pixel >> 8) & 0xff);
1531 *dest++ = (char)( pixel & 0xff);
1532 }
1533 }
1534
1535 } else /* depth == 8 */ {
1536
1537 /* GRR: add 8-bit support */
1538
1539 }
1540
1541
1542/*---------------------------------------------------------------------------
1543 Display after every 16 rows or when on one of last two rows. (Region
1544 may include previously displayed lines due to interlacing--i.e., not
1545 contiguous. Also, second-to-last row is final one in interlaced images
1546 with odd number of rows.) For demos, flush (and delay) after every 16th
1547 row so "sparse" passes don't go twice as fast.
1548 ---------------------------------------------------------------------------*/
1549
1550 if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) {
1551 XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,
1552 (int)firstrow, rpng2_info.width, row - firstrow + 1);
1553 XFlush(display);
1554 rows = 0;
1555 usleep(usleep_duration);
1556 } else
1557 if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) {
1558 XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,
1559 (int)firstrow, rpng2_info.width, row - firstrow + 1);
1560 XFlush(display);
1561 rows = 0;
1562 }
1563
1564}
1565
1566
1567
1568
1569
1570static void rpng2_x_finish_display(void)
1571{
1572 Trace((stderr, "beginning rpng2_x_finish_display()\n"))
1573
1574 /* last row has already been displayed by rpng2_x_display_row(), so we
1575 * have nothing to do here except set a flag and let the user know that
1576 * the image is done */
1577
1578 rpng2_info.state = kDone;
1579 printf(
1580 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
1581 fflush(stdout);
1582}
1583
1584
1585
1586
1587
1588static void rpng2_x_redisplay_image(ulg startcol, ulg startrow,
1589 ulg width, ulg height)
1590{
1591 uch bg_red = rpng2_info.bg_red;
1592 uch bg_green = rpng2_info.bg_green;
1593 uch bg_blue = rpng2_info.bg_blue;
1594 uch *src, *src2=NULL;
1595 char *dest;
1596 uch r, g, b, a;
1597 ulg i, row, lastrow = 0;
1598 ulg pixel;
1599 int ximage_rowbytes = ximage->bytes_per_line;
1600
1601
1602 Trace((stderr, "beginning display loop (image_channels == %d)\n",
1603 rpng2_info.channels))
1604 Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n",
1605 rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes))
1606 Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
1607 Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
1608 "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
1609
1610/*---------------------------------------------------------------------------
1611 Aside from the use of the rpng2_info struct and of src2 (for background
1612 image), this routine is identical to rpng_x_display_image() in the non-
1613 progressive version of the program--for the simple reason that redisplay
1614 of the image against a new background happens after the image is fully
1615 decoded and therefore is, by definition, non-progressive.
1616 ---------------------------------------------------------------------------*/
1617
1618 if (depth == 24 || depth == 32) {
1619 ulg red, green, blue;
1620 int bpp = ximage->bits_per_pixel;
1621
1622 for (lastrow = row = startrow; row < startrow+height; ++row) {
1623 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1624 if (bg_image)
1625 src2 = bg_data + row*bg_rowbytes;
1626 dest = ximage->data + row*ximage_rowbytes;
1627 if (rpng2_info.channels == 3) {
1628 for (i = rpng2_info.width; i > 0; --i) {
1629 red = *src++;
1630 green = *src++;
1631 blue = *src++;
1632#ifdef NO_24BIT_MASKS
1633 pixel = (red << RShift) |
1634 (green << GShift) |
1635 (blue << BShift);
1636 /* recall that we set ximage->byte_order = MSBFirst above */
1637 if (bpp == 32) {
1638 *dest++ = (char)((pixel >> 24) & 0xff);
1639 *dest++ = (char)((pixel >> 16) & 0xff);
1640 *dest++ = (char)((pixel >> 8) & 0xff);
1641 *dest++ = (char)( pixel & 0xff);
1642 } else {
1643 /* this assumes bpp == 24 & bits are packed low */
1644 /* (probably need to use RShift, RMask, etc.) */
1645 *dest++ = (char)((pixel >> 16) & 0xff);
1646 *dest++ = (char)((pixel >> 8) & 0xff);
1647 *dest++ = (char)( pixel & 0xff);
1648 }
1649#else
1650 red = (RShift < 0)? red << (-RShift) : red >> RShift;
1651 green = (GShift < 0)? green << (-GShift) : green >> GShift;
1652 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
1653 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
1654 /* recall that we set ximage->byte_order = MSBFirst above */
1655 if (bpp == 32) {
1656 *dest++ = (char)((pixel >> 24) & 0xff);
1657 *dest++ = (char)((pixel >> 16) & 0xff);
1658 *dest++ = (char)((pixel >> 8) & 0xff);
1659 *dest++ = (char)( pixel & 0xff);
1660 } else {
1661 /* GRR BUG */
1662 /* this assumes bpp == 24 & bits are packed low */
1663 /* (probably need to use RShift/RMask/etc. here, too) */
1664 *dest++ = (char)((pixel >> 16) & 0xff);
1665 *dest++ = (char)((pixel >> 8) & 0xff);
1666 *dest++ = (char)( pixel & 0xff);
1667 }
1668#endif
1669 }
1670
1671 } else /* if (rpng2_info.channels == 4) */ {
1672 for (i = rpng2_info.width; i > 0; --i) {
1673 r = *src++;
1674 g = *src++;
1675 b = *src++;
1676 a = *src++;
1677 if (bg_image) {
1678 bg_red = *src2++;
1679 bg_green = *src2++;
1680 bg_blue = *src2++;
1681 }
1682 if (a == 255) {
1683 red = r;
1684 green = g;
1685 blue = b;
1686 } else if (a == 0) {
1687 red = bg_red;
1688 green = bg_green;
1689 blue = bg_blue;
1690 } else {
1691 /* this macro (from png.h) composites the foreground
1692 * and background values and puts the result into the
1693 * first argument */
1694 alpha_composite(red, r, a, bg_red);
1695 alpha_composite(green, g, a, bg_green);
1696 alpha_composite(blue, b, a, bg_blue);
1697 }
1698#ifdef NO_24BIT_MASKS
1699 pixel = (red << RShift) |
1700 (green << GShift) |
1701 (blue << BShift);
1702 /* recall that we set ximage->byte_order = MSBFirst above */
1703 if (bpp == 32) {
1704 *dest++ = (char)((pixel >> 24) & 0xff);
1705 *dest++ = (char)((pixel >> 16) & 0xff);
1706 *dest++ = (char)((pixel >> 8) & 0xff);
1707 *dest++ = (char)( pixel & 0xff);
1708 } else {
1709 /* this assumes bpp == 24 & bits are packed low */
1710 /* (probably need to use RShift, RMask, etc.) */
1711 *dest++ = (char)((pixel >> 16) & 0xff);
1712 *dest++ = (char)((pixel >> 8) & 0xff);
1713 *dest++ = (char)( pixel & 0xff);
1714 }
1715#else
1716 red = (RShift < 0)? red << (-RShift) : red >> RShift;
1717 green = (GShift < 0)? green << (-GShift) : green >> GShift;
1718 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
1719 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
1720 /* recall that we set ximage->byte_order = MSBFirst above */
1721 if (bpp == 32) {
1722 *dest++ = (char)((pixel >> 24) & 0xff);
1723 *dest++ = (char)((pixel >> 16) & 0xff);
1724 *dest++ = (char)((pixel >> 8) & 0xff);
1725 *dest++ = (char)( pixel & 0xff);
1726 } else {
1727 /* GRR BUG */
1728 /* this assumes bpp == 24 & bits are packed low */
1729 /* (probably need to use RShift/RMask/etc. here, too) */
1730 *dest++ = (char)((pixel >> 16) & 0xff);
1731 *dest++ = (char)((pixel >> 8) & 0xff);
1732 *dest++ = (char)( pixel & 0xff);
1733 }
1734#endif
1735 }
1736 }
1737 /* display after every 16 lines */
1738 if (((row+1) & 0xf) == 0) {
1739 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1740 (int)lastrow, rpng2_info.width, 16);
1741 XFlush(display);
1742 lastrow = row + 1;
1743 }
1744 }
1745
1746 } else if (depth == 16) {
1747 ush red, green, blue;
1748
1749 for (lastrow = row = startrow; row < startrow+height; ++row) {
1750 src = rpng2_info.row_pointers[row];
1751 if (bg_image)
1752 src2 = bg_data + row*bg_rowbytes;
1753 dest = ximage->data + row*ximage_rowbytes;
1754 if (rpng2_info.channels == 3) {
1755 for (i = rpng2_info.width; i > 0; --i) {
1756 red = ((ush)(*src) << 8);
1757 ++src;
1758 green = ((ush)(*src) << 8);
1759 ++src;
1760 blue = ((ush)(*src) << 8);
1761 ++src;
1762 pixel = ((red >> RShift) & RMask) |
1763 ((green >> GShift) & GMask) |
1764 ((blue >> BShift) & BMask);
1765 /* recall that we set ximage->byte_order = MSBFirst above */
1766 *dest++ = (char)((pixel >> 8) & 0xff);
1767 *dest++ = (char)( pixel & 0xff);
1768 }
1769 } else /* if (rpng2_info.channels == 4) */ {
1770 for (i = rpng2_info.width; i > 0; --i) {
1771 r = *src++;
1772 g = *src++;
1773 b = *src++;
1774 a = *src++;
1775 if (bg_image) {
1776 bg_red = *src2++;
1777 bg_green = *src2++;
1778 bg_blue = *src2++;
1779 }
1780 if (a == 255) {
1781 red = ((ush)r << 8);
1782 green = ((ush)g << 8);
1783 blue = ((ush)b << 8);
1784 } else if (a == 0) {
1785 red = ((ush)bg_red << 8);
1786 green = ((ush)bg_green << 8);
1787 blue = ((ush)bg_blue << 8);
1788 } else {
1789 /* this macro (from png.h) composites the foreground
1790 * and background values and puts the result back into
1791 * the first argument (== fg byte here: safe) */
1792 alpha_composite(r, r, a, bg_red);
1793 alpha_composite(g, g, a, bg_green);
1794 alpha_composite(b, b, a, bg_blue);
1795 red = ((ush)r << 8);
1796 green = ((ush)g << 8);
1797 blue = ((ush)b << 8);
1798 }
1799 pixel = ((red >> RShift) & RMask) |
1800 ((green >> GShift) & GMask) |
1801 ((blue >> BShift) & BMask);
1802 /* recall that we set ximage->byte_order = MSBFirst above */
1803 *dest++ = (char)((pixel >> 8) & 0xff);
1804 *dest++ = (char)( pixel & 0xff);
1805 }
1806 }
1807 /* display after every 16 lines */
1808 if (((row+1) & 0xf) == 0) {
1809 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1810 (int)lastrow, rpng2_info.width, 16);
1811 XFlush(display);
1812 lastrow = row + 1;
1813 }
1814 }
1815
1816 } else /* depth == 8 */ {
1817
1818 /* GRR: add 8-bit support */
1819
1820 }
1821
1822 Trace((stderr, "calling final XPutImage()\n"))
1823 if (lastrow < startrow+height) {
1824 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1825 (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow);
1826 XFlush(display);
1827 }
1828
1829} /* end function rpng2_x_redisplay_image() */
1830
1831
1832
1833
1834
1835#ifdef FEATURE_LOOP
1836
1837static void rpng2_x_reload_bg_image(void)
1838{
1839 char *dest;
1840 uch r1, r2, g1, g2, b1, b2;
1841 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
1842 int k, hmax, max;
1843 int xidx, yidx, yidx_max;
1844 int even_odd_vert, even_odd_horiz, even_odd;
1845 int invert_gradient2 = (bg[pat].type & 0x08);
1846 int invert_column;
1847 ulg i, row;
1848
1849
1850 bgscale = (pat == 0)? 8 : bgscale_default;
1851 yidx_max = bgscale - 1;
1852
1853/*---------------------------------------------------------------------------
1854 Vertical gradients (ramps) in NxN squares, alternating direction and
1855 colors (N == bgscale).
1856 ---------------------------------------------------------------------------*/
1857
1858 if ((bg[pat].type & 0x07) == 0) {
1859 uch r1_min = rgb[bg[pat].rgb1_min].r;
1860 uch g1_min = rgb[bg[pat].rgb1_min].g;
1861 uch b1_min = rgb[bg[pat].rgb1_min].b;
1862 uch r2_min = rgb[bg[pat].rgb2_min].r;
1863 uch g2_min = rgb[bg[pat].rgb2_min].g;
1864 uch b2_min = rgb[bg[pat].rgb2_min].b;
1865 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
1866 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
1867 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
1868 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
1869 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
1870 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
1871
1872 for (row = 0; row < rpng2_info.height; ++row) {
1873 yidx = (int)(row % bgscale);
1874 even_odd_vert = (int)((row / bgscale) & 1);
1875
1876 r1 = r1_min + (r1_diff * yidx) / yidx_max;
1877 g1 = g1_min + (g1_diff * yidx) / yidx_max;
1878 b1 = b1_min + (b1_diff * yidx) / yidx_max;
1879 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
1880 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
1881 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
1882
1883 r2 = r2_min + (r2_diff * yidx) / yidx_max;
1884 g2 = g2_min + (g2_diff * yidx) / yidx_max;
1885 b2 = b2_min + (b2_diff * yidx) / yidx_max;
1886 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
1887 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
1888 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
1889
1890 dest = (char *)bg_data + row*bg_rowbytes;
1891 for (i = 0; i < rpng2_info.width; ++i) {
1892 even_odd_horiz = (int)((i / bgscale) & 1);
1893 even_odd = even_odd_vert ^ even_odd_horiz;
1894 invert_column =
1895 (even_odd_horiz && (bg[pat].type & 0x10));
1896 if (even_odd == 0) { /* gradient #1 */
1897 if (invert_column) {
1898 *dest++ = r1_inv;
1899 *dest++ = g1_inv;
1900 *dest++ = b1_inv;
1901 } else {
1902 *dest++ = r1;
1903 *dest++ = g1;
1904 *dest++ = b1;
1905 }
1906 } else { /* gradient #2 */
1907 if ((invert_column && invert_gradient2) ||
1908 (!invert_column && !invert_gradient2))
1909 {
1910 *dest++ = r2; /* not inverted or */
1911 *dest++ = g2; /* doubly inverted */
1912 *dest++ = b2;
1913 } else {
1914 *dest++ = r2_inv;
1915 *dest++ = g2_inv; /* singly inverted */
1916 *dest++ = b2_inv;
1917 }
1918 }
1919 }
1920 }
1921
1922/*---------------------------------------------------------------------------
1923 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
1924 M. Costello.
1925 ---------------------------------------------------------------------------*/
1926
1927 } else if ((bg[pat].type & 0x07) == 1) {
1928
1929 hmax = (bgscale-1)/2; /* half the max weight of a color */
1930 max = 2*hmax; /* the max weight of a color */
1931
1932 r1 = rgb[bg[pat].rgb1_max].r;
1933 g1 = rgb[bg[pat].rgb1_max].g;
1934 b1 = rgb[bg[pat].rgb1_max].b;
1935 r2 = rgb[bg[pat].rgb2_max].r;
1936 g2 = rgb[bg[pat].rgb2_max].g;
1937 b2 = rgb[bg[pat].rgb2_max].b;
1938
1939 for (row = 0; row < rpng2_info.height; ++row) {
1940 yidx = (int)(row % bgscale);
1941 if (yidx > hmax)
1942 yidx = bgscale-1 - yidx;
1943 dest = (char *)bg_data + row*bg_rowbytes;
1944 for (i = 0; i < rpng2_info.width; ++i) {
1945 xidx = (int)(i % bgscale);
1946 if (xidx > hmax)
1947 xidx = bgscale-1 - xidx;
1948 k = xidx + yidx;
1949 *dest++ = (k*r1 + (max-k)*r2) / max;
1950 *dest++ = (k*g1 + (max-k)*g2) / max;
1951 *dest++ = (k*b1 + (max-k)*b2) / max;
1952 }
1953 }
1954
1955/*---------------------------------------------------------------------------
1956 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
1957 soids will equal bgscale?]. This one is slow but very cool. Code con-
1958 tributed by Pieter S. van der Meulen (originally in Smalltalk).
1959 ---------------------------------------------------------------------------*/
1960
1961 } else if ((bg[pat].type & 0x07) == 2) {
1962 uch ch;
1963 int ii, x, y, hw, hh, grayspot;
1964 double freq, rotate, saturate, gray, intensity;
1965 double angle=0.0, aoffset=0.0, maxDist, dist;
1966 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
1967
1968 hh = (int)(rpng2_info.height / 2);
1969 hw = (int)(rpng2_info.width / 2);
1970
1971 /* variables for radial waves:
1972 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
1973 * freq: number of color beams originating from the center
1974 * grayspot: size of the graying center area (anti-alias)
1975 * rotate: rotation of the beams as a function of radius
1976 * saturate: saturation of beams' shape azimuthally
1977 */
1978 angle = CLIP(angle, 0.0, 360.0);
1979 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
1980 freq = MAX((double)bg[pat].bg_freq, 0.0);
1981 saturate = (double)bg[pat].bg_bsat * 0.1;
1982 rotate = (double)bg[pat].bg_brot * 0.1;
1983 gray = 0.0;
1984 intensity = 0.0;
1985 maxDist = (double)((hw*hw) + (hh*hh));
1986
1987 for (row = 0; row < rpng2_info.height; ++row) {
1988 y = (int)(row - hh);
1989 dest = (char *)bg_data + row*bg_rowbytes;
1990 for (i = 0; i < rpng2_info.width; ++i) {
1991 x = (int)(i - hw);
1992 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1993 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1994 gray = MIN(1.0, gray);
1995 dist = (double)((x*x) + (y*y)) / maxDist;
1996 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1997 gray * saturate;
1998 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1999 hue = (angle + PI) * INV_PI_360 + aoffset;
2000 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
2001 s = MIN(MAX(s,0.0), 1.0);
2002 v = MIN(MAX(intensity,0.0), 1.0);
2003
2004 if (s == 0.0) {
2005 ch = (uch)(v * 255.0);
2006 *dest++ = ch;
2007 *dest++ = ch;
2008 *dest++ = ch;
2009 } else {
2010 if ((hue < 0.0) || (hue >= 360.0))
2011 hue -= (((int)(hue / 360.0)) * 360.0);
2012 hue /= 60.0;
2013 ii = (int)hue;
2014 f = hue - (double)ii;
2015 p = (1.0 - s) * v;
2016 q = (1.0 - (s * f)) * v;
2017 t = (1.0 - (s * (1.0 - f))) * v;
2018 if (ii == 0) { red = v; green = t; blue = p; }
2019 else if (ii == 1) { red = q; green = v; blue = p; }
2020 else if (ii == 2) { red = p; green = v; blue = t; }
2021 else if (ii == 3) { red = p; green = q; blue = v; }
2022 else if (ii == 4) { red = t; green = p; blue = v; }
2023 else if (ii == 5) { red = v; green = p; blue = q; }
2024 *dest++ = (uch)(red * 255.0);
2025 *dest++ = (uch)(green * 255.0);
2026 *dest++ = (uch)(blue * 255.0);
2027 }
2028 }
2029 }
2030 }
2031
2032} /* end function rpng2_x_reload_bg_image() */
2033
2034
2035
2036
2037
2038static int is_number(char *p)
2039{
2040 while (*p) {
2041 if (!isdigit(*p))
2042 return FALSE;
2043 ++p;
2044 }
2045 return TRUE;
2046}
2047
2048#endif /* FEATURE_LOOP */
2049
2050
2051
2052
2053
2054static void rpng2_x_cleanup(void)
2055{
2056 if (bg_image && bg_data) {
2057 free(bg_data);
2058 bg_data = NULL;
2059 }
2060
2061 if (rpng2_info.image_data) {
2062 free(rpng2_info.image_data);
2063 rpng2_info.image_data = NULL;
2064 }
2065
2066 if (rpng2_info.row_pointers) {
2067 free(rpng2_info.row_pointers);
2068 rpng2_info.row_pointers = NULL;
2069 }
2070
2071 if (ximage) {
2072 if (ximage->data) {
2073 free(ximage->data); /* we allocated it, so we free it */
2074 ximage->data = (char *)NULL; /* instead of XDestroyImage() */
2075 }
2076 XDestroyImage(ximage);
2077 ximage = NULL;
2078 }
2079
2080 if (have_gc)
2081 XFreeGC(display, gc);
2082
2083 if (have_window)
2084 XDestroyWindow(display, window);
2085
2086 if (have_colormap)
2087 XFreeColormap(display, colormap);
2088
2089 if (have_nondefault_visual)
2090 XFree(visual_list);
2091}
2092
2093
2094
2095
2096
2097static int rpng2_x_msb(ulg u32val)
2098{
2099 int i;
2100
2101 for (i = 31; i >= 0; --i) {
2102 if (u32val & 0x80000000L)
2103 break;
2104 u32val <<= 1;
2105 }
2106 return i;
2107}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png
new file mode 100644
index 0000000..03960d4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c
new file mode 100644
index 0000000..30372a3
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c
@@ -0,0 +1,853 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program wpng.c
4
5 This program converts certain NetPBM binary files (grayscale and RGB,
6 maxval = 255) to PNG. Non-interlaced PNGs are written progressively;
7 interlaced PNGs are read and written in one memory-intensive blast.
8
9 Thanks to Jean-loup Gailly for providing the necessary trick to read
10 interactive text from the keyboard while stdin is redirected. Thanks
11 to Cosmin Truta for Cygwin fixes.
12
13 NOTE: includes provisional support for PNM type "8" (portable alphamap)
14 images, presumed to be a 32-bit interleaved RGBA format; no pro-
15 vision for possible interleaved grayscale+alpha (16-bit) format.
16 THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!
17
18 to do:
19 - delete output file if quit before calling any writepng routines
20 - process backspace with -text option under DOS/Win? (currently get ^H)
21
22 ---------------------------------------------------------------------------
23
24 Changelog:
25 - 1.01: initial public release
26 - 1.02: modified to allow abbreviated options
27 - 1.03: removed extraneous character from usage screen; fixed bug in
28 command-line parsing
29 - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix
30 (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)
31 - 2.00: dual-licensed (added GNU GPL)
32
33 [REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line
34 dose not work! In order to do something useful I needed to redirect
35 both input and output, with cygwin and with bcc32 as well. Under
36 Linux, the same wpng appears to work fine. I don't know what is
37 the problem."]
38
39 ---------------------------------------------------------------------------
40
41 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
42
43 This software is provided "as is," without warranty of any kind,
44 express or implied. In no event shall the author or contributors
45 be held liable for any damages arising in any way from the use of
46 this software.
47
48 The contents of this file are DUAL-LICENSED. You may modify and/or
49 redistribute this software according to the terms of one of the
50 following two licenses (at your option):
51
52
53 LICENSE 1 ("BSD-like with advertising clause"):
54
55 Permission is granted to anyone to use this software for any purpose,
56 including commercial applications, and to alter it and redistribute
57 it freely, subject to the following restrictions:
58
59 1. Redistributions of source code must retain the above copyright
60 notice, disclaimer, and this list of conditions.
61 2. Redistributions in binary form must reproduce the above copyright
62 notice, disclaimer, and this list of conditions in the documenta-
63 tion and/or other materials provided with the distribution.
64 3. All advertising materials mentioning features or use of this
65 software must display the following acknowledgment:
66
67 This product includes software developed by Greg Roelofs
68 and contributors for the book, "PNG: The Definitive Guide,"
69 published by O'Reilly and Associates.
70
71
72 LICENSE 2 (GNU GPL v2 or later):
73
74 This program is free software; you can redistribute it and/or modify
75 it under the terms of the GNU General Public License as published by
76 the Free Software Foundation; either version 2 of the License, or
77 (at your option) any later version.
78
79 This program is distributed in the hope that it will be useful,
80 but WITHOUT ANY WARRANTY; without even the implied warranty of
81 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82 GNU General Public License for more details.
83
84 You should have received a copy of the GNU General Public License
85 along with this program; if not, write to the Free Software Foundation,
86 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
87
88 ---------------------------------------------------------------------------*/
89
90#define PROGNAME "wpng"
91#define VERSION "2.00 of 2 June 2007"
92#define APPNAME "Simple PGM/PPM/PAM to PNG Converter"
93
94#if defined(__MSDOS__) || defined(__OS2__)
95# define DOS_OS2_W32
96#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
97# ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */
98# define DOS_OS2_W32
99# endif
100#endif
101
102#include <stdio.h>
103#include <stdlib.h>
104#include <string.h>
105#include <setjmp.h> /* for jmpbuf declaration in writepng.h */
106#include <time.h>
107
108#ifdef DOS_OS2_W32
109# include <io.h> /* for isatty(), setmode() prototypes */
110# include <fcntl.h> /* O_BINARY for fdopen() without text translation */
111# ifdef __EMX__
112# ifndef getch
113# define getch() _read_kbd(0, 1, 0) /* need getche() */
114# endif
115# else /* !__EMX__ */
116# ifdef __GO32__
117# include <pc.h>
118# define getch() getkey() /* GRR: need getche() */
119# else
120# include <conio.h> /* for getche() console input */
121# endif
122# endif /* ?__EMX__ */
123# define FGETS(buf,len,stream) dos_kbd_gets(buf,len)
124#else
125# include <unistd.h> /* for isatty() prototype */
126# define FGETS fgets
127#endif
128
129/* #define DEBUG : this enables the Trace() macros */
130
131/* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any
132 text that includes control characters discouraged by the PNG spec; text
133 that includes an escape character (27) must be re-entered regardless */
134
135#include "writepng.h" /* typedefs, common macros, writepng prototypes */
136
137
138
139/* local prototypes */
140
141static int wpng_isvalid_latin1(uch *p, int len);
142static void wpng_cleanup(void);
143
144#ifdef DOS_OS2_W32
145 static char *dos_kbd_gets(char *buf, int len);
146#endif
147
148
149
150static mainprog_info wpng_info; /* lone global */
151
152
153
154int main(int argc, char **argv)
155{
156#ifndef DOS_OS2_W32
157 FILE *keybd;
158#endif
159#ifdef sgi
160 FILE *tmpfile; /* or we could just use keybd, since no overlap */
161 char tmpline[80];
162#endif
163 char *inname = NULL, outname[256];
164 char *p, pnmchar, pnmline[256];
165 char *bgstr, *textbuf = NULL;
166 ulg rowbytes;
167 int rc, len = 0;
168 int error = 0;
169 int text = FALSE;
170 int maxval;
171 double LUT_exponent; /* just the lookup table */
172 double CRT_exponent = 2.2; /* just the monitor */
173 double default_display_exponent; /* whole display system */
174 double default_gamma = 0.0;
175
176
177 wpng_info.infile = NULL;
178 wpng_info.outfile = NULL;
179 wpng_info.image_data = NULL;
180 wpng_info.row_pointers = NULL;
181 wpng_info.filter = FALSE;
182 wpng_info.interlaced = FALSE;
183 wpng_info.have_bg = FALSE;
184 wpng_info.have_time = FALSE;
185 wpng_info.have_text = 0;
186 wpng_info.gamma = 0.0;
187
188
189 /* First get the default value for our display-system exponent, i.e.,
190 * the product of the CRT exponent and the exponent corresponding to
191 * the frame-buffer's lookup table (LUT), if any. If the PNM image
192 * looks correct on the user's display system, its file gamma is the
193 * inverse of this value. (Note that this is not an exhaustive list
194 * of LUT values--e.g., OpenStep has a lot of weird ones--but it should
195 * cover 99% of the current possibilities. This section must ensure
196 * that default_display_exponent is positive.) */
197
198#if defined(NeXT)
199 /* third-party utilities can modify the default LUT exponent */
200 LUT_exponent = 1.0 / 2.2;
201 /*
202 if (some_next_function_that_returns_gamma(&next_gamma))
203 LUT_exponent = 1.0 / next_gamma;
204 */
205#elif defined(sgi)
206 LUT_exponent = 1.0 / 1.7;
207 /* there doesn't seem to be any documented function to
208 * get the "gamma" value, so we do it the hard way */
209 tmpfile = fopen("/etc/config/system.glGammaVal", "r");
210 if (tmpfile) {
211 double sgi_gamma;
212
213 fgets(tmpline, 80, tmpfile);
214 fclose(tmpfile);
215 sgi_gamma = atof(tmpline);
216 if (sgi_gamma > 0.0)
217 LUT_exponent = 1.0 / sgi_gamma;
218 }
219#elif defined(Macintosh)
220 LUT_exponent = 1.8 / 2.61;
221 /*
222 if (some_mac_function_that_returns_gamma(&mac_gamma))
223 LUT_exponent = mac_gamma / 2.61;
224 */
225#else
226 LUT_exponent = 1.0; /* assume no LUT: most PCs */
227#endif
228
229 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
230 default_display_exponent = LUT_exponent * CRT_exponent;
231
232
233 /* If the user has set the SCREEN_GAMMA environment variable as suggested
234 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
235 * use the default value we just calculated. Either way, the user may
236 * override this via a command-line option. */
237
238 if ((p = getenv("SCREEN_GAMMA")) != NULL) {
239 double exponent = atof(p);
240
241 if (exponent > 0.0)
242 default_gamma = 1.0 / exponent;
243 }
244
245 if (default_gamma == 0.0)
246 default_gamma = 1.0 / default_display_exponent;
247
248
249 /* Now parse the command line for options and the PNM filename. */
250
251 while (*++argv && !error) {
252 if (!strncmp(*argv, "-i", 2)) {
253 wpng_info.interlaced = TRUE;
254 } else if (!strncmp(*argv, "-time", 3)) {
255 wpng_info.modtime = time(NULL);
256 wpng_info.have_time = TRUE;
257 } else if (!strncmp(*argv, "-text", 3)) {
258 text = TRUE;
259 } else if (!strncmp(*argv, "-gamma", 2)) {
260 if (!*++argv)
261 ++error;
262 else {
263 wpng_info.gamma = atof(*argv);
264 if (wpng_info.gamma <= 0.0)
265 ++error;
266 else if (wpng_info.gamma > 1.01)
267 fprintf(stderr, PROGNAME
268 " warning: file gammas are usually less than 1.0\n");
269 }
270 } else if (!strncmp(*argv, "-bgcolor", 4)) {
271 if (!*++argv)
272 ++error;
273 else {
274 bgstr = *argv;
275 if (strlen(bgstr) != 7 || bgstr[0] != '#')
276 ++error;
277 else {
278 unsigned r, g, b; /* this way quiets compiler warnings */
279
280 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
281 wpng_info.bg_red = (uch)r;
282 wpng_info.bg_green = (uch)g;
283 wpng_info.bg_blue = (uch)b;
284 wpng_info.have_bg = TRUE;
285 }
286 }
287 } else {
288 if (**argv != '-') {
289 inname = *argv;
290 if (argv[1]) /* shouldn't be any more args after filename */
291 ++error;
292 } else
293 ++error; /* not expecting any other options */
294 }
295 }
296
297
298 /* open the input and output files, or register an error and abort */
299
300 if (!inname) {
301 if (isatty(0)) {
302 fprintf(stderr, PROGNAME
303 ": must give input filename or provide image data via stdin\n");
304 ++error;
305 } else {
306#ifdef DOS_OS2_W32
307 /* some buggy C libraries require BOTH setmode() and fdopen(bin) */
308 setmode(fileno(stdin), O_BINARY);
309 setmode(fileno(stdout), O_BINARY);
310#endif
311 if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
312 fprintf(stderr, PROGNAME
313 ": unable to reopen stdin in binary mode\n");
314 ++error;
315 } else
316 if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) {
317 fprintf(stderr, PROGNAME
318 ": unable to reopen stdout in binary mode\n");
319 fclose(wpng_info.infile);
320 ++error;
321 } else
322 wpng_info.filter = TRUE;
323 }
324 } else if ((len = strlen(inname)) > 250) {
325 fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n",
326 len);
327 ++error;
328 } else if (!(wpng_info.infile = fopen(inname, "rb"))) {
329 fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname);
330 ++error;
331 }
332
333 if (!error) {
334 fgets(pnmline, 256, wpng_info.infile);
335 if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&
336 pnmchar != '6' && pnmchar != '8'))
337 {
338 fprintf(stderr, PROGNAME
339 ": input file [%s] is not a binary PGM, PPM or PAM file\n",
340 inname);
341 ++error;
342 } else {
343 wpng_info.pnmtype = (int)(pnmchar - '0');
344 if (wpng_info.pnmtype != 8)
345 wpng_info.have_bg = FALSE; /* no need for bg if opaque */
346 do {
347 fgets(pnmline, 256, wpng_info.infile); /* lose any comments */
348 } while (pnmline[0] == '#');
349 sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height);
350 do {
351 fgets(pnmline, 256, wpng_info.infile); /* more comment lines */
352 } while (pnmline[0] == '#');
353 sscanf(pnmline, "%d", &maxval);
354 if (wpng_info.width <= 0L || wpng_info.height <= 0L ||
355 maxval != 255)
356 {
357 fprintf(stderr, PROGNAME
358 ": only positive width/height, maxval == 255 allowed \n");
359 ++error;
360 }
361 wpng_info.sample_depth = 8; /* <==> maxval 255 */
362
363 if (!wpng_info.filter) {
364 /* make outname from inname */
365 if ((p = strrchr(inname, '.')) == NULL ||
366 (p - inname) != (len - 4))
367 {
368 strcpy(outname, inname);
369 strcpy(outname+len, ".png");
370 } else {
371 len -= 4;
372 strncpy(outname, inname, len);
373 strcpy(outname+len, ".png");
374 }
375 /* check if outname already exists; if not, open */
376 if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) {
377 fprintf(stderr, PROGNAME ": output file exists [%s]\n",
378 outname);
379 fclose(wpng_info.outfile);
380 ++error;
381 } else if (!(wpng_info.outfile = fopen(outname, "wb"))) {
382 fprintf(stderr, PROGNAME ": can't open output file [%s]\n",
383 outname);
384 ++error;
385 }
386 }
387 }
388 if (error) {
389 fclose(wpng_info.infile);
390 wpng_info.infile = NULL;
391 if (wpng_info.filter) {
392 fclose(wpng_info.outfile);
393 wpng_info.outfile = NULL;
394 }
395 }
396 }
397
398
399 /* if we had any errors, print usage and die horrible death...arrr! */
400
401 if (error) {
402 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME);
403 writepng_version_info();
404 fprintf(stderr, "\n"
405"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n"
406"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n"
407 " exp \ttransfer-function exponent (``gamma'') of the image in\n"
408 "\t\t floating-point format (e.g., ``%.5f''); if image looks\n"
409 "\t\t correct on given display system, image gamma is equal to\n"
410 "\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n"
411 "\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n"
412 "\t\t first varies, second is usually 2.2, all are positive)\n"
413 " bg \tdesired background color for alpha-channel images, in\n"
414 "\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n"
415 "\t\t same as HTML colors)\n"
416 " -text\tprompt interactively for text info (tEXt chunks)\n"
417 " -time\tinclude a tIME chunk (last modification time)\n"
418 " -interlace\twrite interlaced PNG image\n"
419 "\n"
420"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n"
421"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n"
422"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n"
423"is converted to the corresponding PNG file with the same base name but a\n"
424"``.png'' extension; files read from stdin are converted and sent to stdout.\n"
425"The conversion is progressive (low memory usage) unless interlacing is\n"
426"requested; in that case the whole image will be buffered in memory and\n"
427"written in one call.\n"
428 "\n", PROGNAME, PROGNAME, default_gamma);
429 exit(1);
430 }
431
432
433 /* prepare the text buffers for libpng's use; note that even though
434 * PNG's png_text struct includes a length field, we don't have to fill
435 * it out */
436
437 if (text &&
438#ifndef DOS_OS2_W32
439 (keybd = fdopen(fileno(stderr), "r")) != NULL &&
440#endif
441 (textbuf = (char *)malloc((5 + 9)*75)) != NULL)
442 {
443 int i, valid, result;
444
445 fprintf(stderr,
446 "Enter text info (no more than 72 characters per line);\n");
447 fprintf(stderr, "to skip a field, hit the <Enter> key.\n");
448 /* note: just <Enter> leaves len == 1 */
449
450 do {
451 valid = TRUE;
452 p = textbuf + TEXT_TITLE_OFFSET;
453 fprintf(stderr, " Title: ");
454 fflush(stderr);
455 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
456 if (p[len-1] == '\n')
457 p[--len] = '\0';
458 wpng_info.title = p;
459 wpng_info.have_text |= TEXT_TITLE;
460 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
461 fprintf(stderr, " " PROGNAME " warning: character code"
462 " %u is %sdiscouraged by the PNG\n specification "
463 "[first occurrence was at character position #%d]\n",
464 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
465 result+1);
466 fflush(stderr);
467#ifdef FORBID_LATIN1_CTRL
468 wpng_info.have_text &= ~TEXT_TITLE;
469 valid = FALSE;
470#else
471 if (p[result] == 27) { /* escape character */
472 wpng_info.have_text &= ~TEXT_TITLE;
473 valid = FALSE;
474 }
475#endif
476 }
477 }
478 } while (!valid);
479
480 do {
481 valid = TRUE;
482 p = textbuf + TEXT_AUTHOR_OFFSET;
483 fprintf(stderr, " Author: ");
484 fflush(stderr);
485 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
486 if (p[len-1] == '\n')
487 p[--len] = '\0';
488 wpng_info.author = p;
489 wpng_info.have_text |= TEXT_AUTHOR;
490 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
491 fprintf(stderr, " " PROGNAME " warning: character code"
492 " %u is %sdiscouraged by the PNG\n specification "
493 "[first occurrence was at character position #%d]\n",
494 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
495 result+1);
496 fflush(stderr);
497#ifdef FORBID_LATIN1_CTRL
498 wpng_info.have_text &= ~TEXT_AUTHOR;
499 valid = FALSE;
500#else
501 if (p[result] == 27) { /* escape character */
502 wpng_info.have_text &= ~TEXT_AUTHOR;
503 valid = FALSE;
504 }
505#endif
506 }
507 }
508 } while (!valid);
509
510 do {
511 valid = TRUE;
512 p = textbuf + TEXT_DESC_OFFSET;
513 fprintf(stderr, " Description (up to 9 lines):\n");
514 for (i = 1; i < 10; ++i) {
515 fprintf(stderr, " [%d] ", i);
516 fflush(stderr);
517 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)
518 p += len; /* now points at NULL; char before is newline */
519 else
520 break;
521 }
522 if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {
523 if (p[-1] == '\n') {
524 p[-1] = '\0';
525 --len;
526 }
527 wpng_info.desc = textbuf + TEXT_DESC_OFFSET;
528 wpng_info.have_text |= TEXT_DESC;
529 p = textbuf + TEXT_DESC_OFFSET;
530 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
531 fprintf(stderr, " " PROGNAME " warning: character code"
532 " %u is %sdiscouraged by the PNG\n specification "
533 "[first occurrence was at character position #%d]\n",
534 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
535 result+1);
536 fflush(stderr);
537#ifdef FORBID_LATIN1_CTRL
538 wpng_info.have_text &= ~TEXT_DESC;
539 valid = FALSE;
540#else
541 if (p[result] == 27) { /* escape character */
542 wpng_info.have_text &= ~TEXT_DESC;
543 valid = FALSE;
544 }
545#endif
546 }
547 }
548 } while (!valid);
549
550 do {
551 valid = TRUE;
552 p = textbuf + TEXT_COPY_OFFSET;
553 fprintf(stderr, " Copyright: ");
554 fflush(stderr);
555 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
556 if (p[len-1] == '\n')
557 p[--len] = '\0';
558 wpng_info.copyright = p;
559 wpng_info.have_text |= TEXT_COPY;
560 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
561 fprintf(stderr, " " PROGNAME " warning: character code"
562 " %u is %sdiscouraged by the PNG\n specification "
563 "[first occurrence was at character position #%d]\n",
564 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
565 result+1);
566 fflush(stderr);
567#ifdef FORBID_LATIN1_CTRL
568 wpng_info.have_text &= ~TEXT_COPY;
569 valid = FALSE;
570#else
571 if (p[result] == 27) { /* escape character */
572 wpng_info.have_text &= ~TEXT_COPY;
573 valid = FALSE;
574 }
575#endif
576 }
577 }
578 } while (!valid);
579
580 do {
581 valid = TRUE;
582 p = textbuf + TEXT_EMAIL_OFFSET;
583 fprintf(stderr, " E-mail: ");
584 fflush(stderr);
585 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
586 if (p[len-1] == '\n')
587 p[--len] = '\0';
588 wpng_info.email = p;
589 wpng_info.have_text |= TEXT_EMAIL;
590 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
591 fprintf(stderr, " " PROGNAME " warning: character code"
592 " %u is %sdiscouraged by the PNG\n specification "
593 "[first occurrence was at character position #%d]\n",
594 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
595 result+1);
596 fflush(stderr);
597#ifdef FORBID_LATIN1_CTRL
598 wpng_info.have_text &= ~TEXT_EMAIL;
599 valid = FALSE;
600#else
601 if (p[result] == 27) { /* escape character */
602 wpng_info.have_text &= ~TEXT_EMAIL;
603 valid = FALSE;
604 }
605#endif
606 }
607 }
608 } while (!valid);
609
610 do {
611 valid = TRUE;
612 p = textbuf + TEXT_URL_OFFSET;
613 fprintf(stderr, " URL: ");
614 fflush(stderr);
615 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
616 if (p[len-1] == '\n')
617 p[--len] = '\0';
618 wpng_info.url = p;
619 wpng_info.have_text |= TEXT_URL;
620 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
621 fprintf(stderr, " " PROGNAME " warning: character code"
622 " %u is %sdiscouraged by the PNG\n specification "
623 "[first occurrence was at character position #%d]\n",
624 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
625 result+1);
626 fflush(stderr);
627#ifdef FORBID_LATIN1_CTRL
628 wpng_info.have_text &= ~TEXT_URL;
629 valid = FALSE;
630#else
631 if (p[result] == 27) { /* escape character */
632 wpng_info.have_text &= ~TEXT_URL;
633 valid = FALSE;
634 }
635#endif
636 }
637 }
638 } while (!valid);
639
640#ifndef DOS_OS2_W32
641 fclose(keybd);
642#endif
643
644 } else if (text) {
645 fprintf(stderr, PROGNAME ": unable to allocate memory for text\n");
646 text = FALSE;
647 wpng_info.have_text = 0;
648 }
649
650
651 /* allocate libpng stuff, initialize transformations, write pre-IDAT data */
652
653 if ((rc = writepng_init(&wpng_info)) != 0) {
654 switch (rc) {
655 case 2:
656 fprintf(stderr, PROGNAME
657 ": libpng initialization problem (longjmp)\n");
658 break;
659 case 4:
660 fprintf(stderr, PROGNAME ": insufficient memory\n");
661 break;
662 case 11:
663 fprintf(stderr, PROGNAME
664 ": internal logic error (unexpected PNM type)\n");
665 break;
666 default:
667 fprintf(stderr, PROGNAME
668 ": unknown writepng_init() error\n");
669 break;
670 }
671 exit(rc);
672 }
673
674
675 /* free textbuf, since it's a completely local variable and all text info
676 * has just been written to the PNG file */
677
678 if (text && textbuf) {
679 free(textbuf);
680 textbuf = NULL;
681 }
682
683
684 /* calculate rowbytes on basis of image type; note that this becomes much
685 * more complicated if we choose to support PBM type, ASCII PNM types, or
686 * 16-bit-per-sample binary data [currently not an official NetPBM type] */
687
688 if (wpng_info.pnmtype == 5)
689 rowbytes = wpng_info.width;
690 else if (wpng_info.pnmtype == 6)
691 rowbytes = wpng_info.width * 3;
692 else /* if (wpng_info.pnmtype == 8) */
693 rowbytes = wpng_info.width * 4;
694
695
696 /* read and write the image, either in its entirety (if writing interlaced
697 * PNG) or row by row (if non-interlaced) */
698
699 fprintf(stderr, "Encoding image data...\n");
700 fflush(stderr);
701
702 if (wpng_info.interlaced) {
703 long i;
704 ulg bytes;
705 ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
706
707 wpng_info.image_data = (uch *)malloc(image_bytes);
708 wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));
709 if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {
710 fprintf(stderr, PROGNAME ": insufficient memory for image data\n");
711 writepng_cleanup(&wpng_info);
712 wpng_cleanup();
713 exit(5);
714 }
715 for (i = 0; i < wpng_info.height; ++i)
716 wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;
717 bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);
718 if (bytes != image_bytes) {
719 fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n",
720 image_bytes, bytes);
721 fprintf(stderr, " (continuing anyway)\n");
722 }
723 if (writepng_encode_image(&wpng_info) != 0) {
724 fprintf(stderr, PROGNAME
725 ": libpng problem (longjmp) while writing image data\n");
726 writepng_cleanup(&wpng_info);
727 wpng_cleanup();
728 exit(2);
729 }
730
731 } else /* not interlaced: write progressively (row by row) */ {
732 long j;
733 ulg bytes;
734
735 wpng_info.image_data = (uch *)malloc(rowbytes);
736 if (wpng_info.image_data == NULL) {
737 fprintf(stderr, PROGNAME ": insufficient memory for row data\n");
738 writepng_cleanup(&wpng_info);
739 wpng_cleanup();
740 exit(5);
741 }
742 error = 0;
743 for (j = wpng_info.height; j > 0L; --j) {
744 bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);
745 if (bytes != rowbytes) {
746 fprintf(stderr, PROGNAME
747 ": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes,
748 bytes, wpng_info.height-j);
749 ++error;
750 break;
751 }
752 if (writepng_encode_row(&wpng_info) != 0) {
753 fprintf(stderr, PROGNAME
754 ": libpng problem (longjmp) while writing row %ld\n",
755 wpng_info.height-j);
756 ++error;
757 break;
758 }
759 }
760 if (error) {
761 writepng_cleanup(&wpng_info);
762 wpng_cleanup();
763 exit(2);
764 }
765 if (writepng_encode_finish(&wpng_info) != 0) {
766 fprintf(stderr, PROGNAME ": error on final libpng call\n");
767 writepng_cleanup(&wpng_info);
768 wpng_cleanup();
769 exit(2);
770 }
771 }
772
773
774 /* OK, we're done (successfully): clean up all resources and quit */
775
776 fprintf(stderr, "Done.\n");
777 fflush(stderr);
778
779 writepng_cleanup(&wpng_info);
780 wpng_cleanup();
781
782 return 0;
783}
784
785
786
787
788
789static int wpng_isvalid_latin1(uch *p, int len)
790{
791 int i, result = -1;
792
793 for (i = 0; i < len; ++i) {
794 if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160)
795 continue; /* character is completely OK */
796 if (result < 0 || (p[result] != 27 && p[i] == 27))
797 result = i; /* mark location of first questionable one */
798 } /* or of first escape character (bad) */
799
800 return result;
801}
802
803
804
805
806
807static void wpng_cleanup(void)
808{
809 if (wpng_info.outfile) {
810 fclose(wpng_info.outfile);
811 wpng_info.outfile = NULL;
812 }
813
814 if (wpng_info.infile) {
815 fclose(wpng_info.infile);
816 wpng_info.infile = NULL;
817 }
818
819 if (wpng_info.image_data) {
820 free(wpng_info.image_data);
821 wpng_info.image_data = NULL;
822 }
823
824 if (wpng_info.row_pointers) {
825 free(wpng_info.row_pointers);
826 wpng_info.row_pointers = NULL;
827 }
828}
829
830
831
832
833#ifdef DOS_OS2_W32
834
835static char *dos_kbd_gets(char *buf, int len)
836{
837 int ch, count=0;
838
839 do {
840 buf[count++] = ch = getche();
841 } while (ch != '\r' && count < len-1);
842
843 buf[count--] = '\0'; /* terminate string */
844 if (buf[count] == '\r') /* Enter key makes CR, so change to newline */
845 buf[count] = '\n';
846
847 fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */
848 fflush(stderr);
849
850 return buf;
851}
852
853#endif /* DOS_OS2_W32 */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c
new file mode 100644
index 0000000..8373c16
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c
@@ -0,0 +1,400 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program writepng.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56
57#include <stdlib.h> /* for exit() prototype */
58
59#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
60#include "writepng.h" /* typedefs, common macros, public prototypes */
61
62
63/* local prototype */
64
65static void writepng_error_handler(png_structp png_ptr, png_const_charp msg);
66
67
68
69void writepng_version_info(void)
70{
71 fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
72 PNG_LIBPNG_VER_STRING, png_libpng_ver);
73 fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
74 ZLIB_VERSION, zlib_version);
75}
76
77
78
79
80/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
81 * unexpected pnmtype; note that outfile might be stdout */
82
83int writepng_init(mainprog_info *mainprog_ptr)
84{
85 png_structp png_ptr; /* note: temporary variables! */
86 png_infop info_ptr;
87 int color_type, interlace_type;
88
89
90 /* could also replace libpng warning-handler (final NULL), but no need: */
91
92 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
93 writepng_error_handler, NULL);
94 if (!png_ptr)
95 return 4; /* out of memory */
96
97 info_ptr = png_create_info_struct(png_ptr);
98 if (!info_ptr) {
99 png_destroy_write_struct(&png_ptr, NULL);
100 return 4; /* out of memory */
101 }
102
103
104 /* setjmp() must be called in every function that calls a PNG-writing
105 * libpng function, unless an alternate error handler was installed--
106 * but compatible error handlers must either use longjmp() themselves
107 * (as in this program) or some other method to return control to
108 * application code, so here we go: */
109
110 if (setjmp(mainprog_ptr->jmpbuf)) {
111 png_destroy_write_struct(&png_ptr, &info_ptr);
112 return 2;
113 }
114
115
116 /* make sure outfile is (re)opened in BINARY mode */
117
118 png_init_io(png_ptr, mainprog_ptr->outfile);
119
120
121 /* set the compression levels--in general, always want to leave filtering
122 * turned on (except for palette images) and allow all of the filters,
123 * which is the default; want 32K zlib window, unless entire image buffer
124 * is 16K or smaller (unknown here)--also the default; usually want max
125 * compression (NOT the default); and remaining compression flags should
126 * be left alone */
127
128 png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
129/*
130 >> this is default for no filtering; Z_FILTERED is default otherwise:
131 png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
132 >> these are all defaults:
133 png_set_compression_mem_level(png_ptr, 8);
134 png_set_compression_window_bits(png_ptr, 15);
135 png_set_compression_method(png_ptr, 8);
136 */
137
138
139 /* set the image parameters appropriately */
140
141 if (mainprog_ptr->pnmtype == 5)
142 color_type = PNG_COLOR_TYPE_GRAY;
143 else if (mainprog_ptr->pnmtype == 6)
144 color_type = PNG_COLOR_TYPE_RGB;
145 else if (mainprog_ptr->pnmtype == 8)
146 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
147 else {
148 png_destroy_write_struct(&png_ptr, &info_ptr);
149 return 11;
150 }
151
152 interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
153 PNG_INTERLACE_NONE;
154
155 png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
156 mainprog_ptr->sample_depth, color_type, interlace_type,
157 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
158
159 if (mainprog_ptr->gamma > 0.0)
160 png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
161
162 if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
163 png_color_16 background;
164
165 background.red = mainprog_ptr->bg_red;
166 background.green = mainprog_ptr->bg_green;
167 background.blue = mainprog_ptr->bg_blue;
168 png_set_bKGD(png_ptr, info_ptr, &background);
169 }
170
171 if (mainprog_ptr->have_time) {
172 png_time modtime;
173
174 png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
175 png_set_tIME(png_ptr, info_ptr, &modtime);
176 }
177
178 if (mainprog_ptr->have_text) {
179 png_text text[6];
180 int num_text = 0;
181
182 if (mainprog_ptr->have_text & TEXT_TITLE) {
183 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
184 text[num_text].key = "Title";
185 text[num_text].text = mainprog_ptr->title;
186 ++num_text;
187 }
188 if (mainprog_ptr->have_text & TEXT_AUTHOR) {
189 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
190 text[num_text].key = "Author";
191 text[num_text].text = mainprog_ptr->author;
192 ++num_text;
193 }
194 if (mainprog_ptr->have_text & TEXT_DESC) {
195 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
196 text[num_text].key = "Description";
197 text[num_text].text = mainprog_ptr->desc;
198 ++num_text;
199 }
200 if (mainprog_ptr->have_text & TEXT_COPY) {
201 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
202 text[num_text].key = "Copyright";
203 text[num_text].text = mainprog_ptr->copyright;
204 ++num_text;
205 }
206 if (mainprog_ptr->have_text & TEXT_EMAIL) {
207 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
208 text[num_text].key = "E-mail";
209 text[num_text].text = mainprog_ptr->email;
210 ++num_text;
211 }
212 if (mainprog_ptr->have_text & TEXT_URL) {
213 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
214 text[num_text].key = "URL";
215 text[num_text].text = mainprog_ptr->url;
216 ++num_text;
217 }
218 png_set_text(png_ptr, info_ptr, text, num_text);
219 }
220
221
222 /* write all chunks up to (but not including) first IDAT */
223
224 png_write_info(png_ptr, info_ptr);
225
226
227 /* if we wanted to write any more text info *after* the image data, we
228 * would set up text struct(s) here and call png_set_text() again, with
229 * just the new data; png_set_tIME() could also go here, but it would
230 * have no effect since we already called it above (only one tIME chunk
231 * allowed) */
232
233
234 /* set up the transformations: for now, just pack low-bit-depth pixels
235 * into bytes (one, two or four pixels per byte) */
236
237 png_set_packing(png_ptr);
238/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
239
240
241 /* make sure we save our pointers for use in writepng_encode_image() */
242
243 mainprog_ptr->png_ptr = png_ptr;
244 mainprog_ptr->info_ptr = info_ptr;
245
246
247 /* OK, that's all we need to do for now; return happy */
248
249 return 0;
250}
251
252
253
254
255
256/* returns 0 for success, 2 for libpng (longjmp) problem */
257
258int writepng_encode_image(mainprog_info *mainprog_ptr)
259{
260 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
261 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
262
263
264 /* as always, setjmp() must be called in every function that calls a
265 * PNG-writing libpng function */
266
267 if (setjmp(mainprog_ptr->jmpbuf)) {
268 png_destroy_write_struct(&png_ptr, &info_ptr);
269 mainprog_ptr->png_ptr = NULL;
270 mainprog_ptr->info_ptr = NULL;
271 return 2;
272 }
273
274
275 /* and now we just write the whole image; libpng takes care of interlacing
276 * for us */
277
278 png_write_image(png_ptr, mainprog_ptr->row_pointers);
279
280
281 /* since that's it, we also close out the end of the PNG file now--if we
282 * had any text or time info to write after the IDATs, second argument
283 * would be info_ptr, but we optimize slightly by sending NULL pointer: */
284
285 png_write_end(png_ptr, NULL);
286
287 return 0;
288}
289
290
291
292
293
294/* returns 0 if succeeds, 2 if libpng problem */
295
296int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
297{
298 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
299 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
300
301
302 /* as always, setjmp() must be called in every function that calls a
303 * PNG-writing libpng function */
304
305 if (setjmp(mainprog_ptr->jmpbuf)) {
306 png_destroy_write_struct(&png_ptr, &info_ptr);
307 mainprog_ptr->png_ptr = NULL;
308 mainprog_ptr->info_ptr = NULL;
309 return 2;
310 }
311
312
313 /* image_data points at our one row of image data */
314
315 png_write_row(png_ptr, mainprog_ptr->image_data);
316
317 return 0;
318}
319
320
321
322
323
324/* returns 0 if succeeds, 2 if libpng problem */
325
326int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */
327{
328 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
329 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
330
331
332 /* as always, setjmp() must be called in every function that calls a
333 * PNG-writing libpng function */
334
335 if (setjmp(mainprog_ptr->jmpbuf)) {
336 png_destroy_write_struct(&png_ptr, &info_ptr);
337 mainprog_ptr->png_ptr = NULL;
338 mainprog_ptr->info_ptr = NULL;
339 return 2;
340 }
341
342
343 /* close out PNG file; if we had any text or time info to write after
344 * the IDATs, second argument would be info_ptr: */
345
346 png_write_end(png_ptr, NULL);
347
348 return 0;
349}
350
351
352
353
354
355void writepng_cleanup(mainprog_info *mainprog_ptr)
356{
357 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
358 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
359
360 if (png_ptr && info_ptr)
361 png_destroy_write_struct(&png_ptr, &info_ptr);
362}
363
364
365
366
367
368static void writepng_error_handler(png_structp png_ptr, png_const_charp msg)
369{
370 mainprog_info *mainprog_ptr;
371
372 /* This function, aside from the extra step of retrieving the "error
373 * pointer" (below) and the fact that it exists within the application
374 * rather than within libpng, is essentially identical to libpng's
375 * default error handler. The second point is critical: since both
376 * setjmp() and longjmp() are called from the same code, they are
377 * guaranteed to have compatible notions of how big a jmp_buf is,
378 * regardless of whether _BSD_SOURCE or anything else has (or has not)
379 * been defined. */
380
381 fprintf(stderr, "writepng libpng error: %s\n", msg);
382 fflush(stderr);
383
384 mainprog_ptr = png_get_error_ptr(png_ptr);
385 if (mainprog_ptr == NULL) { /* we are completely hosed now */
386 fprintf(stderr,
387 "writepng severe error: jmpbuf not recoverable; terminating.\n");
388 fflush(stderr);
389 exit(99);
390 }
391
392 /* Now we have our data structure we can use the information in it
393 * to return control to our own higher level code (all the points
394 * where 'setjmp' is called in this file.) This will work with other
395 * error handling mechanisms as well - libpng always calls png_error
396 * when it can proceed no further, thus, so long as the error handler
397 * is intercepted, application code can do its own error recovery.
398 */
399 longjmp(mainprog_ptr->jmpbuf, 1);
400}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h
new file mode 100644
index 0000000..904e4fb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h
@@ -0,0 +1,133 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program writepng.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72#define TEXT_TITLE 0x01
73#define TEXT_AUTHOR 0x02
74#define TEXT_DESC 0x04
75#define TEXT_COPY 0x08
76#define TEXT_EMAIL 0x10
77#define TEXT_URL 0x20
78
79#define TEXT_TITLE_OFFSET 0
80#define TEXT_AUTHOR_OFFSET 72
81#define TEXT_COPY_OFFSET (2*72)
82#define TEXT_EMAIL_OFFSET (3*72)
83#define TEXT_URL_OFFSET (4*72)
84#define TEXT_DESC_OFFSET (5*72)
85
86typedef unsigned char uch;
87typedef unsigned short ush;
88typedef unsigned long ulg;
89
90typedef struct _mainprog_info {
91 double gamma;
92 long width;
93 long height;
94 time_t modtime;
95 FILE *infile;
96 FILE *outfile;
97 void *png_ptr;
98 void *info_ptr;
99 uch *image_data;
100 uch **row_pointers;
101 char *title;
102 char *author;
103 char *desc;
104 char *copyright;
105 char *email;
106 char *url;
107 int filter; /* command-line-filter flag, not PNG row filter! */
108 int pnmtype;
109 int sample_depth;
110 int interlaced;
111 int have_bg;
112 int have_time;
113 int have_text;
114 jmp_buf jmpbuf;
115 uch bg_red;
116 uch bg_green;
117 uch bg_blue;
118} mainprog_info;
119
120
121/* prototypes for public functions in writepng.c */
122
123void writepng_version_info(void);
124
125int writepng_init(mainprog_info *mainprog_ptr);
126
127int writepng_encode_image(mainprog_info *mainprog_ptr);
128
129int writepng_encode_row(mainprog_info *mainprog_ptr);
130
131int writepng_encode_finish(mainprog_info *mainprog_ptr);
132
133void writepng_cleanup(mainprog_info *mainprog_ptr);
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/libtests/pngvalid.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/libtests/pngvalid.c
new file mode 100644
index 0000000..c7068fa
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/libtests/pngvalid.c
@@ -0,0 +1,9837 @@
1
2/* pngvalid.c - validate libpng by constructing then reading png files.
3 *
4 * Last changed in libpng 1.5.8 [%RDATE%]
5 * Copyright (c) 2012 Glenn Randers-Pehrson
6 * Written by John Cunningham Bowler
7 *
8 * This code is released under the libpng license.
9 * For conditions of distribution and use, see the disclaimer
10 * and license in png.h
11 *
12 * NOTES:
13 * This is a C program that is intended to be linked against libpng. It
14 * generates bitmaps internally, stores them as PNG files (using the
15 * sequential write code) then reads them back (using the sequential
16 * read code) and validates that the result has the correct data.
17 *
18 * The program can be modified and extended to test the correctness of
19 * transformations performed by libpng.
20 */
21
22#define _POSIX_SOURCE 1
23#define _ISOC99_SOURCE 1 /* For floating point */
24#define _GNU_SOURCE 1 /* For the floating point exception extension */
25
26#include <signal.h>
27
28#ifdef HAVE_FEENABLEEXCEPT
29# include <fenv.h>
30#endif
31
32/* Define the following to use this test against your installed libpng, rather
33 * than the one being built here:
34 */
35#ifdef PNG_FREESTANDING_TESTS
36# include <png.h>
37#else
38# include "../../png.h"
39#endif
40
41#if PNG_LIBPNG_VER < 10500
42/* This deliberately lacks the PNG_CONST. */
43typedef png_byte *png_const_bytep;
44
45/* This is copied from 1.5.1 png.h: */
46#define PNG_INTERLACE_ADAM7_PASSES 7
47#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
48#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
49#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
50#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
51#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
52 -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
53#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
54 -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
55#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
56 (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
57#define PNG_COL_FROM_PASS_COL(xIn, pass) \
58 (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
59#define PNG_PASS_MASK(pass,off) ( \
60 ((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
61 ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
62#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
63 ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
64#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
65 ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
66
67/* These are needed too for the default build: */
68#define PNG_WRITE_16BIT_SUPPORTED
69#define PNG_READ_16BIT_SUPPORTED
70
71/* This comes from pnglibconf.h afer 1.5: */
72#define PNG_FP_1 100000
73#define PNG_GAMMA_THRESHOLD_FIXED\
74 ((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))
75#endif
76
77#include "zlib.h" /* For crc32 */
78
79#include <float.h> /* For floating point constants */
80#include <stdlib.h> /* For malloc */
81#include <string.h> /* For memcpy, memset */
82#include <math.h> /* For floor */
83
84/* Unused formal parameter errors are removed using the following macro which is
85 * expected to have no bad effects on performance.
86 */
87#ifndef UNUSED
88# if defined(__GNUC__) || defined(_MSC_VER)
89# define UNUSED(param) (void)param;
90# else
91# define UNUSED(param)
92# endif
93#endif
94
95/***************************** EXCEPTION HANDLING *****************************/
96#include "../visupng/cexcept.h"
97
98#ifdef __cplusplus
99# define this not_the_cpp_this
100# define new not_the_cpp_new
101# define voidcast(type, value) static_cast<type>(value)
102#else
103# define voidcast(type, value) (value)
104#endif /* __cplusplus */
105
106struct png_store;
107define_exception_type(struct png_store*);
108
109/* The following are macros to reduce typing everywhere where the well known
110 * name 'the_exception_context' must be defined.
111 */
112#define anon_context(ps) struct exception_context *the_exception_context = \
113 &(ps)->exception_context
114#define context(ps,fault) anon_context(ps); png_store *fault
115
116/******************************* UTILITIES ************************************/
117/* Error handling is particularly problematic in production code - error
118 * handlers often themselves have bugs which lead to programs that detect
119 * minor errors crashing. The following functions deal with one very
120 * common class of errors in error handlers - attempting to format error or
121 * warning messages into buffers that are too small.
122 */
123static size_t safecat(char *buffer, size_t bufsize, size_t pos,
124 PNG_CONST char *cat)
125{
126 while (pos < bufsize && cat != NULL && *cat != 0)
127 buffer[pos++] = *cat++;
128
129 if (pos >= bufsize)
130 pos = bufsize-1;
131
132 buffer[pos] = 0;
133 return pos;
134}
135
136static size_t safecatn(char *buffer, size_t bufsize, size_t pos, int n)
137{
138 char number[64];
139 sprintf(number, "%d", n);
140 return safecat(buffer, bufsize, pos, number);
141}
142
143#ifdef PNG_READ_TRANSFORMS_SUPPORTED
144static size_t safecatd(char *buffer, size_t bufsize, size_t pos, double d,
145 int precision)
146{
147 char number[64];
148 sprintf(number, "%.*f", precision, d);
149 return safecat(buffer, bufsize, pos, number);
150}
151#endif
152
153static PNG_CONST char invalid[] = "invalid";
154static PNG_CONST char sep[] = ": ";
155
156static PNG_CONST char *colour_types[8] =
157{
158 "grayscale", invalid, "truecolour", "indexed-colour",
159 "grayscale with alpha", invalid, "truecolour with alpha", invalid
160};
161
162/* Convert a double precision value to fixed point. */
163static png_fixed_point
164fix(double d)
165{
166 d = floor(d * PNG_FP_1 + .5);
167 return (png_fixed_point)d;
168}
169
170/* Generate random bytes. This uses a boring repeatable algorithm and it
171 * is implemented here so that it gives the same set of numbers on every
172 * architecture. It's a linear congruential generator (Knuth or Sedgewick
173 * "Algorithms") but it comes from the 'feedback taps' table in Horowitz and
174 * Hill, "The Art of Electronics".
175 */
176static void
177make_random_bytes(png_uint_32* seed, void* pv, size_t size)
178{
179 png_uint_32 u0 = seed[0], u1 = seed[1];
180 png_bytep bytes = voidcast(png_bytep, pv);
181
182 /* There are thirty three bits, the next bit in the sequence is bit-33 XOR
183 * bit-20. The top 1 bit is in u1, the bottom 32 are in u0.
184 */
185 size_t i;
186 for (i=0; i<size; ++i)
187 {
188 /* First generate 8 new bits then shift them in at the end. */
189 png_uint_32 u = ((u0 >> (20-8)) ^ ((u1 << 7) | (u0 >> (32-7)))) & 0xff;
190 u1 <<= 8;
191 u1 |= u0 >> 24;
192 u0 <<= 8;
193 u0 |= u;
194 *bytes++ = (png_byte)u;
195 }
196
197 seed[0] = u0;
198 seed[1] = u1;
199}
200
201static void
202make_four_random_bytes(png_uint_32* seed, png_bytep bytes)
203{
204 make_random_bytes(seed, bytes, 4);
205}
206
207static void
208randomize(void *pv, size_t size)
209{
210 static png_uint_32 random_seed[2] = {0x56789abc, 0xd};
211 make_random_bytes(random_seed, pv, size);
212}
213
214#define RANDOMIZE(this) randomize(&(this), sizeof (this))
215
216static unsigned int
217random_mod(unsigned int max)
218{
219 unsigned int x;
220
221 RANDOMIZE(x);
222
223 return x % max; /* 0 .. max-1 */
224}
225
226static int
227random_choice(void)
228{
229 unsigned char x;
230
231 RANDOMIZE(x);
232
233 return x & 1;
234}
235
236/* A numeric ID based on PNG file characteristics. The 'do_interlace' field
237 * simply records whether pngvalid did the interlace itself or whether it
238 * was done by libpng. Width and height must be less than 256. 'palette' is an
239 * index of the palette to use for formats with a palette (0 otherwise.)
240 */
241#define FILEID(col, depth, palette, interlace, width, height, do_interlace) \
242 ((png_uint_32)((col) + ((depth)<<3) + ((palette)<<8) + ((interlace)<<13) + \
243 (((do_interlace)!=0)<<15) + ((width)<<16) + ((height)<<24)))
244
245#define COL_FROM_ID(id) ((png_byte)((id)& 0x7U))
246#define DEPTH_FROM_ID(id) ((png_byte)(((id) >> 3) & 0x1fU))
247#define PALETTE_FROM_ID(id) ((int)(((id) >> 8) & 0x1f))
248#define INTERLACE_FROM_ID(id) ((int)(((id) >> 13) & 0x3))
249#define DO_INTERLACE_FROM_ID(id) ((int)(((id)>>15) & 1))
250#define WIDTH_FROM_ID(id) (((id)>>16) & 0xff)
251#define HEIGHT_FROM_ID(id) (((id)>>24) & 0xff)
252
253/* Utility to construct a standard name for a standard image. */
254static size_t
255standard_name(char *buffer, size_t bufsize, size_t pos, png_byte colour_type,
256 int bit_depth, int npalette, int interlace_type,
257 png_uint_32 w, png_uint_32 h, int do_interlace)
258{
259 pos = safecat(buffer, bufsize, pos, colour_types[colour_type]);
260 if (npalette > 0)
261 {
262 pos = safecat(buffer, bufsize, pos, "[");
263 pos = safecatn(buffer, bufsize, pos, npalette);
264 pos = safecat(buffer, bufsize, pos, "]");
265 }
266 pos = safecat(buffer, bufsize, pos, " ");
267 pos = safecatn(buffer, bufsize, pos, bit_depth);
268 pos = safecat(buffer, bufsize, pos, " bit");
269
270 if (interlace_type != PNG_INTERLACE_NONE)
271 {
272 pos = safecat(buffer, bufsize, pos, " interlaced");
273 if (do_interlace)
274 pos = safecat(buffer, bufsize, pos, "(pngvalid)");
275 else
276 pos = safecat(buffer, bufsize, pos, "(libpng)");
277 }
278
279 if (w > 0 || h > 0)
280 {
281 pos = safecat(buffer, bufsize, pos, " ");
282 pos = safecatn(buffer, bufsize, pos, w);
283 pos = safecat(buffer, bufsize, pos, "x");
284 pos = safecatn(buffer, bufsize, pos, h);
285 }
286
287 return pos;
288}
289
290static size_t
291standard_name_from_id(char *buffer, size_t bufsize, size_t pos, png_uint_32 id)
292{
293 return standard_name(buffer, bufsize, pos, COL_FROM_ID(id),
294 DEPTH_FROM_ID(id), PALETTE_FROM_ID(id), INTERLACE_FROM_ID(id),
295 WIDTH_FROM_ID(id), HEIGHT_FROM_ID(id), DO_INTERLACE_FROM_ID(id));
296}
297
298/* Convenience API and defines to list valid formats. Note that 16 bit read and
299 * write support is required to do 16 bit read tests (we must be able to make a
300 * 16 bit image to test!)
301 */
302#ifdef PNG_WRITE_16BIT_SUPPORTED
303# define WRITE_BDHI 4
304# ifdef PNG_READ_16BIT_SUPPORTED
305# define READ_BDHI 4
306# define DO_16BIT
307# endif
308#else
309# define WRITE_BDHI 3
310#endif
311#ifndef DO_16BIT
312# define READ_BDHI 3
313#endif
314
315/* The following defines the number of different palettes to generate for
316 * each log bit depth of a colour type 3 standard image.
317 */
318#define PALETTE_COUNT(bit_depth) ((bit_depth) > 4 ? 1 : 16)
319
320static int
321next_format(png_bytep colour_type, png_bytep bit_depth, int* palette_number)
322{
323 if (*bit_depth == 0)
324 {
325 *colour_type = 0, *bit_depth = 1, *palette_number = 0;
326 return 1;
327 }
328
329 if (*colour_type == 3)
330 {
331 /* Add multiple palettes for colour type 3. */
332 if (++*palette_number < PALETTE_COUNT(*bit_depth))
333 return 1;
334
335 *palette_number = 0;
336 }
337
338 *bit_depth = (png_byte)(*bit_depth << 1);
339
340 /* Palette images are restricted to 8 bit depth */
341 if (*bit_depth <= 8
342# ifdef DO_16BIT
343 || (*colour_type != 3 && *bit_depth <= 16)
344# endif
345 )
346 return 1;
347
348 /* Move to the next color type, or return 0 at the end. */
349 switch (*colour_type)
350 {
351 case 0:
352 *colour_type = 2;
353 *bit_depth = 8;
354 return 1;
355
356 case 2:
357 *colour_type = 3;
358 *bit_depth = 1;
359 return 1;
360
361 case 3:
362 *colour_type = 4;
363 *bit_depth = 8;
364 return 1;
365
366 case 4:
367 *colour_type = 6;
368 *bit_depth = 8;
369 return 1;
370
371 default:
372 return 0;
373 }
374}
375
376#ifdef PNG_READ_TRANSFORMS_SUPPORTED
377static unsigned int
378sample(png_const_bytep row, png_byte colour_type, png_byte bit_depth,
379 png_uint_32 x, unsigned int sample_index)
380{
381 png_uint_32 bit_index, result;
382
383 /* Find a sample index for the desired sample: */
384 x *= bit_depth;
385 bit_index = x;
386
387 if ((colour_type & 1) == 0) /* !palette */
388 {
389 if (colour_type & 2)
390 bit_index *= 3;
391
392 if (colour_type & 4)
393 bit_index += x; /* Alpha channel */
394
395 /* Multiple channels; select one: */
396 if (colour_type & (2+4))
397 bit_index += sample_index * bit_depth;
398 }
399
400 /* Return the sample from the row as an integer. */
401 row += bit_index >> 3;
402 result = *row;
403
404 if (bit_depth == 8)
405 return result;
406
407 else if (bit_depth > 8)
408 return (result << 8) + *++row;
409
410 /* Less than 8 bits per sample. */
411 bit_index &= 7;
412 return (result >> (8-bit_index-bit_depth)) & ((1U<<bit_depth)-1);
413}
414#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
415
416/* Copy a single pixel, of a given size, from one buffer to another -
417 * while this is basically bit addressed there is an implicit assumption
418 * that pixels 8 or more bits in size are byte aligned and that pixels
419 * do not otherwise cross byte boundaries. (This is, so far as I know,
420 * universally true in bitmap computer graphics. [JCB 20101212])
421 *
422 * NOTE: The to and from buffers may be the same.
423 */
424static void
425pixel_copy(png_bytep toBuffer, png_uint_32 toIndex,
426 png_const_bytep fromBuffer, png_uint_32 fromIndex, unsigned int pixelSize)
427{
428 /* Assume we can multiply by 'size' without overflow because we are
429 * just working in a single buffer.
430 */
431 toIndex *= pixelSize;
432 fromIndex *= pixelSize;
433 if (pixelSize < 8) /* Sub-byte */
434 {
435 /* Mask to select the location of the copied pixel: */
436 unsigned int destMask = ((1U<<pixelSize)-1) << (8-pixelSize-(toIndex&7));
437 /* The following read the entire pixels and clears the extra: */
438 unsigned int destByte = toBuffer[toIndex >> 3] & ~destMask;
439 unsigned int sourceByte = fromBuffer[fromIndex >> 3];
440
441 /* Don't rely on << or >> supporting '0' here, just in case: */
442 fromIndex &= 7;
443 if (fromIndex > 0) sourceByte <<= fromIndex;
444 if ((toIndex & 7) > 0) sourceByte >>= toIndex & 7;
445
446 toBuffer[toIndex >> 3] = (png_byte)(destByte | (sourceByte & destMask));
447 }
448 else /* One or more bytes */
449 memmove(toBuffer+(toIndex>>3), fromBuffer+(fromIndex>>3), pixelSize>>3);
450}
451
452/* Copy a complete row of pixels, taking into account potential partial
453 * bytes at the end.
454 */
455static void
456row_copy(png_bytep toBuffer, png_const_bytep fromBuffer, unsigned int bitWidth)
457{
458 memcpy(toBuffer, fromBuffer, bitWidth >> 3);
459
460 if ((bitWidth & 7) != 0)
461 {
462 unsigned int mask;
463
464 toBuffer += bitWidth >> 3;
465 fromBuffer += bitWidth >> 3;
466 /* The remaining bits are in the top of the byte, the mask is the bits to
467 * retain.
468 */
469 mask = 0xff >> (bitWidth & 7);
470 *toBuffer = (png_byte)((*toBuffer & mask) | (*fromBuffer & ~mask));
471 }
472}
473
474/* Compare pixels - they are assumed to start at the first byte in the
475 * given buffers.
476 */
477static int
478pixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)
479{
480#if PNG_LIBPNG_VER < 10506
481 if (memcmp(pa, pb, bit_width>>3) == 0)
482 {
483 png_uint_32 p;
484
485 if ((bit_width & 7) == 0) return 0;
486
487 /* Ok, any differences? */
488 p = pa[bit_width >> 3];
489 p ^= pb[bit_width >> 3];
490
491 if (p == 0) return 0;
492
493 /* There are, but they may not be significant, remove the bits
494 * after the end (the low order bits in PNG.)
495 */
496 bit_width &= 7;
497 p >>= 8-bit_width;
498
499 if (p == 0) return 0;
500 }
501#else
502 /* From libpng-1.5.6 the overwrite should be fixed, so compare the trailing
503 * bits too:
504 */
505 if (memcmp(pa, pb, (bit_width+7)>>3) == 0)
506 return 0;
507#endif
508
509 /* Return the index of the changed byte. */
510 {
511 png_uint_32 where = 0;
512
513 while (pa[where] == pb[where]) ++where;
514 return 1+where;
515 }
516}
517
518/*************************** BASIC PNG FILE WRITING ***************************/
519/* A png_store takes data from the sequential writer or provides data
520 * to the sequential reader. It can also store the result of a PNG
521 * write for later retrieval.
522 */
523#define STORE_BUFFER_SIZE 500 /* arbitrary */
524typedef struct png_store_buffer
525{
526 struct png_store_buffer* prev; /* NOTE: stored in reverse order */
527 png_byte buffer[STORE_BUFFER_SIZE];
528} png_store_buffer;
529
530#define FILE_NAME_SIZE 64
531
532typedef struct store_palette_entry /* record of a single palette entry */
533{
534 png_byte red;
535 png_byte green;
536 png_byte blue;
537 png_byte alpha;
538} store_palette_entry, store_palette[256];
539
540typedef struct png_store_file
541{
542 struct png_store_file* next; /* as many as you like... */
543 char name[FILE_NAME_SIZE];
544 png_uint_32 id; /* must be correct (see FILEID) */
545 png_size_t datacount; /* In this (the last) buffer */
546 png_store_buffer data; /* Last buffer in file */
547 int npalette; /* Number of entries in palette */
548 store_palette_entry* palette; /* May be NULL */
549} png_store_file;
550
551/* The following is a pool of memory allocated by a single libpng read or write
552 * operation.
553 */
554typedef struct store_pool
555{
556 struct png_store *store; /* Back pointer */
557 struct store_memory *list; /* List of allocated memory */
558 png_byte mark[4]; /* Before and after data */
559
560 /* Statistics for this run. */
561 png_alloc_size_t max; /* Maximum single allocation */
562 png_alloc_size_t current; /* Current allocation */
563 png_alloc_size_t limit; /* Highest current allocation */
564 png_alloc_size_t total; /* Total allocation */
565
566 /* Overall statistics (retained across successive runs). */
567 png_alloc_size_t max_max;
568 png_alloc_size_t max_limit;
569 png_alloc_size_t max_total;
570} store_pool;
571
572typedef struct png_store
573{
574 /* For cexcept.h exception handling - simply store one of these;
575 * the context is a self pointer but it may point to a different
576 * png_store (in fact it never does in this program.)
577 */
578 struct exception_context
579 exception_context;
580
581 unsigned int verbose :1;
582 unsigned int treat_warnings_as_errors :1;
583 unsigned int expect_error :1;
584 unsigned int expect_warning :1;
585 unsigned int saw_warning :1;
586 unsigned int speed :1;
587 unsigned int progressive :1; /* use progressive read */
588 unsigned int validated :1; /* used as a temporary flag */
589 int nerrors;
590 int nwarnings;
591 char test[128]; /* Name of test */
592 char error[256];
593
594 /* Read fields */
595 png_structp pread; /* Used to read a saved file */
596 png_infop piread;
597 png_store_file* current; /* Set when reading */
598 png_store_buffer* next; /* Set when reading */
599 png_size_t readpos; /* Position in *next */
600 png_byte* image; /* Buffer for reading interlaced images */
601 png_size_t cb_image; /* Size of this buffer */
602 png_size_t cb_row; /* Row size of the image(s) */
603 png_uint_32 image_h; /* Number of rows in a single image */
604 store_pool read_memory_pool;
605
606 /* Write fields */
607 png_store_file* saved;
608 png_structp pwrite; /* Used when writing a new file */
609 png_infop piwrite;
610 png_size_t writepos; /* Position in .new */
611 char wname[FILE_NAME_SIZE];
612 png_store_buffer new; /* The end of the new PNG file being written. */
613 store_pool write_memory_pool;
614 store_palette_entry* palette;
615 int npalette;
616} png_store;
617
618/* Initialization and cleanup */
619static void
620store_pool_mark(png_bytep mark)
621{
622 static png_uint_32 store_seed[2] = { 0x12345678, 1};
623
624 make_four_random_bytes(store_seed, mark);
625}
626
627/* Use this for random 32 bit values; this function makes sure the result is
628 * non-zero.
629 */
630static png_uint_32
631random_32(void)
632{
633
634 for(;;)
635 {
636 png_byte mark[4];
637 png_uint_32 result;
638
639 store_pool_mark(mark);
640 result = png_get_uint_32(mark);
641
642 if (result != 0)
643 return result;
644 }
645}
646
647static void
648store_pool_init(png_store *ps, store_pool *pool)
649{
650 memset(pool, 0, sizeof *pool);
651
652 pool->store = ps;
653 pool->list = NULL;
654 pool->max = pool->current = pool->limit = pool->total = 0;
655 pool->max_max = pool->max_limit = pool->max_total = 0;
656 store_pool_mark(pool->mark);
657}
658
659static void
660store_init(png_store* ps)
661{
662 memset(ps, 0, sizeof *ps);
663 init_exception_context(&ps->exception_context);
664 store_pool_init(ps, &ps->read_memory_pool);
665 store_pool_init(ps, &ps->write_memory_pool);
666 ps->verbose = 0;
667 ps->treat_warnings_as_errors = 0;
668 ps->expect_error = 0;
669 ps->expect_warning = 0;
670 ps->saw_warning = 0;
671 ps->speed = 0;
672 ps->progressive = 0;
673 ps->validated = 0;
674 ps->nerrors = ps->nwarnings = 0;
675 ps->pread = NULL;
676 ps->piread = NULL;
677 ps->saved = ps->current = NULL;
678 ps->next = NULL;
679 ps->readpos = 0;
680 ps->image = NULL;
681 ps->cb_image = 0;
682 ps->cb_row = 0;
683 ps->image_h = 0;
684 ps->pwrite = NULL;
685 ps->piwrite = NULL;
686 ps->writepos = 0;
687 ps->new.prev = NULL;
688 ps->palette = NULL;
689 ps->npalette = 0;
690}
691
692static void
693store_freebuffer(png_store_buffer* psb)
694{
695 if (psb->prev)
696 {
697 store_freebuffer(psb->prev);
698 free(psb->prev);
699 psb->prev = NULL;
700 }
701}
702
703static void
704store_freenew(png_store *ps)
705{
706 store_freebuffer(&ps->new);
707 ps->writepos = 0;
708 if (ps->palette != NULL)
709 {
710 free(ps->palette);
711 ps->palette = NULL;
712 ps->npalette = 0;
713 }
714}
715
716static void
717store_storenew(png_store *ps)
718{
719 png_store_buffer *pb;
720
721 if (ps->writepos != STORE_BUFFER_SIZE)
722 png_error(ps->pwrite, "invalid store call");
723
724 pb = voidcast(png_store_buffer*, malloc(sizeof *pb));
725
726 if (pb == NULL)
727 png_error(ps->pwrite, "store new: OOM");
728
729 *pb = ps->new;
730 ps->new.prev = pb;
731 ps->writepos = 0;
732}
733
734static void
735store_freefile(png_store_file **ppf)
736{
737 if (*ppf != NULL)
738 {
739 store_freefile(&(*ppf)->next);
740
741 store_freebuffer(&(*ppf)->data);
742 (*ppf)->datacount = 0;
743 if ((*ppf)->palette != NULL)
744 {
745 free((*ppf)->palette);
746 (*ppf)->palette = NULL;
747 (*ppf)->npalette = 0;
748 }
749 free(*ppf);
750 *ppf = NULL;
751 }
752}
753
754/* Main interface to file storeage, after writing a new PNG file (see the API
755 * below) call store_storefile to store the result with the given name and id.
756 */
757static void
758store_storefile(png_store *ps, png_uint_32 id)
759{
760 png_store_file *pf = voidcast(png_store_file*, malloc(sizeof *pf));
761 if (pf == NULL)
762 png_error(ps->pwrite, "storefile: OOM");
763 safecat(pf->name, sizeof pf->name, 0, ps->wname);
764 pf->id = id;
765 pf->data = ps->new;
766 pf->datacount = ps->writepos;
767 ps->new.prev = NULL;
768 ps->writepos = 0;
769 pf->palette = ps->palette;
770 pf->npalette = ps->npalette;
771 ps->palette = 0;
772 ps->npalette = 0;
773
774 /* And save it. */
775 pf->next = ps->saved;
776 ps->saved = pf;
777}
778
779/* Generate an error message (in the given buffer) */
780static size_t
781store_message(png_store *ps, png_structp pp, char *buffer, size_t bufsize,
782 size_t pos, PNG_CONST char *msg)
783{
784 if (pp != NULL && pp == ps->pread)
785 {
786 /* Reading a file */
787 pos = safecat(buffer, bufsize, pos, "read: ");
788
789 if (ps->current != NULL)
790 {
791 pos = safecat(buffer, bufsize, pos, ps->current->name);
792 pos = safecat(buffer, bufsize, pos, sep);
793 }
794 }
795
796 else if (pp != NULL && pp == ps->pwrite)
797 {
798 /* Writing a file */
799 pos = safecat(buffer, bufsize, pos, "write: ");
800 pos = safecat(buffer, bufsize, pos, ps->wname);
801 pos = safecat(buffer, bufsize, pos, sep);
802 }
803
804 else
805 {
806 /* Neither reading nor writing (or a memory error in struct delete) */
807 pos = safecat(buffer, bufsize, pos, "pngvalid: ");
808 }
809
810 if (ps->test[0] != 0)
811 {
812 pos = safecat(buffer, bufsize, pos, ps->test);
813 pos = safecat(buffer, bufsize, pos, sep);
814 }
815 pos = safecat(buffer, bufsize, pos, msg);
816 return pos;
817}
818
819/* Verbose output to the error stream: */
820static void
821store_verbose(png_store *ps, png_structp pp, png_const_charp prefix,
822 png_const_charp message)
823{
824 char buffer[512];
825
826 if (prefix)
827 fputs(prefix, stderr);
828
829 (void)store_message(ps, pp, buffer, sizeof buffer, 0, message);
830 fputs(buffer, stderr);
831 fputc('\n', stderr);
832}
833
834/* Log an error or warning - the relevant count is always incremented. */
835static void
836store_log(png_store* ps, png_structp pp, png_const_charp message, int is_error)
837{
838 /* The warning is copied to the error buffer if there are no errors and it is
839 * the first warning. The error is copied to the error buffer if it is the
840 * first error (overwriting any prior warnings).
841 */
842 if (is_error ? (ps->nerrors)++ == 0 :
843 (ps->nwarnings)++ == 0 && ps->nerrors == 0)
844 store_message(ps, pp, ps->error, sizeof ps->error, 0, message);
845
846 if (ps->verbose)
847 store_verbose(ps, pp, is_error ? "error: " : "warning: ", message);
848}
849
850/* Internal error function, called with a png_store but no libpng stuff. */
851static void
852internal_error(png_store *ps, png_const_charp message)
853{
854 store_log(ps, NULL, message, 1 /* error */);
855
856 /* And finally throw an exception. */
857 {
858 struct exception_context *the_exception_context = &ps->exception_context;
859 Throw ps;
860 }
861}
862
863/* Functions to use as PNG callbacks. */
864static void
865store_error(png_structp pp, png_const_charp message) /* PNG_NORETURN */
866{
867 png_store *ps = voidcast(png_store*, png_get_error_ptr(pp));
868
869 if (!ps->expect_error)
870 store_log(ps, pp, message, 1 /* error */);
871
872 /* And finally throw an exception. */
873 {
874 struct exception_context *the_exception_context = &ps->exception_context;
875 Throw ps;
876 }
877}
878
879static void
880store_warning(png_structp pp, png_const_charp message)
881{
882 png_store *ps = voidcast(png_store*, png_get_error_ptr(pp));
883
884 if (!ps->expect_warning)
885 store_log(ps, pp, message, 0 /* warning */);
886 else
887 ps->saw_warning = 1;
888}
889
890/* These somewhat odd functions are used when reading an image to ensure that
891 * the buffer is big enough, the png_structp is for errors.
892 */
893/* Return a single row from the correct image. */
894static png_bytep
895store_image_row(PNG_CONST png_store* ps, png_structp pp, int nImage,
896 png_uint_32 y)
897{
898 png_size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2;
899
900 if (ps->image == NULL)
901 png_error(pp, "no allocated image");
902
903 if (coffset + ps->cb_row + 3 > ps->cb_image)
904 png_error(pp, "image too small");
905
906 return ps->image + coffset;
907}
908
909static void
910store_image_free(png_store *ps, png_structp pp)
911{
912 if (ps->image != NULL)
913 {
914 png_bytep image = ps->image;
915
916 if (image[-1] != 0xed || image[ps->cb_image] != 0xfe)
917 {
918 if (pp != NULL)
919 png_error(pp, "png_store image overwrite (1)");
920 else
921 store_log(ps, NULL, "png_store image overwrite (2)", 1);
922 }
923
924 ps->image = NULL;
925 ps->cb_image = 0;
926 --image;
927 free(image);
928 }
929}
930
931static void
932store_ensure_image(png_store *ps, png_structp pp, int nImages, png_size_t cbRow,
933 png_uint_32 cRows)
934{
935 png_size_t cb = nImages * cRows * (cbRow + 5);
936
937 if (ps->cb_image < cb)
938 {
939 png_bytep image;
940
941 store_image_free(ps, pp);
942
943 /* The buffer is deliberately mis-aligned. */
944 image = voidcast(png_bytep, malloc(cb+2));
945 if (image == NULL)
946 {
947 /* Called from the startup - ignore the error for the moment. */
948 if (pp == NULL)
949 return;
950
951 png_error(pp, "OOM allocating image buffer");
952 }
953
954 /* These magic tags are used to detect overwrites above. */
955 ++image;
956 image[-1] = 0xed;
957 image[cb] = 0xfe;
958
959 ps->image = image;
960 ps->cb_image = cb;
961 }
962
963 /* We have an adequate sized image; lay out the rows. There are 2 bytes at
964 * the start and three at the end of each (this ensures that the row
965 * alignment starts out odd - 2+1 and changes for larger images on each row.)
966 */
967 ps->cb_row = cbRow;
968 ps->image_h = cRows;
969
970 /* For error checking, the whole buffer is set to 10110010 (0xb2 - 178).
971 * This deliberately doesn't match the bits in the size test image which are
972 * outside the image; these are set to 0xff (all 1). To make the row
973 * comparison work in the 'size' test case the size rows are pre-initialized
974 * to the same value prior to calling 'standard_row'.
975 */
976 memset(ps->image, 178, cb);
977
978 /* Then put in the marks. */
979 while (--nImages >= 0)
980 {
981 png_uint_32 y;
982
983 for (y=0; y<cRows; ++y)
984 {
985 png_bytep row = store_image_row(ps, pp, nImages, y);
986
987 /* The markers: */
988 row[-2] = 190;
989 row[-1] = 239;
990 row[cbRow] = 222;
991 row[cbRow+1] = 173;
992 row[cbRow+2] = 17;
993 }
994 }
995}
996
997static void
998store_image_check(PNG_CONST png_store* ps, png_structp pp, int iImage)
999{
1000 png_const_bytep image = ps->image;
1001
1002 if (image[-1] != 0xed || image[ps->cb_image] != 0xfe)
1003 png_error(pp, "image overwrite");
1004 else
1005 {
1006 png_size_t cbRow = ps->cb_row;
1007 png_uint_32 rows = ps->image_h;
1008
1009 image += iImage * (cbRow+5) * ps->image_h;
1010
1011 image += 2; /* skip image first row markers */
1012
1013 while (rows-- > 0)
1014 {
1015 if (image[-2] != 190 || image[-1] != 239)
1016 png_error(pp, "row start overwritten");
1017
1018 if (image[cbRow] != 222 || image[cbRow+1] != 173 ||
1019 image[cbRow+2] != 17)
1020 png_error(pp, "row end overwritten");
1021
1022 image += cbRow+5;
1023 }
1024 }
1025}
1026
1027static void
1028store_write(png_structp pp, png_bytep pb, png_size_t st)
1029{
1030 png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
1031
1032 if (ps->pwrite != pp)
1033 png_error(pp, "store state damaged");
1034
1035 while (st > 0)
1036 {
1037 size_t cb;
1038
1039 if (ps->writepos >= STORE_BUFFER_SIZE)
1040 store_storenew(ps);
1041
1042 cb = st;
1043
1044 if (cb > STORE_BUFFER_SIZE - ps->writepos)
1045 cb = STORE_BUFFER_SIZE - ps->writepos;
1046
1047 memcpy(ps->new.buffer + ps->writepos, pb, cb);
1048 pb += cb;
1049 st -= cb;
1050 ps->writepos += cb;
1051 }
1052}
1053
1054static void
1055store_flush(png_structp pp)
1056{
1057 UNUSED(pp) /*DOES NOTHING*/
1058}
1059
1060static size_t
1061store_read_buffer_size(png_store *ps)
1062{
1063 /* Return the bytes available for read in the current buffer. */
1064 if (ps->next != &ps->current->data)
1065 return STORE_BUFFER_SIZE;
1066
1067 return ps->current->datacount;
1068}
1069
1070#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1071/* Return total bytes available for read. */
1072static size_t
1073store_read_buffer_avail(png_store *ps)
1074{
1075 if (ps->current != NULL && ps->next != NULL)
1076 {
1077 png_store_buffer *next = &ps->current->data;
1078 size_t cbAvail = ps->current->datacount;
1079
1080 while (next != ps->next && next != NULL)
1081 {
1082 next = next->prev;
1083 cbAvail += STORE_BUFFER_SIZE;
1084 }
1085
1086 if (next != ps->next)
1087 png_error(ps->pread, "buffer read error");
1088
1089 if (cbAvail > ps->readpos)
1090 return cbAvail - ps->readpos;
1091 }
1092
1093 return 0;
1094}
1095#endif
1096
1097static int
1098store_read_buffer_next(png_store *ps)
1099{
1100 png_store_buffer *pbOld = ps->next;
1101 png_store_buffer *pbNew = &ps->current->data;
1102 if (pbOld != pbNew)
1103 {
1104 while (pbNew != NULL && pbNew->prev != pbOld)
1105 pbNew = pbNew->prev;
1106
1107 if (pbNew != NULL)
1108 {
1109 ps->next = pbNew;
1110 ps->readpos = 0;
1111 return 1;
1112 }
1113
1114 png_error(ps->pread, "buffer lost");
1115 }
1116
1117 return 0; /* EOF or error */
1118}
1119
1120/* Need separate implementation and callback to allow use of the same code
1121 * during progressive read, where the io_ptr is set internally by libpng.
1122 */
1123static void
1124store_read_imp(png_store *ps, png_bytep pb, png_size_t st)
1125{
1126 if (ps->current == NULL || ps->next == NULL)
1127 png_error(ps->pread, "store state damaged");
1128
1129 while (st > 0)
1130 {
1131 size_t cbAvail = store_read_buffer_size(ps) - ps->readpos;
1132
1133 if (cbAvail > 0)
1134 {
1135 if (cbAvail > st) cbAvail = st;
1136 memcpy(pb, ps->next->buffer + ps->readpos, cbAvail);
1137 st -= cbAvail;
1138 pb += cbAvail;
1139 ps->readpos += cbAvail;
1140 }
1141
1142 else if (!store_read_buffer_next(ps))
1143 png_error(ps->pread, "read beyond end of file");
1144 }
1145}
1146
1147static void
1148store_read(png_structp pp, png_bytep pb, png_size_t st)
1149{
1150 png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));
1151
1152 if (ps == NULL || ps->pread != pp)
1153 png_error(pp, "bad store read call");
1154
1155 store_read_imp(ps, pb, st);
1156}
1157
1158static void
1159store_progressive_read(png_store *ps, png_structp pp, png_infop pi)
1160{
1161 /* Notice that a call to store_read will cause this function to fail because
1162 * readpos will be set.
1163 */
1164 if (ps->pread != pp || ps->current == NULL || ps->next == NULL)
1165 png_error(pp, "store state damaged (progressive)");
1166
1167 do
1168 {
1169 if (ps->readpos != 0)
1170 png_error(pp, "store_read called during progressive read");
1171
1172 png_process_data(pp, pi, ps->next->buffer, store_read_buffer_size(ps));
1173 }
1174 while (store_read_buffer_next(ps));
1175}
1176
1177/* The caller must fill this in: */
1178static store_palette_entry *
1179store_write_palette(png_store *ps, int npalette)
1180{
1181 if (ps->pwrite == NULL)
1182 store_log(ps, NULL, "attempt to write palette without write stream", 1);
1183
1184 if (ps->palette != NULL)
1185 png_error(ps->pwrite, "multiple store_write_palette calls");
1186
1187 /* This function can only return NULL if called with '0'! */
1188 if (npalette > 0)
1189 {
1190 ps->palette = voidcast(store_palette_entry*, malloc(npalette *
1191 sizeof *ps->palette));
1192
1193 if (ps->palette == NULL)
1194 png_error(ps->pwrite, "store new palette: OOM");
1195
1196 ps->npalette = npalette;
1197 }
1198
1199 return ps->palette;
1200}
1201
1202static store_palette_entry *
1203store_current_palette(png_store *ps, int *npalette)
1204{
1205 /* This is an internal error (the call has been made outside a read
1206 * operation.)
1207 */
1208 if (ps->current == NULL)
1209 store_log(ps, ps->pread, "no current stream for palette", 1);
1210
1211 /* The result may be null if there is no palette. */
1212 *npalette = ps->current->npalette;
1213 return ps->current->palette;
1214}
1215
1216/***************************** MEMORY MANAGEMENT*** ***************************/
1217/* A store_memory is simply the header for an allocated block of memory. The
1218 * pointer returned to libpng is just after the end of the header block, the
1219 * allocated memory is followed by a second copy of the 'mark'.
1220 */
1221typedef struct store_memory
1222{
1223 store_pool *pool; /* Originating pool */
1224 struct store_memory *next; /* Singly linked list */
1225 png_alloc_size_t size; /* Size of memory allocated */
1226 png_byte mark[4]; /* ID marker */
1227} store_memory;
1228
1229/* Handle a fatal error in memory allocation. This calls png_error if the
1230 * libpng struct is non-NULL, else it outputs a message and returns. This means
1231 * that a memory problem while libpng is running will abort (png_error) the
1232 * handling of particular file while one in cleanup (after the destroy of the
1233 * struct has returned) will simply keep going and free (or attempt to free)
1234 * all the memory.
1235 */
1236static void
1237store_pool_error(png_store *ps, png_structp pp, PNG_CONST char *msg)
1238{
1239 if (pp != NULL)
1240 png_error(pp, msg);
1241
1242 /* Else we have to do it ourselves. png_error eventually calls store_log,
1243 * above. store_log accepts a NULL png_structp - it just changes what gets
1244 * output by store_message.
1245 */
1246 store_log(ps, pp, msg, 1 /* error */);
1247}
1248
1249static void
1250store_memory_free(png_structp pp, store_pool *pool, store_memory *memory)
1251{
1252 /* Note that pp may be NULL (see store_pool_delete below), the caller has
1253 * found 'memory' in pool->list *and* unlinked this entry, so this is a valid
1254 * pointer (for sure), but the contents may have been trashed.
1255 */
1256 if (memory->pool != pool)
1257 store_pool_error(pool->store, pp, "memory corrupted (pool)");
1258
1259 else if (memcmp(memory->mark, pool->mark, sizeof memory->mark) != 0)
1260 store_pool_error(pool->store, pp, "memory corrupted (start)");
1261
1262 /* It should be safe to read the size field now. */
1263 else
1264 {
1265 png_alloc_size_t cb = memory->size;
1266
1267 if (cb > pool->max)
1268 store_pool_error(pool->store, pp, "memory corrupted (size)");
1269
1270 else if (memcmp((png_bytep)(memory+1)+cb, pool->mark, sizeof pool->mark)
1271 != 0)
1272 store_pool_error(pool->store, pp, "memory corrupted (end)");
1273
1274 /* Finally give the library a chance to find problems too: */
1275 else
1276 {
1277 pool->current -= cb;
1278 free(memory);
1279 }
1280 }
1281}
1282
1283static void
1284store_pool_delete(png_store *ps, store_pool *pool)
1285{
1286 if (pool->list != NULL)
1287 {
1288 fprintf(stderr, "%s: %s %s: memory lost (list follows):\n", ps->test,
1289 pool == &ps->read_memory_pool ? "read" : "write",
1290 pool == &ps->read_memory_pool ? (ps->current != NULL ?
1291 ps->current->name : "unknown file") : ps->wname);
1292 ++ps->nerrors;
1293
1294 do
1295 {
1296 store_memory *next = pool->list;
1297 pool->list = next->next;
1298 next->next = NULL;
1299
1300 fprintf(stderr, "\t%lu bytes @ %p\n",
1301 (unsigned long)next->size, (PNG_CONST void*)(next+1));
1302 /* The NULL means this will always return, even if the memory is
1303 * corrupted.
1304 */
1305 store_memory_free(NULL, pool, next);
1306 }
1307 while (pool->list != NULL);
1308 }
1309
1310 /* And reset the other fields too for the next time. */
1311 if (pool->max > pool->max_max) pool->max_max = pool->max;
1312 pool->max = 0;
1313 if (pool->current != 0) /* unexpected internal error */
1314 fprintf(stderr, "%s: %s %s: memory counter mismatch (internal error)\n",
1315 ps->test, pool == &ps->read_memory_pool ? "read" : "write",
1316 pool == &ps->read_memory_pool ? (ps->current != NULL ?
1317 ps->current->name : "unknown file") : ps->wname);
1318 pool->current = 0;
1319
1320 if (pool->limit > pool->max_limit)
1321 pool->max_limit = pool->limit;
1322
1323 pool->limit = 0;
1324
1325 if (pool->total > pool->max_total)
1326 pool->max_total = pool->total;
1327
1328 pool->total = 0;
1329
1330 /* Get a new mark too. */
1331 store_pool_mark(pool->mark);
1332}
1333
1334/* The memory callbacks: */
1335static png_voidp
1336store_malloc(png_structp pp, png_alloc_size_t cb)
1337{
1338 store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp));
1339 store_memory *new = voidcast(store_memory*, malloc(cb + (sizeof *new) +
1340 (sizeof pool->mark)));
1341
1342 if (new != NULL)
1343 {
1344 if (cb > pool->max)
1345 pool->max = cb;
1346
1347 pool->current += cb;
1348
1349 if (pool->current > pool->limit)
1350 pool->limit = pool->current;
1351
1352 pool->total += cb;
1353
1354 new->size = cb;
1355 memcpy(new->mark, pool->mark, sizeof new->mark);
1356 memcpy((png_byte*)(new+1) + cb, pool->mark, sizeof pool->mark);
1357 new->pool = pool;
1358 new->next = pool->list;
1359 pool->list = new;
1360 ++new;
1361 }
1362
1363 else
1364 {
1365 /* NOTE: the PNG user malloc function cannot use the png_ptr it is passed
1366 * other than to retrieve the allocation pointer! libpng calls the
1367 * store_malloc callback in two basic cases:
1368 *
1369 * 1) From png_malloc; png_malloc will do a png_error itself if NULL is
1370 * returned.
1371 * 2) From png_struct or png_info structure creation; png_malloc is
1372 * to return so cleanup can be performed.
1373 *
1374 * To handle this store_malloc can log a message, but can't do anything
1375 * else.
1376 */
1377 store_log(pool->store, pp, "out of memory", 1 /* is_error */);
1378 }
1379
1380 return new;
1381}
1382
1383static void
1384store_free(png_structp pp, png_voidp memory)
1385{
1386 store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp));
1387 store_memory *this = voidcast(store_memory*, memory), **test;
1388
1389 /* Because libpng calls store_free with a dummy png_struct when deleting
1390 * png_struct or png_info via png_destroy_struct_2 it is necessary to check
1391 * the passed in png_structp to ensure it is valid, and not pass it to
1392 * png_error if it is not.
1393 */
1394 if (pp != pool->store->pread && pp != pool->store->pwrite)
1395 pp = NULL;
1396
1397 /* First check that this 'memory' really is valid memory - it must be in the
1398 * pool list. If it is, use the shared memory_free function to free it.
1399 */
1400 --this;
1401 for (test = &pool->list; *test != this; test = &(*test)->next)
1402 {
1403 if (*test == NULL)
1404 {
1405 store_pool_error(pool->store, pp, "bad pointer to free");
1406 return;
1407 }
1408 }
1409
1410 /* Unlink this entry, *test == this. */
1411 *test = this->next;
1412 this->next = NULL;
1413 store_memory_free(pp, pool, this);
1414}
1415
1416/* Setup functions. */
1417/* Cleanup when aborting a write or after storing the new file. */
1418static void
1419store_write_reset(png_store *ps)
1420{
1421 if (ps->pwrite != NULL)
1422 {
1423 anon_context(ps);
1424
1425 Try
1426 png_destroy_write_struct(&ps->pwrite, &ps->piwrite);
1427
1428 Catch_anonymous
1429 {
1430 /* memory corruption: continue. */
1431 }
1432
1433 ps->pwrite = NULL;
1434 ps->piwrite = NULL;
1435 }
1436
1437 /* And make sure that all the memory has been freed - this will output
1438 * spurious errors in the case of memory corruption above, but this is safe.
1439 */
1440 store_pool_delete(ps, &ps->write_memory_pool);
1441
1442 store_freenew(ps);
1443}
1444
1445/* The following is the main write function, it returns a png_struct and,
1446 * optionally, a png_info suitable for writiing a new PNG file. Use
1447 * store_storefile above to record this file after it has been written. The
1448 * returned libpng structures as destroyed by store_write_reset above.
1449 */
1450static png_structp
1451set_store_for_write(png_store *ps, png_infopp ppi,
1452 PNG_CONST char * volatile name)
1453{
1454 anon_context(ps);
1455
1456 Try
1457 {
1458 if (ps->pwrite != NULL)
1459 png_error(ps->pwrite, "write store already in use");
1460
1461 store_write_reset(ps);
1462 safecat(ps->wname, sizeof ps->wname, 0, name);
1463
1464 /* Don't do the slow memory checks if doing a speed test. */
1465 if (ps->speed)
1466 ps->pwrite = png_create_write_struct(PNG_LIBPNG_VER_STRING,
1467 ps, store_error, store_warning);
1468
1469 else
1470 ps->pwrite = png_create_write_struct_2(PNG_LIBPNG_VER_STRING,
1471 ps, store_error, store_warning, &ps->write_memory_pool,
1472 store_malloc, store_free);
1473
1474 png_set_write_fn(ps->pwrite, ps, store_write, store_flush);
1475
1476 if (ppi != NULL)
1477 *ppi = ps->piwrite = png_create_info_struct(ps->pwrite);
1478 }
1479
1480 Catch_anonymous
1481 return NULL;
1482
1483 return ps->pwrite;
1484}
1485
1486/* Cleanup when finished reading (either due to error or in the success case).
1487 */
1488static void
1489store_read_reset(png_store *ps)
1490{
1491 if (ps->pread != NULL)
1492 {
1493 anon_context(ps);
1494
1495 Try
1496 png_destroy_read_struct(&ps->pread, &ps->piread, NULL);
1497
1498 Catch_anonymous
1499 {
1500 /* error already output: continue */
1501 }
1502
1503 ps->pread = NULL;
1504 ps->piread = NULL;
1505 }
1506
1507 /* Always do this to be safe. */
1508 store_pool_delete(ps, &ps->read_memory_pool);
1509
1510 ps->current = NULL;
1511 ps->next = NULL;
1512 ps->readpos = 0;
1513 ps->validated = 0;
1514}
1515
1516static void
1517store_read_set(png_store *ps, png_uint_32 id)
1518{
1519 png_store_file *pf = ps->saved;
1520
1521 while (pf != NULL)
1522 {
1523 if (pf->id == id)
1524 {
1525 ps->current = pf;
1526 ps->next = NULL;
1527 store_read_buffer_next(ps);
1528 return;
1529 }
1530
1531 pf = pf->next;
1532 }
1533
1534 {
1535 size_t pos;
1536 char msg[FILE_NAME_SIZE+64];
1537
1538 pos = standard_name_from_id(msg, sizeof msg, 0, id);
1539 pos = safecat(msg, sizeof msg, pos, ": file not found");
1540 png_error(ps->pread, msg);
1541 }
1542}
1543
1544/* The main interface for reading a saved file - pass the id number of the file
1545 * to retrieve. Ids must be unique or the earlier file will be hidden. The API
1546 * returns a png_struct and, optionally, a png_info. Both of these will be
1547 * destroyed by store_read_reset above.
1548 */
1549static png_structp
1550set_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,
1551 PNG_CONST char *name)
1552{
1553 /* Set the name for png_error */
1554 safecat(ps->test, sizeof ps->test, 0, name);
1555
1556 if (ps->pread != NULL)
1557 png_error(ps->pread, "read store already in use");
1558
1559 store_read_reset(ps);
1560
1561 /* Both the create APIs can return NULL if used in their default mode
1562 * (because there is no other way of handling an error because the jmp_buf
1563 * by default is stored in png_struct and that has not been allocated!)
1564 * However, given that store_error works correctly in these circumstances
1565 * we don't ever expect NULL in this program.
1566 */
1567 if (ps->speed)
1568 ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps,
1569 store_error, store_warning);
1570
1571 else
1572 ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,
1573 store_error, store_warning, &ps->read_memory_pool, store_malloc,
1574 store_free);
1575
1576 if (ps->pread == NULL)
1577 {
1578 struct exception_context *the_exception_context = &ps->exception_context;
1579
1580 store_log(ps, NULL, "png_create_read_struct returned NULL (unexpected)",
1581 1 /*error*/);
1582
1583 Throw ps;
1584 }
1585
1586 store_read_set(ps, id);
1587
1588 if (ppi != NULL)
1589 *ppi = ps->piread = png_create_info_struct(ps->pread);
1590
1591 return ps->pread;
1592}
1593
1594/* The overall cleanup of a store simply calls the above then removes all the
1595 * saved files. This does not delete the store itself.
1596 */
1597static void
1598store_delete(png_store *ps)
1599{
1600 store_write_reset(ps);
1601 store_read_reset(ps);
1602 store_freefile(&ps->saved);
1603 store_image_free(ps, NULL);
1604}
1605
1606/*********************** PNG FILE MODIFICATION ON READ ************************/
1607/* Files may be modified on read. The following structure contains a complete
1608 * png_store together with extra members to handle modification and a special
1609 * read callback for libpng. To use this the 'modifications' field must be set
1610 * to a list of png_modification structures that actually perform the
1611 * modification, otherwise a png_modifier is functionally equivalent to a
1612 * png_store. There is a special read function, set_modifier_for_read, which
1613 * replaces set_store_for_read.
1614 */
1615typedef enum modifier_state
1616{
1617 modifier_start, /* Initial value */
1618 modifier_signature, /* Have a signature */
1619 modifier_IHDR /* Have an IHDR */
1620} modifier_state;
1621
1622typedef struct CIE_color
1623{
1624 /* A single CIE tristimulus value, representing the unique response of a
1625 * standard observer to a variety of light spectra. The observer recognizes
1626 * all spectra that produce this response as the same color, therefore this
1627 * is effectively a description of a color.
1628 */
1629 double X, Y, Z;
1630} CIE_color;
1631
1632static double
1633chromaticity_x(CIE_color c)
1634{
1635 return c.X / (c.X + c.Y + c.Z);
1636}
1637
1638static double
1639chromaticity_y(CIE_color c)
1640{
1641 return c.Y / (c.X + c.Y + c.Z);
1642}
1643
1644typedef struct color_encoding
1645{
1646 /* A description of an (R,G,B) encoding of color (as defined above); this
1647 * includes the actual colors of the (R,G,B) triples (1,0,0), (0,1,0) and
1648 * (0,0,1) plus an encoding value that is used to encode the linear
1649 * components R, G and B to give the actual values R^gamma, G^gamma and
1650 * B^gamma that are stored.
1651 */
1652 double gamma; /* Encoding (file) gamma of space */
1653 CIE_color red, green, blue; /* End points */
1654} color_encoding;
1655
1656static CIE_color
1657white_point(PNG_CONST color_encoding *encoding)
1658{
1659 CIE_color white;
1660
1661 white.X = encoding->red.X + encoding->green.X + encoding->blue.X;
1662 white.Y = encoding->red.Y + encoding->green.Y + encoding->blue.Y;
1663 white.Z = encoding->red.Z + encoding->green.Z + encoding->blue.Z;
1664
1665 return white;
1666}
1667
1668static void
1669normalize_color_encoding(color_encoding *encoding)
1670{
1671 PNG_CONST double whiteY = encoding->red.Y + encoding->green.Y +
1672 encoding->blue.Y;
1673
1674 if (whiteY != 1)
1675 {
1676 encoding->red.X /= whiteY;
1677 encoding->red.Y /= whiteY;
1678 encoding->red.Z /= whiteY;
1679 encoding->green.X /= whiteY;
1680 encoding->green.Y /= whiteY;
1681 encoding->green.Z /= whiteY;
1682 encoding->blue.X /= whiteY;
1683 encoding->blue.Y /= whiteY;
1684 encoding->blue.Z /= whiteY;
1685 }
1686}
1687
1688static size_t
1689safecat_color_encoding(char *buffer, size_t bufsize, size_t pos,
1690 PNG_CONST color_encoding *e, double encoding_gamma)
1691{
1692 if (e != 0)
1693 {
1694 if (encoding_gamma != 0)
1695 pos = safecat(buffer, bufsize, pos, "(");
1696 pos = safecat(buffer, bufsize, pos, "R(");
1697 pos = safecatd(buffer, bufsize, pos, e->red.X, 4);
1698 pos = safecat(buffer, bufsize, pos, ",");
1699 pos = safecatd(buffer, bufsize, pos, e->red.Y, 4);
1700 pos = safecat(buffer, bufsize, pos, ",");
1701 pos = safecatd(buffer, bufsize, pos, e->red.Z, 4);
1702 pos = safecat(buffer, bufsize, pos, "),G(");
1703 pos = safecatd(buffer, bufsize, pos, e->green.X, 4);
1704 pos = safecat(buffer, bufsize, pos, ",");
1705 pos = safecatd(buffer, bufsize, pos, e->green.Y, 4);
1706 pos = safecat(buffer, bufsize, pos, ",");
1707 pos = safecatd(buffer, bufsize, pos, e->green.Z, 4);
1708 pos = safecat(buffer, bufsize, pos, "),B(");
1709 pos = safecatd(buffer, bufsize, pos, e->blue.X, 4);
1710 pos = safecat(buffer, bufsize, pos, ",");
1711 pos = safecatd(buffer, bufsize, pos, e->blue.Y, 4);
1712 pos = safecat(buffer, bufsize, pos, ",");
1713 pos = safecatd(buffer, bufsize, pos, e->blue.Z, 4);
1714 pos = safecat(buffer, bufsize, pos, ")");
1715 if (encoding_gamma != 0)
1716 pos = safecat(buffer, bufsize, pos, ")");
1717 }
1718
1719 if (encoding_gamma != 0)
1720 {
1721 pos = safecat(buffer, bufsize, pos, "^");
1722 pos = safecatd(buffer, bufsize, pos, encoding_gamma, 5);
1723 }
1724
1725 return pos;
1726}
1727
1728typedef struct png_modifier
1729{
1730 png_store this; /* I am a png_store */
1731 struct png_modification *modifications; /* Changes to make */
1732
1733 modifier_state state; /* My state */
1734
1735 /* Information from IHDR: */
1736 png_byte bit_depth; /* From IHDR */
1737 png_byte colour_type; /* From IHDR */
1738
1739 /* While handling PLTE, IDAT and IEND these chunks may be pended to allow
1740 * other chunks to be inserted.
1741 */
1742 png_uint_32 pending_len;
1743 png_uint_32 pending_chunk;
1744
1745 /* Test values */
1746 double *gammas;
1747 unsigned int ngammas;
1748 unsigned int ngamma_tests; /* Number of gamma tests to run*/
1749 double current_gamma; /* 0 if not set */
1750 PNG_CONST color_encoding *encodings;
1751 unsigned int nencodings;
1752 PNG_CONST color_encoding *current_encoding; /* If an encoding has been set */
1753 unsigned int encoding_counter; /* For iteration */
1754 int encoding_ignored; /* Something overwrote it */
1755
1756 /* Control variables used to iterate through possible encodings, the
1757 * following must be set to 0 and tested by the function that uses the
1758 * png_modifier because the modifier only sets it to 1 (true.)
1759 */
1760 unsigned int repeat :1; /* Repeat this transform test. */
1761 unsigned int test_uses_encoding :1;
1762
1763 /* Lowest sbit to test (libpng fails for sbit < 8) */
1764 png_byte sbitlow;
1765
1766 /* Error control - these are the limits on errors accepted by the gamma tests
1767 * below.
1768 */
1769 double maxout8; /* Maximum output value error */
1770 double maxabs8; /* Absolute sample error 0..1 */
1771 double maxcalc8; /* Absolute sample error 0..1 */
1772 double maxpc8; /* Percentage sample error 0..100% */
1773 double maxout16; /* Maximum output value error */
1774 double maxabs16; /* Absolute sample error 0..1 */
1775 double maxcalc16;/* Absolute sample error 0..1 */
1776 double maxpc16; /* Percentage sample error 0..100% */
1777
1778 /* This is set by transforms that need to allow a higher limit, it is an
1779 * internal check on pngvalid to ensure that the calculated error limits are
1780 * not ridiculous; without this it is too easy to make a mistake in pngvalid
1781 * that allows any value through.
1782 */
1783 double limit; /* limit on error values, normally 4E-3 */
1784
1785 /* Log limits - values above this are logged, but not necessarily
1786 * warned.
1787 */
1788 double log8; /* Absolute error in 8 bits to log */
1789 double log16; /* Absolute error in 16 bits to log */
1790
1791 /* Logged 8 and 16 bit errors ('output' values): */
1792 double error_gray_2;
1793 double error_gray_4;
1794 double error_gray_8;
1795 double error_gray_16;
1796 double error_color_8;
1797 double error_color_16;
1798 double error_indexed;
1799
1800 /* Flags: */
1801 /* Whether to call png_read_update_info, not png_read_start_image, and how
1802 * many times to call it.
1803 */
1804 int use_update_info;
1805
1806 /* Whether or not to interlace. */
1807 int interlace_type :9; /* int, but must store '1' */
1808
1809 /* Run the standard tests? */
1810 unsigned int test_standard :1;
1811
1812 /* Run the odd-sized image and interlace read/write tests? */
1813 unsigned int test_size :1;
1814
1815 /* Run tests on reading with a combiniation of transforms, */
1816 unsigned int test_transform :1;
1817
1818 /* When to use the use_input_precision option: */
1819 unsigned int use_input_precision :1;
1820 unsigned int use_input_precision_sbit :1;
1821 unsigned int use_input_precision_16to8 :1;
1822
1823 /* If set assume that the calculation bit depth is set by the input
1824 * precision, not the output precision.
1825 */
1826 unsigned int calculations_use_input_precision :1;
1827
1828 /* If set assume that the calculations are done in 16 bits even if both input
1829 * and output are 8 bit or less.
1830 */
1831 unsigned int assume_16_bit_calculations :1;
1832
1833 /* Which gamma tests to run: */
1834 unsigned int test_gamma_threshold :1;
1835 unsigned int test_gamma_transform :1; /* main tests */
1836 unsigned int test_gamma_sbit :1;
1837 unsigned int test_gamma_scale16 :1;
1838 unsigned int test_gamma_background :1;
1839 unsigned int test_gamma_alpha_mode :1;
1840 unsigned int test_gamma_expand16 :1;
1841 unsigned int test_exhaustive :1;
1842
1843 unsigned int log :1; /* Log max error */
1844
1845 /* Buffer information, the buffer size limits the size of the chunks that can
1846 * be modified - they must fit (including header and CRC) into the buffer!
1847 */
1848 size_t flush; /* Count of bytes to flush */
1849 size_t buffer_count; /* Bytes in buffer */
1850 size_t buffer_position; /* Position in buffer */
1851 png_byte buffer[1024];
1852} png_modifier;
1853
1854/* This returns true if the test should be stopped now because it has already
1855 * failed and it is running silently.
1856 */
1857static int fail(png_modifier *pm)
1858{
1859 return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 ||
1860 (pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0));
1861}
1862
1863static void
1864modifier_init(png_modifier *pm)
1865{
1866 memset(pm, 0, sizeof *pm);
1867 store_init(&pm->this);
1868 pm->modifications = NULL;
1869 pm->state = modifier_start;
1870 pm->sbitlow = 1U;
1871 pm->ngammas = 0;
1872 pm->ngamma_tests = 0;
1873 pm->gammas = 0;
1874 pm->current_gamma = 0;
1875 pm->encodings = 0;
1876 pm->nencodings = 0;
1877 pm->current_encoding = 0;
1878 pm->encoding_counter = 0;
1879 pm->encoding_ignored = 0;
1880 pm->repeat = 0;
1881 pm->test_uses_encoding = 0;
1882 pm->maxout8 = pm->maxpc8 = pm->maxabs8 = pm->maxcalc8 = 0;
1883 pm->maxout16 = pm->maxpc16 = pm->maxabs16 = pm->maxcalc16 = 0;
1884 pm->limit = 4E-3;
1885 pm->log8 = pm->log16 = 0; /* Means 'off' */
1886 pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
1887 pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0;
1888 pm->error_indexed = 0;
1889 pm->use_update_info = 0;
1890 pm->interlace_type = PNG_INTERLACE_NONE;
1891 pm->test_standard = 0;
1892 pm->test_size = 0;
1893 pm->test_transform = 0;
1894 pm->use_input_precision = 0;
1895 pm->use_input_precision_sbit = 0;
1896 pm->use_input_precision_16to8 = 0;
1897 pm->calculations_use_input_precision = 0;
1898 pm->test_gamma_threshold = 0;
1899 pm->test_gamma_transform = 0;
1900 pm->test_gamma_sbit = 0;
1901 pm->test_gamma_scale16 = 0;
1902 pm->test_gamma_background = 0;
1903 pm->test_gamma_alpha_mode = 0;
1904 pm->test_gamma_expand16 = 0;
1905 pm->test_exhaustive = 0;
1906 pm->log = 0;
1907
1908 /* Rely on the memset for all the other fields - there are no pointers */
1909}
1910
1911#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1912/* If pm->calculations_use_input_precision is set then operations will happen
1913 * with only 8 bit precision unless both the input and output bit depth are 16.
1914 *
1915 * If pm->assume_16_bit_calculations is set then even 8 bit calculations use 16
1916 * bit precision. This only affects those of the following limits that pertain
1917 * to a calculation - not a digitization operation - unless the following API is
1918 * called directly.
1919 */
1920static double digitize(PNG_CONST png_modifier *pm, double value,
1921 int sample_depth, int do_round)
1922{
1923 /* 'value' is in the range 0 to 1, the result is the same value rounded to a
1924 * multiple of the digitization factor - 8 or 16 bits depending on both the
1925 * sample depth and the 'assume' setting. Digitization is normally by
1926 * rounding and 'do_round' should be 1, if it is 0 the digitized value will
1927 * be truncated.
1928 */
1929 PNG_CONST unsigned int digitization_factor =
1930 (pm->assume_16_bit_calculations || sample_depth == 16) ? 65535 : 255;
1931
1932 /* Limiting the range is done as a convenience to the caller - it's easier to
1933 * do it once here than every time at the call site.
1934 */
1935 if (value <= 0)
1936 value = 0;
1937 else if (value >= 1)
1938 value = 1;
1939
1940 value *= digitization_factor;
1941 if (do_round) value += .5;
1942 return floor(value)/digitization_factor;
1943}
1944
1945static double abserr(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
1946{
1947 /* Absolute error permitted in linear values - affected by the bit depth of
1948 * the calculations.
1949 */
1950 if (pm->assume_16_bit_calculations || (out_depth == 16 && (in_depth == 16 ||
1951 !pm->calculations_use_input_precision)))
1952 return pm->maxabs16;
1953 else
1954 return pm->maxabs8;
1955}
1956
1957static double calcerr(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
1958{
1959 /* Error in the linear composition arithmetic - only relevant when
1960 * composition actually happens (0 < alpha < 1).
1961 */
1962 if (pm->assume_16_bit_calculations || (out_depth == 16 && (in_depth == 16 ||
1963 !pm->calculations_use_input_precision)))
1964 return pm->maxcalc16;
1965 else
1966 return pm->maxcalc8;
1967}
1968
1969static double pcerr(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
1970{
1971 /* Percentage error permitted in the linear values. Note that the specified
1972 * value is a percentage but this routine returns a simple number.
1973 */
1974 if (pm->assume_16_bit_calculations || (out_depth == 16 && (in_depth == 16 ||
1975 !pm->calculations_use_input_precision)))
1976 return pm->maxpc16 * .01;
1977 else
1978 return pm->maxpc8 * .01;
1979}
1980
1981/* Output error - the error in the encoded value. This is determined by the
1982 * digitization of the output so can be +/-0.5 in the actual output value. In
1983 * the expand_16 case with the current code in libpng the expand happens after
1984 * all the calculations are done in 8 bit arithmetic, so even though the output
1985 * depth is 16 the output error is determined by the 8 bit calculation.
1986 *
1987 * This limit is not determined by the bit depth of internal calculations.
1988 *
1989 * The specified parameter does *not* include the base .5 digitization error but
1990 * it is added here.
1991 */
1992static double outerr(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
1993{
1994 /* There is a serious error in the 2 and 4 bit grayscale transform because
1995 * the gamma table value (8 bits) is simply shifted, not rounded, so the
1996 * error in 4 bit grayscale gamma is up to the value below. This is a hack
1997 * to allow pngvalid to succeed:
1998 *
1999 * TODO: fix this in libpng
2000 */
2001 if (out_depth == 2)
2002 return .73182-.5;
2003
2004 if (out_depth == 4)
2005 return .90644-.5;
2006
2007 if (out_depth == 16 && (in_depth == 16 ||
2008 !pm->calculations_use_input_precision))
2009 return pm->maxout16;
2010
2011 /* This is the case where the value was calculated at 8-bit precision then
2012 * scaled to 16 bits.
2013 */
2014 else if (out_depth == 16)
2015 return pm->maxout8 * 257;
2016
2017 else
2018 return pm->maxout8;
2019}
2020
2021/* This does the same thing as the above however it returns the value to log,
2022 * rather than raising a warning. This is useful for debugging to track down
2023 * exactly what set of parameters cause high error values.
2024 */
2025static double outlog(PNG_CONST png_modifier *pm, int in_depth, int out_depth)
2026{
2027 /* The command line parameters are either 8 bit (0..255) or 16 bit (0..65535)
2028 * and so must be adjusted for low bit depth grayscale:
2029 */
2030 if (out_depth <= 8)
2031 {
2032 if (pm->log8 == 0) /* switched off */
2033 return 256;
2034
2035 if (out_depth < 8)
2036 return pm->log8 / 255 * ((1<<out_depth)-1);
2037
2038 return pm->log8;
2039 }
2040
2041 if (out_depth == 16 && (in_depth == 16 ||
2042 !pm->calculations_use_input_precision))
2043 {
2044 if (pm->log16 == 0)
2045 return 65536;
2046
2047 return pm->log16;
2048 }
2049
2050 /* This is the case where the value was calculated at 8-bit precision then
2051 * scaled to 16 bits.
2052 */
2053 if (pm->log8 == 0)
2054 return 65536;
2055
2056 return pm->log8 * 257;
2057}
2058
2059/* This complements the above by providing the appropriate quantization for the
2060 * final value. Normally this would just be quantization to an integral value,
2061 * but in the 8 bit calculation case it's actually quantization to a multiple of
2062 * 257!
2063 */
2064static int output_quantization_factor(PNG_CONST png_modifier *pm, int in_depth,
2065 int out_depth)
2066{
2067 if (out_depth == 16 && in_depth != 16
2068 && pm->calculations_use_input_precision)
2069 return 257;
2070 else
2071 return 1;
2072}
2073
2074/* One modification structure must be provided for each chunk to be modified (in
2075 * fact more than one can be provided if multiple separate changes are desired
2076 * for a single chunk.) Modifications include adding a new chunk when a
2077 * suitable chunk does not exist.
2078 *
2079 * The caller of modify_fn will reset the CRC of the chunk and record 'modified'
2080 * or 'added' as appropriate if the modify_fn returns 1 (true). If the
2081 * modify_fn is NULL the chunk is simply removed.
2082 */
2083typedef struct png_modification
2084{
2085 struct png_modification *next;
2086 png_uint_32 chunk;
2087
2088 /* If the following is NULL all matching chunks will be removed: */
2089 int (*modify_fn)(struct png_modifier *pm,
2090 struct png_modification *me, int add);
2091
2092 /* If the following is set to PLTE, IDAT or IEND and the chunk has not been
2093 * found and modified (and there is a modify_fn) the modify_fn will be called
2094 * to add the chunk before the relevant chunk.
2095 */
2096 png_uint_32 add;
2097 unsigned int modified :1; /* Chunk was modified */
2098 unsigned int added :1; /* Chunk was added */
2099 unsigned int removed :1; /* Chunk was removed */
2100} png_modification;
2101
2102static void
2103modification_reset(png_modification *pmm)
2104{
2105 if (pmm != NULL)
2106 {
2107 pmm->modified = 0;
2108 pmm->added = 0;
2109 pmm->removed = 0;
2110 modification_reset(pmm->next);
2111 }
2112}
2113
2114static void
2115modification_init(png_modification *pmm)
2116{
2117 memset(pmm, 0, sizeof *pmm);
2118 pmm->next = NULL;
2119 pmm->chunk = 0;
2120 pmm->modify_fn = NULL;
2121 pmm->add = 0;
2122 modification_reset(pmm);
2123}
2124
2125static void
2126modifier_current_encoding(PNG_CONST png_modifier *pm, color_encoding *ce)
2127{
2128 if (pm->current_encoding != 0)
2129 *ce = *pm->current_encoding;
2130
2131 else
2132 memset(ce, 0, sizeof *ce);
2133
2134 ce->gamma = pm->current_gamma;
2135}
2136
2137static size_t
2138safecat_current_encoding(char *buffer, size_t bufsize, size_t pos,
2139 PNG_CONST png_modifier *pm)
2140{
2141 pos = safecat_color_encoding(buffer, bufsize, pos, pm->current_encoding,
2142 pm->current_gamma);
2143
2144 if (pm->encoding_ignored)
2145 pos = safecat(buffer, bufsize, pos, "[overridden]");
2146
2147 return pos;
2148}
2149
2150/* Iterate through the usefully testable color encodings. An encoding is one
2151 * of:
2152 *
2153 * 1) Nothing (no color space, no gamma).
2154 * 2) Just a gamma value from the gamma array (including 1.0)
2155 * 3) A color space from the encodings array with the corresponding gamma.
2156 * 4) The same, but with gamma 1.0 (only really useful with 16 bit calculations)
2157 *
2158 * The iterator selects these in turn, the randomizer selects one at random,
2159 * which is used depends on the setting of the 'test_exhaustive' flag. Notice
2160 * that this function changes the colour space encoding so it must only be
2161 * called on completion of the previous test. This is what 'modifier_reset'
2162 * does, below.
2163 *
2164 * After the function has been called the 'repeat' flag will still be set; the
2165 * caller of modifier_reset must reset it at the start of each run of the test!
2166 */
2167static unsigned int
2168modifier_total_encodings(PNG_CONST png_modifier *pm)
2169{
2170 return 1 + /* (1) nothing */
2171 pm->ngammas + /* (2) gamma values to test */
2172 pm->nencodings + /* (3) total number of encodings */
2173 /* The following test only works after the first time through the
2174 * png_modifier code because 'bit_depth' is set when the IHDR is read.
2175 * modifier_reset, below, preserves the setting until after it has called
2176 * the iterate function (also below.)
2177 *
2178 * For this reason do not rely on this function outside a call to
2179 * modifier_reset.
2180 */
2181 ((pm->bit_depth == 16 || pm->assume_16_bit_calculations) ?
2182 pm->nencodings : 0); /* (4) encodings with gamma == 1.0 */
2183}
2184
2185static void
2186modifier_encoding_iterate(png_modifier *pm)
2187{
2188 if (!pm->repeat && /* Else something needs the current encoding again. */
2189 pm->test_uses_encoding) /* Some transform is encoding dependent */
2190 {
2191 if (pm->test_exhaustive)
2192 {
2193 if (++pm->encoding_counter >= modifier_total_encodings(pm))
2194 pm->encoding_counter = 0; /* This will stop the repeat */
2195 }
2196
2197 else
2198 {
2199 /* Not exhaustive - choose an encoding at random; generate a number in
2200 * the range 1..(max-1), so the result is always non-zero:
2201 */
2202 if (pm->encoding_counter == 0)
2203 pm->encoding_counter = random_mod(modifier_total_encodings(pm)-1)+1;
2204 else
2205 pm->encoding_counter = 0;
2206 }
2207
2208 if (pm->encoding_counter > 0)
2209 pm->repeat = 1;
2210 }
2211
2212 else if (!pm->repeat)
2213 pm->encoding_counter = 0;
2214}
2215
2216static void
2217modifier_reset(png_modifier *pm)
2218{
2219 store_read_reset(&pm->this);
2220 pm->limit = 4E-3;
2221 pm->pending_len = pm->pending_chunk = 0;
2222 pm->flush = pm->buffer_count = pm->buffer_position = 0;
2223 pm->modifications = NULL;
2224 pm->state = modifier_start;
2225 modifier_encoding_iterate(pm);
2226 /* The following must be set in the next run. In particular
2227 * test_uses_encodings must be set in the _ini function of each transform
2228 * that looks at the encodings. (Not the 'add' function!)
2229 */
2230 pm->test_uses_encoding = 0;
2231 pm->current_gamma = 0;
2232 pm->current_encoding = 0;
2233 pm->encoding_ignored = 0;
2234 /* These only become value after IHDR is read: */
2235 pm->bit_depth = pm->colour_type = 0;
2236}
2237
2238/* The following must be called before anything else to get the encoding set up
2239 * on the modifier. In particular it must be called before the transform init
2240 * functions are called.
2241 */
2242static void
2243modifier_set_encoding(png_modifier *pm)
2244{
2245 /* Set the encoding to the one specified by the current encoding counter,
2246 * first clear out all the settings - this corresponds to an encoding_counter
2247 * of 0.
2248 */
2249 pm->current_gamma = 0;
2250 pm->current_encoding = 0;
2251 pm->encoding_ignored = 0; /* not ignored yet - happens in _ini functions. */
2252
2253 /* Now, if required, set the gamma and encoding fields. */
2254 if (pm->encoding_counter > 0)
2255 {
2256 /* The gammas[] array is an array of screen gammas, not encoding gammas,
2257 * so we need the inverse:
2258 */
2259 if (pm->encoding_counter <= pm->ngammas)
2260 pm->current_gamma = 1/pm->gammas[pm->encoding_counter-1];
2261
2262 else
2263 {
2264 unsigned int i = pm->encoding_counter - pm->ngammas;
2265
2266 if (i >= pm->nencodings)
2267 {
2268 i %= pm->nencodings;
2269 pm->current_gamma = 1; /* Linear, only in the 16 bit case */
2270 }
2271
2272 else
2273 pm->current_gamma = pm->encodings[i].gamma;
2274
2275 pm->current_encoding = pm->encodings + i;
2276 }
2277 }
2278}
2279
2280/* Enquiry functions to find out what is set. Notice that there is an implicit
2281 * assumption below that the first encoding in the list is the one for sRGB.
2282 */
2283static int
2284modifier_color_encoding_is_sRGB(PNG_CONST png_modifier *pm)
2285{
2286 return pm->current_encoding != 0 && pm->current_encoding == pm->encodings &&
2287 pm->current_encoding->gamma == pm->current_gamma;
2288}
2289
2290static int
2291modifier_color_encoding_is_set(PNG_CONST png_modifier *pm)
2292{
2293 return pm->current_gamma != 0;
2294}
2295
2296/* Convenience macros. */
2297#define CHUNK(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))
2298#define CHUNK_IHDR CHUNK(73,72,68,82)
2299#define CHUNK_PLTE CHUNK(80,76,84,69)
2300#define CHUNK_IDAT CHUNK(73,68,65,84)
2301#define CHUNK_IEND CHUNK(73,69,78,68)
2302#define CHUNK_cHRM CHUNK(99,72,82,77)
2303#define CHUNK_gAMA CHUNK(103,65,77,65)
2304#define CHUNK_sBIT CHUNK(115,66,73,84)
2305#define CHUNK_sRGB CHUNK(115,82,71,66)
2306
2307/* The guts of modification are performed during a read. */
2308static void
2309modifier_crc(png_bytep buffer)
2310{
2311 /* Recalculate the chunk CRC - a complete chunk must be in
2312 * the buffer, at the start.
2313 */
2314 uInt datalen = png_get_uint_32(buffer);
2315 uLong crc = crc32(0, buffer+4, datalen+4);
2316 /* The cast to png_uint_32 is safe because a crc32 is always a 32 bit value.
2317 */
2318 png_save_uint_32(buffer+datalen+8, (png_uint_32)crc);
2319}
2320
2321static void
2322modifier_setbuffer(png_modifier *pm)
2323{
2324 modifier_crc(pm->buffer);
2325 pm->buffer_count = png_get_uint_32(pm->buffer)+12;
2326 pm->buffer_position = 0;
2327}
2328
2329/* Separate the callback into the actual implementation (which is passed the
2330 * png_modifier explicitly) and the callback, which gets the modifier from the
2331 * png_struct.
2332 */
2333static void
2334modifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)
2335{
2336 while (st > 0)
2337 {
2338 size_t cb;
2339 png_uint_32 len, chunk;
2340 png_modification *mod;
2341
2342 if (pm->buffer_position >= pm->buffer_count) switch (pm->state)
2343 {
2344 static png_byte sign[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };
2345 case modifier_start:
2346 store_read_imp(&pm->this, pm->buffer, 8); /* size of signature. */
2347 pm->buffer_count = 8;
2348 pm->buffer_position = 0;
2349
2350 if (memcmp(pm->buffer, sign, 8) != 0)
2351 png_error(pm->this.pread, "invalid PNG file signature");
2352 pm->state = modifier_signature;
2353 break;
2354
2355 case modifier_signature:
2356 store_read_imp(&pm->this, pm->buffer, 13+12); /* size of IHDR */
2357 pm->buffer_count = 13+12;
2358 pm->buffer_position = 0;
2359
2360 if (png_get_uint_32(pm->buffer) != 13 ||
2361 png_get_uint_32(pm->buffer+4) != CHUNK_IHDR)
2362 png_error(pm->this.pread, "invalid IHDR");
2363
2364 /* Check the list of modifiers for modifications to the IHDR. */
2365 mod = pm->modifications;
2366 while (mod != NULL)
2367 {
2368 if (mod->chunk == CHUNK_IHDR && mod->modify_fn &&
2369 (*mod->modify_fn)(pm, mod, 0))
2370 {
2371 mod->modified = 1;
2372 modifier_setbuffer(pm);
2373 }
2374
2375 /* Ignore removal or add if IHDR! */
2376 mod = mod->next;
2377 }
2378
2379 /* Cache information from the IHDR (the modified one.) */
2380 pm->bit_depth = pm->buffer[8+8];
2381 pm->colour_type = pm->buffer[8+8+1];
2382
2383 pm->state = modifier_IHDR;
2384 pm->flush = 0;
2385 break;
2386
2387 case modifier_IHDR:
2388 default:
2389 /* Read a new chunk and process it until we see PLTE, IDAT or
2390 * IEND. 'flush' indicates that there is still some data to
2391 * output from the preceding chunk.
2392 */
2393 if ((cb = pm->flush) > 0)
2394 {
2395 if (cb > st) cb = st;
2396 pm->flush -= cb;
2397 store_read_imp(&pm->this, pb, cb);
2398 pb += cb;
2399 st -= cb;
2400 if (st == 0) return;
2401 }
2402
2403 /* No more bytes to flush, read a header, or handle a pending
2404 * chunk.
2405 */
2406 if (pm->pending_chunk != 0)
2407 {
2408 png_save_uint_32(pm->buffer, pm->pending_len);
2409 png_save_uint_32(pm->buffer+4, pm->pending_chunk);
2410 pm->pending_len = 0;
2411 pm->pending_chunk = 0;
2412 }
2413 else
2414 store_read_imp(&pm->this, pm->buffer, 8);
2415
2416 pm->buffer_count = 8;
2417 pm->buffer_position = 0;
2418
2419 /* Check for something to modify or a terminator chunk. */
2420 len = png_get_uint_32(pm->buffer);
2421 chunk = png_get_uint_32(pm->buffer+4);
2422
2423 /* Terminators first, they may have to be delayed for added
2424 * chunks
2425 */
2426 if (chunk == CHUNK_PLTE || chunk == CHUNK_IDAT ||
2427 chunk == CHUNK_IEND)
2428 {
2429 mod = pm->modifications;
2430
2431 while (mod != NULL)
2432 {
2433 if ((mod->add == chunk ||
2434 (mod->add == CHUNK_PLTE && chunk == CHUNK_IDAT)) &&
2435 mod->modify_fn != NULL && !mod->modified && !mod->added)
2436 {
2437 /* Regardless of what the modify function does do not run
2438 * this again.
2439 */
2440 mod->added = 1;
2441
2442 if ((*mod->modify_fn)(pm, mod, 1 /*add*/))
2443 {
2444 /* Reset the CRC on a new chunk */
2445 if (pm->buffer_count > 0)
2446 modifier_setbuffer(pm);
2447
2448 else
2449 {
2450 pm->buffer_position = 0;
2451 mod->removed = 1;
2452 }
2453
2454 /* The buffer has been filled with something (we assume)
2455 * so output this. Pend the current chunk.
2456 */
2457 pm->pending_len = len;
2458 pm->pending_chunk = chunk;
2459 break; /* out of while */
2460 }
2461 }
2462
2463 mod = mod->next;
2464 }
2465
2466 /* Don't do any further processing if the buffer was modified -
2467 * otherwise the code will end up modifying a chunk that was
2468 * just added.
2469 */
2470 if (mod != NULL)
2471 break; /* out of switch */
2472 }
2473
2474 /* If we get to here then this chunk may need to be modified. To
2475 * do this it must be less than 1024 bytes in total size, otherwise
2476 * it just gets flushed.
2477 */
2478 if (len+12 <= sizeof pm->buffer)
2479 {
2480 store_read_imp(&pm->this, pm->buffer+pm->buffer_count,
2481 len+12-pm->buffer_count);
2482 pm->buffer_count = len+12;
2483
2484 /* Check for a modification, else leave it be. */
2485 mod = pm->modifications;
2486 while (mod != NULL)
2487 {
2488 if (mod->chunk == chunk)
2489 {
2490 if (mod->modify_fn == NULL)
2491 {
2492 /* Remove this chunk */
2493 pm->buffer_count = pm->buffer_position = 0;
2494 mod->removed = 1;
2495 break; /* Terminate the while loop */
2496 }
2497
2498 else if ((*mod->modify_fn)(pm, mod, 0))
2499 {
2500 mod->modified = 1;
2501 /* The chunk may have been removed: */
2502 if (pm->buffer_count == 0)
2503 {
2504 pm->buffer_position = 0;
2505 break;
2506 }
2507 modifier_setbuffer(pm);
2508 }
2509 }
2510
2511 mod = mod->next;
2512 }
2513 }
2514
2515 else
2516 pm->flush = len+12 - pm->buffer_count; /* data + crc */
2517
2518 /* Take the data from the buffer (if there is any). */
2519 break;
2520 }
2521
2522 /* Here to read from the modifier buffer (not directly from
2523 * the store, as in the flush case above.)
2524 */
2525 cb = pm->buffer_count - pm->buffer_position;
2526
2527 if (cb > st)
2528 cb = st;
2529
2530 memcpy(pb, pm->buffer + pm->buffer_position, cb);
2531 st -= cb;
2532 pb += cb;
2533 pm->buffer_position += cb;
2534 }
2535}
2536
2537/* The callback: */
2538static void
2539modifier_read(png_structp pp, png_bytep pb, png_size_t st)
2540{
2541 png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));
2542
2543 if (pm == NULL || pm->this.pread != pp)
2544 png_error(pp, "bad modifier_read call");
2545
2546 modifier_read_imp(pm, pb, st);
2547}
2548
2549/* Like store_progressive_read but the data is getting changed as we go so we
2550 * need a local buffer.
2551 */
2552static void
2553modifier_progressive_read(png_modifier *pm, png_structp pp, png_infop pi)
2554{
2555 if (pm->this.pread != pp || pm->this.current == NULL ||
2556 pm->this.next == NULL)
2557 png_error(pp, "store state damaged (progressive)");
2558
2559 /* This is another Horowitz and Hill random noise generator. In this case
2560 * the aim is to stress the progressive reader with truly horrible variable
2561 * buffer sizes in the range 1..500, so a sequence of 9 bit random numbers
2562 * is generated. We could probably just count from 1 to 32767 and get as
2563 * good a result.
2564 */
2565 for (;;)
2566 {
2567 static png_uint_32 noise = 1;
2568 png_size_t cb, cbAvail;
2569 png_byte buffer[512];
2570
2571 /* Generate 15 more bits of stuff: */
2572 noise = (noise << 9) | ((noise ^ (noise >> (9-5))) & 0x1ff);
2573 cb = noise & 0x1ff;
2574
2575 /* Check that this number of bytes are available (in the current buffer.)
2576 * (This doesn't quite work - the modifier might delete a chunk; unlikely
2577 * but possible, it doesn't happen at present because the modifier only
2578 * adds chunks to standard images.)
2579 */
2580 cbAvail = store_read_buffer_avail(&pm->this);
2581 if (pm->buffer_count > pm->buffer_position)
2582 cbAvail += pm->buffer_count - pm->buffer_position;
2583
2584 if (cb > cbAvail)
2585 {
2586 /* Check for EOF: */
2587 if (cbAvail == 0)
2588 break;
2589
2590 cb = cbAvail;
2591 }
2592
2593 modifier_read_imp(pm, buffer, cb);
2594 png_process_data(pp, pi, buffer, cb);
2595 }
2596
2597 /* Check the invariants at the end (if this fails it's a problem in this
2598 * file!)
2599 */
2600 if (pm->buffer_count > pm->buffer_position ||
2601 pm->this.next != &pm->this.current->data ||
2602 pm->this.readpos < pm->this.current->datacount)
2603 png_error(pp, "progressive read implementation error");
2604}
2605
2606/* Set up a modifier. */
2607static png_structp
2608set_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id,
2609 PNG_CONST char *name)
2610{
2611 /* Do this first so that the modifier fields are cleared even if an error
2612 * happens allocating the png_struct. No allocation is done here so no
2613 * cleanup is required.
2614 */
2615 pm->state = modifier_start;
2616 pm->bit_depth = 0;
2617 pm->colour_type = 255;
2618
2619 pm->pending_len = 0;
2620 pm->pending_chunk = 0;
2621 pm->flush = 0;
2622 pm->buffer_count = 0;
2623 pm->buffer_position = 0;
2624
2625 return set_store_for_read(&pm->this, ppi, id, name);
2626}
2627
2628
2629/******************************** MODIFICATIONS *******************************/
2630/* Standard modifications to add chunks. These do not require the _SUPPORTED
2631 * macros because the chunks can be there regardless of whether this specific
2632 * libpng supports them.
2633 */
2634typedef struct gama_modification
2635{
2636 png_modification this;
2637 png_fixed_point gamma;
2638} gama_modification;
2639
2640static int
2641gama_modify(png_modifier *pm, png_modification *me, int add)
2642{
2643 UNUSED(add)
2644 /* This simply dumps the given gamma value into the buffer. */
2645 png_save_uint_32(pm->buffer, 4);
2646 png_save_uint_32(pm->buffer+4, CHUNK_gAMA);
2647 png_save_uint_32(pm->buffer+8, ((gama_modification*)me)->gamma);
2648 return 1;
2649}
2650
2651static void
2652gama_modification_init(gama_modification *me, png_modifier *pm, double gammad)
2653{
2654 double g;
2655
2656 modification_init(&me->this);
2657 me->this.chunk = CHUNK_gAMA;
2658 me->this.modify_fn = gama_modify;
2659 me->this.add = CHUNK_PLTE;
2660 g = fix(gammad);
2661 me->gamma = (png_fixed_point)g;
2662 me->this.next = pm->modifications;
2663 pm->modifications = &me->this;
2664}
2665
2666typedef struct chrm_modification
2667{
2668 png_modification this;
2669 PNG_CONST color_encoding *encoding;
2670 png_fixed_point wx, wy, rx, ry, gx, gy, bx, by;
2671} chrm_modification;
2672
2673static int
2674chrm_modify(png_modifier *pm, png_modification *me, int add)
2675{
2676 UNUSED(add)
2677 /* As with gAMA this just adds the required cHRM chunk to the buffer. */
2678 png_save_uint_32(pm->buffer , 32);
2679 png_save_uint_32(pm->buffer+ 4, CHUNK_cHRM);
2680 png_save_uint_32(pm->buffer+ 8, ((chrm_modification*)me)->wx);
2681 png_save_uint_32(pm->buffer+12, ((chrm_modification*)me)->wy);
2682 png_save_uint_32(pm->buffer+16, ((chrm_modification*)me)->rx);
2683 png_save_uint_32(pm->buffer+20, ((chrm_modification*)me)->ry);
2684 png_save_uint_32(pm->buffer+24, ((chrm_modification*)me)->gx);
2685 png_save_uint_32(pm->buffer+28, ((chrm_modification*)me)->gy);
2686 png_save_uint_32(pm->buffer+32, ((chrm_modification*)me)->bx);
2687 png_save_uint_32(pm->buffer+36, ((chrm_modification*)me)->by);
2688 return 1;
2689}
2690
2691static void
2692chrm_modification_init(chrm_modification *me, png_modifier *pm,
2693 PNG_CONST color_encoding *encoding)
2694{
2695 CIE_color white = white_point(encoding);
2696
2697 /* Original end points: */
2698 me->encoding = encoding;
2699
2700 /* Chromaticities (in fixed point): */
2701 me->wx = fix(chromaticity_x(white));
2702 me->wy = fix(chromaticity_y(white));
2703
2704 me->rx = fix(chromaticity_x(encoding->red));
2705 me->ry = fix(chromaticity_y(encoding->red));
2706 me->gx = fix(chromaticity_x(encoding->green));
2707 me->gy = fix(chromaticity_y(encoding->green));
2708 me->bx = fix(chromaticity_x(encoding->blue));
2709 me->by = fix(chromaticity_y(encoding->blue));
2710
2711 modification_init(&me->this);
2712 me->this.chunk = CHUNK_cHRM;
2713 me->this.modify_fn = chrm_modify;
2714 me->this.add = CHUNK_PLTE;
2715 me->this.next = pm->modifications;
2716 pm->modifications = &me->this;
2717}
2718
2719typedef struct srgb_modification
2720{
2721 png_modification this;
2722 png_byte intent;
2723} srgb_modification;
2724
2725static int
2726srgb_modify(png_modifier *pm, png_modification *me, int add)
2727{
2728 UNUSED(add)
2729 /* As above, ignore add and just make a new chunk */
2730 png_save_uint_32(pm->buffer, 1);
2731 png_save_uint_32(pm->buffer+4, CHUNK_sRGB);
2732 pm->buffer[8] = ((srgb_modification*)me)->intent;
2733 return 1;
2734}
2735
2736static void
2737srgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent)
2738{
2739 modification_init(&me->this);
2740 me->this.chunk = CHUNK_sBIT;
2741
2742 if (intent <= 3) /* if valid, else *delete* sRGB chunks */
2743 {
2744 me->this.modify_fn = srgb_modify;
2745 me->this.add = CHUNK_PLTE;
2746 me->intent = intent;
2747 }
2748
2749 else
2750 {
2751 me->this.modify_fn = 0;
2752 me->this.add = 0;
2753 me->intent = 0;
2754 }
2755
2756 me->this.next = pm->modifications;
2757 pm->modifications = &me->this;
2758}
2759
2760typedef struct sbit_modification
2761{
2762 png_modification this;
2763 png_byte sbit;
2764} sbit_modification;
2765
2766static int
2767sbit_modify(png_modifier *pm, png_modification *me, int add)
2768{
2769 png_byte sbit = ((sbit_modification*)me)->sbit;
2770 if (pm->bit_depth > sbit)
2771 {
2772 int cb = 0;
2773 switch (pm->colour_type)
2774 {
2775 case 0:
2776 cb = 1;
2777 break;
2778
2779 case 2:
2780 case 3:
2781 cb = 3;
2782 break;
2783
2784 case 4:
2785 cb = 2;
2786 break;
2787
2788 case 6:
2789 cb = 4;
2790 break;
2791
2792 default:
2793 png_error(pm->this.pread,
2794 "unexpected colour type in sBIT modification");
2795 }
2796
2797 png_save_uint_32(pm->buffer, cb);
2798 png_save_uint_32(pm->buffer+4, CHUNK_sBIT);
2799
2800 while (cb > 0)
2801 (pm->buffer+8)[--cb] = sbit;
2802
2803 return 1;
2804 }
2805 else if (!add)
2806 {
2807 /* Remove the sBIT chunk */
2808 pm->buffer_count = pm->buffer_position = 0;
2809 return 1;
2810 }
2811 else
2812 return 0; /* do nothing */
2813}
2814
2815static void
2816sbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit)
2817{
2818 modification_init(&me->this);
2819 me->this.chunk = CHUNK_sBIT;
2820 me->this.modify_fn = sbit_modify;
2821 me->this.add = CHUNK_PLTE;
2822 me->sbit = sbit;
2823 me->this.next = pm->modifications;
2824 pm->modifications = &me->this;
2825}
2826#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
2827
2828/***************************** STANDARD PNG FILES *****************************/
2829/* Standard files - write and save standard files. */
2830/* There are two basic forms of standard images. Those which attempt to have
2831 * all the possible pixel values (not possible for 16bpp images, but a range of
2832 * values are produced) and those which have a range of image sizes. The former
2833 * are used for testing transforms, in particular gamma correction and bit
2834 * reduction and increase. The latter are reserved for testing the behavior of
2835 * libpng with respect to 'odd' image sizes - particularly small images where
2836 * rows become 1 byte and interlace passes disappear.
2837 *
2838 * The first, most useful, set are the 'transform' images, the second set of
2839 * small images are the 'size' images.
2840 *
2841 * The transform files are constructed with rows which fit into a 1024 byte row
2842 * buffer. This makes allocation easier below. Further regardless of the file
2843 * format every row has 128 pixels (giving 1024 bytes for 64bpp formats).
2844 *
2845 * Files are stored with no gAMA or sBIT chunks, with a PLTE only when needed
2846 * and with an ID derived from the colour type, bit depth and interlace type
2847 * as above (FILEID). The width (128) and height (variable) are not stored in
2848 * the FILEID - instead the fields are set to 0, indicating a transform file.
2849 *
2850 * The size files ar constructed with rows a maximum of 128 bytes wide, allowing
2851 * a maximum width of 16 pixels (for the 64bpp case.) They also have a maximum
2852 * height of 16 rows. The width and height are stored in the FILEID and, being
2853 * non-zero, indicate a size file.
2854 *
2855 * For palette image (colour type 3) multiple transform images are stored with
2856 * the same bit depth to allow testing of more colour combinations -
2857 * particularly important for testing the gamma code because libpng uses a
2858 * different code path for palette images. For size images a single palette is
2859 * used.
2860 */
2861
2862/* Make a 'standard' palette. Because there are only 256 entries in a palette
2863 * (maximum) this actually makes a random palette in the hope that enough tests
2864 * will catch enough errors. (Note that the same palette isn't produced every
2865 * time for the same test - it depends on what previous tests have been run -
2866 * but a given set of arguments to pngvalid will always produce the same palette
2867 * at the same test! This is why pseudo-random number generators are useful for
2868 * testing.)
2869 *
2870 * The store must be open for write when this is called, otherwise an internal
2871 * error will occur. This routine contains its own magic number seed, so the
2872 * palettes generated don't change if there are intervening errors (changing the
2873 * calls to the store_mark seed.)
2874 */
2875static store_palette_entry *
2876make_standard_palette(png_store* ps, int npalette, int do_tRNS)
2877{
2878 static png_uint_32 palette_seed[2] = { 0x87654321, 9 };
2879
2880 int i = 0;
2881 png_byte values[256][4];
2882
2883 /* Always put in black and white plus the six primary and secondary colors.
2884 */
2885 for (; i<8; ++i)
2886 {
2887 values[i][1] = (i&1) ? 255 : 0;
2888 values[i][2] = (i&2) ? 255 : 0;
2889 values[i][3] = (i&4) ? 255 : 0;
2890 }
2891
2892 /* Then add 62 grays (one quarter of the remaining 256 slots). */
2893 {
2894 int j = 0;
2895 png_byte random_bytes[4];
2896 png_byte need[256];
2897
2898 need[0] = 0; /*got black*/
2899 memset(need+1, 1, (sizeof need)-2); /*need these*/
2900 need[255] = 0; /*but not white*/
2901
2902 while (i<70)
2903 {
2904 png_byte b;
2905
2906 if (j==0)
2907 {
2908 make_four_random_bytes(palette_seed, random_bytes);
2909 j = 4;
2910 }
2911
2912 b = random_bytes[--j];
2913 if (need[b])
2914 {
2915 values[i][1] = b;
2916 values[i][2] = b;
2917 values[i++][3] = b;
2918 }
2919 }
2920 }
2921
2922 /* Finally add 192 colors at random - don't worry about matches to things we
2923 * already have, chance is less than 1/65536. Don't worry about grays,
2924 * chance is the same, so we get a duplicate or extra gray less than 1 time
2925 * in 170.
2926 */
2927 for (; i<256; ++i)
2928 make_four_random_bytes(palette_seed, values[i]);
2929
2930 /* Fill in the alpha values in the first byte. Just use all possible values
2931 * (0..255) in an apparently random order:
2932 */
2933 {
2934 store_palette_entry *palette;
2935 png_byte selector[4];
2936
2937 make_four_random_bytes(palette_seed, selector);
2938
2939 if (do_tRNS)
2940 for (i=0; i<256; ++i)
2941 values[i][0] = (png_byte)(i ^ selector[0]);
2942
2943 else
2944 for (i=0; i<256; ++i)
2945 values[i][0] = 255; /* no transparency/tRNS chunk */
2946
2947 /* 'values' contains 256 ARGB values, but we only need 'npalette'.
2948 * 'npalette' will always be a power of 2: 2, 4, 16 or 256. In the low
2949 * bit depth cases select colors at random, else it is difficult to have
2950 * a set of low bit depth palette test with any chance of a reasonable
2951 * range of colors. Do this by randomly permuting values into the low
2952 * 'npalette' entries using an XOR mask generated here. This also
2953 * permutes the npalette == 256 case in a potentially useful way (there is
2954 * no relationship between palette index and the color value therein!)
2955 */
2956 palette = store_write_palette(ps, npalette);
2957
2958 for (i=0; i<npalette; ++i)
2959 {
2960 palette[i].alpha = values[i ^ selector[1]][0];
2961 palette[i].red = values[i ^ selector[1]][1];
2962 palette[i].green = values[i ^ selector[1]][2];
2963 palette[i].blue = values[i ^ selector[1]][3];
2964 }
2965
2966 return palette;
2967 }
2968}
2969
2970/* Initialize a standard palette on a write stream. The 'do_tRNS' argument
2971 * indicates whether or not to also set the tRNS chunk.
2972 */
2973static void
2974init_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette,
2975 int do_tRNS)
2976{
2977 store_palette_entry *ppal = make_standard_palette(ps, npalette, do_tRNS);
2978
2979 {
2980 int i;
2981 png_color palette[256];
2982
2983 /* Set all entries to detect overread errors. */
2984 for (i=0; i<npalette; ++i)
2985 {
2986 palette[i].red = ppal[i].red;
2987 palette[i].green = ppal[i].green;
2988 palette[i].blue = ppal[i].blue;
2989 }
2990
2991 /* Just in case fill in the rest with detectable values: */
2992 for (; i<256; ++i)
2993 palette[i].red = palette[i].green = palette[i].blue = 42;
2994
2995 png_set_PLTE(pp, pi, palette, npalette);
2996 }
2997
2998 if (do_tRNS)
2999 {
3000 int i, j;
3001 png_byte tRNS[256];
3002
3003 /* Set all the entries, but skip trailing opaque entries */
3004 for (i=j=0; i<npalette; ++i)
3005 if ((tRNS[i] = ppal[i].alpha) < 255)
3006 j = i+1;
3007
3008 /* Fill in the remainder with a detectable value: */
3009 for (; i<256; ++i)
3010 tRNS[i] = 24;
3011
3012 if (j > 0)
3013 png_set_tRNS(pp, pi, tRNS, j, 0/*color*/);
3014 }
3015}
3016
3017/* The number of passes is related to the interlace type. There was no libpng
3018 * API to determine this prior to 1.5, so we need an inquiry function:
3019 */
3020static int
3021npasses_from_interlace_type(png_structp pp, int interlace_type)
3022{
3023 switch (interlace_type)
3024 {
3025 default:
3026 png_error(pp, "invalid interlace type");
3027
3028 case PNG_INTERLACE_NONE:
3029 return 1;
3030
3031 case PNG_INTERLACE_ADAM7:
3032 return PNG_INTERLACE_ADAM7_PASSES;
3033 }
3034}
3035
3036static unsigned int
3037bit_size(png_structp pp, png_byte colour_type, png_byte bit_depth)
3038{
3039 switch (colour_type)
3040 {
3041 default: png_error(pp, "invalid color type");
3042
3043 case 0: return bit_depth;
3044
3045 case 2: return 3*bit_depth;
3046
3047 case 3: return bit_depth;
3048
3049 case 4: return 2*bit_depth;
3050
3051 case 6: return 4*bit_depth;
3052 }
3053}
3054
3055#define TRANSFORM_WIDTH 128U
3056#define TRANSFORM_ROWMAX (TRANSFORM_WIDTH*8U)
3057#define SIZE_ROWMAX (16*8U) /* 16 pixels, max 8 bytes each - 128 bytes */
3058#define STANDARD_ROWMAX TRANSFORM_ROWMAX /* The larger of the two */
3059#define SIZE_HEIGHTMAX 16 /* Maximum range of size images */
3060
3061static size_t
3062transform_rowsize(png_structp pp, png_byte colour_type, png_byte bit_depth)
3063{
3064 return (TRANSFORM_WIDTH * bit_size(pp, colour_type, bit_depth)) / 8;
3065}
3066
3067/* transform_width(pp, colour_type, bit_depth) current returns the same number
3068 * every time, so just use a macro:
3069 */
3070#define transform_width(pp, colour_type, bit_depth) TRANSFORM_WIDTH
3071
3072static png_uint_32
3073transform_height(png_structp pp, png_byte colour_type, png_byte bit_depth)
3074{
3075 switch (bit_size(pp, colour_type, bit_depth))
3076 {
3077 case 1:
3078 case 2:
3079 case 4:
3080 return 1; /* Total of 128 pixels */
3081
3082 case 8:
3083 return 2; /* Total of 256 pixels/bytes */
3084
3085 case 16:
3086 return 512; /* Total of 65536 pixels */
3087
3088 case 24:
3089 case 32:
3090 return 512; /* 65536 pixels */
3091
3092 case 48:
3093 case 64:
3094 return 2048;/* 4 x 65536 pixels. */
3095# define TRANSFORM_HEIGHTMAX 2048
3096
3097 default:
3098 return 0; /* Error, will be caught later */
3099 }
3100}
3101
3102/* The following can only be defined here, now we have the definitions
3103 * of the transform image sizes.
3104 */
3105static png_uint_32
3106standard_width(png_structp pp, png_uint_32 id)
3107{
3108 png_uint_32 width = WIDTH_FROM_ID(id);
3109 UNUSED(pp)
3110
3111 if (width == 0)
3112 width = transform_width(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
3113
3114 return width;
3115}
3116
3117static png_uint_32
3118standard_height(png_structp pp, png_uint_32 id)
3119{
3120 png_uint_32 height = HEIGHT_FROM_ID(id);
3121
3122 if (height == 0)
3123 height = transform_height(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
3124
3125 return height;
3126}
3127
3128static png_uint_32
3129standard_rowsize(png_structp pp, png_uint_32 id)
3130{
3131 png_uint_32 width = standard_width(pp, id);
3132
3133 /* This won't overflow: */
3134 width *= bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));
3135 return (width + 7) / 8;
3136}
3137
3138static void
3139transform_row(png_structp pp, png_byte buffer[TRANSFORM_ROWMAX],
3140 png_byte colour_type, png_byte bit_depth, png_uint_32 y)
3141{
3142 png_uint_32 v = y << 7;
3143 png_uint_32 i = 0;
3144
3145 switch (bit_size(pp, colour_type, bit_depth))
3146 {
3147 case 1:
3148 while (i<128/8) buffer[i] = v & 0xff, v += 17, ++i;
3149 return;
3150
3151 case 2:
3152 while (i<128/4) buffer[i] = v & 0xff, v += 33, ++i;
3153 return;
3154
3155 case 4:
3156 while (i<128/2) buffer[i] = v & 0xff, v += 65, ++i;
3157 return;
3158
3159 case 8:
3160 /* 256 bytes total, 128 bytes in each row set as follows: */
3161 while (i<128) buffer[i] = v & 0xff, ++v, ++i;
3162 return;
3163
3164 case 16:
3165 /* Generate all 65536 pixel values in order, which includes the 8 bit
3166 * GA case as well as the 16 bit G case.
3167 */
3168 while (i<128)
3169 buffer[2*i] = (v>>8) & 0xff, buffer[2*i+1] = v & 0xff, ++v, ++i;
3170
3171 return;
3172
3173 case 24:
3174 /* 65535 pixels, but rotate the values. */
3175 while (i<128)
3176 {
3177 /* Three bytes per pixel, r, g, b, make b by r^g */
3178 buffer[3*i+0] = (v >> 8) & 0xff;
3179 buffer[3*i+1] = v & 0xff;
3180 buffer[3*i+2] = ((v >> 8) ^ v) & 0xff;
3181 ++v;
3182 ++i;
3183 }
3184
3185 return;
3186
3187 case 32:
3188 /* 65535 pixels, r, g, b, a; just replicate */
3189 while (i<128)
3190 {
3191 buffer[4*i+0] = (v >> 8) & 0xff;
3192 buffer[4*i+1] = v & 0xff;
3193 buffer[4*i+2] = (v >> 8) & 0xff;
3194 buffer[4*i+3] = v & 0xff;
3195 ++v;
3196 ++i;
3197 }
3198
3199 return;
3200
3201 case 48:
3202 /* y is maximum 2047, giving 4x65536 pixels, make 'r' increase by 1 at
3203 * each pixel, g increase by 257 (0x101) and 'b' by 0x1111:
3204 */
3205 while (i<128)
3206 {
3207 png_uint_32 t = v++;
3208 buffer[6*i+0] = (t >> 8) & 0xff;
3209 buffer[6*i+1] = t & 0xff;
3210 t *= 257;
3211 buffer[6*i+2] = (t >> 8) & 0xff;
3212 buffer[6*i+3] = t & 0xff;
3213 t *= 17;
3214 buffer[6*i+4] = (t >> 8) & 0xff;
3215 buffer[6*i+5] = t & 0xff;
3216 ++i;
3217 }
3218
3219 return;
3220
3221 case 64:
3222 /* As above in the 32 bit case. */
3223 while (i<128)
3224 {
3225 png_uint_32 t = v++;
3226 buffer[8*i+0] = (t >> 8) & 0xff;
3227 buffer[8*i+1] = t & 0xff;
3228 buffer[8*i+4] = (t >> 8) & 0xff;
3229 buffer[8*i+5] = t & 0xff;
3230 t *= 257;
3231 buffer[8*i+2] = (t >> 8) & 0xff;
3232 buffer[8*i+3] = t & 0xff;
3233 buffer[8*i+6] = (t >> 8) & 0xff;
3234 buffer[8*i+7] = t & 0xff;
3235 ++i;
3236 }
3237 return;
3238
3239 default:
3240 break;
3241 }
3242
3243 png_error(pp, "internal error");
3244}
3245
3246/* This is just to do the right cast - could be changed to a function to check
3247 * 'bd' but there isn't much point.
3248 */
3249#define DEPTH(bd) ((png_byte)(1U << (bd)))
3250
3251/* Make a standardized image given a an image colour type, bit depth and
3252 * interlace type. The standard images have a very restricted range of
3253 * rows and heights and are used for testing transforms rather than image
3254 * layout details. See make_size_images below for a way to make images
3255 * that test odd sizes along with the libpng interlace handling.
3256 */
3257static void
3258make_transform_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
3259 png_byte PNG_CONST bit_depth, int palette_number, int interlace_type,
3260 png_const_charp name)
3261{
3262 context(ps, fault);
3263
3264 Try
3265 {
3266 png_infop pi;
3267 png_structp pp = set_store_for_write(ps, &pi, name);
3268 png_uint_32 h;
3269
3270 /* In the event of a problem return control to the Catch statement below
3271 * to do the clean up - it is not possible to 'return' directly from a Try
3272 * block.
3273 */
3274 if (pp == NULL)
3275 Throw ps;
3276
3277 h = transform_height(pp, colour_type, bit_depth);
3278
3279 png_set_IHDR(pp, pi, transform_width(pp, colour_type, bit_depth), h,
3280 bit_depth, colour_type, interlace_type,
3281 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
3282
3283#ifdef PNG_TEXT_SUPPORTED
3284 {
3285 static char key[] = "image name"; /* must be writeable */
3286 size_t pos;
3287 png_text text;
3288 char copy[FILE_NAME_SIZE];
3289
3290 /* Use a compressed text string to test the correct interaction of text
3291 * compression and IDAT compression.
3292 */
3293 text.compression = PNG_TEXT_COMPRESSION_zTXt;
3294 text.key = key;
3295 /* Yuck: the text must be writable! */
3296 pos = safecat(copy, sizeof copy, 0, ps->wname);
3297 text.text = copy;
3298 text.text_length = pos;
3299 text.itxt_length = 0;
3300 text.lang = 0;
3301 text.lang_key = 0;
3302
3303 png_set_text(pp, pi, &text, 1);
3304 }
3305#endif
3306
3307 if (colour_type == 3) /* palette */
3308 init_standard_palette(ps, pp, pi, 1U << bit_depth, 1/*do tRNS*/);
3309
3310 png_write_info(pp, pi);
3311
3312 if (png_get_rowbytes(pp, pi) !=
3313 transform_rowsize(pp, colour_type, bit_depth))
3314 png_error(pp, "row size incorrect");
3315
3316 else
3317 {
3318 /* Somewhat confusingly this must be called *after* png_write_info
3319 * because if it is called before, the information in *pp has not been
3320 * updated to reflect the interlaced image.
3321 */
3322 int npasses = png_set_interlace_handling(pp);
3323 int pass;
3324
3325 if (npasses != npasses_from_interlace_type(pp, interlace_type))
3326 png_error(pp, "write: png_set_interlace_handling failed");
3327
3328 for (pass=0; pass<npasses; ++pass)
3329 {
3330 png_uint_32 y;
3331
3332 for (y=0; y<h; ++y)
3333 {
3334 png_byte buffer[TRANSFORM_ROWMAX];
3335
3336 transform_row(pp, buffer, colour_type, bit_depth, y);
3337 png_write_row(pp, buffer);
3338 }
3339 }
3340 }
3341
3342#ifdef PNG_TEXT_SUPPORTED
3343 {
3344 static char key[] = "end marker";
3345 static char comment[] = "end";
3346 png_text text;
3347
3348 /* Use a compressed text string to test the correct interaction of text
3349 * compression and IDAT compression.
3350 */
3351 text.compression = PNG_TEXT_COMPRESSION_zTXt;
3352 text.key = key;
3353 text.text = comment;
3354 text.text_length = (sizeof comment)-1;
3355 text.itxt_length = 0;
3356 text.lang = 0;
3357 text.lang_key = 0;
3358
3359 png_set_text(pp, pi, &text, 1);
3360 }
3361#endif
3362
3363 png_write_end(pp, pi);
3364
3365 /* And store this under the appropriate id, then clean up. */
3366 store_storefile(ps, FILEID(colour_type, bit_depth, palette_number,
3367 interlace_type, 0, 0, 0));
3368
3369 store_write_reset(ps);
3370 }
3371
3372 Catch(fault)
3373 {
3374 /* Use the png_store returned by the exception. This may help the compiler
3375 * because 'ps' is not used in this branch of the setjmp. Note that fault
3376 * and ps will always be the same value.
3377 */
3378 store_write_reset(fault);
3379 }
3380}
3381
3382static void
3383make_transform_images(png_store *ps)
3384{
3385 png_byte colour_type = 0;
3386 png_byte bit_depth = 0;
3387 int palette_number = 0;
3388
3389 /* This is in case of errors. */
3390 safecat(ps->test, sizeof ps->test, 0, "make standard images");
3391
3392 /* Use next_format to enumerate all the combinations we test, including
3393 * generating multiple low bit depth palette images.
3394 */
3395 while (next_format(&colour_type, &bit_depth, &palette_number))
3396 {
3397 int interlace_type;
3398
3399 for (interlace_type = PNG_INTERLACE_NONE;
3400 interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
3401 {
3402 char name[FILE_NAME_SIZE];
3403
3404 standard_name(name, sizeof name, 0, colour_type, bit_depth,
3405 palette_number, interlace_type, 0, 0, 0);
3406 make_transform_image(ps, colour_type, bit_depth, palette_number,
3407 interlace_type, name);
3408 }
3409 }
3410}
3411
3412/* The following two routines use the PNG interlace support macros from
3413 * png.h to interlace or deinterlace rows.
3414 */
3415static void
3416interlace_row(png_bytep buffer, png_const_bytep imageRow,
3417 unsigned int pixel_size, png_uint_32 w, int pass)
3418{
3419 png_uint_32 xin, xout, xstep;
3420
3421 /* Note that this can, trivially, be optimized to a memcpy on pass 7, the
3422 * code is presented this way to make it easier to understand. In practice
3423 * consult the code in the libpng source to see other ways of doing this.
3424 */
3425 xin = PNG_PASS_START_COL(pass);
3426 xstep = 1U<<PNG_PASS_COL_SHIFT(pass);
3427
3428 for (xout=0; xin<w; xin+=xstep)
3429 {
3430 pixel_copy(buffer, xout, imageRow, xin, pixel_size);
3431 ++xout;
3432 }
3433}
3434
3435static void
3436deinterlace_row(png_bytep buffer, png_const_bytep row,
3437 unsigned int pixel_size, png_uint_32 w, int pass)
3438{
3439 /* The inverse of the above, 'row' is part of row 'y' of the output image,
3440 * in 'buffer'. The image is 'w' wide and this is pass 'pass', distribute
3441 * the pixels of row into buffer and return the number written (to allow
3442 * this to be checked).
3443 */
3444 png_uint_32 xin, xout, xstep;
3445
3446 xout = PNG_PASS_START_COL(pass);
3447 xstep = 1U<<PNG_PASS_COL_SHIFT(pass);
3448
3449 for (xin=0; xout<w; xout+=xstep)
3450 {
3451 pixel_copy(buffer, xout, row, xin, pixel_size);
3452 ++xin;
3453 }
3454}
3455
3456/* Build a single row for the 'size' test images; this fills in only the
3457 * first bit_width bits of the sample row.
3458 */
3459static void
3460size_row(png_byte buffer[SIZE_ROWMAX], png_uint_32 bit_width, png_uint_32 y)
3461{
3462 /* height is in the range 1 to 16, so: */
3463 y = ((y & 1) << 7) + ((y & 2) << 6) + ((y & 4) << 5) + ((y & 8) << 4);
3464 /* the following ensures bits are set in small images: */
3465 y ^= 0xA5;
3466
3467 while (bit_width >= 8)
3468 *buffer++ = (png_byte)y++, bit_width -= 8;
3469
3470 /* There may be up to 7 remaining bits, these go in the most significant
3471 * bits of the byte.
3472 */
3473 if (bit_width > 0)
3474 {
3475 png_uint_32 mask = (1U<<(8-bit_width))-1;
3476 *buffer = (png_byte)((*buffer & mask) | (y & ~mask));
3477 }
3478}
3479
3480static void
3481make_size_image(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type,
3482 png_byte PNG_CONST bit_depth, int PNG_CONST interlace_type,
3483 png_uint_32 PNG_CONST w, png_uint_32 PNG_CONST h,
3484 int PNG_CONST do_interlace)
3485{
3486 context(ps, fault);
3487
3488 Try
3489 {
3490 png_infop pi;
3491 png_structp pp;
3492 unsigned int pixel_size;
3493
3494 /* Make a name and get an appropriate id for the store: */
3495 char name[FILE_NAME_SIZE];
3496 PNG_CONST png_uint_32 id = FILEID(colour_type, bit_depth, 0/*palette*/,
3497 interlace_type, w, h, do_interlace);
3498
3499 standard_name_from_id(name, sizeof name, 0, id);
3500 pp = set_store_for_write(ps, &pi, name);
3501
3502 /* In the event of a problem return control to the Catch statement below
3503 * to do the clean up - it is not possible to 'return' directly from a Try
3504 * block.
3505 */
3506 if (pp == NULL)
3507 Throw ps;
3508
3509 png_set_IHDR(pp, pi, w, h, bit_depth, colour_type, interlace_type,
3510 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
3511
3512 if (colour_type == 3) /* palette */
3513 init_standard_palette(ps, pp, pi, 1U << bit_depth, 0/*do tRNS*/);
3514
3515 png_write_info(pp, pi);
3516
3517 /* Calculate the bit size, divide by 8 to get the byte size - this won't
3518 * overflow because we know the w values are all small enough even for
3519 * a system where 'unsigned int' is only 16 bits.
3520 */
3521 pixel_size = bit_size(pp, colour_type, bit_depth);
3522 if (png_get_rowbytes(pp, pi) != ((w * pixel_size) + 7) / 8)
3523 png_error(pp, "row size incorrect");
3524
3525 else
3526 {
3527 int npasses = npasses_from_interlace_type(pp, interlace_type);
3528 png_uint_32 y;
3529 int pass;
3530 png_byte image[16][SIZE_ROWMAX];
3531
3532 /* To help consistent error detection make the parts of this buffer
3533 * that aren't set below all '1':
3534 */
3535 memset(image, 0xff, sizeof image);
3536
3537 if (!do_interlace && npasses != png_set_interlace_handling(pp))
3538 png_error(pp, "write: png_set_interlace_handling failed");
3539
3540 /* Prepare the whole image first to avoid making it 7 times: */
3541 for (y=0; y<h; ++y)
3542 size_row(image[y], w * pixel_size, y);
3543
3544 for (pass=0; pass<npasses; ++pass)
3545 {
3546 /* The following two are for checking the macros: */
3547 PNG_CONST png_uint_32 wPass = PNG_PASS_COLS(w, pass);
3548
3549 /* If do_interlace is set we don't call png_write_row for every
3550 * row because some of them are empty. In fact, for a 1x1 image,
3551 * most of them are empty!
3552 */
3553 for (y=0; y<h; ++y)
3554 {
3555 png_const_bytep row = image[y];
3556 png_byte tempRow[SIZE_ROWMAX];
3557
3558 /* If do_interlace *and* the image is interlaced we
3559 * need a reduced interlace row; this may be reduced
3560 * to empty.
3561 */
3562 if (do_interlace && interlace_type == PNG_INTERLACE_ADAM7)
3563 {
3564 /* The row must not be written if it doesn't exist, notice
3565 * that there are two conditions here, either the row isn't
3566 * ever in the pass or the row would be but isn't wide
3567 * enough to contribute any pixels. In fact the wPass test
3568 * can be used to skip the whole y loop in this case.
3569 */
3570 if (PNG_ROW_IN_INTERLACE_PASS(y, pass) && wPass > 0)
3571 {
3572 /* Set to all 1's for error detection (libpng tends to
3573 * set unset things to 0).
3574 */
3575 memset(tempRow, 0xff, sizeof tempRow);
3576 interlace_row(tempRow, row, pixel_size, w, pass);
3577 row = tempRow;
3578 }
3579 else
3580 continue;
3581 }
3582
3583 /* Only get to here if the row has some pixels in it. */
3584 png_write_row(pp, row);
3585 }
3586 }
3587 }
3588
3589 png_write_end(pp, pi);
3590
3591 /* And store this under the appropriate id, then clean up. */
3592 store_storefile(ps, id);
3593
3594 store_write_reset(ps);
3595 }
3596
3597 Catch(fault)
3598 {
3599 /* Use the png_store returned by the exception. This may help the compiler
3600 * because 'ps' is not used in this branch of the setjmp. Note that fault
3601 * and ps will always be the same value.
3602 */
3603 store_write_reset(fault);
3604 }
3605}
3606
3607static void
3608make_size(png_store* PNG_CONST ps, png_byte PNG_CONST colour_type, int bdlo,
3609 int PNG_CONST bdhi)
3610{
3611 for (; bdlo <= bdhi; ++bdlo)
3612 {
3613 png_uint_32 width;
3614
3615 for (width = 1; width <= 16; ++width)
3616 {
3617 png_uint_32 height;
3618
3619 for (height = 1; height <= 16; ++height)
3620 {
3621 /* The four combinations of DIY interlace and interlace or not -
3622 * no interlace + DIY should be identical to no interlace with
3623 * libpng doing it.
3624 */
3625 make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_NONE,
3626 width, height, 0);
3627 make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_NONE,
3628 width, height, 1);
3629 make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
3630 width, height, 0);
3631 make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,
3632 width, height, 1);
3633 }
3634 }
3635 }
3636}
3637
3638static void
3639make_size_images(png_store *ps)
3640{
3641 /* This is in case of errors. */
3642 safecat(ps->test, sizeof ps->test, 0, "make size images");
3643
3644 /* Arguments are colour_type, low bit depth, high bit depth
3645 */
3646 make_size(ps, 0, 0, WRITE_BDHI);
3647 make_size(ps, 2, 3, WRITE_BDHI);
3648 make_size(ps, 3, 0, 3 /*palette: max 8 bits*/);
3649 make_size(ps, 4, 3, WRITE_BDHI);
3650 make_size(ps, 6, 3, WRITE_BDHI);
3651}
3652
3653/* Return a row based on image id and 'y' for checking: */
3654static void
3655standard_row(png_structp pp, png_byte std[STANDARD_ROWMAX], png_uint_32 id,
3656 png_uint_32 y)
3657{
3658 if (WIDTH_FROM_ID(id) == 0)
3659 transform_row(pp, std, COL_FROM_ID(id), DEPTH_FROM_ID(id), y);
3660 else
3661 size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id),
3662 DEPTH_FROM_ID(id)), y);
3663}
3664
3665/* Tests - individual test cases */
3666/* Like 'make_standard' but errors are deliberately introduced into the calls
3667 * to ensure that they get detected - it should not be possible to write an
3668 * invalid image with libpng!
3669 */
3670#ifdef PNG_WARNINGS_SUPPORTED
3671static void
3672sBIT0_error_fn(png_structp pp, png_infop pi)
3673{
3674 /* 0 is invalid... */
3675 png_color_8 bad;
3676 bad.red = bad.green = bad.blue = bad.gray = bad.alpha = 0;
3677 png_set_sBIT(pp, pi, &bad);
3678}
3679
3680static void
3681sBIT_error_fn(png_structp pp, png_infop pi)
3682{
3683 png_byte bit_depth;
3684 png_color_8 bad;
3685
3686 if (png_get_color_type(pp, pi) == PNG_COLOR_TYPE_PALETTE)
3687 bit_depth = 8;
3688
3689 else
3690 bit_depth = png_get_bit_depth(pp, pi);
3691
3692 /* Now we know the bit depth we can easily generate an invalid sBIT entry */
3693 bad.red = bad.green = bad.blue = bad.gray = bad.alpha =
3694 (png_byte)(bit_depth+1);
3695 png_set_sBIT(pp, pi, &bad);
3696}
3697
3698static PNG_CONST struct
3699{
3700 void (*fn)(png_structp, png_infop);
3701 PNG_CONST char *msg;
3702 unsigned int warning :1; /* the error is a warning... */
3703} error_test[] =
3704 {
3705 /* no warnings makes these errors undetectable. */
3706 { sBIT0_error_fn, "sBIT(0): failed to detect error", 1 },
3707 { sBIT_error_fn, "sBIT(too big): failed to detect error", 1 },
3708 };
3709
3710static void
3711make_error(png_store* volatile psIn, png_byte PNG_CONST colour_type,
3712 png_byte bit_depth, int interlace_type, int test, png_const_charp name)
3713{
3714 png_store * volatile ps = psIn;
3715
3716 context(ps, fault);
3717
3718 Try
3719 {
3720 png_structp pp;
3721 png_infop pi;
3722
3723 pp = set_store_for_write(ps, &pi, name);
3724
3725 if (pp == NULL)
3726 Throw ps;
3727
3728 png_set_IHDR(pp, pi, transform_width(pp, colour_type, bit_depth),
3729 transform_height(pp, colour_type, bit_depth), bit_depth, colour_type,
3730 interlace_type, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
3731
3732 if (colour_type == 3) /* palette */
3733 init_standard_palette(ps, pp, pi, 1U << bit_depth, 0/*do tRNS*/);
3734
3735 /* Time for a few errors; these are in various optional chunks, the
3736 * standard tests test the standard chunks pretty well.
3737 */
3738# define exception__prev exception_prev_1
3739# define exception__env exception_env_1
3740 Try
3741 {
3742 /* Expect this to throw: */
3743 ps->expect_error = !error_test[test].warning;
3744 ps->expect_warning = error_test[test].warning;
3745 ps->saw_warning = 0;
3746 error_test[test].fn(pp, pi);
3747
3748 /* Normally the error is only detected here: */
3749 png_write_info(pp, pi);
3750
3751 /* And handle the case where it was only a warning: */
3752 if (ps->expect_warning && ps->saw_warning)
3753 Throw ps;
3754
3755 /* If we get here there is a problem, we have success - no error or
3756 * no warning - when we shouldn't have success. Log an error.
3757 */
3758 store_log(ps, pp, error_test[test].msg, 1 /*error*/);
3759 }
3760
3761 Catch (fault)
3762 ps = fault; /* expected exit, make sure ps is not clobbered */
3763#undef exception__prev
3764#undef exception__env
3765
3766 /* And clear these flags */
3767 ps->expect_error = 0;
3768 ps->expect_warning = 0;
3769
3770 /* Now write the whole image, just to make sure that the detected, or
3771 * undetected, errro has not created problems inside libpng.
3772 */
3773 if (png_get_rowbytes(pp, pi) !=
3774 transform_rowsize(pp, colour_type, bit_depth))
3775 png_error(pp, "row size incorrect");
3776
3777 else
3778 {
3779 png_uint_32 h = transform_height(pp, colour_type, bit_depth);
3780 int npasses = png_set_interlace_handling(pp);
3781 int pass;
3782
3783 if (npasses != npasses_from_interlace_type(pp, interlace_type))
3784 png_error(pp, "write: png_set_interlace_handling failed");
3785
3786 for (pass=0; pass<npasses; ++pass)
3787 {
3788 png_uint_32 y;
3789
3790 for (y=0; y<h; ++y)
3791 {
3792 png_byte buffer[TRANSFORM_ROWMAX];
3793
3794 transform_row(pp, buffer, colour_type, bit_depth, y);
3795 png_write_row(pp, buffer);
3796 }
3797 }
3798 }
3799
3800 png_write_end(pp, pi);
3801
3802 /* The following deletes the file that was just written. */
3803 store_write_reset(ps);
3804 }
3805
3806 Catch(fault)
3807 {
3808 store_write_reset(fault);
3809 }
3810}
3811
3812static int
3813make_errors(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
3814 int bdlo, int PNG_CONST bdhi)
3815{
3816 for (; bdlo <= bdhi; ++bdlo)
3817 {
3818 int interlace_type;
3819
3820 for (interlace_type = PNG_INTERLACE_NONE;
3821 interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
3822 {
3823 unsigned int test;
3824 char name[FILE_NAME_SIZE];
3825
3826 standard_name(name, sizeof name, 0, colour_type, 1<<bdlo, 0,
3827 interlace_type, 0, 0, 0);
3828
3829 for (test=0; test<(sizeof error_test)/(sizeof error_test[0]); ++test)
3830 {
3831 make_error(&pm->this, colour_type, DEPTH(bdlo), interlace_type,
3832 test, name);
3833
3834 if (fail(pm))
3835 return 0;
3836 }
3837 }
3838 }
3839
3840 return 1; /* keep going */
3841}
3842#endif
3843
3844static void
3845perform_error_test(png_modifier *pm)
3846{
3847#ifdef PNG_WARNINGS_SUPPORTED /* else there are no cases that work! */
3848 /* Need to do this here because we just write in this test. */
3849 safecat(pm->this.test, sizeof pm->this.test, 0, "error test");
3850
3851 if (!make_errors(pm, 0, 0, WRITE_BDHI))
3852 return;
3853
3854 if (!make_errors(pm, 2, 3, WRITE_BDHI))
3855 return;
3856
3857 if (!make_errors(pm, 3, 0, 3))
3858 return;
3859
3860 if (!make_errors(pm, 4, 3, WRITE_BDHI))
3861 return;
3862
3863 if (!make_errors(pm, 6, 3, WRITE_BDHI))
3864 return;
3865#else
3866 UNUSED(pm)
3867#endif
3868}
3869
3870/* This is just to validate the internal PNG formatting code - if this fails
3871 * then the warning messages the library outputs will probably be garbage.
3872 */
3873static void
3874perform_formatting_test(png_store *volatile ps)
3875{
3876#ifdef PNG_TIME_RFC1123_SUPPORTED
3877 /* The handle into the formatting code is the RFC1123 support; this test does
3878 * nothing if that is compiled out.
3879 */
3880 context(ps, fault);
3881
3882 Try
3883 {
3884 png_const_charp correct = "29 Aug 2079 13:53:60 +0000";
3885 png_const_charp result;
3886 png_structp pp;
3887 png_time pt;
3888
3889 pp = set_store_for_write(ps, NULL, "libpng formatting test");
3890
3891 if (pp == NULL)
3892 Throw ps;
3893
3894
3895 /* Arbitrary settings: */
3896 pt.year = 2079;
3897 pt.month = 8;
3898 pt.day = 29;
3899 pt.hour = 13;
3900 pt.minute = 53;
3901 pt.second = 60; /* a leap second */
3902
3903 result = png_convert_to_rfc1123(pp, &pt);
3904
3905 if (result == NULL)
3906 png_error(pp, "png_convert_to_rfc1123 failed");
3907
3908 if (strcmp(result, correct) != 0)
3909 {
3910 size_t pos = 0;
3911 char msg[128];
3912
3913 pos = safecat(msg, sizeof msg, pos, "png_convert_to_rfc1123(");
3914 pos = safecat(msg, sizeof msg, pos, correct);
3915 pos = safecat(msg, sizeof msg, pos, ") returned: '");
3916 pos = safecat(msg, sizeof msg, pos, result);
3917 pos = safecat(msg, sizeof msg, pos, "'");
3918
3919 png_error(pp, msg);
3920 }
3921
3922 store_write_reset(ps);
3923 }
3924
3925 Catch(fault)
3926 {
3927 store_write_reset(fault);
3928 }
3929#else
3930 UNUSED(ps)
3931#endif
3932}
3933
3934/* Because we want to use the same code in both the progressive reader and the
3935 * sequential reader it is necessary to deal with the fact that the progressive
3936 * reader callbacks only have one parameter (png_get_progressive_ptr()), so this
3937 * must contain all the test parameters and all the local variables directly
3938 * accessible to the sequential reader implementation.
3939 *
3940 * The technique adopted is to reinvent part of what Dijkstra termed a
3941 * 'display'; an array of pointers to the stack frames of enclosing functions so
3942 * that a nested function definition can access the local (C auto) variables of
3943 * the functions that contain its definition. In fact C provides the first
3944 * pointer (the local variables - the stack frame pointer) and the last (the
3945 * global variables - the BCPL global vector typically implemented as global
3946 * addresses), this code requires one more pointer to make the display - the
3947 * local variables (and function call parameters) of the function that actually
3948 * invokes either the progressive or sequential reader.
3949 *
3950 * Perhaps confusingly this technique is confounded with classes - the
3951 * 'standard_display' defined here is sub-classed as the 'gamma_display' below.
3952 * A gamma_display is a standard_display, taking advantage of the ANSI-C
3953 * requirement that the pointer to the first member of a structure must be the
3954 * same as the pointer to the structure. This allows us to reuse standard_
3955 * functions in the gamma test code; something that could not be done with
3956 * nested functions!
3957 */
3958typedef struct standard_display
3959{
3960 png_store* ps; /* Test parameters (passed to the function) */
3961 png_byte colour_type;
3962 png_byte bit_depth;
3963 png_byte red_sBIT; /* Input data sBIT values. */
3964 png_byte green_sBIT;
3965 png_byte blue_sBIT;
3966 png_byte alpha_sBIT;
3967 int interlace_type;
3968 png_uint_32 id; /* Calculated file ID */
3969 png_uint_32 w; /* Width of image */
3970 png_uint_32 h; /* Height of image */
3971 int npasses; /* Number of interlaced passes */
3972 png_uint_32 pixel_size; /* Width of one pixel in bits */
3973 png_uint_32 bit_width; /* Width of output row in bits */
3974 size_t cbRow; /* Bytes in a row of the output image */
3975 int do_interlace; /* Do interlacing internally */
3976 int is_transparent; /* Transparency information was present. */
3977 int speed; /* Doing a speed test */
3978 int use_update_info;/* Call update_info, not start_image */
3979 struct
3980 {
3981 png_uint_16 red;
3982 png_uint_16 green;
3983 png_uint_16 blue;
3984 } transparent; /* The transparent color, if set. */
3985 int npalette; /* Number of entries in the palette. */
3986 store_palette
3987 palette;
3988} standard_display;
3989
3990static void
3991standard_display_init(standard_display *dp, png_store* ps, png_uint_32 id,
3992 int do_interlace, int use_update_info)
3993{
3994 memset(dp, 0, sizeof *dp);
3995
3996 dp->ps = ps;
3997 dp->colour_type = COL_FROM_ID(id);
3998 dp->bit_depth = DEPTH_FROM_ID(id);
3999 if (dp->bit_depth < 1 || dp->bit_depth > 16)
4000 internal_error(ps, "internal: bad bit depth");
4001 if (dp->colour_type == 3)
4002 dp->red_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT = 8;
4003 else
4004 dp->red_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT =
4005 dp->bit_depth;
4006 dp->interlace_type = INTERLACE_FROM_ID(id);
4007 dp->id = id;
4008 /* All the rest are filled in after the read_info: */
4009 dp->w = 0;
4010 dp->h = 0;
4011 dp->npasses = 0;
4012 dp->pixel_size = 0;
4013 dp->bit_width = 0;
4014 dp->cbRow = 0;
4015 dp->do_interlace = do_interlace;
4016 dp->is_transparent = 0;
4017 dp->speed = ps->speed;
4018 dp->use_update_info = use_update_info;
4019 dp->npalette = 0;
4020 /* Preset the transparent color to black: */
4021 memset(&dp->transparent, 0, sizeof dp->transparent);
4022 /* Preset the palette to full intensity/opaque througout: */
4023 memset(dp->palette, 0xff, sizeof dp->palette);
4024}
4025
4026/* Initialize the palette fields - this must be done later because the palette
4027 * comes from the particular png_store_file that is selected.
4028 */
4029static void
4030standard_palette_init(standard_display *dp)
4031{
4032 store_palette_entry *palette = store_current_palette(dp->ps, &dp->npalette);
4033
4034 /* The remaining entries remain white/opaque. */
4035 if (dp->npalette > 0)
4036 {
4037 int i = dp->npalette;
4038 memcpy(dp->palette, palette, i * sizeof *palette);
4039
4040 /* Check for a non-opaque palette entry: */
4041 while (--i >= 0)
4042 if (palette[i].alpha < 255)
4043 break;
4044
4045# ifdef __GNUC__
4046 /* GCC can't handle the more obviously optimizable version. */
4047 if (i >= 0)
4048 dp->is_transparent = 1;
4049 else
4050 dp->is_transparent = 0;
4051# else
4052 dp->is_transparent = (i >= 0);
4053# endif
4054 }
4055}
4056
4057/* Utility to read the palette from the PNG file and convert it into
4058 * store_palette format. This returns 1 if there is any transparency in the
4059 * palette (it does not check for a transparent colour in the non-palette case.)
4060 */
4061static int
4062read_palette(store_palette palette, int *npalette, png_structp pp, png_infop pi)
4063{
4064 png_colorp pal;
4065 png_bytep trans_alpha;
4066 int num;
4067
4068 pal = 0;
4069 *npalette = -1;
4070
4071 if (png_get_PLTE(pp, pi, &pal, npalette) & PNG_INFO_PLTE)
4072 {
4073 int i = *npalette;
4074
4075 if (i <= 0 || i > 256)
4076 png_error(pp, "validate: invalid PLTE count");
4077
4078 while (--i >= 0)
4079 {
4080 palette[i].red = pal[i].red;
4081 palette[i].green = pal[i].green;
4082 palette[i].blue = pal[i].blue;
4083 }
4084
4085 /* Mark the remainder of the entries with a flag value (other than
4086 * white/opaque which is the flag value stored above.)
4087 */
4088 memset(palette + *npalette, 126, (256-*npalette) * sizeof *palette);
4089 }
4090
4091 else /* !png_get_PLTE */
4092 {
4093 if (*npalette != (-1))
4094 png_error(pp, "validate: invalid PLTE result");
4095 /* But there is no palette, so record this: */
4096 *npalette = 0;
4097 memset(palette, 113, sizeof (store_palette));
4098 }
4099
4100 trans_alpha = 0;
4101 num = 2; /* force error below */
4102 if ((png_get_tRNS(pp, pi, &trans_alpha, &num, 0) & PNG_INFO_tRNS) != 0 &&
4103 (trans_alpha != NULL || num != 1/*returns 1 for a transparent color*/) &&
4104 /* Oops, if a palette tRNS gets expanded png_read_update_info (at least so
4105 * far as 1.5.4) does not remove the trans_alpha pointer, only num_trans,
4106 * so in the above call we get a success, we get a pointer (who knows what
4107 * to) and we get num_trans == 0:
4108 */
4109 !(trans_alpha != NULL && num == 0)) /* TODO: fix this in libpng. */
4110 {
4111 int i;
4112
4113 /* Any of these are crash-worthy - given the implementation of
4114 * png_get_tRNS up to 1.5 an app won't crash if it just checks the
4115 * result above and fails to check that the variables it passed have
4116 * actually been filled in! Note that if the app were to pass the
4117 * last, png_color_16p, variable too it couldn't rely on this.
4118 */
4119 if (trans_alpha == NULL || num <= 0 || num > 256 || num > *npalette)
4120 png_error(pp, "validate: unexpected png_get_tRNS (palette) result");
4121
4122 for (i=0; i<num; ++i)
4123 palette[i].alpha = trans_alpha[i];
4124
4125 for (num=*npalette; i<num; ++i)
4126 palette[i].alpha = 255;
4127
4128 for (; i<256; ++i)
4129 palette[i].alpha = 33; /* flag value */
4130
4131 return 1; /* transparency */
4132 }
4133
4134 else
4135 {
4136 /* No palette transparency - just set the alpha channel to opaque. */
4137 int i;
4138
4139 for (i=0, num=*npalette; i<num; ++i)
4140 palette[i].alpha = 255;
4141
4142 for (; i<256; ++i)
4143 palette[i].alpha = 55; /* flag value */
4144
4145 return 0; /* no transparency */
4146 }
4147}
4148
4149/* Utility to validate the palette if it should not have changed (the
4150 * non-transform case).
4151 */
4152static void
4153standard_palette_validate(standard_display *dp, png_structp pp, png_infop pi)
4154{
4155 int npalette;
4156 store_palette palette;
4157
4158 if (read_palette(palette, &npalette, pp, pi) != dp->is_transparent)
4159 png_error(pp, "validate: palette transparency changed");
4160
4161 if (npalette != dp->npalette)
4162 {
4163 size_t pos = 0;
4164 char msg[64];
4165
4166 pos = safecat(msg, sizeof msg, pos, "validate: palette size changed: ");
4167 pos = safecatn(msg, sizeof msg, pos, dp->npalette);
4168 pos = safecat(msg, sizeof msg, pos, " -> ");
4169 pos = safecatn(msg, sizeof msg, pos, npalette);
4170 png_error(pp, msg);
4171 }
4172
4173 {
4174 int i = npalette; /* npalette is aliased */
4175
4176 while (--i >= 0)
4177 if (palette[i].red != dp->palette[i].red ||
4178 palette[i].green != dp->palette[i].green ||
4179 palette[i].blue != dp->palette[i].blue ||
4180 palette[i].alpha != dp->palette[i].alpha)
4181 png_error(pp, "validate: PLTE or tRNS chunk changed");
4182 }
4183}
4184
4185/* By passing a 'standard_display' the progressive callbacks can be used
4186 * directly by the sequential code, the functions suffixed "_imp" are the
4187 * implementations, the functions without the suffix are the callbacks.
4188 *
4189 * The code for the info callback is split into two because this callback calls
4190 * png_read_update_info or png_start_read_image and what gets called depends on
4191 * whether the info needs updating (we want to test both calls in pngvalid.)
4192 */
4193static void
4194standard_info_part1(standard_display *dp, png_structp pp, png_infop pi)
4195{
4196 if (png_get_bit_depth(pp, pi) != dp->bit_depth)
4197 png_error(pp, "validate: bit depth changed");
4198
4199 if (png_get_color_type(pp, pi) != dp->colour_type)
4200 png_error(pp, "validate: color type changed");
4201
4202 if (png_get_filter_type(pp, pi) != PNG_FILTER_TYPE_BASE)
4203 png_error(pp, "validate: filter type changed");
4204
4205 if (png_get_interlace_type(pp, pi) != dp->interlace_type)
4206 png_error(pp, "validate: interlacing changed");
4207
4208 if (png_get_compression_type(pp, pi) != PNG_COMPRESSION_TYPE_BASE)
4209 png_error(pp, "validate: compression type changed");
4210
4211 dp->w = png_get_image_width(pp, pi);
4212
4213 if (dp->w != standard_width(pp, dp->id))
4214 png_error(pp, "validate: image width changed");
4215
4216 dp->h = png_get_image_height(pp, pi);
4217
4218 if (dp->h != standard_height(pp, dp->id))
4219 png_error(pp, "validate: image height changed");
4220
4221 /* Record (but don't check at present) the input sBIT according to the colour
4222 * type information.
4223 */
4224 {
4225 png_color_8p sBIT = 0;
4226
4227 if (png_get_sBIT(pp, pi, &sBIT) & PNG_INFO_sBIT)
4228 {
4229 int sBIT_invalid = 0;
4230
4231 if (sBIT == 0)
4232 png_error(pp, "validate: unexpected png_get_sBIT result");
4233
4234 if (dp->colour_type & PNG_COLOR_MASK_COLOR)
4235 {
4236 if (sBIT->red == 0 || sBIT->red > dp->bit_depth)
4237 sBIT_invalid = 1;
4238 else
4239 dp->red_sBIT = sBIT->red;
4240
4241 if (sBIT->green == 0 || sBIT->green > dp->bit_depth)
4242 sBIT_invalid = 1;
4243 else
4244 dp->green_sBIT = sBIT->green;
4245
4246 if (sBIT->blue == 0 || sBIT->blue > dp->bit_depth)
4247 sBIT_invalid = 1;
4248 else
4249 dp->blue_sBIT = sBIT->blue;
4250 }
4251
4252 else /* !COLOR */
4253 {
4254 if (sBIT->gray == 0 || sBIT->gray > dp->bit_depth)
4255 sBIT_invalid = 1;
4256 else
4257 dp->blue_sBIT = dp->green_sBIT = dp->red_sBIT = sBIT->gray;
4258 }
4259
4260 /* All 8 bits in tRNS for a palette image are significant - see the
4261 * spec.
4262 */
4263 if (dp->colour_type & PNG_COLOR_MASK_ALPHA)
4264 {
4265 if (sBIT->alpha == 0 || sBIT->alpha > dp->bit_depth)
4266 sBIT_invalid = 1;
4267 else
4268 dp->alpha_sBIT = sBIT->alpha;
4269 }
4270
4271 if (sBIT_invalid)
4272 png_error(pp, "validate: sBIT value out of range");
4273 }
4274 }
4275
4276 /* Important: this is validating the value *before* any transforms have been
4277 * put in place. It doesn't matter for the standard tests, where there are
4278 * no transforms, but it does for other tests where rowbytes may change after
4279 * png_read_update_info.
4280 */
4281 if (png_get_rowbytes(pp, pi) != standard_rowsize(pp, dp->id))
4282 png_error(pp, "validate: row size changed");
4283
4284 /* Validate the colour type 3 palette (this can be present on other color
4285 * types.)
4286 */
4287 standard_palette_validate(dp, pp, pi);
4288
4289 /* In any case always check for a tranparent color (notice that the
4290 * colour type 3 case must not give a successful return on the get_tRNS call
4291 * with these arguments!)
4292 */
4293 {
4294 png_color_16p trans_color = 0;
4295
4296 if (png_get_tRNS(pp, pi, 0, 0, &trans_color) & PNG_INFO_tRNS)
4297 {
4298 if (trans_color == 0)
4299 png_error(pp, "validate: unexpected png_get_tRNS (color) result");
4300
4301 switch (dp->colour_type)
4302 {
4303 case 0:
4304 dp->transparent.red = dp->transparent.green = dp->transparent.blue =
4305 trans_color->gray;
4306 dp->is_transparent = 1;
4307 break;
4308
4309 case 2:
4310 dp->transparent.red = trans_color->red;
4311 dp->transparent.green = trans_color->green;
4312 dp->transparent.blue = trans_color->blue;
4313 dp->is_transparent = 1;
4314 break;
4315
4316 case 3:
4317 /* Not expected because it should result in the array case
4318 * above.
4319 */
4320 png_error(pp, "validate: unexpected png_get_tRNS result");
4321 break;
4322
4323 default:
4324 png_error(pp, "validate: invalid tRNS chunk with alpha image");
4325 }
4326 }
4327 }
4328
4329 /* Read the number of passes - expected to match the value used when
4330 * creating the image (interlaced or not). This has the side effect of
4331 * turning on interlace handling (if do_interlace is not set.)
4332 */
4333 dp->npasses = npasses_from_interlace_type(pp, dp->interlace_type);
4334 if (!dp->do_interlace && dp->npasses != png_set_interlace_handling(pp))
4335 png_error(pp, "validate: file changed interlace type");
4336
4337 /* Caller calls png_read_update_info or png_start_read_image now, then calls
4338 * part2.
4339 */
4340}
4341
4342/* This must be called *after* the png_read_update_info call to get the correct
4343 * 'rowbytes' value, otherwise png_get_rowbytes will refer to the untransformed
4344 * image.
4345 */
4346static void
4347standard_info_part2(standard_display *dp, png_structp pp, png_infop pi,
4348 int nImages)
4349{
4350 /* Record cbRow now that it can be found. */
4351 dp->pixel_size = bit_size(pp, png_get_color_type(pp, pi),
4352 png_get_bit_depth(pp, pi));
4353 dp->bit_width = png_get_image_width(pp, pi) * dp->pixel_size;
4354 dp->cbRow = png_get_rowbytes(pp, pi);
4355
4356 /* Validate the rowbytes here again. */
4357 if (dp->cbRow != (dp->bit_width+7)/8)
4358 png_error(pp, "bad png_get_rowbytes calculation");
4359
4360 /* Then ensure there is enough space for the output image(s). */
4361 store_ensure_image(dp->ps, pp, nImages, dp->cbRow, dp->h);
4362}
4363
4364static void
4365standard_info_imp(standard_display *dp, png_structp pp, png_infop pi,
4366 int nImages)
4367{
4368 /* Note that the validation routine has the side effect of turning on
4369 * interlace handling in the subsequent code.
4370 */
4371 standard_info_part1(dp, pp, pi);
4372
4373 /* And the info callback has to call this (or png_read_update_info - see
4374 * below in the png_modifier code for that variant.
4375 */
4376 if (dp->use_update_info)
4377 {
4378 /* For debugging the effect of multiple calls: */
4379 int i = dp->use_update_info;
4380 while (i-- > 0)
4381 png_read_update_info(pp, pi);
4382 }
4383
4384 else
4385 png_start_read_image(pp);
4386
4387 /* Validate the height, width and rowbytes plus ensure that sufficient buffer
4388 * exists for decoding the image.
4389 */
4390 standard_info_part2(dp, pp, pi, nImages);
4391}
4392
4393static void
4394standard_info(png_structp pp, png_infop pi)
4395{
4396 standard_display *dp = voidcast(standard_display*,
4397 png_get_progressive_ptr(pp));
4398
4399 /* Call with nImages==1 because the progressive reader can only produce one
4400 * image.
4401 */
4402 standard_info_imp(dp, pp, pi, 1 /*only one image*/);
4403}
4404
4405static void
4406progressive_row(png_structp pp, png_bytep new_row, png_uint_32 y, int pass)
4407{
4408 PNG_CONST standard_display *dp = voidcast(standard_display*,
4409 png_get_progressive_ptr(pp));
4410
4411 /* When handling interlacing some rows will be absent in each pass, the
4412 * callback still gets called, but with a NULL pointer. This is checked
4413 * in the 'else' clause below. We need our own 'cbRow', but we can't call
4414 * png_get_rowbytes because we got no info structure.
4415 */
4416 if (new_row != NULL)
4417 {
4418 png_bytep row;
4419
4420 /* In the case where the reader doesn't do the interlace it gives
4421 * us the y in the sub-image:
4422 */
4423 if (dp->do_interlace && dp->interlace_type == PNG_INTERLACE_ADAM7)
4424 {
4425#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
4426 /* Use this opportunity to validate the png 'current' APIs: */
4427 if (y != png_get_current_row_number(pp))
4428 png_error(pp, "png_get_current_row_number is broken");
4429
4430 if (pass != png_get_current_pass_number(pp))
4431 png_error(pp, "png_get_current_pass_number is broken");
4432#endif
4433
4434 y = PNG_ROW_FROM_PASS_ROW(y, pass);
4435 }
4436
4437 /* Validate this just in case. */
4438 if (y >= dp->h)
4439 png_error(pp, "invalid y to progressive row callback");
4440
4441 row = store_image_row(dp->ps, pp, 0, y);
4442
4443#ifdef PNG_READ_INTERLACING_SUPPORTED
4444 /* Combine the new row into the old: */
4445 if (dp->do_interlace)
4446 {
4447 if (dp->interlace_type == PNG_INTERLACE_ADAM7)
4448 deinterlace_row(row, new_row, dp->pixel_size, dp->w, pass);
4449 else
4450 row_copy(row, new_row, dp->pixel_size * dp->w);
4451 }
4452 else
4453 png_progressive_combine_row(pp, row, new_row);
4454 } else if (dp->interlace_type == PNG_INTERLACE_ADAM7 &&
4455 PNG_ROW_IN_INTERLACE_PASS(y, pass) &&
4456 PNG_PASS_COLS(dp->w, pass) > 0)
4457 png_error(pp, "missing row in progressive de-interlacing");
4458#endif /* PNG_READ_INTERLACING_SUPPORTED */
4459}
4460
4461static void
4462sequential_row(standard_display *dp, png_structp pp, png_infop pi,
4463 PNG_CONST int iImage, PNG_CONST int iDisplay)
4464{
4465 PNG_CONST int npasses = dp->npasses;
4466 PNG_CONST int do_interlace = dp->do_interlace &&
4467 dp->interlace_type == PNG_INTERLACE_ADAM7;
4468 PNG_CONST png_uint_32 height = standard_height(pp, dp->id);
4469 PNG_CONST png_uint_32 width = standard_width(pp, dp->id);
4470 PNG_CONST png_store* ps = dp->ps;
4471 int pass;
4472
4473 for (pass=0; pass<npasses; ++pass)
4474 {
4475 png_uint_32 y;
4476 png_uint_32 wPass = PNG_PASS_COLS(width, pass);
4477
4478 for (y=0; y<height; ++y)
4479 {
4480 if (do_interlace)
4481 {
4482 /* wPass may be zero or this row may not be in this pass.
4483 * png_read_row must not be called in either case.
4484 */
4485 if (wPass > 0 && PNG_ROW_IN_INTERLACE_PASS(y, pass))
4486 {
4487 /* Read the row into a pair of temporary buffers, then do the
4488 * merge here into the output rows.
4489 */
4490 png_byte row[STANDARD_ROWMAX], display[STANDARD_ROWMAX];
4491
4492 /* The following aids (to some extent) error detection - we can
4493 * see where png_read_row wrote. Use opposite values in row and
4494 * display to make this easier. Don't use 0xff (which is used in
4495 * the image write code to fill unused bits) or 0 (which is a
4496 * likely value to overwrite unused bits with).
4497 */
4498 memset(row, 0xc5, sizeof row);
4499 memset(display, 0x5c, sizeof display);
4500
4501 png_read_row(pp, row, display);
4502
4503 if (iImage >= 0)
4504 deinterlace_row(store_image_row(ps, pp, iImage, y), row,
4505 dp->pixel_size, dp->w, pass);
4506
4507 if (iDisplay >= 0)
4508 deinterlace_row(store_image_row(ps, pp, iDisplay, y), display,
4509 dp->pixel_size, dp->w, pass);
4510 }
4511 }
4512 else
4513 png_read_row(pp,
4514 iImage >= 0 ? store_image_row(ps, pp, iImage, y) : NULL,
4515 iDisplay >= 0 ? store_image_row(ps, pp, iDisplay, y) : NULL);
4516 }
4517 }
4518
4519 /* And finish the read operation (only really necessary if the caller wants
4520 * to find additional data in png_info from chunks after the last IDAT.)
4521 */
4522 png_read_end(pp, pi);
4523}
4524
4525static void
4526standard_row_validate(standard_display *dp, png_structp pp,
4527 int iImage, int iDisplay, png_uint_32 y)
4528{
4529 int where;
4530 png_byte std[STANDARD_ROWMAX];
4531
4532 /* The row must be pre-initialized to the magic number here for the size
4533 * tests to pass:
4534 */
4535 memset(std, 178, sizeof std);
4536 standard_row(pp, std, dp->id, y);
4537
4538 /* At the end both the 'row' and 'display' arrays should end up identical.
4539 * In earlier passes 'row' will be partially filled in, with only the pixels
4540 * that have been read so far, but 'display' will have those pixels
4541 * replicated to fill the unread pixels while reading an interlaced image.
4542#if PNG_LIBPNG_VER < 10506
4543 * The side effect inside the libpng sequential reader is that the 'row'
4544 * array retains the correct values for unwritten pixels within the row
4545 * bytes, while the 'display' array gets bits off the end of the image (in
4546 * the last byte) trashed. Unfortunately in the progressive reader the
4547 * row bytes are always trashed, so we always do a pixel_cmp here even though
4548 * a memcmp of all cbRow bytes will succeed for the sequential reader.
4549#endif
4550 */
4551 if (iImage >= 0 &&
4552 (where = pixel_cmp(std, store_image_row(dp->ps, pp, iImage, y),
4553 dp->bit_width)) != 0)
4554 {
4555 char msg[64];
4556 sprintf(msg, "PNG image row[%d][%d] changed from %.2x to %.2x", y,
4557 where-1, std[where-1],
4558 store_image_row(dp->ps, pp, iImage, y)[where-1]);
4559 png_error(pp, msg);
4560 }
4561
4562#if PNG_LIBPNG_VER < 10506
4563 /* In this case use pixel_cmp because we need to compare a partial
4564 * byte at the end of the row if the row is not an exact multiple
4565 * of 8 bits wide. (This is fixed in libpng-1.5.6 and pixel_cmp is
4566 * changed to match!)
4567 */
4568#endif
4569 if (iDisplay >= 0 &&
4570 (where = pixel_cmp(std, store_image_row(dp->ps, pp, iDisplay, y),
4571 dp->bit_width)) != 0)
4572 {
4573 char msg[64];
4574 sprintf(msg, "display row[%d][%d] changed from %.2x to %.2x", y,
4575 where-1, std[where-1],
4576 store_image_row(dp->ps, pp, iDisplay, y)[where-1]);
4577 png_error(pp, msg);
4578 }
4579}
4580
4581static void
4582standard_image_validate(standard_display *dp, png_structp pp, int iImage,
4583 int iDisplay)
4584{
4585 png_uint_32 y;
4586
4587 if (iImage >= 0)
4588 store_image_check(dp->ps, pp, iImage);
4589
4590 if (iDisplay >= 0)
4591 store_image_check(dp->ps, pp, iDisplay);
4592
4593 for (y=0; y<dp->h; ++y)
4594 standard_row_validate(dp, pp, iImage, iDisplay, y);
4595
4596 /* This avoids false positives if the validation code is never called! */
4597 dp->ps->validated = 1;
4598}
4599
4600static void
4601standard_end(png_structp pp, png_infop pi)
4602{
4603 standard_display *dp = voidcast(standard_display*,
4604 png_get_progressive_ptr(pp));
4605
4606 UNUSED(pi)
4607
4608 /* Validate the image - progressive reading only produces one variant for
4609 * interlaced images.
4610 */
4611 standard_image_validate(dp, pp, 0, -1);
4612}
4613
4614/* A single test run checking the standard image to ensure it is not damaged. */
4615static void
4616standard_test(png_store* PNG_CONST psIn, png_uint_32 PNG_CONST id,
4617 int do_interlace, int use_update_info)
4618{
4619 standard_display d;
4620 context(psIn, fault);
4621
4622 /* Set up the display (stack frame) variables from the arguments to the
4623 * function and initialize the locals that are filled in later.
4624 */
4625 standard_display_init(&d, psIn, id, do_interlace, use_update_info);
4626
4627 /* Everything is protected by a Try/Catch. The functions called also
4628 * typically have local Try/Catch blocks.
4629 */
4630 Try
4631 {
4632 png_structp pp;
4633 png_infop pi;
4634
4635 /* Get a png_struct for reading the image. This will throw an error if it
4636 * fails, so we don't need to check the result.
4637 */
4638 pp = set_store_for_read(d.ps, &pi, d.id,
4639 d.do_interlace ? (d.ps->progressive ?
4640 "pngvalid progressive deinterlacer" :
4641 "pngvalid sequential deinterlacer") : (d.ps->progressive ?
4642 "progressive reader" : "sequential reader"));
4643
4644 /* Initialize the palette correctly from the png_store_file. */
4645 standard_palette_init(&d);
4646
4647 /* Introduce the correct read function. */
4648 if (d.ps->progressive)
4649 {
4650 png_set_progressive_read_fn(pp, &d, standard_info, progressive_row,
4651 standard_end);
4652
4653 /* Now feed data into the reader until we reach the end: */
4654 store_progressive_read(d.ps, pp, pi);
4655 }
4656 else
4657 {
4658 /* Note that this takes the store, not the display. */
4659 png_set_read_fn(pp, d.ps, store_read);
4660
4661 /* Check the header values: */
4662 png_read_info(pp, pi);
4663
4664 /* The code tests both versions of the images that the sequential
4665 * reader can produce.
4666 */
4667 standard_info_imp(&d, pp, pi, 2 /*images*/);
4668
4669 /* Need the total bytes in the image below; we can't get to this point
4670 * unless the PNG file values have been checked against the expected
4671 * values.
4672 */
4673 {
4674 sequential_row(&d, pp, pi, 0, 1);
4675
4676 /* After the last pass loop over the rows again to check that the
4677 * image is correct.
4678 */
4679 if (!d.speed)
4680 standard_image_validate(&d, pp, 0, 1);
4681 else
4682 d.ps->validated = 1;
4683 }
4684 }
4685
4686 /* Check for validation. */
4687 if (!d.ps->validated)
4688 png_error(pp, "image read failed silently");
4689
4690 /* Successful completion. */
4691 }
4692
4693 Catch(fault)
4694 d.ps = fault; /* make sure this hasn't been clobbered. */
4695
4696 /* In either case clean up the store. */
4697 store_read_reset(d.ps);
4698}
4699
4700static int
4701test_standard(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
4702 int bdlo, int PNG_CONST bdhi)
4703{
4704 for (; bdlo <= bdhi; ++bdlo)
4705 {
4706 int interlace_type;
4707
4708 for (interlace_type = PNG_INTERLACE_NONE;
4709 interlace_type < PNG_INTERLACE_LAST; ++interlace_type)
4710 {
4711 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4712 interlace_type, 0, 0, 0), 0/*do_interlace*/, pm->use_update_info);
4713
4714 if (fail(pm))
4715 return 0;
4716 }
4717 }
4718
4719 return 1; /* keep going */
4720}
4721
4722static void
4723perform_standard_test(png_modifier *pm)
4724{
4725 /* Test each colour type over the valid range of bit depths (expressed as
4726 * log2(bit_depth) in turn, stop as soon as any error is detected.
4727 */
4728 if (!test_standard(pm, 0, 0, READ_BDHI))
4729 return;
4730
4731 if (!test_standard(pm, 2, 3, READ_BDHI))
4732 return;
4733
4734 if (!test_standard(pm, 3, 0, 3))
4735 return;
4736
4737 if (!test_standard(pm, 4, 3, READ_BDHI))
4738 return;
4739
4740 if (!test_standard(pm, 6, 3, READ_BDHI))
4741 return;
4742}
4743
4744
4745/********************************** SIZE TESTS ********************************/
4746static int
4747test_size(png_modifier* PNG_CONST pm, png_byte PNG_CONST colour_type,
4748 int bdlo, int PNG_CONST bdhi)
4749{
4750 /* Run the tests on each combination.
4751 *
4752 * NOTE: on my 32 bit x86 each of the following blocks takes
4753 * a total of 3.5 seconds if done across every combo of bit depth
4754 * width and height. This is a waste of time in practice, hence the
4755 * hinc and winc stuff:
4756 */
4757 static PNG_CONST png_byte hinc[] = {1, 3, 11, 1, 5};
4758 static PNG_CONST png_byte winc[] = {1, 9, 5, 7, 1};
4759 for (; bdlo <= bdhi; ++bdlo)
4760 {
4761 png_uint_32 h, w;
4762
4763 for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])
4764 {
4765 /* First test all the 'size' images against the sequential
4766 * reader using libpng to deinterlace (where required.) This
4767 * validates the write side of libpng. There are four possibilities
4768 * to validate.
4769 */
4770 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4771 PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,
4772 pm->use_update_info);
4773
4774 if (fail(pm))
4775 return 0;
4776
4777 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4778 PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,
4779 pm->use_update_info);
4780
4781 if (fail(pm))
4782 return 0;
4783
4784 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4785 PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,
4786 pm->use_update_info);
4787
4788 if (fail(pm))
4789 return 0;
4790
4791 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4792 PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,
4793 pm->use_update_info);
4794
4795 if (fail(pm))
4796 return 0;
4797
4798 /* Now validate the interlaced read side - do_interlace true,
4799 * in the progressive case this does actually make a difference
4800 * to the code used in the non-interlaced case too.
4801 */
4802 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4803 PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,
4804 pm->use_update_info);
4805
4806 if (fail(pm))
4807 return 0;
4808
4809 standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,
4810 PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,
4811 pm->use_update_info);
4812
4813 if (fail(pm))
4814 return 0;
4815 }
4816 }
4817
4818 return 1; /* keep going */
4819}
4820
4821static void
4822perform_size_test(png_modifier *pm)
4823{
4824 /* Test each colour type over the valid range of bit depths (expressed as
4825 * log2(bit_depth) in turn, stop as soon as any error is detected.
4826 */
4827 if (!test_size(pm, 0, 0, READ_BDHI))
4828 return;
4829
4830 if (!test_size(pm, 2, 3, READ_BDHI))
4831 return;
4832
4833 /* For the moment don't do the palette test - it's a waste of time when
4834 * compared to the grayscale test.
4835 */
4836#if 0
4837 if (!test_size(pm, 3, 0, 3))
4838 return;
4839#endif
4840
4841 if (!test_size(pm, 4, 3, READ_BDHI))
4842 return;
4843
4844 if (!test_size(pm, 6, 3, READ_BDHI))
4845 return;
4846}
4847
4848
4849/******************************* TRANSFORM TESTS ******************************/
4850#ifdef PNG_READ_TRANSFORMS_SUPPORTED
4851/* A set of tests to validate libpng image transforms. The possibilities here
4852 * are legion because the transforms can be combined in a combinatorial
4853 * fashion. To deal with this some measure of restraint is required, otherwise
4854 * the tests would take forever.
4855 */
4856typedef struct image_pixel
4857{
4858 /* A local (pngvalid) representation of a PNG pixel, in all its
4859 * various forms.
4860 */
4861 unsigned int red, green, blue, alpha; /* For non-palette images. */
4862 unsigned int palette_index; /* For a palette image. */
4863 png_byte colour_type; /* As in the spec. */
4864 png_byte bit_depth; /* Defines bit size in row */
4865 png_byte sample_depth; /* Scale of samples */
4866 int have_tRNS; /* tRNS chunk may need processing */
4867
4868 /* For checking the code calculates double precision floating point values
4869 * along with an error value, accumulated from the transforms. Because an
4870 * sBIT setting allows larger error bounds (indeed, by the spec, apparently
4871 * up to just less than +/-1 in the scaled value) the *lowest* sBIT for each
4872 * channel is stored. This sBIT value is folded in to the stored error value
4873 * at the end of the application of the transforms to the pixel.
4874 */
4875 double redf, greenf, bluef, alphaf;
4876 double rede, greene, bluee, alphae;
4877 png_byte red_sBIT, green_sBIT, blue_sBIT, alpha_sBIT;
4878} image_pixel;
4879
4880/* Shared utility function, see below. */
4881static void
4882image_pixel_setf(image_pixel *this, unsigned int max)
4883{
4884 this->redf = this->red / (double)max;
4885 this->greenf = this->green / (double)max;
4886 this->bluef = this->blue / (double)max;
4887 this->alphaf = this->alpha / (double)max;
4888
4889 if (this->red < max)
4890 this->rede = this->redf * DBL_EPSILON;
4891 else
4892 this->rede = 0;
4893 if (this->green < max)
4894 this->greene = this->greenf * DBL_EPSILON;
4895 else
4896 this->greene = 0;
4897 if (this->blue < max)
4898 this->bluee = this->bluef * DBL_EPSILON;
4899 else
4900 this->bluee = 0;
4901 if (this->alpha < max)
4902 this->alphae = this->alphaf * DBL_EPSILON;
4903 else
4904 this->alphae = 0;
4905}
4906
4907/* Initialize the structure for the next pixel - call this before doing any
4908 * transforms and call it for each pixel since all the fields may need to be
4909 * reset.
4910 */
4911static void
4912image_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,
4913 png_byte bit_depth, png_uint_32 x, store_palette palette)
4914{
4915 PNG_CONST png_byte sample_depth = (png_byte)(colour_type ==
4916 PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth);
4917 PNG_CONST unsigned int max = (1U<<sample_depth)-1;
4918
4919 /* Initially just set everything to the same number and the alpha to opaque.
4920 * Note that this currently assumes a simple palette where entry x has colour
4921 * rgb(x,x,x)!
4922 */
4923 this->palette_index = this->red = this->green = this->blue =
4924 sample(row, colour_type, bit_depth, x, 0);
4925 this->alpha = max;
4926 this->red_sBIT = this->green_sBIT = this->blue_sBIT = this->alpha_sBIT =
4927 sample_depth;
4928
4929 /* Then override as appropriate: */
4930 if (colour_type == 3) /* palette */
4931 {
4932 /* This permits the caller to default to the sample value. */
4933 if (palette != 0)
4934 {
4935 PNG_CONST unsigned int i = this->palette_index;
4936
4937 this->red = palette[i].red;
4938 this->green = palette[i].green;
4939 this->blue = palette[i].blue;
4940 this->alpha = palette[i].alpha;
4941 }
4942 }
4943
4944 else /* not palette */
4945 {
4946 unsigned int i = 0;
4947
4948 if (colour_type & 2)
4949 {
4950 this->green = sample(row, colour_type, bit_depth, x, 1);
4951 this->blue = sample(row, colour_type, bit_depth, x, 2);
4952 i = 2;
4953 }
4954 if (colour_type & 4)
4955 this->alpha = sample(row, colour_type, bit_depth, x, ++i);
4956 }
4957
4958 /* Calculate the scaled values, these are simply the values divided by
4959 * 'max' and the error is initialized to the double precision epsilon value
4960 * from the header file.
4961 */
4962 image_pixel_setf(this, max);
4963
4964 /* Store the input information for use in the transforms - these will
4965 * modify the information.
4966 */
4967 this->colour_type = colour_type;
4968 this->bit_depth = bit_depth;
4969 this->sample_depth = sample_depth;
4970 this->have_tRNS = 0;
4971}
4972
4973/* Convert a palette image to an rgb image. This necessarily converts the tRNS
4974 * chunk at the same time, because the tRNS will be in palette form. The way
4975 * palette validation works means that the original palette is never updated,
4976 * instead the image_pixel value from the row contains the RGB of the
4977 * corresponding palette entry and *this* is updated. Consequently this routine
4978 * only needs to change the colour type information.
4979 */
4980static void
4981image_pixel_convert_PLTE(image_pixel *this)
4982{
4983 if (this->colour_type == PNG_COLOR_TYPE_PALETTE)
4984 {
4985 if (this->have_tRNS)
4986 {
4987 this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
4988 this->have_tRNS = 0;
4989 }
4990 else
4991 this->colour_type = PNG_COLOR_TYPE_RGB;
4992
4993 /* The bit depth of the row changes at this point too (notice that this is
4994 * the row format, not the sample depth, which is separate.)
4995 */
4996 this->bit_depth = 8;
4997 }
4998}
4999
5000/* Add an alpha channel; this will import the tRNS information because tRNS is
5001 * not valid in an alpha image. The bit depth will invariably be set to at
5002 * least 8. Palette images will be converted to alpha (using the above API).
5003 */
5004static void
5005image_pixel_add_alpha(image_pixel *this, PNG_CONST standard_display *display)
5006{
5007 if (this->colour_type == PNG_COLOR_TYPE_PALETTE)
5008 image_pixel_convert_PLTE(this);
5009
5010 if ((this->colour_type & PNG_COLOR_MASK_ALPHA) == 0)
5011 {
5012 if (this->colour_type == PNG_COLOR_TYPE_GRAY)
5013 {
5014 if (this->bit_depth < 8)
5015 this->bit_depth = 8;
5016
5017 if (this->have_tRNS)
5018 {
5019 this->have_tRNS = 0;
5020
5021 /* Check the input, original, channel value here against the
5022 * original tRNS gray chunk valie.
5023 */
5024 if (this->red == display->transparent.red)
5025 this->alphaf = 0;
5026 else
5027 this->alphaf = 1;
5028 }
5029 else
5030 this->alphaf = 1;
5031
5032 this->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA;
5033 }
5034
5035 else if (this->colour_type == PNG_COLOR_TYPE_RGB)
5036 {
5037 if (this->have_tRNS)
5038 {
5039 this->have_tRNS = 0;
5040
5041 /* Again, check the exact input values, not the current transformed
5042 * value!
5043 */
5044 if (this->red == display->transparent.red &&
5045 this->green == display->transparent.green &&
5046 this->blue == display->transparent.blue)
5047 this->alphaf = 0;
5048 else
5049 this->alphaf = 1;
5050
5051 this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
5052 }
5053 }
5054
5055 /* The error in the alpha is zero and the sBIT value comes from the
5056 * original sBIT data (actually it will always be the original bit depth).
5057 */
5058 this->alphae = 0;
5059 this->alpha_sBIT = display->alpha_sBIT;
5060 }
5061}
5062
5063struct transform_display;
5064typedef struct image_transform
5065{
5066 /* The name of this transform: a string. */
5067 PNG_CONST char *name;
5068
5069 /* Each transform can be disabled from the command line: */
5070 int enable;
5071
5072 /* The global list of transforms; read only. */
5073 struct image_transform *PNG_CONST list;
5074
5075 /* The global count of the number of times this transform has been set on an
5076 * image.
5077 */
5078 unsigned int global_use;
5079
5080 /* The local count of the number of times this transform has been set. */
5081 unsigned int local_use;
5082
5083 /* The next transform in the list, each transform must call its own next
5084 * transform after it has processed the pixel successfully.
5085 */
5086 PNG_CONST struct image_transform *next;
5087
5088 /* A single transform for the image, expressed as a series of function
5089 * callbacks and some space for values.
5090 *
5091 * First a callback to add any required modifications to the png_modifier;
5092 * this gets called just before the modifier is set up for read.
5093 */
5094 void (*ini)(PNG_CONST struct image_transform *this,
5095 struct transform_display *that);
5096
5097 /* And a callback to set the transform on the current png_read_struct:
5098 */
5099 void (*set)(PNG_CONST struct image_transform *this,
5100 struct transform_display *that, png_structp pp, png_infop pi);
5101
5102 /* Then a transform that takes an input pixel in one PNG format or another
5103 * and modifies it by a pngvalid implementation of the transform (thus
5104 * duplicating the libpng intent without, we hope, duplicating the bugs
5105 * in the libpng implementation!) The png_structp is solely to allow error
5106 * reporting via png_error and png_warning.
5107 */
5108 void (*mod)(PNG_CONST struct image_transform *this, image_pixel *that,
5109 png_structp pp, PNG_CONST struct transform_display *display);
5110
5111 /* Add this transform to the list and return true if the transform is
5112 * meaningful for this colour type and bit depth - if false then the
5113 * transform should have no effect on the image so there's not a lot of
5114 * point running it.
5115 */
5116 int (*add)(struct image_transform *this,
5117 PNG_CONST struct image_transform **that, png_byte colour_type,
5118 png_byte bit_depth);
5119} image_transform;
5120
5121typedef struct transform_display
5122{
5123 standard_display this;
5124
5125 /* Parameters */
5126 png_modifier* pm;
5127 PNG_CONST image_transform* transform_list;
5128
5129 /* Local variables */
5130 png_byte output_colour_type;
5131 png_byte output_bit_depth;
5132
5133 /* Modifications (not necessarily used.) */
5134 gama_modification gama_mod;
5135 chrm_modification chrm_mod;
5136 srgb_modification srgb_mod;
5137} transform_display;
5138
5139/* Set sRGB, cHRM and gAMA transforms as required by the current encoding. */
5140static void
5141transform_set_encoding(transform_display *this)
5142{
5143 /* Set up the png_modifier '_current' fields then use these to determine how
5144 * to add appropriate chunks.
5145 */
5146 png_modifier *pm = this->pm;
5147
5148 modifier_set_encoding(pm);
5149
5150 if (modifier_color_encoding_is_set(pm))
5151 {
5152 if (modifier_color_encoding_is_sRGB(pm))
5153 srgb_modification_init(&this->srgb_mod, pm, PNG_sRGB_INTENT_ABSOLUTE);
5154
5155 else
5156 {
5157 /* Set gAMA and cHRM separately. */
5158 gama_modification_init(&this->gama_mod, pm, pm->current_gamma);
5159
5160 if (pm->current_encoding != 0)
5161 chrm_modification_init(&this->chrm_mod, pm, pm->current_encoding);
5162 }
5163 }
5164}
5165
5166/* Three functions to end the list: */
5167static void
5168image_transform_ini_end(PNG_CONST image_transform *this,
5169 transform_display *that)
5170{
5171 UNUSED(this)
5172 UNUSED(that)
5173}
5174
5175static void
5176image_transform_set_end(PNG_CONST image_transform *this,
5177 transform_display *that, png_structp pp, png_infop pi)
5178{
5179 UNUSED(this)
5180 UNUSED(that)
5181 UNUSED(pp)
5182 UNUSED(pi)
5183}
5184
5185/* At the end of the list recalculate the output image pixel value from the
5186 * double precision values set up by the preceding 'mod' calls:
5187 */
5188static unsigned int
5189sample_scale(double sample_value, unsigned int scale)
5190{
5191 sample_value = floor(sample_value * scale + .5);
5192
5193 /* Return NaN as 0: */
5194 if (!(sample_value > 0))
5195 sample_value = 0;
5196 else if (sample_value > scale)
5197 sample_value = scale;
5198
5199 return (unsigned int)sample_value;
5200}
5201
5202static void
5203image_transform_mod_end(PNG_CONST image_transform *this, image_pixel *that,
5204 png_structp pp, PNG_CONST transform_display *display)
5205{
5206 PNG_CONST unsigned int scale = (1U<<that->sample_depth)-1;
5207
5208 UNUSED(this)
5209 UNUSED(pp)
5210 UNUSED(display)
5211
5212 /* At the end recalculate the digitized red green and blue values according
5213 * to the current sample_depth of the pixel.
5214 *
5215 * The sample value is simply scaled to the maximum, checking for over
5216 * and underflow (which can both happen for some image transforms,
5217 * including simple size scaling, though libpng doesn't do that at present.
5218 */
5219 that->red = sample_scale(that->redf, scale);
5220
5221 /* The error value is increased, at the end, according to the lowest sBIT
5222 * value seen. Common sense tells us that the intermediate integer
5223 * representations are no more accurate than +/- 0.5 in the integral values,
5224 * the sBIT allows the implementation to be worse than this. In addition the
5225 * PNG specification actually permits any error within the range (-1..+1),
5226 * but that is ignored here. Instead the final digitized value is compared,
5227 * below to the digitized value of the error limits - this has the net effect
5228 * of allowing (almost) +/-1 in the output value. It's difficult to see how
5229 * any algorithm that digitizes intermediate results can be more accurate.
5230 */
5231 that->rede += 1./(2*((1U<<that->red_sBIT)-1));
5232
5233 if (that->colour_type & PNG_COLOR_MASK_COLOR)
5234 {
5235 that->green = sample_scale(that->greenf, scale);
5236 that->blue = sample_scale(that->bluef, scale);
5237 that->greene += 1./(2*((1U<<that->green_sBIT)-1));
5238 that->bluee += 1./(2*((1U<<that->blue_sBIT)-1));
5239 }
5240 else
5241 {
5242 that->blue = that->green = that->red;
5243 that->bluef = that->greenf = that->redf;
5244 that->bluee = that->greene = that->rede;
5245 }
5246
5247 if ((that->colour_type & PNG_COLOR_MASK_ALPHA) ||
5248 that->colour_type == PNG_COLOR_TYPE_PALETTE)
5249 {
5250 that->alpha = sample_scale(that->alphaf, scale);
5251 that->alphae += 1./(2*((1U<<that->alpha_sBIT)-1));
5252 }
5253 else
5254 {
5255 that->alpha = scale; /* opaque */
5256 that->alpha = 1; /* Override this. */
5257 that->alphae = 0; /* It's exact ;-) */
5258 }
5259}
5260
5261/* Static 'end' structure: */
5262static image_transform image_transform_end =
5263{
5264 "(end)", /* name */
5265 1, /* enable */
5266 0, /* list */
5267 0, /* global_use */
5268 0, /* local_use */
5269 0, /* next */
5270 image_transform_ini_end,
5271 image_transform_set_end,
5272 image_transform_mod_end,
5273 0 /* never called, I want it to crash if it is! */
5274};
5275
5276/* Reader callbacks and implementations, where they differ from the standard
5277 * ones.
5278 */
5279static void
5280transform_display_init(transform_display *dp, png_modifier *pm, png_uint_32 id,
5281 PNG_CONST image_transform *transform_list)
5282{
5283 memset(dp, 0, sizeof *dp);
5284
5285 /* Standard fields */
5286 standard_display_init(&dp->this, &pm->this, id, 0/*do_interlace*/,
5287 pm->use_update_info);
5288
5289 /* Parameter fields */
5290 dp->pm = pm;
5291 dp->transform_list = transform_list;
5292
5293 /* Local variable fields */
5294 dp->output_colour_type = 255; /* invalid */
5295 dp->output_bit_depth = 255; /* invalid */
5296}
5297
5298static void
5299transform_info_imp(transform_display *dp, png_structp pp, png_infop pi)
5300{
5301 /* Reuse the standard stuff as appropriate. */
5302 standard_info_part1(&dp->this, pp, pi);
5303
5304 /* Now set the list of transforms. */
5305 dp->transform_list->set(dp->transform_list, dp, pp, pi);
5306
5307 /* Update the info structure for these transforms: */
5308 {
5309 int i = dp->this.use_update_info;
5310 /* Always do one call, even if use_update_info is 0. */
5311 do
5312 png_read_update_info(pp, pi);
5313 while (--i > 0);
5314 }
5315
5316 /* And get the output information into the standard_display */
5317 standard_info_part2(&dp->this, pp, pi, 1/*images*/);
5318
5319 /* Plus the extra stuff we need for the transform tests: */
5320 dp->output_colour_type = png_get_color_type(pp, pi);
5321 dp->output_bit_depth = png_get_bit_depth(pp, pi);
5322
5323 /* Validate the combination of colour type and bit depth that we are getting
5324 * out of libpng; the semantics of something not in the PNG spec are, at
5325 * best, unclear.
5326 */
5327 switch (dp->output_colour_type)
5328 {
5329 case PNG_COLOR_TYPE_PALETTE:
5330 if (dp->output_bit_depth > 8) goto error;
5331 /*FALL THROUGH*/
5332 case PNG_COLOR_TYPE_GRAY:
5333 if (dp->output_bit_depth == 1 || dp->output_bit_depth == 2 ||
5334 dp->output_bit_depth == 4)
5335 break;
5336 /*FALL THROUGH*/
5337 default:
5338 if (dp->output_bit_depth == 8 || dp->output_bit_depth == 16)
5339 break;
5340 /*FALL THROUGH*/
5341 error:
5342 {
5343 char message[128];
5344 size_t pos;
5345
5346 pos = safecat(message, sizeof message, 0,
5347 "invalid final bit depth: colour type(");
5348 pos = safecatn(message, sizeof message, pos, dp->output_colour_type);
5349 pos = safecat(message, sizeof message, pos, ") with bit depth: ");
5350 pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);
5351
5352 png_error(pp, message);
5353 }
5354 }
5355
5356 /* Use a test pixel to check that the output agrees with what we expect -
5357 * this avoids running the whole test if the output is unexpected.
5358 */
5359 {
5360 image_pixel test_pixel;
5361
5362 memset(&test_pixel, 0, sizeof test_pixel);
5363 test_pixel.colour_type = dp->this.colour_type; /* input */
5364 test_pixel.bit_depth = dp->this.bit_depth;
5365 if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE)
5366 test_pixel.sample_depth = 8;
5367 else
5368 test_pixel.sample_depth = test_pixel.bit_depth;
5369 /* Don't need sBIT here, but it must be set to non-zero to avoid
5370 * arithmetic overflows.
5371 */
5372 test_pixel.have_tRNS = dp->this.is_transparent;
5373 test_pixel.red_sBIT = test_pixel.green_sBIT = test_pixel.blue_sBIT =
5374 test_pixel.alpha_sBIT = test_pixel.sample_depth;
5375
5376 dp->transform_list->mod(dp->transform_list, &test_pixel, pp, dp);
5377
5378 if (test_pixel.colour_type != dp->output_colour_type)
5379 {
5380 char message[128];
5381 size_t pos = safecat(message, sizeof message, 0, "colour type ");
5382
5383 pos = safecatn(message, sizeof message, pos, dp->output_colour_type);
5384 pos = safecat(message, sizeof message, pos, " expected ");
5385 pos = safecatn(message, sizeof message, pos, test_pixel.colour_type);
5386
5387 png_error(pp, message);
5388 }
5389
5390 if (test_pixel.bit_depth != dp->output_bit_depth)
5391 {
5392 char message[128];
5393 size_t pos = safecat(message, sizeof message, 0, "bit depth ");
5394
5395 pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);
5396 pos = safecat(message, sizeof message, pos, " expected ");
5397 pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);
5398
5399 png_error(pp, message);
5400 }
5401
5402 /* If both bit depth and colour type are correct check the sample depth.
5403 * I believe these are both internal errors.
5404 */
5405 if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE)
5406 {
5407 if (test_pixel.sample_depth != 8) /* oops - internal error! */
5408 png_error(pp, "pngvalid: internal: palette sample depth not 8");
5409 }
5410 else if (test_pixel.sample_depth != dp->output_bit_depth)
5411 {
5412 char message[128];
5413 size_t pos = safecat(message, sizeof message, 0,
5414 "internal: sample depth ");
5415
5416 pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);
5417 pos = safecat(message, sizeof message, pos, " expected ");
5418 pos = safecatn(message, sizeof message, pos, test_pixel.sample_depth);
5419
5420 png_error(pp, message);
5421 }
5422 }
5423}
5424
5425static void
5426transform_info(png_structp pp, png_infop pi)
5427{
5428 transform_info_imp(voidcast(transform_display*, png_get_progressive_ptr(pp)),
5429 pp, pi);
5430}
5431
5432static void
5433transform_range_check(png_structp pp, unsigned int r, unsigned int g,
5434 unsigned int b, unsigned int a, unsigned int in_digitized, double in,
5435 unsigned int out, png_byte sample_depth, double err, double limit,
5436 PNG_CONST char *name, double digitization_error)
5437{
5438 /* Compare the scaled, digitzed, values of our local calculation (in+-err)
5439 * with the digitized values libpng produced; 'sample_depth' is the actual
5440 * digitization depth of the libpng output colors (the bit depth except for
5441 * palette images where it is always 8.) The check on 'err' is to detect
5442 * internal errors in pngvalid itself.
5443 */
5444 unsigned int max = (1U<<sample_depth)-1;
5445 double in_min = ceil((in-err)*max - digitization_error);
5446 double in_max = floor((in+err)*max + digitization_error);
5447 if (err > limit || !(out >= in_min && out <= in_max))
5448 {
5449 char message[256];
5450 size_t pos;
5451
5452 pos = safecat(message, sizeof message, 0, name);
5453 pos = safecat(message, sizeof message, pos, " output value error: rgba(");
5454 pos = safecatn(message, sizeof message, pos, r);
5455 pos = safecat(message, sizeof message, pos, ",");
5456 pos = safecatn(message, sizeof message, pos, g);
5457 pos = safecat(message, sizeof message, pos, ",");
5458 pos = safecatn(message, sizeof message, pos, b);
5459 pos = safecat(message, sizeof message, pos, ",");
5460 pos = safecatn(message, sizeof message, pos, a);
5461 pos = safecat(message, sizeof message, pos, "): ");
5462 pos = safecatn(message, sizeof message, pos, out);
5463 pos = safecat(message, sizeof message, pos, " expected: ");
5464 pos = safecatn(message, sizeof message, pos, in_digitized);
5465 pos = safecat(message, sizeof message, pos, " (");
5466 pos = safecatd(message, sizeof message, pos, (in-err)*max, 3);
5467 pos = safecat(message, sizeof message, pos, "..");
5468 pos = safecatd(message, sizeof message, pos, (in+err)*max, 3);
5469 pos = safecat(message, sizeof message, pos, ")");
5470
5471 png_error(pp, message);
5472 }
5473}
5474
5475static void
5476transform_image_validate(transform_display *dp, png_structp pp, png_infop pi)
5477{
5478 /* Constants for the loop below: */
5479 PNG_CONST png_store* PNG_CONST ps = dp->this.ps;
5480 PNG_CONST png_byte in_ct = dp->this.colour_type;
5481 PNG_CONST png_byte in_bd = dp->this.bit_depth;
5482 PNG_CONST png_uint_32 w = dp->this.w;
5483 PNG_CONST png_uint_32 h = dp->this.h;
5484 PNG_CONST png_byte out_ct = dp->output_colour_type;
5485 PNG_CONST png_byte out_bd = dp->output_bit_depth;
5486 PNG_CONST png_byte sample_depth = (png_byte)(out_ct ==
5487 PNG_COLOR_TYPE_PALETTE ? 8 : out_bd);
5488 PNG_CONST png_byte red_sBIT = dp->this.red_sBIT;
5489 PNG_CONST png_byte green_sBIT = dp->this.green_sBIT;
5490 PNG_CONST png_byte blue_sBIT = dp->this.blue_sBIT;
5491 PNG_CONST png_byte alpha_sBIT = dp->this.alpha_sBIT;
5492 PNG_CONST int have_tRNS = dp->this.is_transparent;
5493 double digitization_error;
5494
5495 store_palette out_palette;
5496 png_uint_32 y;
5497
5498 UNUSED(pi)
5499
5500 /* Check for row overwrite errors */
5501 store_image_check(dp->this.ps, pp, 0);
5502
5503 /* Read the palette corresponding to the output if the output colour type
5504 * indicates a palette, othewise set out_palette to garbage.
5505 */
5506 if (out_ct == PNG_COLOR_TYPE_PALETTE)
5507 {
5508 /* Validate that the palette count itself has not changed - this is not
5509 * expected.
5510 */
5511 int npalette = (-1);
5512
5513 (void)read_palette(out_palette, &npalette, pp, pi);
5514 if (npalette != dp->this.npalette)
5515 png_error(pp, "unexpected change in palette size");
5516
5517 digitization_error = .5;
5518 }
5519 else
5520 {
5521 png_byte in_sample_depth;
5522
5523 memset(out_palette, 0x5e, sizeof out_palette);
5524
5525 /* assume-8-bit-calculations means assume that if the input has 8 bit
5526 * (or less) samples and the output has 16 bit samples the calculations
5527 * will be done with 8 bit precision, not 16.
5528 *
5529 * TODO: fix this in libpng; png_set_expand_16 should cause 16 bit
5530 * calculations to be used throughout.
5531 */
5532 if (in_ct == PNG_COLOR_TYPE_PALETTE || in_bd < 16)
5533 in_sample_depth = 8;
5534 else
5535 in_sample_depth = in_bd;
5536
5537 if (sample_depth != 16 || in_sample_depth > 8 ||
5538 !dp->pm->calculations_use_input_precision)
5539 digitization_error = .5;
5540
5541 /* Else errors are at 8 bit precision, scale .5 in 8 bits to the 16 bits:
5542 */
5543 else
5544 digitization_error = .5 * 257;
5545 }
5546
5547 for (y=0; y<h; ++y)
5548 {
5549 png_const_bytep PNG_CONST pRow = store_image_row(ps, pp, 0, y);
5550 png_uint_32 x;
5551
5552 /* The original, standard, row pre-transforms. */
5553 png_byte std[STANDARD_ROWMAX];
5554
5555 transform_row(pp, std, in_ct, in_bd, y);
5556
5557 /* Go through each original pixel transforming it and comparing with what
5558 * libpng did to the same pixel.
5559 */
5560 for (x=0; x<w; ++x)
5561 {
5562 image_pixel in_pixel, out_pixel;
5563 unsigned int r, g, b, a;
5564
5565 /* Find out what we think the pixel should be: */
5566 image_pixel_init(&in_pixel, std, in_ct, in_bd, x, dp->this.palette);
5567
5568 in_pixel.red_sBIT = red_sBIT;
5569 in_pixel.green_sBIT = green_sBIT;
5570 in_pixel.blue_sBIT = blue_sBIT;
5571 in_pixel.alpha_sBIT = alpha_sBIT;
5572 in_pixel.have_tRNS = have_tRNS;
5573
5574 /* For error detection, below. */
5575 r = in_pixel.red;
5576 g = in_pixel.green;
5577 b = in_pixel.blue;
5578 a = in_pixel.alpha;
5579
5580 dp->transform_list->mod(dp->transform_list, &in_pixel, pp, dp);
5581
5582 /* Read the output pixel and compare it to what we got, we don't
5583 * use the error field here, so no need to update sBIT.
5584 */
5585 image_pixel_init(&out_pixel, pRow, out_ct, out_bd, x, out_palette);
5586
5587 /* We don't expect changes to the index here even if the bit depth is
5588 * changed.
5589 */
5590 if (in_ct == PNG_COLOR_TYPE_PALETTE &&
5591 out_ct == PNG_COLOR_TYPE_PALETTE)
5592 {
5593 if (in_pixel.palette_index != out_pixel.palette_index)
5594 png_error(pp, "unexpected transformed palette index");
5595 }
5596
5597 /* Check the colours for palette images too - in fact the palette could
5598 * be separately verified itself in most cases.
5599 */
5600 if (in_pixel.red != out_pixel.red)
5601 transform_range_check(pp, r, g, b, a, in_pixel.red, in_pixel.redf,
5602 out_pixel.red, sample_depth, in_pixel.rede,
5603 dp->pm->limit + 1./(2*((1U<<in_pixel.red_sBIT)-1)), "red/gray",
5604 digitization_error);
5605
5606 if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 &&
5607 in_pixel.green != out_pixel.green)
5608 transform_range_check(pp, r, g, b, a, in_pixel.green,
5609 in_pixel.greenf, out_pixel.green, sample_depth, in_pixel.greene,
5610 dp->pm->limit + 1./(2*((1U<<in_pixel.green_sBIT)-1)), "green",
5611 digitization_error);
5612
5613 if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 &&
5614 in_pixel.blue != out_pixel.blue)
5615 transform_range_check(pp, r, g, b, a, in_pixel.blue, in_pixel.bluef,
5616 out_pixel.blue, sample_depth, in_pixel.bluee,
5617 dp->pm->limit + 1./(2*((1U<<in_pixel.blue_sBIT)-1)), "blue",
5618 digitization_error);
5619
5620 if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0 &&
5621 in_pixel.alpha != out_pixel.alpha)
5622 transform_range_check(pp, r, g, b, a, in_pixel.alpha,
5623 in_pixel.alphaf, out_pixel.alpha, sample_depth, in_pixel.alphae,
5624 dp->pm->limit + 1./(2*((1U<<in_pixel.alpha_sBIT)-1)), "alpha",
5625 digitization_error);
5626 } /* pixel (x) loop */
5627 } /* row (y) loop */
5628
5629 /* Record that something was actually checked to avoid a false positive. */
5630 dp->this.ps->validated = 1;
5631}
5632
5633static void
5634transform_end(png_structp pp, png_infop pi)
5635{
5636 transform_display *dp = voidcast(transform_display*,
5637 png_get_progressive_ptr(pp));
5638
5639 if (!dp->this.speed)
5640 transform_image_validate(dp, pp, pi);
5641 else
5642 dp->this.ps->validated = 1;
5643}
5644
5645/* A single test run. */
5646static void
5647transform_test(png_modifier *pmIn, PNG_CONST png_uint_32 idIn,
5648 PNG_CONST image_transform* transform_listIn, PNG_CONST char * volatile name)
5649{
5650 transform_display d;
5651 context(&pmIn->this, fault);
5652
5653 transform_display_init(&d, pmIn, idIn, transform_listIn);
5654
5655 Try
5656 {
5657 size_t pos = 0;
5658 png_structp pp;
5659 png_infop pi;
5660 char full_name[256];
5661
5662 /* Make sure the encoding fields are correct and enter the required
5663 * modifications.
5664 */
5665 transform_set_encoding(&d);
5666
5667 /* Add any modifications required by the transform list. */
5668 d.transform_list->ini(d.transform_list, &d);
5669
5670 /* Add the color space information, if any, to the name. */
5671 pos = safecat(full_name, sizeof full_name, pos, name);
5672 pos = safecat_current_encoding(full_name, sizeof full_name, pos, d.pm);
5673
5674 /* Get a png_struct for reading the image. */
5675 pp = set_modifier_for_read(d.pm, &pi, d.this.id, full_name);
5676 standard_palette_init(&d.this);
5677
5678# if 0
5679 /* Logging (debugging only) */
5680 {
5681 char buffer[256];
5682
5683 (void)store_message(&d.pm->this, pp, buffer, sizeof buffer, 0,
5684 "running test");
5685
5686 fprintf(stderr, "%s\n", buffer);
5687 }
5688# endif
5689
5690 /* Introduce the correct read function. */
5691 if (d.pm->this.progressive)
5692 {
5693 /* Share the row function with the standard implementation. */
5694 png_set_progressive_read_fn(pp, &d, transform_info, progressive_row,
5695 transform_end);
5696
5697 /* Now feed data into the reader until we reach the end: */
5698 modifier_progressive_read(d.pm, pp, pi);
5699 }
5700 else
5701 {
5702 /* modifier_read expects a png_modifier* */
5703 png_set_read_fn(pp, d.pm, modifier_read);
5704
5705 /* Check the header values: */
5706 png_read_info(pp, pi);
5707
5708 /* Process the 'info' requirements. Only one image is generated */
5709 transform_info_imp(&d, pp, pi);
5710
5711 sequential_row(&d.this, pp, pi, -1, 0);
5712
5713 if (!d.this.speed)
5714 transform_image_validate(&d, pp, pi);
5715 else
5716 d.this.ps->validated = 1;
5717 }
5718
5719 modifier_reset(d.pm);
5720 }
5721
5722 Catch(fault)
5723 {
5724 modifier_reset((png_modifier*)fault);
5725 }
5726}
5727
5728/* The transforms: */
5729#define ITSTRUCT(name) image_transform_##name
5730#define ITDATA(name) image_transform_data_##name
5731#define image_transform_ini image_transform_default_ini
5732#define IT(name)\
5733static image_transform ITSTRUCT(name) =\
5734{\
5735 #name,\
5736 1, /*enable*/\
5737 &PT, /*list*/\
5738 0, /*global_use*/\
5739 0, /*local_use*/\
5740 0, /*next*/\
5741 image_transform_ini,\
5742 image_transform_png_set_##name##_set,\
5743 image_transform_png_set_##name##_mod,\
5744 image_transform_png_set_##name##_add\
5745}
5746#define PT ITSTRUCT(end) /* stores the previous transform */
5747
5748/* To save code: */
5749static void
5750image_transform_default_ini(PNG_CONST image_transform *this,
5751 transform_display *that)
5752{
5753 this->next->ini(this->next, that);
5754}
5755
5756static int
5757image_transform_default_add(image_transform *this,
5758 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5759{
5760 UNUSED(colour_type)
5761 UNUSED(bit_depth)
5762
5763 this->next = *that;
5764 *that = this;
5765
5766 return 1;
5767}
5768
5769#ifdef PNG_READ_EXPAND_SUPPORTED
5770/* png_set_palette_to_rgb */
5771static void
5772image_transform_png_set_palette_to_rgb_set(PNG_CONST image_transform *this,
5773 transform_display *that, png_structp pp, png_infop pi)
5774{
5775 png_set_palette_to_rgb(pp);
5776 this->next->set(this->next, that, pp, pi);
5777}
5778
5779static void
5780image_transform_png_set_palette_to_rgb_mod(PNG_CONST image_transform *this,
5781 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
5782{
5783 if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
5784 image_pixel_convert_PLTE(that);
5785
5786 this->next->mod(this->next, that, pp, display);
5787}
5788
5789static int
5790image_transform_png_set_palette_to_rgb_add(image_transform *this,
5791 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5792{
5793 UNUSED(bit_depth)
5794
5795 this->next = *that;
5796 *that = this;
5797
5798 return colour_type == PNG_COLOR_TYPE_PALETTE;
5799}
5800
5801IT(palette_to_rgb);
5802#undef PT
5803#define PT ITSTRUCT(palette_to_rgb)
5804#endif /* PNG_READ_EXPAND_SUPPORTED */
5805
5806#ifdef PNG_READ_EXPAND_SUPPORTED
5807/* png_set_tRNS_to_alpha */
5808static void
5809image_transform_png_set_tRNS_to_alpha_set(PNG_CONST image_transform *this,
5810 transform_display *that, png_structp pp, png_infop pi)
5811{
5812 png_set_tRNS_to_alpha(pp);
5813 this->next->set(this->next, that, pp, pi);
5814}
5815
5816static void
5817image_transform_png_set_tRNS_to_alpha_mod(PNG_CONST image_transform *this,
5818 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
5819{
5820 /* LIBPNG BUG: this always forces palette images to RGB. */
5821 if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
5822 image_pixel_convert_PLTE(that);
5823
5824 /* This effectively does an 'expand' only if there is some transparency to
5825 * convert to an alpha channel.
5826 */
5827 if (that->have_tRNS)
5828 image_pixel_add_alpha(that, &display->this);
5829
5830 /* LIBPNG BUG: otherwise libpng still expands to 8 bits! */
5831 else
5832 {
5833 if (that->bit_depth < 8)
5834 that->bit_depth =8;
5835 if (that->sample_depth < 8)
5836 that->sample_depth = 8;
5837 }
5838
5839 this->next->mod(this->next, that, pp, display);
5840}
5841
5842static int
5843image_transform_png_set_tRNS_to_alpha_add(image_transform *this,
5844 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5845{
5846 UNUSED(bit_depth)
5847
5848 this->next = *that;
5849 *that = this;
5850
5851 /* We don't know yet whether there will be a tRNS chunk, but we know that
5852 * this transformation should do nothing if there already is an alpha
5853 * channel.
5854 */
5855 return (colour_type & PNG_COLOR_MASK_ALPHA) == 0;
5856}
5857
5858IT(tRNS_to_alpha);
5859#undef PT
5860#define PT ITSTRUCT(tRNS_to_alpha)
5861#endif /* PNG_READ_EXPAND_SUPPORTED */
5862
5863#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
5864/* png_set_gray_to_rgb */
5865static void
5866image_transform_png_set_gray_to_rgb_set(PNG_CONST image_transform *this,
5867 transform_display *that, png_structp pp, png_infop pi)
5868{
5869 png_set_gray_to_rgb(pp);
5870 this->next->set(this->next, that, pp, pi);
5871}
5872
5873static void
5874image_transform_png_set_gray_to_rgb_mod(PNG_CONST image_transform *this,
5875 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
5876{
5877 /* NOTE: we can actually pend the tRNS processing at this point because we
5878 * can correctly recognize the original pixel value even though we have
5879 * mapped the one gray channel to the three RGB ones, but in fact libpng
5880 * doesn't do this, so we don't either.
5881 */
5882 if ((that->colour_type & PNG_COLOR_MASK_COLOR) == 0 && that->have_tRNS)
5883 image_pixel_add_alpha(that, &display->this);
5884
5885 /* Simply expand the bit depth and alter the colour type as required. */
5886 if (that->colour_type == PNG_COLOR_TYPE_GRAY)
5887 {
5888 /* RGB images have a bit depth at least equal to '8' */
5889 if (that->bit_depth < 8)
5890 that->sample_depth = that->bit_depth = 8;
5891
5892 /* And just changing the colour type works here because the green and blue
5893 * channels are being maintained in lock-step with the red/gray:
5894 */
5895 that->colour_type = PNG_COLOR_TYPE_RGB;
5896 }
5897
5898 else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
5899 that->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;
5900
5901 this->next->mod(this->next, that, pp, display);
5902}
5903
5904static int
5905image_transform_png_set_gray_to_rgb_add(image_transform *this,
5906 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5907{
5908 UNUSED(bit_depth)
5909
5910 this->next = *that;
5911 *that = this;
5912
5913 return (colour_type & PNG_COLOR_MASK_COLOR) == 0;
5914}
5915
5916IT(gray_to_rgb);
5917#undef PT
5918#define PT ITSTRUCT(gray_to_rgb)
5919#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
5920
5921#ifdef PNG_READ_EXPAND_SUPPORTED
5922/* png_set_expand */
5923static void
5924image_transform_png_set_expand_set(PNG_CONST image_transform *this,
5925 transform_display *that, png_structp pp, png_infop pi)
5926{
5927 png_set_expand(pp);
5928 this->next->set(this->next, that, pp, pi);
5929}
5930
5931static void
5932image_transform_png_set_expand_mod(PNG_CONST image_transform *this,
5933 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
5934{
5935 /* The general expand case depends on what the colour type is: */
5936 if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
5937 image_pixel_convert_PLTE(that);
5938 else if (that->bit_depth < 8) /* grayscale */
5939 that->sample_depth = that->bit_depth = 8;
5940
5941 if (that->have_tRNS)
5942 image_pixel_add_alpha(that, &display->this);
5943
5944 this->next->mod(this->next, that, pp, display);
5945}
5946
5947static int
5948image_transform_png_set_expand_add(image_transform *this,
5949 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5950{
5951 UNUSED(bit_depth)
5952
5953 this->next = *that;
5954 *that = this;
5955
5956 /* 'expand' should do nothing for RGBA or GA input - no tRNS and the bit
5957 * depth is at least 8 already.
5958 */
5959 return (colour_type & PNG_COLOR_MASK_ALPHA) == 0;
5960}
5961
5962IT(expand);
5963#undef PT
5964#define PT ITSTRUCT(expand)
5965#endif /* PNG_READ_EXPAND_SUPPORTED */
5966
5967#ifdef PNG_READ_EXPAND_SUPPORTED
5968/* png_set_expand_gray_1_2_4_to_8
5969 * LIBPNG BUG: this just does an 'expand'
5970 */
5971static void
5972image_transform_png_set_expand_gray_1_2_4_to_8_set(
5973 PNG_CONST image_transform *this, transform_display *that, png_structp pp,
5974 png_infop pi)
5975{
5976 png_set_expand_gray_1_2_4_to_8(pp);
5977 this->next->set(this->next, that, pp, pi);
5978}
5979
5980static void
5981image_transform_png_set_expand_gray_1_2_4_to_8_mod(
5982 PNG_CONST image_transform *this, image_pixel *that, png_structp pp,
5983 PNG_CONST transform_display *display)
5984{
5985 image_transform_png_set_expand_mod(this, that, pp, display);
5986}
5987
5988static int
5989image_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this,
5990 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
5991{
5992 return image_transform_png_set_expand_add(this, that, colour_type,
5993 bit_depth);
5994}
5995
5996IT(expand_gray_1_2_4_to_8);
5997#undef PT
5998#define PT ITSTRUCT(expand_gray_1_2_4_to_8)
5999#endif /* PNG_READ_EXPAND_SUPPORTED */
6000
6001#ifdef PNG_READ_EXPAND_16_SUPPORTED
6002/* png_set_expand_16 */
6003static void
6004image_transform_png_set_expand_16_set(PNG_CONST image_transform *this,
6005 transform_display *that, png_structp pp, png_infop pi)
6006{
6007 png_set_expand_16(pp);
6008 this->next->set(this->next, that, pp, pi);
6009}
6010
6011static void
6012image_transform_png_set_expand_16_mod(PNG_CONST image_transform *this,
6013 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6014{
6015 /* Expect expand_16 to expand everything to 16 bits as a result of also
6016 * causing 'expand' to happen.
6017 */
6018 if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
6019 image_pixel_convert_PLTE(that);
6020
6021 if (that->have_tRNS)
6022 image_pixel_add_alpha(that, &display->this);
6023
6024 if (that->bit_depth < 16)
6025 that->sample_depth = that->bit_depth = 16;
6026
6027 this->next->mod(this->next, that, pp, display);
6028}
6029
6030static int
6031image_transform_png_set_expand_16_add(image_transform *this,
6032 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
6033{
6034 UNUSED(colour_type)
6035
6036 this->next = *that;
6037 *that = this;
6038
6039 /* expand_16 does something unless the bit depth is already 16. */
6040 return bit_depth < 16;
6041}
6042
6043IT(expand_16);
6044#undef PT
6045#define PT ITSTRUCT(expand_16)
6046#endif /* PNG_READ_EXPAND_16_SUPPORTED */
6047
6048#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED /* API added in 1.5.4 */
6049/* png_set_scale_16 */
6050static void
6051image_transform_png_set_scale_16_set(PNG_CONST image_transform *this,
6052 transform_display *that, png_structp pp, png_infop pi)
6053{
6054 png_set_scale_16(pp);
6055 this->next->set(this->next, that, pp, pi);
6056}
6057
6058static void
6059image_transform_png_set_scale_16_mod(PNG_CONST image_transform *this,
6060 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6061{
6062 if (that->bit_depth == 16)
6063 {
6064 that->sample_depth = that->bit_depth = 8;
6065 if (that->red_sBIT > 8) that->red_sBIT = 8;
6066 if (that->green_sBIT > 8) that->green_sBIT = 8;
6067 if (that->blue_sBIT > 8) that->blue_sBIT = 8;
6068 if (that->alpha_sBIT > 8) that->alpha_sBIT = 8;
6069 }
6070
6071 this->next->mod(this->next, that, pp, display);
6072}
6073
6074static int
6075image_transform_png_set_scale_16_add(image_transform *this,
6076 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
6077{
6078 UNUSED(colour_type)
6079
6080 this->next = *that;
6081 *that = this;
6082
6083 return bit_depth > 8;
6084}
6085
6086IT(scale_16);
6087#undef PT
6088#define PT ITSTRUCT(scale_16)
6089#endif /* PNG_READ_SCALE_16_TO_8_SUPPORTED (1.5.4 on) */
6090
6091#ifdef PNG_READ_16_TO_8_SUPPORTED /* the default before 1.5.4 */
6092/* png_set_strip_16 */
6093static void
6094image_transform_png_set_strip_16_set(PNG_CONST image_transform *this,
6095 transform_display *that, png_structp pp, png_infop pi)
6096{
6097 png_set_strip_16(pp);
6098 this->next->set(this->next, that, pp, pi);
6099}
6100
6101static void
6102image_transform_png_set_strip_16_mod(PNG_CONST image_transform *this,
6103 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6104{
6105 if (that->bit_depth == 16)
6106 {
6107 that->sample_depth = that->bit_depth = 8;
6108 if (that->red_sBIT > 8) that->red_sBIT = 8;
6109 if (that->green_sBIT > 8) that->green_sBIT = 8;
6110 if (that->blue_sBIT > 8) that->blue_sBIT = 8;
6111 if (that->alpha_sBIT > 8) that->alpha_sBIT = 8;
6112
6113 /* Prior to 1.5.4 png_set_strip_16 would use an 'accurate' method if this
6114 * configuration option is set. From 1.5.4 the flag is never set and the
6115 * 'scale' API (above) must be used.
6116 */
6117# ifdef PNG_READ_ACCURATE_SCALE_SUPPORTED
6118# if PNG_LIBPNG_VER >= 10504
6119# error PNG_READ_ACCURATE_SCALE should not be set
6120# endif
6121
6122 /* The strip 16 algorithm drops the low 8 bits rather than calculating
6123 * 1/257, so we need to adjust the permitted errors appropriately:
6124 * Notice that this is only relevant prior to the addition of the
6125 * png_set_scale_16 API in 1.5.4 (but 1.5.4+ always defines the above!)
6126 */
6127 {
6128 PNG_CONST double d = (255-128.5)/65535;
6129 that->rede += d;
6130 that->greene += d;
6131 that->bluee += d;
6132 that->alphae += d;
6133 }
6134# endif
6135 }
6136
6137 this->next->mod(this->next, that, pp, display);
6138}
6139
6140static int
6141image_transform_png_set_strip_16_add(image_transform *this,
6142 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
6143{
6144 UNUSED(colour_type)
6145
6146 this->next = *that;
6147 *that = this;
6148
6149 return bit_depth > 8;
6150}
6151
6152IT(strip_16);
6153#undef PT
6154#define PT ITSTRUCT(strip_16)
6155#endif /* PNG_READ_16_TO_8_SUPPORTED */
6156
6157#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
6158/* png_set_strip_alpha */
6159static void
6160image_transform_png_set_strip_alpha_set(PNG_CONST image_transform *this,
6161 transform_display *that, png_structp pp, png_infop pi)
6162{
6163 png_set_strip_alpha(pp);
6164 this->next->set(this->next, that, pp, pi);
6165}
6166
6167static void
6168image_transform_png_set_strip_alpha_mod(PNG_CONST image_transform *this,
6169 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6170{
6171 if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
6172 that->colour_type = PNG_COLOR_TYPE_GRAY;
6173 else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)
6174 that->colour_type = PNG_COLOR_TYPE_RGB;
6175
6176 that->have_tRNS = 0;
6177 that->alphaf = 1;
6178
6179 this->next->mod(this->next, that, pp, display);
6180}
6181
6182static int
6183image_transform_png_set_strip_alpha_add(image_transform *this,
6184 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
6185{
6186 UNUSED(bit_depth)
6187
6188 this->next = *that;
6189 *that = this;
6190
6191 return (colour_type & PNG_COLOR_MASK_ALPHA) != 0;
6192}
6193
6194IT(strip_alpha);
6195#undef PT
6196#define PT ITSTRUCT(strip_alpha)
6197#endif /* PNG_READ_STRIP_ALPHA_SUPPORTED */
6198
6199#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
6200/* png_set_rgb_to_gray(png_structp, int err_action, double red, double green)
6201 * png_set_rgb_to_gray_fixed(png_structp, int err_action, png_fixed_point red,
6202 * png_fixed_point green)
6203 * png_get_rgb_to_gray_status
6204 *
6205 * The 'default' test here uses values known to be used inside libpng:
6206 *
6207 * red: 6968
6208 * green: 23434
6209 * blue: 2366
6210 *
6211 * These values are being retained for compatibility, along with the somewhat
6212 * broken truncation calculation in the fast-and-inaccurate code path. Older
6213 * versions of libpng will fail the accuracy tests below because they use the
6214 * truncation algorithm everywhere.
6215 */
6216#define data ITDATA(rgb_to_gray)
6217static struct
6218{
6219 double gamma; /* File gamma to use in processing */
6220
6221 /* The following are the parameters for png_set_rgb_to_gray: */
6222# ifdef PNG_FLOATING_POINT_SUPPORTED
6223 double red_to_set;
6224 double green_to_set;
6225# else
6226 png_fixed_point red_to_set;
6227 png_fixed_point green_to_set;
6228# endif
6229
6230 /* The actual coefficients: */
6231 double red_coefficient;
6232 double green_coefficient;
6233 double blue_coefficient;
6234
6235 /* Set if the coeefficients have been overridden. */
6236 int coefficients_overridden;
6237} data;
6238
6239#undef image_transform_ini
6240#define image_transform_ini image_transform_png_set_rgb_to_gray_ini
6241static void
6242image_transform_png_set_rgb_to_gray_ini(PNG_CONST image_transform *this,
6243 transform_display *that)
6244{
6245 png_modifier *pm = that->pm;
6246 PNG_CONST color_encoding *e = pm->current_encoding;
6247
6248 UNUSED(this)
6249
6250 /* Since we check the encoding this flag must be set: */
6251 pm->test_uses_encoding = 1;
6252
6253 /* If 'e' is not NULL chromaticity information is present and either a cHRM
6254 * or an sRGB chunk will be inserted.
6255 */
6256 if (e != 0)
6257 {
6258 /* Coefficients come from the encoding, but may need to be normalized to a
6259 * white point Y of 1.0
6260 */
6261 PNG_CONST double whiteY = e->red.Y + e->green.Y + e->blue.Y;
6262
6263 data.red_coefficient = e->red.Y;
6264 data.green_coefficient = e->green.Y;
6265 data.blue_coefficient = e->blue.Y;
6266
6267 if (whiteY != 1)
6268 {
6269 data.red_coefficient /= whiteY;
6270 data.green_coefficient /= whiteY;
6271 data.blue_coefficient /= whiteY;
6272 }
6273 }
6274
6275 else
6276 {
6277 /* The default (built in) coeffcients, as above: */
6278 data.red_coefficient = 6968 / 32768.;
6279 data.green_coefficient = 23434 / 32768.;
6280 data.blue_coefficient = 2366 / 32768.;
6281 }
6282
6283 data.gamma = pm->current_gamma;
6284
6285 /* If not set then the calculations assume linear encoding (implicitly): */
6286 if (data.gamma == 0)
6287 data.gamma = 1;
6288
6289 /* The arguments to png_set_rgb_to_gray can override the coefficients implied
6290 * by the color space encoding. If doing exhaustive checks do the override
6291 * in each case, otherwise do it randomly.
6292 */
6293 if (pm->test_exhaustive)
6294 {
6295 /* First time in coefficients_overridden is 0, the following sets it to 1,
6296 * so repeat if it is set. If a test fails this may mean we subsequently
6297 * skip a non-override test, ignore that.
6298 */
6299 data.coefficients_overridden = !data.coefficients_overridden;
6300 pm->repeat = data.coefficients_overridden != 0;
6301 }
6302
6303 else
6304 data.coefficients_overridden = random_choice();
6305
6306 if (data.coefficients_overridden)
6307 {
6308 /* These values override the color encoding defaults, simply use random
6309 * numbers.
6310 */
6311 png_uint_32 ru;
6312 double total;
6313
6314 RANDOMIZE(ru);
6315 data.green_coefficient = total = (ru & 0xffff) / 65535.;
6316 ru >>= 16;
6317 data.red_coefficient = (1 - total) * (ru & 0xffff) / 65535.;
6318 total += data.red_coefficient;
6319 data.blue_coefficient = 1 - total;
6320
6321# ifdef PNG_FLOATING_POINT_SUPPORTED
6322 data.red_to_set = data.red_coefficient;
6323 data.green_to_set = data.green_coefficient;
6324# else
6325 data.red_to_set = fix(data.red_coefficient);
6326 data.green_to_set = fix(data.green_coefficient);
6327# endif
6328
6329 /* The following just changes the error messages: */
6330 pm->encoding_ignored = 1;
6331 }
6332
6333 else
6334 {
6335 data.red_to_set = -1;
6336 data.green_to_set = -1;
6337 }
6338
6339 /* Adjust the error limit in the png_modifier because of the larger errors
6340 * produced in the digitization during the gamma handling.
6341 */
6342 if (data.gamma != 1) /* Use gamma tables */
6343 {
6344 if (that->this.bit_depth == 16 || pm->assume_16_bit_calculations)
6345 {
6346 /* The 16 bit case ends up producing a maximum error of about
6347 * +/-5 in 65535, allow for +/-8 with the given gamma.
6348 */
6349 that->pm->limit += pow(8./65535, data.gamma);
6350 }
6351
6352 else
6353 {
6354 /* Rounding to 8 bits in the linear space causes massive errors which
6355 * will trigger the error check in transform_range_check. Fix that
6356 * here by taking the gamma encoding into account.
6357 */
6358 that->pm->limit += pow(1./255, data.gamma);
6359 }
6360 }
6361
6362 else
6363 {
6364 /* With no gamma correction a large error comes from the truncation of the
6365 * calculation in the 8 bit case, allow for that here.
6366 */
6367 if (that->this.bit_depth != 16)
6368 that->pm->limit += 4E-3;
6369 }
6370}
6371
6372static void
6373image_transform_png_set_rgb_to_gray_set(PNG_CONST image_transform *this,
6374 transform_display *that, png_structp pp, png_infop pi)
6375{
6376 PNG_CONST int error_action = 1; /* no error, no defines in png.h */
6377
6378# ifdef PNG_FLOATING_POINT_SUPPORTED
6379 png_set_rgb_to_gray(pp, error_action, data.red_to_set, data.green_to_set);
6380# else
6381 png_set_rgb_to_gray_fixed(pp, error_action, data.red_to_set,
6382 data.green_to_set);
6383# endif
6384
6385# ifdef PNG_READ_cHRM_SUPPORTED
6386 if (that->pm->current_encoding != 0)
6387 {
6388 /* We have an encoding so a cHRM chunk may have been set; if so then
6389 * check that the libpng APIs give the correct (X,Y,Z) values within
6390 * some margin of error for the round trip through the chromaticity
6391 * form.
6392 */
6393# ifdef PNG_FLOATING_POINT_SUPPORTED
6394# define API_function png_get_cHRM_XYZ
6395# define API_form "FP"
6396# define API_type double
6397# define API_cvt(x) (x)
6398# else
6399# define API_function png_get_cHRM_XYZ_fixed
6400# define API_form "fixed"
6401# define API_type png_fixed_point
6402# define API_cvt(x) ((double)(x)/PNG_FP_1)
6403# endif
6404
6405 API_type rX, gX, bX;
6406 API_type rY, gY, bY;
6407 API_type rZ, gZ, bZ;
6408
6409 if ((API_function(pp, pi, &rX, &rY, &rZ, &gX, &gY, &gZ, &bX, &bY, &bZ)
6410 & PNG_INFO_cHRM) != 0)
6411 {
6412 double maxe;
6413 PNG_CONST char *el;
6414 color_encoding e, o;
6415
6416 /* Expect libpng to return a normalized result, but the original
6417 * color space encoding may not be normalized.
6418 */
6419 modifier_current_encoding(that->pm, &o);
6420 normalize_color_encoding(&o);
6421
6422 /* Sanity check the pngvalid code - the coefficients should match
6423 * the normalized Y values of the encoding unless they were
6424 * overridden.
6425 */
6426 if (data.red_to_set == -1 && data.green_to_set == -1 &&
6427 (fabs(o.red.Y - data.red_coefficient) > DBL_EPSILON ||
6428 fabs(o.green.Y - data.green_coefficient) > DBL_EPSILON ||
6429 fabs(o.blue.Y - data.blue_coefficient) > DBL_EPSILON))
6430 png_error(pp, "internal pngvalid cHRM coefficient error");
6431
6432 /* Generate a colour space encoding. */
6433 e.gamma = o.gamma; /* not used */
6434 e.red.X = API_cvt(rX);
6435 e.red.Y = API_cvt(rY);
6436 e.red.Z = API_cvt(rZ);
6437 e.green.X = API_cvt(gX);
6438 e.green.Y = API_cvt(gY);
6439 e.green.Z = API_cvt(gZ);
6440 e.blue.X = API_cvt(bX);
6441 e.blue.Y = API_cvt(bY);
6442 e.blue.Z = API_cvt(bZ);
6443
6444 /* This should match the original one from the png_modifier, within
6445 * the range permitted by the libpng fixed point representation.
6446 */
6447 maxe = 0;
6448 el = "-"; /* Set to element name with error */
6449
6450# define CHECK(col,x)\
6451 {\
6452 double err = fabs(o.col.x - e.col.x);\
6453 if (err > maxe)\
6454 {\
6455 maxe = err;\
6456 el = #col "(" #x ")";\
6457 }\
6458 }
6459
6460 CHECK(red,X)
6461 CHECK(red,Y)
6462 CHECK(red,Z)
6463 CHECK(green,X)
6464 CHECK(green,Y)
6465 CHECK(green,Z)
6466 CHECK(blue,X)
6467 CHECK(blue,Y)
6468 CHECK(blue,Z)
6469
6470 /* Here in both fixed and floating cases to check the values read
6471 * from the cHRm chunk. PNG uses fixed point in the cHRM chunk, so
6472 * we can't expect better than +/-.5E-5 on the result, allow 1E-5.
6473 */
6474 if (maxe >= 1E-5)
6475 {
6476 size_t pos = 0;
6477 char buffer[256];
6478
6479 pos = safecat(buffer, sizeof buffer, pos, API_form);
6480 pos = safecat(buffer, sizeof buffer, pos, " cHRM ");
6481 pos = safecat(buffer, sizeof buffer, pos, el);
6482 pos = safecat(buffer, sizeof buffer, pos, " error: ");
6483 pos = safecatd(buffer, sizeof buffer, pos, maxe, 7);
6484 pos = safecat(buffer, sizeof buffer, pos, " ");
6485 /* Print the color space without the gamma value: */
6486 pos = safecat_color_encoding(buffer, sizeof buffer, pos, &o, 0);
6487 pos = safecat(buffer, sizeof buffer, pos, " -> ");
6488 pos = safecat_color_encoding(buffer, sizeof buffer, pos, &e, 0);
6489
6490 png_error(pp, buffer);
6491 }
6492 }
6493 }
6494# endif /* READ_cHRM */
6495
6496 this->next->set(this->next, that, pp, pi);
6497}
6498
6499static void
6500image_transform_png_set_rgb_to_gray_mod(PNG_CONST image_transform *this,
6501 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6502{
6503 if ((that->colour_type & PNG_COLOR_MASK_COLOR) != 0)
6504 {
6505 double gray, err;
6506
6507 if (that->colour_type == PNG_COLOR_TYPE_PALETTE)
6508 image_pixel_convert_PLTE(that);
6509
6510 /* Image now has RGB channels... */
6511 {
6512 PNG_CONST png_modifier *pm = display->pm;
6513 PNG_CONST unsigned int sample_depth = that->sample_depth;
6514 int isgray;
6515 double r, g, b;
6516 double rlo, rhi, glo, ghi, blo, bhi, graylo, grayhi;
6517
6518 /* Do this using interval arithmetic, otherwise it is too difficult to
6519 * handle the errors correctly.
6520 *
6521 * To handle the gamma correction work out the upper and lower bounds
6522 * of the digitized value. Assume rounding here - normally the values
6523 * will be identical after this operation if there is only one
6524 * transform, feel free to delete the png_error checks on this below in
6525 * the future (this is just me trying to ensure it works!)
6526 */
6527 r = rlo = rhi = that->redf;
6528 rlo -= that->rede;
6529 rlo = digitize(pm, rlo, sample_depth, 1/*round*/);
6530 rhi += that->rede;
6531 rhi = digitize(pm, rhi, sample_depth, 1/*round*/);
6532
6533 g = glo = ghi = that->greenf;
6534 glo -= that->greene;
6535 glo = digitize(pm, glo, sample_depth, 1/*round*/);
6536 ghi += that->greene;
6537 ghi = digitize(pm, ghi, sample_depth, 1/*round*/);
6538
6539 b = blo = bhi = that->bluef;
6540 blo -= that->bluee;
6541 blo = digitize(pm, blo, sample_depth, 1/*round*/);
6542 bhi += that->greene;
6543 bhi = digitize(pm, bhi, sample_depth, 1/*round*/);
6544
6545 isgray = r==g && g==b;
6546
6547 if (data.gamma != 1)
6548 {
6549 PNG_CONST double power = 1/data.gamma;
6550 PNG_CONST double abse = abserr(pm, sample_depth, sample_depth);
6551
6552 /* 'abse' is the absolute error permitted in linear calculations. It
6553 * is used here to capture the error permitted in the handling
6554 * (undoing) of the gamma encoding. Once again digitization occurs
6555 * to handle the upper and lower bounds of the values. This is
6556 * where the real errors are introduced.
6557 */
6558 r = pow(r, power);
6559 rlo = digitize(pm, pow(rlo, power)-abse, sample_depth, 1);
6560 rhi = digitize(pm, pow(rhi, power)+abse, sample_depth, 1);
6561
6562 g = pow(g, power);
6563 glo = digitize(pm, pow(glo, power)-abse, sample_depth, 1);
6564 ghi = digitize(pm, pow(ghi, power)+abse, sample_depth, 1);
6565
6566 b = pow(b, power);
6567 blo = digitize(pm, pow(blo, power)-abse, sample_depth, 1);
6568 bhi = digitize(pm, pow(bhi, power)+abse, sample_depth, 1);
6569 }
6570
6571 /* Now calculate the actual gray values. Although the error in the
6572 * coefficients depends on whether they were specified on the command
6573 * line (in which case truncation to 15 bits happened) or not (rounding
6574 * was used) the maxium error in an individual coefficient is always
6575 * 1/32768, because even in the rounding case the requirement that
6576 * coefficients add up to 32768 can cause a larger rounding error.
6577 *
6578 * The only time when rounding doesn't occur in 1.5.5 and later is when
6579 * the non-gamma code path is used for less than 16 bit data.
6580 */
6581 gray = r * data.red_coefficient + g * data.green_coefficient +
6582 b * data.blue_coefficient;
6583
6584 {
6585 PNG_CONST int do_round = data.gamma != 1 || sample_depth == 16;
6586 PNG_CONST double ce = 1. / 32768;
6587
6588 graylo = digitize(pm, rlo * (data.red_coefficient-ce) +
6589 glo * (data.green_coefficient-ce) +
6590 blo * (data.blue_coefficient-ce), sample_depth, do_round);
6591 if (graylo <= 0)
6592 graylo = 0;
6593
6594 grayhi = digitize(pm, rhi * (data.red_coefficient+ce) +
6595 ghi * (data.green_coefficient+ce) +
6596 bhi * (data.blue_coefficient+ce), sample_depth, do_round);
6597 if (grayhi >= 1)
6598 grayhi = 1;
6599 }
6600
6601 /* And invert the gamma. */
6602 if (data.gamma != 1)
6603 {
6604 PNG_CONST double power = data.gamma;
6605
6606 gray = pow(gray, power);
6607 graylo = digitize(pm, pow(graylo, power), sample_depth, 1);
6608 grayhi = digitize(pm, pow(grayhi, power), sample_depth, 1);
6609 }
6610
6611 /* Now the error can be calculated.
6612 *
6613 * If r==g==b because there is no overall gamma correction libpng
6614 * currently preserves the original value.
6615 */
6616 if (isgray)
6617 err = (that->rede + that->greene + that->bluee)/3;
6618
6619 else
6620 {
6621 err = fabs(grayhi-gray);
6622 if (fabs(gray - graylo) > err)
6623 err = fabs(graylo-gray);
6624
6625 /* Check that this worked: */
6626 if (err > display->pm->limit)
6627 {
6628 size_t pos = 0;
6629 char buffer[128];
6630
6631 pos = safecat(buffer, sizeof buffer, pos, "rgb_to_gray error ");
6632 pos = safecatd(buffer, sizeof buffer, pos, err, 6);
6633 pos = safecat(buffer, sizeof buffer, pos, " exceeds limit ");
6634 pos = safecatd(buffer, sizeof buffer, pos,
6635 display->pm->limit, 6);
6636 png_error(pp, buffer);
6637 }
6638 }
6639 }
6640
6641 that->bluef = that->greenf = that->redf = gray;
6642 that->bluee = that->greene = that->rede = err;
6643
6644 /* The sBIT is the minium of the three colour channel sBITs. */
6645 if (that->red_sBIT > that->green_sBIT)
6646 that->red_sBIT = that->green_sBIT;
6647 if (that->red_sBIT > that->blue_sBIT)
6648 that->red_sBIT = that->blue_sBIT;
6649 that->blue_sBIT = that->green_sBIT = that->red_sBIT;
6650
6651 /* And remove the colour bit in the type: */
6652 if (that->colour_type == PNG_COLOR_TYPE_RGB)
6653 that->colour_type = PNG_COLOR_TYPE_GRAY;
6654 else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)
6655 that->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA;
6656 }
6657
6658 this->next->mod(this->next, that, pp, display);
6659}
6660
6661static int
6662image_transform_png_set_rgb_to_gray_add(image_transform *this,
6663 PNG_CONST image_transform **that, png_byte colour_type, png_byte bit_depth)
6664{
6665 UNUSED(bit_depth)
6666
6667 this->next = *that;
6668 *that = this;
6669
6670 return (colour_type & PNG_COLOR_MASK_COLOR) != 0;
6671}
6672
6673#undef data
6674IT(rgb_to_gray);
6675#undef PT
6676#define PT ITSTRUCT(rgb_to_gray)
6677#undef image_transform_ini
6678#define image_transform_ini image_transform_default_ini
6679#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
6680
6681#ifdef PNG_READ_BACKGROUND_SUPPORTED
6682/* png_set_background(png_structp, png_const_color_16p background_color,
6683 * int background_gamma_code, int need_expand, double background_gamma)
6684 * png_set_background_fixed(png_structp, png_const_color_16p background_color,
6685 * int background_gamma_code, int need_expand,
6686 * png_fixed_point background_gamma)
6687 *
6688 * As with rgb_to_gray this ignores the gamma (at present.)
6689*/
6690#define data ITDATA(background)
6691static image_pixel data;
6692
6693static void
6694image_transform_png_set_background_set(PNG_CONST image_transform *this,
6695 transform_display *that, png_structp pp, png_infop pi)
6696{
6697 png_byte colour_type, bit_depth;
6698 png_byte random_bytes[8]; /* 8 bytes - 64 bits - the biggest pixel */
6699 png_color_16 back;
6700
6701 /* We need a background colour, because we don't know exactly what transforms
6702 * have been set we have to supply the colour in the original file format and
6703 * so we need to know what that is! The background colour is stored in the
6704 * transform_display.
6705 */
6706 RANDOMIZE(random_bytes);
6707
6708 /* Read the random value, for colour type 3 the background colour is actually
6709 * expressed as a 24bit rgb, not an index.
6710 */
6711 colour_type = that->this.colour_type;
6712 if (colour_type == 3)
6713 {
6714 colour_type = PNG_COLOR_TYPE_RGB;
6715 bit_depth = 8;
6716 }
6717
6718 else
6719 bit_depth = that->this.bit_depth;
6720
6721 image_pixel_init(&data, random_bytes, colour_type,
6722 bit_depth, 0/*x*/, 0/*unused: palette*/);
6723
6724 /* Extract the background colour from this image_pixel, but make sure the
6725 * unused fields of 'back' are garbage.
6726 */
6727 RANDOMIZE(back);
6728
6729 if (colour_type & PNG_COLOR_MASK_COLOR)
6730 {
6731 back.red = (png_uint_16)data.red;
6732 back.green = (png_uint_16)data.green;
6733 back.blue = (png_uint_16)data.blue;
6734 }
6735
6736 else
6737 back.gray = (png_uint_16)data.red;
6738
6739# ifdef PNG_FLOATING_POINT_SUPPORTED
6740 png_set_background(pp, &back, PNG_BACKGROUND_GAMMA_FILE, 1/*need expand*/,
6741 0);
6742# else
6743 png_set_background_fixed(pp, &back, PNG_BACKGROUND_GAMMA_FILE,
6744 1/*need expand*/, 0);
6745# endif
6746
6747 this->next->set(this->next, that, pp, pi);
6748}
6749
6750static void
6751image_transform_png_set_background_mod(PNG_CONST image_transform *this,
6752 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
6753{
6754 /* Check for tRNS first: */
6755 if (that->have_tRNS && that->colour_type != PNG_COLOR_TYPE_PALETTE)
6756 image_pixel_add_alpha(that, &display->this);
6757
6758 /* This is only necessary if the alpha value is less than 1. */
6759 if (that->alphaf < 1)
6760 {
6761 /* Now we do the background calculation without any gamma correction. */
6762 if (that->alphaf <= 0)
6763 {
6764 that->redf = data.redf;
6765 that->greenf = data.greenf;
6766 that->bluef = data.bluef;
6767
6768 that->rede = data.rede;
6769 that->greene = data.greene;
6770 that->bluee = data.bluee;
6771
6772 that->red_sBIT= data.red_sBIT;
6773 that->green_sBIT= data.green_sBIT;
6774 that->blue_sBIT= data.blue_sBIT;
6775 }
6776
6777 else /* 0 < alpha < 1 */
6778 {
6779 double alf = 1 - that->alphaf;
6780
6781 that->redf = that->redf * that->alphaf + data.redf * alf;
6782 that->rede = that->rede * that->alphaf + data.rede * alf +
6783 DBL_EPSILON;
6784 that->greenf = that->greenf * that->alphaf + data.greenf * alf;
6785 that->greene = that->greene * that->alphaf + data.greene * alf +
6786 DBL_EPSILON;
6787 that->bluef = that->bluef * that->alphaf + data.bluef * alf;
6788 that->bluee = that->bluee * that->alphaf + data.bluee * alf +
6789 DBL_EPSILON;
6790 }
6791
6792 /* Remove the alpha type and set the alpha (not in that order.) */
6793 that->alphaf = 1;
6794 that->alphae = 0;
6795
6796 if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)
6797 that->colour_type = PNG_COLOR_TYPE_RGB;
6798 else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)
6799 that->colour_type = PNG_COLOR_TYPE_GRAY;
6800 /* PNG_COLOR_TYPE_PALETTE is not changed */
6801 }
6802
6803 this->next->mod(this->next, that, pp, display);
6804}
6805
6806#define image_transform_png_set_background_add image_transform_default_add
6807
6808#undef data
6809IT(background);
6810#undef PT
6811#define PT ITSTRUCT(background)
6812#endif /* PNG_READ_BACKGROUND_SUPPORTED */
6813
6814/* This may just be 'end' if all the transforms are disabled! */
6815static image_transform *PNG_CONST image_transform_first = &PT;
6816
6817static void
6818transform_enable(PNG_CONST char *name)
6819{
6820 /* Everything starts out enabled, so if we see an 'enable' disabled
6821 * everything else the first time round.
6822 */
6823 static int all_disabled = 0;
6824 int found_it = 0;
6825 image_transform *list = image_transform_first;
6826
6827 while (list != &image_transform_end)
6828 {
6829 if (strcmp(list->name, name) == 0)
6830 {
6831 list->enable = 1;
6832 found_it = 1;
6833 }
6834 else if (!all_disabled)
6835 list->enable = 0;
6836
6837 list = list->list;
6838 }
6839
6840 all_disabled = 1;
6841
6842 if (!found_it)
6843 {
6844 fprintf(stderr, "pngvalid: --transform-enable=%s: unknown transform\n",
6845 name);
6846 exit(1);
6847 }
6848}
6849
6850static void
6851transform_disable(PNG_CONST char *name)
6852{
6853 image_transform *list = image_transform_first;
6854
6855 while (list != &image_transform_end)
6856 {
6857 if (strcmp(list->name, name) == 0)
6858 {
6859 list->enable = 0;
6860 return;
6861 }
6862
6863 list = list->list;
6864 }
6865
6866 fprintf(stderr, "pngvalid: --transform-disable=%s: unknown transform\n",
6867 name);
6868 exit(1);
6869}
6870
6871static void
6872image_transform_reset_count(void)
6873{
6874 image_transform *next = image_transform_first;
6875 int count = 0;
6876
6877 while (next != &image_transform_end)
6878 {
6879 next->local_use = 0;
6880 next->next = 0;
6881 next = next->list;
6882 ++count;
6883 }
6884
6885 /* This can only happen if we every have more than 32 transforms (excluding
6886 * the end) in the list.
6887 */
6888 if (count > 32) abort();
6889}
6890
6891static int
6892image_transform_test_counter(png_uint_32 counter, unsigned int max)
6893{
6894 /* Test the list to see if there is any point contining, given a current
6895 * counter and a 'max' value.
6896 */
6897 image_transform *next = image_transform_first;
6898
6899 while (next != &image_transform_end)
6900 {
6901 /* For max 0 or 1 continue until the counter overflows: */
6902 counter >>= 1;
6903
6904 /* Continue if any entry hasn't reacked the max. */
6905 if (max > 1 && next->local_use < max)
6906 return 1;
6907 next = next->list;
6908 }
6909
6910 return max <= 1 && counter == 0;
6911}
6912
6913static png_uint_32
6914image_transform_add(PNG_CONST image_transform **this, unsigned int max,
6915 png_uint_32 counter, char *name, size_t sizeof_name, size_t *pos,
6916 png_byte colour_type, png_byte bit_depth)
6917{
6918 for (;;) /* until we manage to add something */
6919 {
6920 png_uint_32 mask;
6921 image_transform *list;
6922
6923 /* Find the next counter value, if the counter is zero this is the start
6924 * of the list. This routine always returns the current counter (not the
6925 * next) so it returns 0 at the end and expects 0 at the beginning.
6926 */
6927 if (counter == 0) /* first time */
6928 {
6929 image_transform_reset_count();
6930 if (max <= 1)
6931 counter = 1;
6932 else
6933 counter = random_32();
6934 }
6935 else /* advance the counter */
6936 {
6937 switch (max)
6938 {
6939 case 0: ++counter; break;
6940 case 1: counter <<= 1; break;
6941 default: counter = random_32(); break;
6942 }
6943 }
6944
6945 /* Now add all these items, if possible */
6946 *this = &image_transform_end;
6947 list = image_transform_first;
6948 mask = 1;
6949
6950 /* Go through the whole list adding anything that the counter selects: */
6951 while (list != &image_transform_end)
6952 {
6953 if ((counter & mask) != 0 && list->enable &&
6954 (max == 0 || list->local_use < max))
6955 {
6956 /* Candidate to add: */
6957 if (list->add(list, this, colour_type, bit_depth) || max == 0)
6958 {
6959 /* Added, so add to the name too. */
6960 *pos = safecat(name, sizeof_name, *pos, " +");
6961 *pos = safecat(name, sizeof_name, *pos, list->name);
6962 }
6963
6964 else
6965 {
6966 /* Not useful and max>0, so remove it from *this: */
6967 *this = list->next;
6968 list->next = 0;
6969
6970 /* And, since we know it isn't useful, stop it being added again
6971 * in this run:
6972 */
6973 list->local_use = max;
6974 }
6975 }
6976
6977 mask <<= 1;
6978 list = list->list;
6979 }
6980
6981 /* Now if anything was added we have something to do. */
6982 if (*this != &image_transform_end)
6983 return counter;
6984
6985 /* Nothing added, but was there anything in there to add? */
6986 if (!image_transform_test_counter(counter, max))
6987 return 0;
6988 }
6989}
6990
6991#ifdef THIS_IS_THE_PROFORMA
6992static void
6993image_transform_png_set_@_set(PNG_CONST image_transform *this,
6994 transform_display *that, png_structp pp, png_infop pi)
6995{
6996 png_set_@(pp);
6997 this->next->set(this->next, that, pp, pi);
6998}
6999
7000static void
7001image_transform_png_set_@_mod(PNG_CONST image_transform *this,
7002 image_pixel *that, png_structp pp, PNG_CONST transform_display *display)
7003{
7004 this->next->mod(this->next, that, pp, display);
7005}
7006
7007static int
7008image_transform_png_set_@_add(image_transform *this,
7009 PNG_CONST image_transform **that, char *name, size_t sizeof_name,
7010 size_t *pos, png_byte colour_type, png_byte bit_depth)
7011{
7012 this->next = *that;
7013 *that = this;
7014
7015 *pos = safecat(name, sizeof_name, *pos, " +@");
7016
7017 return 1;
7018}
7019
7020IT(@);
7021#endif
7022
7023/* png_set_quantize(png_structp, png_colorp palette, int num_palette,
7024 * int maximum_colors, png_const_uint_16p histogram, int full_quantize)
7025 *
7026 * Very difficult to validate this!
7027 */
7028/*NOTE: TBD NYI */
7029
7030/* The data layout transforms are handled by swapping our own channel data,
7031 * necessarily these need to happen at the end of the transform list because the
7032 * semantic of the channels changes after these are executed. Some of these,
7033 * like set_shift and set_packing, can't be done at present because they change
7034 * the layout of the data at the sub-sample level so sample() won't get the
7035 * right answer.
7036 */
7037/* png_set_invert_alpha */
7038/*NOTE: TBD NYI */
7039
7040/* png_set_bgr */
7041/*NOTE: TBD NYI */
7042
7043/* png_set_swap_alpha */
7044/*NOTE: TBD NYI */
7045
7046/* png_set_swap */
7047/*NOTE: TBD NYI */
7048
7049/* png_set_filler, (png_structp png_ptr, png_uint_32 filler, int flags)); */
7050/*NOTE: TBD NYI */
7051
7052/* png_set_add_alpha, (png_structp png_ptr, png_uint_32 filler, int flags)); */
7053/*NOTE: TBD NYI */
7054
7055/* png_set_packing */
7056/*NOTE: TBD NYI */
7057
7058/* png_set_packswap */
7059/*NOTE: TBD NYI */
7060
7061/* png_set_invert_mono */
7062/*NOTE: TBD NYI */
7063
7064/* png_set_shift(png_structp, png_const_color_8p true_bits) */
7065/*NOTE: TBD NYI */
7066
7067static void
7068perform_transform_test(png_modifier *pm)
7069{
7070 png_byte colour_type = 0;
7071 png_byte bit_depth = 0;
7072 int palette_number = 0;
7073
7074 while (next_format(&colour_type, &bit_depth, &palette_number))
7075 {
7076 png_uint_32 counter = 0;
7077 size_t base_pos;
7078 char name[64];
7079
7080 base_pos = safecat(name, sizeof name, 0, "transform:");
7081
7082 for (;;)
7083 {
7084 size_t pos = base_pos;
7085 PNG_CONST image_transform *list = 0;
7086
7087 /* 'max' is currently hardwired to '1'; this should be settable on the
7088 * command line.
7089 */
7090 counter = image_transform_add(&list, 1/*max*/, counter,
7091 name, sizeof name, &pos, colour_type, bit_depth);
7092
7093 if (counter == 0)
7094 break;
7095
7096 /* The command line can change this to checking interlaced images. */
7097 do
7098 {
7099 pm->repeat = 0;
7100 transform_test(pm, FILEID(colour_type, bit_depth, palette_number,
7101 pm->interlace_type, 0, 0, 0), list, name);
7102
7103 if (fail(pm))
7104 return;
7105 }
7106 while (pm->repeat);
7107 }
7108 }
7109}
7110#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
7111
7112/********************************* GAMMA TESTS ********************************/
7113#ifdef PNG_READ_GAMMA_SUPPORTED
7114/* Reader callbacks and implementations, where they differ from the standard
7115 * ones.
7116 */
7117typedef struct gamma_display
7118{
7119 standard_display this;
7120
7121 /* Parameters */
7122 png_modifier* pm;
7123 double file_gamma;
7124 double screen_gamma;
7125 double background_gamma;
7126 png_byte sbit;
7127 int threshold_test;
7128 int use_input_precision;
7129 int scale16;
7130 int expand16;
7131 int do_background;
7132 png_color_16 background_color;
7133
7134 /* Local variables */
7135 double maxerrout;
7136 double maxerrpc;
7137 double maxerrabs;
7138} gamma_display;
7139
7140#define ALPHA_MODE_OFFSET 4
7141
7142static void
7143gamma_display_init(gamma_display *dp, png_modifier *pm, png_uint_32 id,
7144 double file_gamma, double screen_gamma, png_byte sbit, int threshold_test,
7145 int use_input_precision, int scale16, int expand16,
7146 int do_background, PNG_CONST png_color_16 *pointer_to_the_background_color,
7147 double background_gamma)
7148{
7149 /* Standard fields */
7150 standard_display_init(&dp->this, &pm->this, id, 0/*do_interlace*/,
7151 pm->use_update_info);
7152
7153 /* Parameter fields */
7154 dp->pm = pm;
7155 dp->file_gamma = file_gamma;
7156 dp->screen_gamma = screen_gamma;
7157 dp->background_gamma = background_gamma;
7158 dp->sbit = sbit;
7159 dp->threshold_test = threshold_test;
7160 dp->use_input_precision = use_input_precision;
7161 dp->scale16 = scale16;
7162 dp->expand16 = expand16;
7163 dp->do_background = do_background;
7164 if (do_background && pointer_to_the_background_color != 0)
7165 dp->background_color = *pointer_to_the_background_color;
7166 else
7167 memset(&dp->background_color, 0, sizeof dp->background_color);
7168
7169 /* Local variable fields */
7170 dp->maxerrout = dp->maxerrpc = dp->maxerrabs = 0;
7171}
7172
7173static void
7174gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
7175{
7176 /* Reuse the standard stuff as appropriate. */
7177 standard_info_part1(&dp->this, pp, pi);
7178
7179 /* If requested strip 16 to 8 bits - this is handled automagically below
7180 * because the output bit depth is read from the library. Note that there
7181 * are interactions with sBIT but, internally, libpng makes sbit at most
7182 * PNG_MAX_GAMMA_8 when doing the following.
7183 */
7184 if (dp->scale16)
7185# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
7186 png_set_scale_16(pp);
7187# else
7188 /* The following works both in 1.5.4 and earlier versions: */
7189# ifdef PNG_READ_16_TO_8_SUPPORTED
7190 png_set_strip_16(pp);
7191# else
7192 png_error(pp, "scale16 (16 to 8 bit conversion) not supported");
7193# endif
7194# endif
7195
7196 if (dp->expand16)
7197# ifdef PNG_READ_EXPAND_16_SUPPORTED
7198 png_set_expand_16(pp);
7199# else
7200 png_error(pp, "expand16 (8 to 16 bit conversion) not supported");
7201# endif
7202
7203 if (dp->do_background >= ALPHA_MODE_OFFSET)
7204 {
7205# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7206 {
7207 /* This tests the alpha mode handling, if supported. */
7208 int mode = dp->do_background - ALPHA_MODE_OFFSET;
7209
7210 /* The gamma value is the output gamma, and is in the standard,
7211 * non-inverted, represenation. It provides a default for the PNG file
7212 * gamma, but since the file has a gAMA chunk this does not matter.
7213 */
7214 PNG_CONST double sg = dp->screen_gamma;
7215# ifndef PNG_FLOATING_POINT_SUPPORTED
7216 PNG_CONST png_fixed_point g = fix(sg);
7217# endif
7218
7219# ifdef PNG_FLOATING_POINT_SUPPORTED
7220 png_set_alpha_mode(pp, mode, sg);
7221# else
7222 png_set_alpha_mode_fixed(pp, mode, g);
7223# endif
7224
7225 /* However, for the standard Porter-Duff algorithm the output defaults
7226 * to be linear, so if the test requires non-linear output it must be
7227 * corrected here.
7228 */
7229 if (mode == PNG_ALPHA_STANDARD && sg != 1)
7230 {
7231# ifdef PNG_FLOATING_POINT_SUPPORTED
7232 png_set_gamma(pp, sg, dp->file_gamma);
7233# else
7234 png_fixed_point f = fix(dp->file_gamma);
7235 png_set_gamma_fixed(pp, g, f);
7236# endif
7237 }
7238 }
7239# else
7240 png_error(pp, "alpha mode handling not supported");
7241# endif
7242 }
7243
7244 else
7245 {
7246 /* Set up gamma processing. */
7247# ifdef PNG_FLOATING_POINT_SUPPORTED
7248 png_set_gamma(pp, dp->screen_gamma, dp->file_gamma);
7249# else
7250 {
7251 png_fixed_point s = fix(dp->screen_gamma);
7252 png_fixed_point f = fix(dp->file_gamma);
7253 png_set_gamma_fixed(pp, s, f);
7254 }
7255# endif
7256
7257 if (dp->do_background)
7258 {
7259# ifdef PNG_READ_BACKGROUND_SUPPORTED
7260 /* NOTE: this assumes the caller provided the correct background gamma!
7261 */
7262 PNG_CONST double bg = dp->background_gamma;
7263# ifndef PNG_FLOATING_POINT_SUPPORTED
7264 PNG_CONST png_fixed_point g = fix(bg);
7265# endif
7266
7267# ifdef PNG_FLOATING_POINT_SUPPORTED
7268 png_set_background(pp, &dp->background_color, dp->do_background,
7269 0/*need_expand*/, bg);
7270# else
7271 png_set_background_fixed(pp, &dp->background_color,
7272 dp->do_background, 0/*need_expand*/, g);
7273# endif
7274# else
7275 png_error(pp, "png_set_background not supported");
7276# endif
7277 }
7278 }
7279
7280 {
7281 int i = dp->this.use_update_info;
7282 /* Always do one call, even if use_update_info is 0. */
7283 do
7284 png_read_update_info(pp, pi);
7285 while (--i > 0);
7286 }
7287
7288 /* Now we may get a different cbRow: */
7289 standard_info_part2(&dp->this, pp, pi, 1 /*images*/);
7290}
7291
7292static void
7293gamma_info(png_structp pp, png_infop pi)
7294{
7295 gamma_info_imp(voidcast(gamma_display*, png_get_progressive_ptr(pp)), pp,
7296 pi);
7297}
7298
7299/* Validate a single component value - the routine gets the input and output
7300 * sample values as unscaled PNG component values along with a cache of all the
7301 * information required to validate the values.
7302 */
7303typedef struct validate_info
7304{
7305 png_structp pp;
7306 gamma_display *dp;
7307 png_byte sbit;
7308 int use_input_precision;
7309 int do_background;
7310 int scale16;
7311 unsigned int sbit_max;
7312 unsigned int isbit_shift;
7313 unsigned int outmax;
7314
7315 double gamma_correction; /* Overall correction required. */
7316 double file_inverse; /* Inverse of file gamma. */
7317 double screen_gamma;
7318 double screen_inverse; /* Inverse of screen gamma. */
7319
7320 double background_red; /* Linear background value, red or gray. */
7321 double background_green;
7322 double background_blue;
7323
7324 double maxabs;
7325 double maxpc;
7326 double maxcalc;
7327 double maxout;
7328 double maxout_total; /* Total including quantization error */
7329 double outlog;
7330 int outquant;
7331}
7332validate_info;
7333
7334static void
7335init_validate_info(validate_info *vi, gamma_display *dp, png_struct *pp,
7336 int in_depth, int out_depth)
7337{
7338 PNG_CONST unsigned int outmax = (1U<<out_depth)-1;
7339
7340 vi->pp = pp;
7341 vi->dp = dp;
7342
7343 if (dp->sbit > 0 && dp->sbit < in_depth)
7344 {
7345 vi->sbit = dp->sbit;
7346 vi->isbit_shift = in_depth - dp->sbit;
7347 }
7348
7349 else
7350 {
7351 vi->sbit = (png_byte)in_depth;
7352 vi->isbit_shift = 0;
7353 }
7354
7355 vi->sbit_max = (1U << vi->sbit)-1;
7356
7357 /* This mimics the libpng threshold test, '0' is used to prevent gamma
7358 * correction in the validation test.
7359 */
7360 vi->screen_gamma = dp->screen_gamma;
7361 if (fabs(vi->screen_gamma-1) < PNG_GAMMA_THRESHOLD)
7362 vi->screen_gamma = vi->screen_inverse = 0;
7363 else
7364 vi->screen_inverse = 1/vi->screen_gamma;
7365
7366 vi->use_input_precision = dp->use_input_precision;
7367 vi->outmax = outmax;
7368 vi->maxabs = abserr(dp->pm, in_depth, out_depth);
7369 vi->maxpc = pcerr(dp->pm, in_depth, out_depth);
7370 vi->maxcalc = calcerr(dp->pm, in_depth, out_depth);
7371 vi->maxout = outerr(dp->pm, in_depth, out_depth);
7372 vi->outquant = output_quantization_factor(dp->pm, in_depth, out_depth);
7373 vi->maxout_total = vi->maxout + vi->outquant * .5;
7374 vi->outlog = outlog(dp->pm, in_depth, out_depth);
7375
7376 if ((dp->this.colour_type & PNG_COLOR_MASK_ALPHA) != 0 ||
7377 (dp->this.colour_type == 3 && dp->this.is_transparent))
7378 {
7379 vi->do_background = dp->do_background;
7380
7381 if (vi->do_background != 0)
7382 {
7383 PNG_CONST double bg_inverse = 1/dp->background_gamma;
7384 double r, g, b;
7385
7386 /* Caller must at least put the gray value into the red channel */
7387 r = dp->background_color.red; r /= outmax;
7388 g = dp->background_color.green; g /= outmax;
7389 b = dp->background_color.blue; b /= outmax;
7390
7391# if 0
7392 /* libpng doesn't do this optimization, if we do pngvalid will fail.
7393 */
7394 if (fabs(bg_inverse-1) >= PNG_GAMMA_THRESHOLD)
7395# endif
7396 {
7397 r = pow(r, bg_inverse);
7398 g = pow(g, bg_inverse);
7399 b = pow(b, bg_inverse);
7400 }
7401
7402 vi->background_red = r;
7403 vi->background_green = g;
7404 vi->background_blue = b;
7405 }
7406 }
7407 else
7408 vi->do_background = 0;
7409
7410 if (vi->do_background == 0)
7411 vi->background_red = vi->background_green = vi->background_blue = 0;
7412
7413 vi->gamma_correction = 1/(dp->file_gamma*dp->screen_gamma);
7414 if (fabs(vi->gamma_correction-1) < PNG_GAMMA_THRESHOLD)
7415 vi->gamma_correction = 0;
7416
7417 vi->file_inverse = 1/dp->file_gamma;
7418 if (fabs(vi->file_inverse-1) < PNG_GAMMA_THRESHOLD)
7419 vi->file_inverse = 0;
7420
7421 vi->scale16 = dp->scale16;
7422}
7423
7424/* This function handles composition of a single non-alpha component. The
7425 * argument is the input sample value, in the range 0..1, and the alpha value.
7426 * The result is the composed, linear, input sample. If alpha is less than zero
7427 * this is the alpha component and the function should not be called!
7428 */
7429static double
7430gamma_component_compose(int do_background, double input_sample, double alpha,
7431 double background, int *compose)
7432{
7433 switch (do_background)
7434 {
7435 case PNG_BACKGROUND_GAMMA_SCREEN:
7436 case PNG_BACKGROUND_GAMMA_FILE:
7437 case PNG_BACKGROUND_GAMMA_UNIQUE:
7438 /* Standard PNG background processing. */
7439 if (alpha < 1)
7440 {
7441 if (alpha > 0)
7442 {
7443 input_sample = input_sample * alpha + background * (1-alpha);
7444 if (compose != NULL)
7445 *compose = 1;
7446 }
7447
7448 else
7449 input_sample = background;
7450 }
7451 break;
7452
7453#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7454 case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:
7455 case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
7456 /* The components are premultiplied in either case and the output is
7457 * gamma encoded (to get standard Porter-Duff we expect the output
7458 * gamma to be set to 1.0!)
7459 */
7460 case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
7461 /* The optimization is that the partial-alpha entries are linear
7462 * while the opaque pixels are gamma encoded, but this only affects the
7463 * output encoding.
7464 */
7465 if (alpha < 1)
7466 {
7467 if (alpha > 0)
7468 {
7469 input_sample *= alpha;
7470 if (compose != NULL)
7471 *compose = 1;
7472 }
7473
7474 else
7475 input_sample = 0;
7476 }
7477 break;
7478#endif
7479
7480 default:
7481 /* Standard cases where no compositing is done (so the component
7482 * value is already correct.)
7483 */
7484 break;
7485 }
7486
7487 return input_sample;
7488}
7489
7490/* This API returns the encoded *input* component, in the range 0..1 */
7491static double
7492gamma_component_validate(PNG_CONST char *name, PNG_CONST validate_info *vi,
7493 PNG_CONST unsigned int id, PNG_CONST unsigned int od,
7494 PNG_CONST double alpha /* <0 for the alpha channel itself */,
7495 PNG_CONST double background /* component background value */)
7496{
7497 PNG_CONST unsigned int isbit = id >> vi->isbit_shift;
7498 PNG_CONST unsigned int sbit_max = vi->sbit_max;
7499 PNG_CONST unsigned int outmax = vi->outmax;
7500 PNG_CONST int do_background = vi->do_background;
7501
7502 double i;
7503
7504 /* First check on the 'perfect' result obtained from the digitized input
7505 * value, id, and compare this against the actual digitized result, 'od'.
7506 * 'i' is the input result in the range 0..1:
7507 */
7508 i = isbit; i /= sbit_max;
7509
7510 /* Check for the fast route: if we don't do any background composition or if
7511 * this is the alpha channel ('alpha' < 0) or if the pixel is opaque then
7512 * just use the gamma_correction field to correct to the final output gamma.
7513 */
7514 if (alpha == 1 /* opaque pixel component */ || !do_background
7515#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7516 || do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_PNG
7517#endif
7518 || (alpha < 0 /* alpha channel */
7519#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7520 && do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN
7521#endif
7522 ))
7523 {
7524 /* Then get the gamma corrected version of 'i' and compare to 'od', any
7525 * error less than .5 is insignificant - just quantization of the output
7526 * value to the nearest digital value (nevertheless the error is still
7527 * recorded - it's interesting ;-)
7528 */
7529 double encoded_sample = i;
7530 double encoded_error;
7531
7532 /* alpha less than 0 indicates the alpha channel, which is always linear
7533 */
7534 if (alpha >= 0 && vi->gamma_correction > 0)
7535 encoded_sample = pow(encoded_sample, vi->gamma_correction);
7536 encoded_sample *= outmax;
7537
7538 encoded_error = fabs(od-encoded_sample);
7539
7540 if (encoded_error > vi->dp->maxerrout)
7541 vi->dp->maxerrout = encoded_error;
7542
7543 if (encoded_error < vi->maxout_total && encoded_error < vi->outlog)
7544 return i;
7545 }
7546
7547 /* The slow route - attempt to do linear calculations. */
7548 /* There may be an error, or background processing is required, so calculate
7549 * the actual sample values - unencoded light intensity values. Note that in
7550 * practice these are not completely unencoded because they include a
7551 * 'viewing correction' to decrease or (normally) increase the perceptual
7552 * contrast of the image. There's nothing we can do about this - we don't
7553 * know what it is - so assume the unencoded value is perceptually linear.
7554 */
7555 {
7556 double input_sample = i; /* In range 0..1 */
7557 double output, error, encoded_sample, encoded_error;
7558 double es_lo, es_hi;
7559 int compose = 0; /* Set to one if composition done */
7560 int output_is_encoded; /* Set if encoded to screen gamma */
7561 int log_max_error = 1; /* Check maximum error values */
7562 png_const_charp pass = 0; /* Reason test passes (or 0 for fail) */
7563
7564 /* Convert to linear light (with the above caveat.) The alpha channel is
7565 * already linear.
7566 */
7567 if (alpha >= 0)
7568 {
7569 int tcompose;
7570
7571 if (vi->file_inverse > 0)
7572 input_sample = pow(input_sample, vi->file_inverse);
7573
7574 /* Handle the compose processing: */
7575 tcompose = 0;
7576 input_sample = gamma_component_compose(do_background, input_sample,
7577 alpha, background, &tcompose);
7578
7579 if (tcompose)
7580 compose = 1;
7581 }
7582
7583 /* And similarly for the output value, but we need to check the background
7584 * handling to linearize it correctly.
7585 */
7586 output = od;
7587 output /= outmax;
7588
7589 output_is_encoded = vi->screen_gamma > 0;
7590
7591 if (alpha < 0) /* The alpha channel */
7592 {
7593#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7594 if (do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN)
7595#endif
7596 {
7597 /* In all other cases the output alpha channel is linear already,
7598 * don't log errors here, they are much larger in linear data.
7599 */
7600 output_is_encoded = 0;
7601 log_max_error = 0;
7602 }
7603 }
7604
7605#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7606 else /* A component */
7607 {
7608 if (do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED &&
7609 alpha < 1) /* the optimized case - linear output */
7610 {
7611 if (alpha > 0) log_max_error = 0;
7612 output_is_encoded = 0;
7613 }
7614 }
7615#endif
7616
7617 if (output_is_encoded)
7618 output = pow(output, vi->screen_gamma);
7619
7620 /* Calculate (or recalculate) the encoded_sample value and repeat the
7621 * check above (unnecessary if we took the fast route, but harmless.)
7622 */
7623 encoded_sample = input_sample;
7624 if (output_is_encoded)
7625 encoded_sample = pow(encoded_sample, vi->screen_inverse);
7626 encoded_sample *= outmax;
7627
7628 encoded_error = fabs(od-encoded_sample);
7629
7630 /* Don't log errors in the alpha channel, or the 'optimized' case,
7631 * neither are significant to the overall perception.
7632 */
7633 if (log_max_error && encoded_error > vi->dp->maxerrout)
7634 vi->dp->maxerrout = encoded_error;
7635
7636 if (encoded_error < vi->maxout_total)
7637 {
7638 if (encoded_error < vi->outlog)
7639 return i;
7640
7641 /* Test passed but error is bigger than the log limit, record why the
7642 * test passed:
7643 */
7644 pass = "less than maxout:\n";
7645 }
7646
7647 /* i: the original input value in the range 0..1
7648 *
7649 * pngvalid calculations:
7650 * input_sample: linear result; i linearized and composed, range 0..1
7651 * encoded_sample: encoded result; input_sample scaled to ouput bit depth
7652 *
7653 * libpng calculations:
7654 * output: linear result; od scaled to 0..1 and linearized
7655 * od: encoded result from libpng
7656 */
7657
7658 /* Now we have the numbers for real errors, both absolute values as as a
7659 * percentage of the correct value (output):
7660 */
7661 error = fabs(input_sample-output);
7662
7663 if (log_max_error && error > vi->dp->maxerrabs)
7664 vi->dp->maxerrabs = error;
7665
7666 /* The following is an attempt to ignore the tendency of quantization to
7667 * dominate the percentage errors for lower result values:
7668 */
7669 if (log_max_error && input_sample > .5)
7670 {
7671 double percentage_error = error/input_sample;
7672 if (percentage_error > vi->dp->maxerrpc)
7673 vi->dp->maxerrpc = percentage_error;
7674 }
7675
7676 /* Now calculate the digitization limits for 'encoded_sample' using the
7677 * 'max' values. Note that maxout is in the encoded space but maxpc and
7678 * maxabs are in linear light space.
7679 *
7680 * First find the maximum error in linear light space, range 0..1:
7681 */
7682 {
7683 double tmp = input_sample * vi->maxpc;
7684 if (tmp < vi->maxabs) tmp = vi->maxabs;
7685 /* If 'compose' is true the composition was done in linear space using
7686 * integer arithmetic. This introduces an extra error of +/- 0.5 (at
7687 * least) in the integer space used. 'maxcalc' records this, taking
7688 * into account the possibility that even for 16 bit output 8 bit space
7689 * may have been used.
7690 */
7691 if (compose && tmp < vi->maxcalc) tmp = vi->maxcalc;
7692
7693 /* The 'maxout' value refers to the encoded result, to compare with
7694 * this encode input_sample adjusted by the maximum error (tmp) above.
7695 */
7696 es_lo = encoded_sample - vi->maxout;
7697
7698 if (es_lo > 0 && input_sample-tmp > 0)
7699 {
7700 double low_value = input_sample-tmp;
7701 if (output_is_encoded)
7702 low_value = pow(low_value, vi->screen_inverse);
7703 low_value *= outmax;
7704 if (low_value < es_lo) es_lo = low_value;
7705
7706 /* Quantize this appropriately: */
7707 es_lo = ceil(es_lo / vi->outquant - .5) * vi->outquant;
7708 }
7709
7710 else
7711 es_lo = 0;
7712
7713 es_hi = encoded_sample + vi->maxout;
7714
7715 if (es_hi < outmax && input_sample+tmp < 1)
7716 {
7717 double high_value = input_sample+tmp;
7718 if (output_is_encoded)
7719 high_value = pow(high_value, vi->screen_inverse);
7720 high_value *= outmax;
7721 if (high_value > es_hi) es_hi = high_value;
7722
7723 es_hi = floor(es_hi / vi->outquant + .5) * vi->outquant;
7724 }
7725
7726 else
7727 es_hi = outmax;
7728 }
7729
7730 /* The primary test is that the final encoded value returned by the
7731 * library should be between the two limits (inclusive) that were
7732 * calculated above.
7733 */
7734 if (od >= es_lo && od <= es_hi)
7735 {
7736 /* The value passes, but we may need to log the information anyway. */
7737 if (encoded_error < vi->outlog)
7738 return i;
7739
7740 if (pass == 0)
7741 pass = "within digitization limits:\n";
7742 }
7743
7744 {
7745 /* There has been an error in processing, or we need to log this
7746 * value.
7747 */
7748 double is_lo, is_hi;
7749
7750 /* pass is set at this point if either of the tests above would have
7751 * passed. Don't do these additional tests here - just log the
7752 * original [es_lo..es_hi] values.
7753 */
7754 if (pass == 0 && vi->use_input_precision)
7755 {
7756 /* Ok, something is wrong - this actually happens in current libpng
7757 * 16-to-8 processing. Assume that the input value (id, adjusted
7758 * for sbit) can be anywhere between value-.5 and value+.5 - quite a
7759 * large range if sbit is low.
7760 */
7761 double tmp = (isbit - .5)/sbit_max;
7762
7763 if (tmp <= 0)
7764 tmp = 0;
7765
7766 else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)
7767 tmp = pow(tmp, vi->file_inverse);
7768
7769 tmp = gamma_component_compose(do_background, tmp, alpha, background,
7770 NULL);
7771
7772 if (output_is_encoded && tmp > 0 && tmp < 1)
7773 tmp = pow(tmp, vi->screen_inverse);
7774
7775 is_lo = ceil(outmax * tmp - vi->maxout_total);
7776
7777 if (is_lo < 0)
7778 is_lo = 0;
7779
7780 tmp = (isbit + .5)/sbit_max;
7781
7782 if (tmp <= 0)
7783 tmp = 0;
7784
7785 else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)
7786 tmp = pow(tmp, vi->file_inverse);
7787
7788 tmp = gamma_component_compose(do_background, tmp, alpha, background,
7789 NULL);
7790
7791 if (output_is_encoded && tmp > 0 && tmp < 1)
7792 tmp = pow(tmp, vi->screen_inverse);
7793
7794 is_hi = floor(outmax * tmp + vi->maxout_total);
7795
7796 if (is_hi > outmax)
7797 is_hi = outmax;
7798
7799 if (!(od < is_lo || od > is_hi))
7800 {
7801 if (encoded_error < vi->outlog)
7802 return i;
7803
7804 pass = "within input precision limits:\n";
7805 }
7806
7807 /* One last chance. If this is an alpha channel and the 16to8
7808 * option has been used and 'inaccurate' scaling is used then the
7809 * bit reduction is obtained by simply using the top 8 bits of the
7810 * value.
7811 *
7812 * This is only done for older libpng versions when the 'inaccurate'
7813 * (chop) method of scaling was used.
7814 */
7815# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
7816# if PNG_LIBPNG_VER < 10504
7817 /* This may be required for other components in the future,
7818 * but at present the presence of gamma correction effectively
7819 * prevents the errors in the component scaling (I don't quite
7820 * understand why, but since it's better this way I care not
7821 * to ask, JB 20110419.)
7822 */
7823 if (pass == 0 && alpha < 0 && vi->scale16 && vi->sbit > 8 &&
7824 vi->sbit + vi->isbit_shift == 16)
7825 {
7826 tmp = ((id >> 8) - .5)/255;
7827
7828 if (tmp > 0)
7829 {
7830 is_lo = ceil(outmax * tmp - vi->maxout_total);
7831 if (is_lo < 0) is_lo = 0;
7832 }
7833
7834 else
7835 is_lo = 0;
7836
7837 tmp = ((id >> 8) + .5)/255;
7838
7839 if (tmp < 1)
7840 {
7841 is_hi = floor(outmax * tmp + vi->maxout_total);
7842 if (is_hi > outmax) is_hi = outmax;
7843 }
7844
7845 else
7846 is_hi = outmax;
7847
7848 if (!(od < is_lo || od > is_hi))
7849 {
7850 if (encoded_error < vi->outlog)
7851 return i;
7852
7853 pass = "within 8 bit limits:\n";
7854 }
7855 }
7856# endif
7857# endif
7858 }
7859 else /* !use_input_precision */
7860 is_lo = es_lo, is_hi = es_hi;
7861
7862 /* Attempt to output a meaningful error/warning message: the message
7863 * output depends on the background/composite operation being performed
7864 * because this changes what parameters were actually used above.
7865 */
7866 {
7867 size_t pos = 0;
7868 /* Need either 1/255 or 1/65535 precision here; 3 or 6 decimal
7869 * places. Just use outmax to work out which.
7870 */
7871 int precision = (outmax >= 1000 ? 6 : 3);
7872 int use_input=1, use_background=0, do_compose=0;
7873 char msg[256];
7874
7875 if (pass != 0)
7876 pos = safecat(msg, sizeof msg, pos, "\n\t");
7877
7878 /* Set up the various flags, the output_is_encoded flag above
7879 * is also used below. do_compose is just a double check.
7880 */
7881 switch (do_background)
7882 {
7883 case PNG_BACKGROUND_GAMMA_SCREEN:
7884 case PNG_BACKGROUND_GAMMA_FILE:
7885 case PNG_BACKGROUND_GAMMA_UNIQUE:
7886 use_background = (alpha >= 0 && alpha < 1);
7887 /*FALL THROUGH*/
7888# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
7889 case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:
7890 case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
7891 case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
7892# endif /* ALPHA_MODE_SUPPORTED */
7893 do_compose = (alpha > 0 && alpha < 1);
7894 use_input = (alpha != 0);
7895 break;
7896
7897 default:
7898 break;
7899 }
7900
7901 /* Check the 'compose' flag */
7902 if (compose != do_compose)
7903 png_error(vi->pp, "internal error (compose)");
7904
7905 /* 'name' is the component name */
7906 pos = safecat(msg, sizeof msg, pos, name);
7907 pos = safecat(msg, sizeof msg, pos, "(");
7908 pos = safecatn(msg, sizeof msg, pos, id);
7909 if (use_input || pass != 0/*logging*/)
7910 {
7911 if (isbit != id)
7912 {
7913 /* sBIT has reduced the precision of the input: */
7914 pos = safecat(msg, sizeof msg, pos, ", sbit(");
7915 pos = safecatn(msg, sizeof msg, pos, vi->sbit);
7916 pos = safecat(msg, sizeof msg, pos, "): ");
7917 pos = safecatn(msg, sizeof msg, pos, isbit);
7918 }
7919 pos = safecat(msg, sizeof msg, pos, "/");
7920 /* The output is either "id/max" or "id sbit(sbit): isbit/max" */
7921 pos = safecatn(msg, sizeof msg, pos, vi->sbit_max);
7922 }
7923 pos = safecat(msg, sizeof msg, pos, ")");
7924
7925 /* A component may have been multiplied (in linear space) by the
7926 * alpha value, 'compose' says whether this is relevant.
7927 */
7928 if (compose || pass != 0)
7929 {
7930 /* If any form of composition is being done report our
7931 * calculated linear value here (the code above doesn't record
7932 * the input value before composition is performed, so what
7933 * gets reported is the value after composition.)
7934 */
7935 if (use_input || pass != 0)
7936 {
7937 if (vi->file_inverse > 0)
7938 {
7939 pos = safecat(msg, sizeof msg, pos, "^");
7940 pos = safecatd(msg, sizeof msg, pos, vi->file_inverse, 2);
7941 }
7942
7943 else
7944 pos = safecat(msg, sizeof msg, pos, "[linear]");
7945
7946 pos = safecat(msg, sizeof msg, pos, "*(alpha)");
7947 pos = safecatd(msg, sizeof msg, pos, alpha, precision);
7948 }
7949
7950 /* Now record the *linear* background value if it was used
7951 * (this function is not passed the original, non-linear,
7952 * value but it is contained in the test name.)
7953 */
7954 if (use_background)
7955 {
7956 pos = safecat(msg, sizeof msg, pos, use_input ? "+" : " ");
7957 pos = safecat(msg, sizeof msg, pos, "(background)");
7958 pos = safecatd(msg, sizeof msg, pos, background, precision);
7959 pos = safecat(msg, sizeof msg, pos, "*");
7960 pos = safecatd(msg, sizeof msg, pos, 1-alpha, precision);
7961 }
7962 }
7963
7964 /* Report the calculated value (input_sample) and the linearized
7965 * libpng value (output) unless this is just a component gamma
7966 * correction.
7967 */
7968 if (compose || alpha < 0 || pass != 0)
7969 {
7970 pos = safecat(msg, sizeof msg, pos,
7971 pass != 0 ? " =\n\t" : " = ");
7972 pos = safecatd(msg, sizeof msg, pos, input_sample, precision);
7973 pos = safecat(msg, sizeof msg, pos, " (libpng: ");
7974 pos = safecatd(msg, sizeof msg, pos, output, precision);
7975 pos = safecat(msg, sizeof msg, pos, ")");
7976
7977 /* Finally report the output gamma encoding, if any. */
7978 if (output_is_encoded)
7979 {
7980 pos = safecat(msg, sizeof msg, pos, " ^");
7981 pos = safecatd(msg, sizeof msg, pos, vi->screen_inverse, 2);
7982 pos = safecat(msg, sizeof msg, pos, "(to screen) =");
7983 }
7984
7985 else
7986 pos = safecat(msg, sizeof msg, pos, " [screen is linear] =");
7987 }
7988
7989 if ((!compose && alpha >= 0) || pass != 0)
7990 {
7991 if (pass != 0) /* logging */
7992 pos = safecat(msg, sizeof msg, pos, "\n\t[overall:");
7993
7994 /* This is the non-composition case, the internal linear
7995 * values are irrelevant (though the log below will reveal
7996 * them.) Output a much shorter warning/error message and report
7997 * the overall gamma correction.
7998 */
7999 if (vi->gamma_correction > 0)
8000 {
8001 pos = safecat(msg, sizeof msg, pos, " ^");
8002 pos = safecatd(msg, sizeof msg, pos, vi->gamma_correction, 2);
8003 pos = safecat(msg, sizeof msg, pos, "(gamma correction) =");
8004 }
8005
8006 else
8007 pos = safecat(msg, sizeof msg, pos,
8008 " [no gamma correction] =");
8009
8010 if (pass != 0)
8011 pos = safecat(msg, sizeof msg, pos, "]");
8012 }
8013
8014 /* This is our calculated encoded_sample which should (but does
8015 * not) match od:
8016 */
8017 pos = safecat(msg, sizeof msg, pos, pass != 0 ? "\n\t" : " ");
8018 pos = safecatd(msg, sizeof msg, pos, is_lo, 1);
8019 pos = safecat(msg, sizeof msg, pos, " < ");
8020 pos = safecatd(msg, sizeof msg, pos, encoded_sample, 1);
8021 pos = safecat(msg, sizeof msg, pos, " (libpng: ");
8022 pos = safecatn(msg, sizeof msg, pos, od);
8023 pos = safecat(msg, sizeof msg, pos, ")");
8024 pos = safecat(msg, sizeof msg, pos, "/");
8025 pos = safecatn(msg, sizeof msg, pos, outmax);
8026 pos = safecat(msg, sizeof msg, pos, " < ");
8027 pos = safecatd(msg, sizeof msg, pos, is_hi, 1);
8028
8029 if (pass == 0) /* The error condition */
8030 {
8031# ifdef PNG_WARNINGS_SUPPORTED
8032 png_warning(vi->pp, msg);
8033# else
8034 store_warning(vi->pp, msg);
8035# endif
8036 }
8037
8038 else /* logging this value */
8039 store_verbose(&vi->dp->pm->this, vi->pp, pass, msg);
8040 }
8041 }
8042 }
8043
8044 return i;
8045}
8046
8047static void
8048gamma_image_validate(gamma_display *dp, png_structp pp, png_infop pi)
8049{
8050 /* Get some constants derived from the input and output file formats: */
8051 PNG_CONST png_store* PNG_CONST ps = dp->this.ps;
8052 PNG_CONST png_byte in_ct = dp->this.colour_type;
8053 PNG_CONST png_byte in_bd = dp->this.bit_depth;
8054 PNG_CONST png_uint_32 w = dp->this.w;
8055 PNG_CONST png_uint_32 h = dp->this.h;
8056 PNG_CONST size_t cbRow = dp->this.cbRow;
8057 PNG_CONST png_byte out_ct = png_get_color_type(pp, pi);
8058 PNG_CONST png_byte out_bd = png_get_bit_depth(pp, pi);
8059
8060 /* There are three sources of error, firstly the quantization in the
8061 * file encoding, determined by sbit and/or the file depth, secondly
8062 * the output (screen) gamma and thirdly the output file encoding.
8063 *
8064 * Since this API receives the screen and file gamma in double
8065 * precision it is possible to calculate an exact answer given an input
8066 * pixel value. Therefore we assume that the *input* value is exact -
8067 * sample/maxsample - calculate the corresponding gamma corrected
8068 * output to the limits of double precision arithmetic and compare with
8069 * what libpng returns.
8070 *
8071 * Since the library must quantize the output to 8 or 16 bits there is
8072 * a fundamental limit on the accuracy of the output of +/-.5 - this
8073 * quantization limit is included in addition to the other limits
8074 * specified by the paramaters to the API. (Effectively, add .5
8075 * everywhere.)
8076 *
8077 * The behavior of the 'sbit' paramter is defined by section 12.5
8078 * (sample depth scaling) of the PNG spec. That section forces the
8079 * decoder to assume that the PNG values have been scaled if sBIT is
8080 * present:
8081 *
8082 * png-sample = floor( input-sample * (max-out/max-in) + .5);
8083 *
8084 * This means that only a subset of the possible PNG values should
8085 * appear in the input. However, the spec allows the encoder to use a
8086 * variety of approximations to the above and doesn't require any
8087 * restriction of the values produced.
8088 *
8089 * Nevertheless the spec requires that the upper 'sBIT' bits of the
8090 * value stored in a PNG file be the original sample bits.
8091 * Consequently the code below simply scales the top sbit bits by
8092 * (1<<sbit)-1 to obtain an original sample value.
8093 *
8094 * Because there is limited precision in the input it is arguable that
8095 * an acceptable result is any valid result from input-.5 to input+.5.
8096 * The basic tests below do not do this, however if 'use_input_precision'
8097 * is set a subsequent test is performed below.
8098 */
8099 PNG_CONST unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U;
8100 int processing;
8101 png_uint_32 y;
8102 PNG_CONST store_palette_entry *in_palette = dp->this.palette;
8103 PNG_CONST int in_is_transparent = dp->this.is_transparent;
8104 int out_npalette = -1;
8105 int out_is_transparent = 0; /* Just refers to the palette case */
8106 store_palette out_palette;
8107 validate_info vi;
8108
8109 /* Check for row overwrite errors */
8110 store_image_check(dp->this.ps, pp, 0);
8111
8112 /* Supply the input and output sample depths here - 8 for an indexed image,
8113 * otherwise the bit depth.
8114 */
8115 init_validate_info(&vi, dp, pp, in_ct==3?8:in_bd, out_ct==3?8:out_bd);
8116
8117 processing = (vi.gamma_correction > 0 && !dp->threshold_test)
8118 || in_bd != out_bd || in_ct != out_ct || vi.do_background;
8119
8120 /* TODO: FIX THIS: MAJOR BUG! If the transformations all happen inside
8121 * the palette there is no way of finding out, because libpng fails to
8122 * update the palette on png_read_update_info. Indeed, libpng doesn't
8123 * even do the required work until much later, when it doesn't have any
8124 * info pointer. Oops. For the moment 'processing' is turned off if
8125 * out_ct is palette.
8126 */
8127 if (in_ct == 3 && out_ct == 3)
8128 processing = 0;
8129
8130 if (processing && out_ct == 3)
8131 out_is_transparent = read_palette(out_palette, &out_npalette, pp, pi);
8132
8133 for (y=0; y<h; ++y)
8134 {
8135 png_const_bytep pRow = store_image_row(ps, pp, 0, y);
8136 png_byte std[STANDARD_ROWMAX];
8137
8138 transform_row(pp, std, in_ct, in_bd, y);
8139
8140 if (processing)
8141 {
8142 unsigned int x;
8143
8144 for (x=0; x<w; ++x)
8145 {
8146 double alpha = 1; /* serves as a flag value */
8147
8148 /* Record the palette index for index images. */
8149 PNG_CONST unsigned int in_index =
8150 in_ct == 3 ? sample(std, 3, in_bd, x, 0) : 256;
8151 PNG_CONST unsigned int out_index =
8152 out_ct == 3 ? sample(std, 3, out_bd, x, 0) : 256;
8153
8154 /* Handle input alpha - png_set_background will cause the output
8155 * alpha to disappear so there is nothing to check.
8156 */
8157 if ((in_ct & PNG_COLOR_MASK_ALPHA) != 0 || (in_ct == 3 &&
8158 in_is_transparent))
8159 {
8160 PNG_CONST unsigned int input_alpha = in_ct == 3 ?
8161 dp->this.palette[in_index].alpha :
8162 sample(std, in_ct, in_bd, x, samples_per_pixel);
8163
8164 unsigned int output_alpha = 65536 /* as a flag value */;
8165
8166 if (out_ct == 3)
8167 {
8168 if (out_is_transparent)
8169 output_alpha = out_palette[out_index].alpha;
8170 }
8171
8172 else if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0)
8173 output_alpha = sample(pRow, out_ct, out_bd, x,
8174 samples_per_pixel);
8175
8176 if (output_alpha != 65536)
8177 alpha = gamma_component_validate("alpha", &vi, input_alpha,
8178 output_alpha, -1/*alpha*/, 0/*background*/);
8179
8180 else /* no alpha in output */
8181 {
8182 /* This is a copy of the calculation of 'i' above in order to
8183 * have the alpha value to use in the background calculation.
8184 */
8185 alpha = input_alpha >> vi.isbit_shift;
8186 alpha /= vi.sbit_max;
8187 }
8188 }
8189
8190 /* Handle grayscale or RGB components. */
8191 if ((in_ct & PNG_COLOR_MASK_COLOR) == 0) /* grayscale */
8192 (void)gamma_component_validate("gray", &vi,
8193 sample(std, in_ct, in_bd, x, 0),
8194 sample(pRow, out_ct, out_bd, x, 0), alpha/*component*/,
8195 vi.background_red);
8196 else /* RGB or palette */
8197 {
8198 (void)gamma_component_validate("red", &vi,
8199 in_ct == 3 ? in_palette[in_index].red :
8200 sample(std, in_ct, in_bd, x, 0),
8201 out_ct == 3 ? out_palette[out_index].red :
8202 sample(pRow, out_ct, out_bd, x, 0),
8203 alpha/*component*/, vi.background_red);
8204
8205 (void)gamma_component_validate("green", &vi,
8206 in_ct == 3 ? in_palette[in_index].green :
8207 sample(std, in_ct, in_bd, x, 1),
8208 out_ct == 3 ? out_palette[out_index].green :
8209 sample(pRow, out_ct, out_bd, x, 1),
8210 alpha/*component*/, vi.background_green);
8211
8212 (void)gamma_component_validate("blue", &vi,
8213 in_ct == 3 ? in_palette[in_index].blue :
8214 sample(std, in_ct, in_bd, x, 2),
8215 out_ct == 3 ? out_palette[out_index].blue :
8216 sample(pRow, out_ct, out_bd, x, 2),
8217 alpha/*component*/, vi.background_blue);
8218 }
8219 }
8220 }
8221
8222 else if (memcmp(std, pRow, cbRow) != 0)
8223 {
8224 char msg[64];
8225
8226 /* No transform is expected on the threshold tests. */
8227 sprintf(msg, "gamma: below threshold row %d changed", y);
8228
8229 png_error(pp, msg);
8230 }
8231 } /* row (y) loop */
8232
8233 dp->this.ps->validated = 1;
8234}
8235
8236static void
8237gamma_end(png_structp pp, png_infop pi)
8238{
8239 gamma_display *dp = voidcast(gamma_display*, png_get_progressive_ptr(pp));
8240
8241 if (!dp->this.speed)
8242 gamma_image_validate(dp, pp, pi);
8243 else
8244 dp->this.ps->validated = 1;
8245}
8246
8247/* A single test run checking a gamma transformation.
8248 *
8249 * maxabs: maximum absolute error as a fraction
8250 * maxout: maximum output error in the output units
8251 * maxpc: maximum percentage error (as a percentage)
8252 */
8253static void
8254gamma_test(png_modifier *pmIn, PNG_CONST png_byte colour_typeIn,
8255 PNG_CONST png_byte bit_depthIn, PNG_CONST int palette_numberIn,
8256 PNG_CONST int interlace_typeIn,
8257 PNG_CONST double file_gammaIn, PNG_CONST double screen_gammaIn,
8258 PNG_CONST png_byte sbitIn, PNG_CONST int threshold_testIn,
8259 PNG_CONST char *name,
8260 PNG_CONST int use_input_precisionIn, PNG_CONST int scale16In,
8261 PNG_CONST int expand16In, PNG_CONST int do_backgroundIn,
8262 PNG_CONST png_color_16 *bkgd_colorIn, double bkgd_gammaIn)
8263{
8264 gamma_display d;
8265 context(&pmIn->this, fault);
8266
8267 gamma_display_init(&d, pmIn, FILEID(colour_typeIn, bit_depthIn,
8268 palette_numberIn, interlace_typeIn, 0, 0, 0),
8269 file_gammaIn, screen_gammaIn, sbitIn,
8270 threshold_testIn, use_input_precisionIn, scale16In,
8271 expand16In, do_backgroundIn, bkgd_colorIn, bkgd_gammaIn);
8272
8273 Try
8274 {
8275 png_structp pp;
8276 png_infop pi;
8277 gama_modification gama_mod;
8278 srgb_modification srgb_mod;
8279 sbit_modification sbit_mod;
8280
8281 /* For the moment don't use the png_modifier support here. */
8282 d.pm->encoding_counter = 0;
8283 modifier_set_encoding(d.pm); /* Just resets everything */
8284 d.pm->current_gamma = d.file_gamma;
8285
8286 /* Make an appropriate modifier to set the PNG file gamma to the
8287 * given gamma value and the sBIT chunk to the given precision.
8288 */
8289 d.pm->modifications = NULL;
8290 gama_modification_init(&gama_mod, d.pm, d.file_gamma);
8291 srgb_modification_init(&srgb_mod, d.pm, 127 /*delete*/);
8292 if (d.sbit > 0)
8293 sbit_modification_init(&sbit_mod, d.pm, d.sbit);
8294
8295 modification_reset(d.pm->modifications);
8296
8297 /* Get a png_struct for writing the image. */
8298 pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);
8299 standard_palette_init(&d.this);
8300
8301 /* Introduce the correct read function. */
8302 if (d.pm->this.progressive)
8303 {
8304 /* Share the row function with the standard implementation. */
8305 png_set_progressive_read_fn(pp, &d, gamma_info, progressive_row,
8306 gamma_end);
8307
8308 /* Now feed data into the reader until we reach the end: */
8309 modifier_progressive_read(d.pm, pp, pi);
8310 }
8311 else
8312 {
8313 /* modifier_read expects a png_modifier* */
8314 png_set_read_fn(pp, d.pm, modifier_read);
8315
8316 /* Check the header values: */
8317 png_read_info(pp, pi);
8318
8319 /* Process the 'info' requirements. Only one image is generated */
8320 gamma_info_imp(&d, pp, pi);
8321
8322 sequential_row(&d.this, pp, pi, -1, 0);
8323
8324 if (!d.this.speed)
8325 gamma_image_validate(&d, pp, pi);
8326 else
8327 d.this.ps->validated = 1;
8328 }
8329
8330 modifier_reset(d.pm);
8331
8332 if (d.pm->log && !d.threshold_test && !d.this.speed)
8333 fprintf(stderr, "%d bit %s %s: max error %f (%.2g, %2g%%)\n",
8334 d.this.bit_depth, colour_types[d.this.colour_type], name,
8335 d.maxerrout, d.maxerrabs, 100*d.maxerrpc);
8336
8337 /* Log the summary values too. */
8338 if (d.this.colour_type == 0 || d.this.colour_type == 4)
8339 {
8340 switch (d.this.bit_depth)
8341 {
8342 case 1:
8343 break;
8344
8345 case 2:
8346 if (d.maxerrout > d.pm->error_gray_2)
8347 d.pm->error_gray_2 = d.maxerrout;
8348
8349 break;
8350
8351 case 4:
8352 if (d.maxerrout > d.pm->error_gray_4)
8353 d.pm->error_gray_4 = d.maxerrout;
8354
8355 break;
8356
8357 case 8:
8358 if (d.maxerrout > d.pm->error_gray_8)
8359 d.pm->error_gray_8 = d.maxerrout;
8360
8361 break;
8362
8363 case 16:
8364 if (d.maxerrout > d.pm->error_gray_16)
8365 d.pm->error_gray_16 = d.maxerrout;
8366
8367 break;
8368
8369 default:
8370 png_error(pp, "bad bit depth (internal: 1)");
8371 }
8372 }
8373
8374 else if (d.this.colour_type == 2 || d.this.colour_type == 6)
8375 {
8376 switch (d.this.bit_depth)
8377 {
8378 case 8:
8379
8380 if (d.maxerrout > d.pm->error_color_8)
8381 d.pm->error_color_8 = d.maxerrout;
8382
8383 break;
8384
8385 case 16:
8386
8387 if (d.maxerrout > d.pm->error_color_16)
8388 d.pm->error_color_16 = d.maxerrout;
8389
8390 break;
8391
8392 default:
8393 png_error(pp, "bad bit depth (internal: 2)");
8394 }
8395 }
8396
8397 else if (d.this.colour_type == 3)
8398 {
8399 if (d.maxerrout > d.pm->error_indexed)
8400 d.pm->error_indexed = d.maxerrout;
8401 }
8402 }
8403
8404 Catch(fault)
8405 modifier_reset((png_modifier*)fault);
8406}
8407
8408static void gamma_threshold_test(png_modifier *pm, png_byte colour_type,
8409 png_byte bit_depth, int interlace_type, double file_gamma,
8410 double screen_gamma)
8411{
8412 size_t pos = 0;
8413 char name[64];
8414 pos = safecat(name, sizeof name, pos, "threshold ");
8415 pos = safecatd(name, sizeof name, pos, file_gamma, 3);
8416 pos = safecat(name, sizeof name, pos, "/");
8417 pos = safecatd(name, sizeof name, pos, screen_gamma, 3);
8418
8419 (void)gamma_test(pm, colour_type, bit_depth, 0/*palette*/, interlace_type,
8420 file_gamma, screen_gamma, 0/*sBIT*/, 1/*threshold test*/, name,
8421 0 /*no input precision*/,
8422 0 /*no scale16*/, 0 /*no expand16*/, 0 /*no background*/, 0 /*hence*/,
8423 0 /*no background gamma*/);
8424}
8425
8426static void
8427perform_gamma_threshold_tests(png_modifier *pm)
8428{
8429 png_byte colour_type = 0;
8430 png_byte bit_depth = 0;
8431 int palette_number = 0;
8432
8433 /* Don't test more than one instance of each palette - it's pointless, in
8434 * fact this test is somewhat excessive since libpng doesn't make this
8435 * decision based on colour type or bit depth!
8436 */
8437 while (next_format(&colour_type, &bit_depth, &palette_number))
8438 if (palette_number == 0)
8439 {
8440 double test_gamma = 1.0;
8441 while (test_gamma >= .4)
8442 {
8443 /* There's little point testing the interlacing vs non-interlacing,
8444 * but this can be set from the command line.
8445 */
8446 gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,
8447 test_gamma, 1/test_gamma);
8448 test_gamma *= .95;
8449 }
8450
8451 /* And a special test for sRGB */
8452 gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,
8453 .45455, 2.2);
8454
8455 if (fail(pm))
8456 return;
8457 }
8458}
8459
8460static void gamma_transform_test(png_modifier *pm,
8461 PNG_CONST png_byte colour_type, PNG_CONST png_byte bit_depth,
8462 PNG_CONST int palette_number,
8463 PNG_CONST int interlace_type, PNG_CONST double file_gamma,
8464 PNG_CONST double screen_gamma, PNG_CONST png_byte sbit,
8465 PNG_CONST int use_input_precision, PNG_CONST int scale16)
8466{
8467 size_t pos = 0;
8468 char name[64];
8469
8470 if (sbit != bit_depth && sbit != 0)
8471 {
8472 pos = safecat(name, sizeof name, pos, "sbit(");
8473 pos = safecatn(name, sizeof name, pos, sbit);
8474 pos = safecat(name, sizeof name, pos, ") ");
8475 }
8476
8477 else
8478 pos = safecat(name, sizeof name, pos, "gamma ");
8479
8480 if (scale16)
8481 pos = safecat(name, sizeof name, pos, "16to8 ");
8482
8483 pos = safecatd(name, sizeof name, pos, file_gamma, 3);
8484 pos = safecat(name, sizeof name, pos, "->");
8485 pos = safecatd(name, sizeof name, pos, screen_gamma, 3);
8486
8487 gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,
8488 file_gamma, screen_gamma, sbit, 0, name, use_input_precision,
8489 scale16, pm->test_gamma_expand16, 0 , 0, 0);
8490}
8491
8492static void perform_gamma_transform_tests(png_modifier *pm)
8493{
8494 png_byte colour_type = 0;
8495 png_byte bit_depth = 0;
8496 int palette_number = 0;
8497
8498 while (next_format(&colour_type, &bit_depth, &palette_number))
8499 {
8500 unsigned int i, j;
8501
8502 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
8503 if (i != j)
8504 {
8505 gamma_transform_test(pm, colour_type, bit_depth, palette_number,
8506 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/,
8507 pm->use_input_precision, 0 /*do not scale16*/);
8508
8509 if (fail(pm))
8510 return;
8511 }
8512 }
8513}
8514
8515static void perform_gamma_sbit_tests(png_modifier *pm)
8516{
8517 png_byte sbit;
8518
8519 /* The only interesting cases are colour and grayscale, alpha is ignored here
8520 * for overall speed. Only bit depths where sbit is less than the bit depth
8521 * are tested.
8522 */
8523 for (sbit=pm->sbitlow; sbit<(1<<READ_BDHI); ++sbit)
8524 {
8525 png_byte colour_type, bit_depth;
8526 int npalette;
8527
8528 colour_type = bit_depth = 0;
8529 npalette = 0;
8530
8531 while (next_format(&colour_type, &bit_depth, &npalette))
8532 if ((colour_type & PNG_COLOR_MASK_ALPHA) == 0 &&
8533 ((colour_type == 3 && sbit < 8) ||
8534 (colour_type != 3 && sbit < bit_depth)))
8535 {
8536 unsigned int i;
8537
8538 for (i=0; i<pm->ngamma_tests; ++i)
8539 {
8540 unsigned int j;
8541
8542 for (j=0; j<pm->ngamma_tests; ++j) if (i != j)
8543 {
8544 gamma_transform_test(pm, colour_type, bit_depth, npalette,
8545 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
8546 sbit, pm->use_input_precision_sbit, 0 /*scale16*/);
8547
8548 if (fail(pm))
8549 return;
8550 }
8551 }
8552 }
8553 }
8554}
8555
8556/* Note that this requires a 16 bit source image but produces 8 bit output, so
8557 * we only need the 16bit write support, but the 16 bit images are only
8558 * generated if DO_16BIT is defined.
8559 */
8560#ifdef DO_16BIT
8561static void perform_gamma_scale16_tests(png_modifier *pm)
8562{
8563# ifndef PNG_MAX_GAMMA_8
8564# define PNG_MAX_GAMMA_8 11
8565# endif
8566 /* Include the alpha cases here. Note that sbit matches the internal value
8567 * used by the library - otherwise we will get spurious errors from the
8568 * internal sbit style approximation.
8569 *
8570 * The threshold test is here because otherwise the 16 to 8 conversion will
8571 * proceed *without* gamma correction, and the tests above will fail (but not
8572 * by much) - this could be fixed, it only appears with the -g option.
8573 */
8574 unsigned int i, j;
8575 for (i=0; i<pm->ngamma_tests; ++i)
8576 {
8577 for (j=0; j<pm->ngamma_tests; ++j)
8578 {
8579 if (i != j &&
8580 fabs(pm->gammas[j]/pm->gammas[i]-1) >= PNG_GAMMA_THRESHOLD)
8581 {
8582 gamma_transform_test(pm, 0, 16, 0, pm->interlace_type,
8583 1/pm->gammas[i], pm->gammas[j], PNG_MAX_GAMMA_8,
8584 pm->use_input_precision_16to8, 1 /*scale16*/);
8585
8586 if (fail(pm))
8587 return;
8588
8589 gamma_transform_test(pm, 2, 16, 0, pm->interlace_type,
8590 1/pm->gammas[i], pm->gammas[j], PNG_MAX_GAMMA_8,
8591 pm->use_input_precision_16to8, 1 /*scale16*/);
8592
8593 if (fail(pm))
8594 return;
8595
8596 gamma_transform_test(pm, 4, 16, 0, pm->interlace_type,
8597 1/pm->gammas[i], pm->gammas[j], PNG_MAX_GAMMA_8,
8598 pm->use_input_precision_16to8, 1 /*scale16*/);
8599
8600 if (fail(pm))
8601 return;
8602
8603 gamma_transform_test(pm, 6, 16, 0, pm->interlace_type,
8604 1/pm->gammas[i], pm->gammas[j], PNG_MAX_GAMMA_8,
8605 pm->use_input_precision_16to8, 1 /*scale16*/);
8606
8607 if (fail(pm))
8608 return;
8609 }
8610 }
8611 }
8612}
8613#endif /* 16 to 8 bit conversion */
8614
8615#if defined PNG_READ_BACKGROUND_SUPPORTED ||\
8616 defined PNG_READ_ALPHA_MODE_SUPPORTED
8617static void gamma_composition_test(png_modifier *pm,
8618 PNG_CONST png_byte colour_type, PNG_CONST png_byte bit_depth,
8619 PNG_CONST int palette_number,
8620 PNG_CONST int interlace_type, PNG_CONST double file_gamma,
8621 PNG_CONST double screen_gamma,
8622 PNG_CONST int use_input_precision, PNG_CONST int do_background,
8623 PNG_CONST int expand_16)
8624{
8625 size_t pos = 0;
8626 png_const_charp base;
8627 double bg;
8628 char name[128];
8629 png_color_16 background;
8630
8631 /* Make up a name and get an appropriate background gamma value. */
8632 switch (do_background)
8633 {
8634 default:
8635 base = "";
8636 bg = 4; /* should not be used */
8637 break;
8638 case PNG_BACKGROUND_GAMMA_SCREEN:
8639 base = " bckg(Screen):";
8640 bg = 1/screen_gamma;
8641 break;
8642 case PNG_BACKGROUND_GAMMA_FILE:
8643 base = " bckg(File):";
8644 bg = file_gamma;
8645 break;
8646 case PNG_BACKGROUND_GAMMA_UNIQUE:
8647 base = " bckg(Unique):";
8648 /* This tests the handling of a unique value, the math is such that the
8649 * value tends to be <1, but is neither screen nor file (even if they
8650 * match!)
8651 */
8652 bg = (file_gamma + screen_gamma) / 3;
8653 break;
8654#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
8655 case ALPHA_MODE_OFFSET + PNG_ALPHA_PNG:
8656 base = " alpha(PNG)";
8657 bg = 4; /* should not be used */
8658 break;
8659 case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:
8660 base = " alpha(Porter-Duff)";
8661 bg = 4; /* should not be used */
8662 break;
8663 case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:
8664 base = " alpha(Optimized)";
8665 bg = 4; /* should not be used */
8666 break;
8667 case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:
8668 base = " alpha(Broken)";
8669 bg = 4; /* should not be used */
8670 break;
8671#endif
8672 }
8673
8674 /* Use random background values - the background is always presented in the
8675 * output space (8 or 16 bit components).
8676 */
8677 if (expand_16 || bit_depth == 16)
8678 {
8679 png_uint_32 r = random_32();
8680
8681 background.red = (png_uint_16)r;
8682 background.green = (png_uint_16)(r >> 16);
8683 r = random_32();
8684 background.blue = (png_uint_16)r;
8685 background.gray = (png_uint_16)(r >> 16);
8686 }
8687
8688 else /* 8 bit colors */
8689 {
8690 png_uint_32 r = random_32();
8691
8692 background.red = (png_byte)r;
8693 background.green = (png_byte)(r >> 8);
8694 background.blue = (png_byte)(r >> 16);
8695 background.gray = (png_byte)(r >> 24);
8696 }
8697
8698 background.index = 193; /* rgb(193,193,193) to detect errors */
8699 if (!(colour_type & PNG_COLOR_MASK_COLOR))
8700 {
8701 /* Grayscale input, we do not convert to RGB (TBD), so we must set the
8702 * background to gray - else libpng seems to fail.
8703 */
8704 background.red = background.green = background.blue = background.gray;
8705 }
8706
8707 pos = safecat(name, sizeof name, pos, "gamma ");
8708 pos = safecatd(name, sizeof name, pos, file_gamma, 3);
8709 pos = safecat(name, sizeof name, pos, "->");
8710 pos = safecatd(name, sizeof name, pos, screen_gamma, 3);
8711
8712 pos = safecat(name, sizeof name, pos, base);
8713 if (do_background < ALPHA_MODE_OFFSET)
8714 {
8715 /* Include the background color and gamma in the name: */
8716 pos = safecat(name, sizeof name, pos, "(");
8717 /* This assumes no expand gray->rgb - the current code won't handle that!
8718 */
8719 if (colour_type & PNG_COLOR_MASK_COLOR)
8720 {
8721 pos = safecatn(name, sizeof name, pos, background.red);
8722 pos = safecat(name, sizeof name, pos, ",");
8723 pos = safecatn(name, sizeof name, pos, background.green);
8724 pos = safecat(name, sizeof name, pos, ",");
8725 pos = safecatn(name, sizeof name, pos, background.blue);
8726 }
8727 else
8728 pos = safecatn(name, sizeof name, pos, background.gray);
8729 pos = safecat(name, sizeof name, pos, ")^");
8730 pos = safecatd(name, sizeof name, pos, bg, 3);
8731 }
8732
8733 gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,
8734 file_gamma, screen_gamma, 0/*sBIT*/, 0, name, use_input_precision,
8735 0/*strip 16*/, expand_16, do_background, &background, bg);
8736}
8737
8738
8739static void
8740perform_gamma_composition_tests(png_modifier *pm, int do_background,
8741 int expand_16)
8742{
8743 png_byte colour_type = 0;
8744 png_byte bit_depth = 0;
8745 int palette_number = 0;
8746
8747 /* Skip the non-alpha cases - there is no setting of a transparency colour at
8748 * present.
8749 */
8750 while (next_format(&colour_type, &bit_depth, &palette_number))
8751 if ((colour_type & PNG_COLOR_MASK_ALPHA) != 0)
8752 {
8753 unsigned int i, j;
8754
8755 /* Don't skip the i==j case here - it's relevant. */
8756 for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)
8757 {
8758 gamma_composition_test(pm, colour_type, bit_depth, palette_number,
8759 pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],
8760 pm->use_input_precision, do_background, expand_16);
8761
8762 if (fail(pm))
8763 return;
8764 }
8765 }
8766}
8767#endif /* READ_BACKGROUND || READ_ALPHA_MODE */
8768
8769static void
8770init_gamma_errors(png_modifier *pm)
8771{
8772 pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;
8773 pm->error_color_8 = 0;
8774 pm->error_indexed = 0;
8775 pm->error_gray_16 = pm->error_color_16 = 0;
8776}
8777
8778static void
8779summarize_gamma_errors(png_modifier *pm, png_const_charp who, int low_bit_depth)
8780{
8781 if (who)
8782 printf("Gamma correction with %s:\n", who);
8783
8784 if (low_bit_depth)
8785 {
8786 printf(" 2 bit gray: %.5f\n", pm->error_gray_2);
8787 printf(" 4 bit gray: %.5f\n", pm->error_gray_4);
8788 printf(" 8 bit gray: %.5f\n", pm->error_gray_8);
8789 printf(" 8 bit color: %.5f\n", pm->error_color_8);
8790 printf(" indexed: %.5f\n", pm->error_indexed);
8791 }
8792
8793#ifdef DO_16BIT
8794 printf(" 16 bit gray: %.5f\n", pm->error_gray_16);
8795 printf(" 16 bit color: %.5f\n", pm->error_color_16);
8796#endif
8797}
8798
8799static void
8800perform_gamma_test(png_modifier *pm, int summary)
8801{
8802 /*TODO: remove this*/
8803 /* Save certain values for the temporary overrides below. */
8804 unsigned int calculations_use_input_precision =
8805 pm->calculations_use_input_precision;
8806 double maxout8 = pm->maxout8;
8807
8808 /* First some arbitrary no-transform tests: */
8809 if (!pm->this.speed && pm->test_gamma_threshold)
8810 {
8811 perform_gamma_threshold_tests(pm);
8812
8813 if (fail(pm))
8814 return;
8815 }
8816
8817 /* Now some real transforms. */
8818 if (pm->test_gamma_transform)
8819 {
8820 init_gamma_errors(pm);
8821 /*TODO: remove this. Necessary because the current libpng
8822 * implementation works in 8 bits:
8823 */
8824 if (pm->test_gamma_expand16)
8825 pm->calculations_use_input_precision = 1;
8826 perform_gamma_transform_tests(pm);
8827 if (!calculations_use_input_precision)
8828 pm->calculations_use_input_precision = 0;
8829
8830 if (summary)
8831 {
8832 printf("Gamma correction error summary\n\n");
8833 printf("The printed value is the maximum error in the pixel values\n");
8834 printf("calculated by the libpng gamma correction code. The error\n");
8835 printf("is calculated as the difference between the output pixel\n");
8836 printf("value (always an integer) and the ideal value from the\n");
8837 printf("libpng specification (typically not an integer).\n\n");
8838
8839 printf("Expect this value to be less than .5 for 8 bit formats,\n");
8840 printf("less than 1 for formats with fewer than 8 bits and a small\n");
8841 printf("number (typically less than 5) for the 16 bit formats.\n");
8842 printf("For performance reasons the value for 16 bit formats\n");
8843 printf("increases when the image file includes an sBIT chunk.\n\n");
8844
8845 summarize_gamma_errors(pm, 0/*who*/, 1);
8846 }
8847 }
8848
8849 /* The sbit tests produce much larger errors: */
8850 if (pm->test_gamma_sbit)
8851 {
8852 init_gamma_errors(pm);
8853 perform_gamma_sbit_tests(pm);
8854
8855 if (summary)
8856 summarize_gamma_errors(pm, "sBIT", pm->sbitlow < 8U);
8857 }
8858
8859#ifdef DO_16BIT /* Should be READ_16BIT_SUPPORTED */
8860 if (pm->test_gamma_scale16)
8861 {
8862 /* The 16 to 8 bit strip operations: */
8863 init_gamma_errors(pm);
8864 perform_gamma_scale16_tests(pm);
8865
8866 if (summary)
8867 {
8868 printf("Gamma correction with 16 to 8 bit reduction:\n");
8869 printf(" 16 bit gray: %.5f\n", pm->error_gray_16);
8870 printf(" 16 bit color: %.5f\n", pm->error_color_16);
8871 }
8872 }
8873#endif
8874
8875#ifdef PNG_READ_BACKGROUND_SUPPORTED
8876 if (pm->test_gamma_background)
8877 {
8878 init_gamma_errors(pm);
8879
8880 /*TODO: remove this. Necessary because the current libpng
8881 * implementation works in 8 bits:
8882 */
8883 if (pm->test_gamma_expand16)
8884 {
8885 pm->calculations_use_input_precision = 1;
8886 pm->maxout8 = .499; /* because the 16 bit background is smashed */
8887 }
8888 perform_gamma_composition_tests(pm, PNG_BACKGROUND_GAMMA_UNIQUE,
8889 pm->test_gamma_expand16);
8890 if (!calculations_use_input_precision)
8891 pm->calculations_use_input_precision = 0;
8892 pm->maxout8 = maxout8;
8893
8894 if (summary)
8895 summarize_gamma_errors(pm, "background", 1);
8896 }
8897#endif
8898
8899#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
8900 if (pm->test_gamma_alpha_mode)
8901 {
8902 int do_background;
8903
8904 init_gamma_errors(pm);
8905
8906 /*TODO: remove this. Necessary because the current libpng
8907 * implementation works in 8 bits:
8908 */
8909 if (pm->test_gamma_expand16)
8910 pm->calculations_use_input_precision = 1;
8911 for (do_background = ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD;
8912 do_background <= ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN && !fail(pm);
8913 ++do_background)
8914 perform_gamma_composition_tests(pm, do_background,
8915 pm->test_gamma_expand16);
8916 if (!calculations_use_input_precision)
8917 pm->calculations_use_input_precision = 0;
8918
8919 if (summary)
8920 summarize_gamma_errors(pm, "alpha mode", 1);
8921 }
8922#endif
8923}
8924#endif /* PNG_READ_GAMMA_SUPPORTED */
8925
8926/* INTERLACE MACRO VALIDATION */
8927/* This is copied verbatim from the specification, it is simply the pass
8928 * number in which each pixel in each 8x8 tile appears. The array must
8929 * be indexed adam7[y][x] and notice that the pass numbers are based at
8930 * 1, not 0 - the base libpng uses.
8931 */
8932static PNG_CONST
8933png_byte adam7[8][8] =
8934{
8935 { 1,6,4,6,2,6,4,6 },
8936 { 7,7,7,7,7,7,7,7 },
8937 { 5,6,5,6,5,6,5,6 },
8938 { 7,7,7,7,7,7,7,7 },
8939 { 3,6,4,6,3,6,4,6 },
8940 { 7,7,7,7,7,7,7,7 },
8941 { 5,6,5,6,5,6,5,6 },
8942 { 7,7,7,7,7,7,7,7 }
8943};
8944
8945/* This routine validates all the interlace support macros in png.h for
8946 * a variety of valid PNG widths and heights. It uses a number of similarly
8947 * named internal routines that feed off the above array.
8948 */
8949static png_uint_32
8950png_pass_start_row(int pass)
8951{
8952 int x, y;
8953 ++pass;
8954 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
8955 return y;
8956 return 0xf;
8957}
8958
8959static png_uint_32
8960png_pass_start_col(int pass)
8961{
8962 int x, y;
8963 ++pass;
8964 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
8965 return x;
8966 return 0xf;
8967}
8968
8969static int
8970png_pass_row_shift(int pass)
8971{
8972 int x, y, base=(-1), inc=8;
8973 ++pass;
8974 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
8975 {
8976 if (base == (-1))
8977 base = y;
8978 else if (base == y)
8979 {}
8980 else if (inc == y-base)
8981 base=y;
8982 else if (inc == 8)
8983 inc = y-base, base=y;
8984 else if (inc != y-base)
8985 return 0xff; /* error - more than one 'inc' value! */
8986 }
8987
8988 if (base == (-1)) return 0xfe; /* error - no row in pass! */
8989
8990 /* The shift is always 1, 2 or 3 - no pass has all the rows! */
8991 switch (inc)
8992 {
8993case 2: return 1;
8994case 4: return 2;
8995case 8: return 3;
8996default: break;
8997 }
8998
8999 /* error - unrecognized 'inc' */
9000 return (inc << 8) + 0xfd;
9001}
9002
9003static int
9004png_pass_col_shift(int pass)
9005{
9006 int x, y, base=(-1), inc=8;
9007 ++pass;
9008 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
9009 {
9010 if (base == (-1))
9011 base = x;
9012 else if (base == x)
9013 {}
9014 else if (inc == x-base)
9015 base=x;
9016 else if (inc == 8)
9017 inc = x-base, base=x;
9018 else if (inc != x-base)
9019 return 0xff; /* error - more than one 'inc' value! */
9020 }
9021
9022 if (base == (-1)) return 0xfe; /* error - no row in pass! */
9023
9024 /* The shift is always 1, 2 or 3 - no pass has all the rows! */
9025 switch (inc)
9026 {
9027case 1: return 0; /* pass 7 has all the columns */
9028case 2: return 1;
9029case 4: return 2;
9030case 8: return 3;
9031default: break;
9032 }
9033
9034 /* error - unrecognized 'inc' */
9035 return (inc << 8) + 0xfd;
9036}
9037
9038static png_uint_32
9039png_row_from_pass_row(png_uint_32 yIn, int pass)
9040{
9041 /* By examination of the array: */
9042 switch (pass)
9043 {
9044case 0: return yIn * 8;
9045case 1: return yIn * 8;
9046case 2: return yIn * 8 + 4;
9047case 3: return yIn * 4;
9048case 4: return yIn * 4 + 2;
9049case 5: return yIn * 2;
9050case 6: return yIn * 2 + 1;
9051default: break;
9052 }
9053
9054 return 0xff; /* bad pass number */
9055}
9056
9057static png_uint_32
9058png_col_from_pass_col(png_uint_32 xIn, int pass)
9059{
9060 /* By examination of the array: */
9061 switch (pass)
9062 {
9063case 0: return xIn * 8;
9064case 1: return xIn * 8 + 4;
9065case 2: return xIn * 4;
9066case 3: return xIn * 4 + 2;
9067case 4: return xIn * 2;
9068case 5: return xIn * 2 + 1;
9069case 6: return xIn;
9070default: break;
9071 }
9072
9073 return 0xff; /* bad pass number */
9074}
9075
9076static int
9077png_row_in_interlace_pass(png_uint_32 y, int pass)
9078{
9079 /* Is row 'y' in pass 'pass'? */
9080 int x;
9081 y &= 7;
9082 ++pass;
9083 for (x=0; x<8; ++x) if (adam7[y][x] == pass)
9084 return 1;
9085
9086 return 0;
9087}
9088
9089static int
9090png_col_in_interlace_pass(png_uint_32 x, int pass)
9091{
9092 /* Is column 'x' in pass 'pass'? */
9093 int y;
9094 x &= 7;
9095 ++pass;
9096 for (y=0; y<8; ++y) if (adam7[y][x] == pass)
9097 return 1;
9098
9099 return 0;
9100}
9101
9102static png_uint_32
9103png_pass_rows(png_uint_32 height, int pass)
9104{
9105 png_uint_32 tiles = height>>3;
9106 png_uint_32 rows = 0;
9107 unsigned int x, y;
9108
9109 height &= 7;
9110 ++pass;
9111 for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)
9112 {
9113 rows += tiles;
9114 if (y < height) ++rows;
9115 break; /* i.e. break the 'x', column, loop. */
9116 }
9117
9118 return rows;
9119}
9120
9121static png_uint_32
9122png_pass_cols(png_uint_32 width, int pass)
9123{
9124 png_uint_32 tiles = width>>3;
9125 png_uint_32 cols = 0;
9126 unsigned int x, y;
9127
9128 width &= 7;
9129 ++pass;
9130 for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)
9131 {
9132 cols += tiles;
9133 if (x < width) ++cols;
9134 break; /* i.e. break the 'y', row, loop. */
9135 }
9136
9137 return cols;
9138}
9139
9140static void
9141perform_interlace_macro_validation(void)
9142{
9143 /* The macros to validate, first those that depend only on pass:
9144 *
9145 * PNG_PASS_START_ROW(pass)
9146 * PNG_PASS_START_COL(pass)
9147 * PNG_PASS_ROW_SHIFT(pass)
9148 * PNG_PASS_COL_SHIFT(pass)
9149 */
9150 int pass;
9151
9152 for (pass=0; pass<7; ++pass)
9153 {
9154 png_uint_32 m, f, v;
9155
9156 m = PNG_PASS_START_ROW(pass);
9157 f = png_pass_start_row(pass);
9158 if (m != f)
9159 {
9160 fprintf(stderr, "PNG_PASS_START_ROW(%d) = %u != %x\n", pass, m, f);
9161 exit(1);
9162 }
9163
9164 m = PNG_PASS_START_COL(pass);
9165 f = png_pass_start_col(pass);
9166 if (m != f)
9167 {
9168 fprintf(stderr, "PNG_PASS_START_COL(%d) = %u != %x\n", pass, m, f);
9169 exit(1);
9170 }
9171
9172 m = PNG_PASS_ROW_SHIFT(pass);
9173 f = png_pass_row_shift(pass);
9174 if (m != f)
9175 {
9176 fprintf(stderr, "PNG_PASS_ROW_SHIFT(%d) = %u != %x\n", pass, m, f);
9177 exit(1);
9178 }
9179
9180 m = PNG_PASS_COL_SHIFT(pass);
9181 f = png_pass_col_shift(pass);
9182 if (m != f)
9183 {
9184 fprintf(stderr, "PNG_PASS_COL_SHIFT(%d) = %u != %x\n", pass, m, f);
9185 exit(1);
9186 }
9187
9188 /* Macros that depend on the image or sub-image height too:
9189 *
9190 * PNG_PASS_ROWS(height, pass)
9191 * PNG_PASS_COLS(width, pass)
9192 * PNG_ROW_FROM_PASS_ROW(yIn, pass)
9193 * PNG_COL_FROM_PASS_COL(xIn, pass)
9194 * PNG_ROW_IN_INTERLACE_PASS(y, pass)
9195 * PNG_COL_IN_INTERLACE_PASS(x, pass)
9196 */
9197 for (v=0;;)
9198 {
9199 /* First the base 0 stuff: */
9200 m = PNG_ROW_FROM_PASS_ROW(v, pass);
9201 f = png_row_from_pass_row(v, pass);
9202 if (m != f)
9203 {
9204 fprintf(stderr, "PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\n",
9205 v, pass, m, f);
9206 exit(1);
9207 }
9208
9209 m = PNG_COL_FROM_PASS_COL(v, pass);
9210 f = png_col_from_pass_col(v, pass);
9211 if (m != f)
9212 {
9213 fprintf(stderr, "PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\n",
9214 v, pass, m, f);
9215 exit(1);
9216 }
9217
9218 m = PNG_ROW_IN_INTERLACE_PASS(v, pass);
9219 f = png_row_in_interlace_pass(v, pass);
9220 if (m != f)
9221 {
9222 fprintf(stderr, "PNG_ROW_IN_INTERLACE_PASS(%u, %d) = %u != %x\n",
9223 v, pass, m, f);
9224 exit(1);
9225 }
9226
9227 m = PNG_COL_IN_INTERLACE_PASS(v, pass);
9228 f = png_col_in_interlace_pass(v, pass);
9229 if (m != f)
9230 {
9231 fprintf(stderr, "PNG_COL_IN_INTERLACE_PASS(%u, %d) = %u != %x\n",
9232 v, pass, m, f);
9233 exit(1);
9234 }
9235
9236 /* Then the base 1 stuff: */
9237 ++v;
9238 m = PNG_PASS_ROWS(v, pass);
9239 f = png_pass_rows(v, pass);
9240 if (m != f)
9241 {
9242 fprintf(stderr, "PNG_PASS_ROWS(%u, %d) = %u != %x\n",
9243 v, pass, m, f);
9244 exit(1);
9245 }
9246
9247 m = PNG_PASS_COLS(v, pass);
9248 f = png_pass_cols(v, pass);
9249 if (m != f)
9250 {
9251 fprintf(stderr, "PNG_PASS_COLS(%u, %d) = %u != %x\n",
9252 v, pass, m, f);
9253 exit(1);
9254 }
9255
9256 /* Move to the next v - the stepping algorithm starts skipping
9257 * values above 1024.
9258 */
9259 if (v > 1024)
9260 {
9261 if (v == PNG_UINT_31_MAX)
9262 break;
9263
9264 v = (v << 1) ^ v;
9265 if (v >= PNG_UINT_31_MAX)
9266 v = PNG_UINT_31_MAX-1;
9267 }
9268 }
9269 }
9270}
9271
9272/* Test color encodings. These values are back-calculated from the published
9273 * chromaticities. The values are accurate to about 14 decimal places; 15 are
9274 * given. These values are much more accurate than the ones given in the spec,
9275 * which typically don't exceed 4 decimal places. This allows testing of the
9276 * libpng code to its theoretical accuracy of 4 decimal places. (If pngvalid
9277 * used the published errors the 'slack' permitted would have to be +/-.5E-4 or
9278 * more.)
9279 *
9280 * The png_modifier code assumes that encodings[0] is sRGB and treats it
9281 * specially: do not change the first entry in this list!
9282 */
9283static PNG_CONST color_encoding test_encodings[] =
9284{
9285/* sRGB: must be first in this list! */
9286/*gamma:*/ { 1/2.2,
9287/*red: */ { 0.412390799265959, 0.212639005871510, 0.019330818715592 },
9288/*green:*/ { 0.357584339383878, 0.715168678767756, 0.119194779794626 },
9289/*blue: */ { 0.180480788401834, 0.072192315360734, 0.950532152249660} },
9290/* Kodak ProPhoto (wide gamut) */
9291/*gamma:*/ { 1/1.6 /*approximate: uses 1.8 power law compared to sRGB 2.4*/,
9292/*red: */ { 0.797760489672303, 0.288071128229293, 0.000000000000000 },
9293/*green:*/ { 0.135185837175740, 0.711843217810102, 0.000000000000000 },
9294/*blue: */ { 0.031349349581525, 0.000085653960605, 0.825104602510460} },
9295/* Adobe RGB (1998) */
9296/*gamma:*/ { 1/(2+51./256),
9297/*red: */ { 0.576669042910131, 0.297344975250536, 0.027031361386412 },
9298/*green:*/ { 0.185558237906546, 0.627363566255466, 0.070688852535827 },
9299/*blue: */ { 0.188228646234995, 0.075291458493998, 0.991337536837639} },
9300/* Adobe Wide Gamut RGB */
9301/*gamma:*/ { 1/(2+51./256),
9302/*red: */ { 0.716500716779386, 0.258728243040113, 0.000000000000000 },
9303/*green:*/ { 0.101020574397477, 0.724682314948566, 0.051211818965388 },
9304/*blue: */ { 0.146774385252705, 0.016589442011321, 0.773892783545073} },
9305};
9306
9307/* signal handler
9308 *
9309 * This attempts to trap signals and escape without crashing. It needs a
9310 * context pointer so that it can throw an exception (call longjmp) to recover
9311 * from the condition; this is handled by making the png_modifier used by 'main'
9312 * into a global variable.
9313 */
9314static png_modifier pm;
9315
9316static void signal_handler(int signum)
9317{
9318
9319 size_t pos = 0;
9320 char msg[64];
9321
9322 pos = safecat(msg, sizeof msg, pos, "caught signal: ");
9323
9324 switch (signum)
9325 {
9326 case SIGABRT:
9327 pos = safecat(msg, sizeof msg, pos, "abort");
9328 break;
9329
9330 case SIGFPE:
9331 pos = safecat(msg, sizeof msg, pos, "floating point exception");
9332 break;
9333
9334 case SIGILL:
9335 pos = safecat(msg, sizeof msg, pos, "illegal instruction");
9336 break;
9337
9338 case SIGINT:
9339 pos = safecat(msg, sizeof msg, pos, "interrupt");
9340 break;
9341
9342 case SIGSEGV:
9343 pos = safecat(msg, sizeof msg, pos, "invalid memory access");
9344 break;
9345
9346 case SIGTERM:
9347 pos = safecat(msg, sizeof msg, pos, "termination request");
9348 break;
9349
9350 default:
9351 pos = safecat(msg, sizeof msg, pos, "unknown ");
9352 pos = safecatn(msg, sizeof msg, pos, signum);
9353 break;
9354 }
9355
9356 store_log(&pm.this, NULL/*png_structp*/, msg, 1/*error*/);
9357
9358 /* And finally throw an exception so we can keep going, unless this is
9359 * SIGTERM in which case stop now.
9360 */
9361 if (signum != SIGTERM)
9362 {
9363 struct exception_context *the_exception_context =
9364 &pm.this.exception_context;
9365
9366 Throw &pm.this;
9367 }
9368
9369 else
9370 exit(1);
9371}
9372
9373/* main program */
9374int main(int argc, PNG_CONST char **argv)
9375{
9376 volatile int summary = 1; /* Print the error summary at the end */
9377 volatile int memstats = 0; /* Print memory statistics at the end */
9378
9379 /* Create the given output file on success: */
9380 PNG_CONST char *volatile touch = NULL;
9381
9382 /* This is an array of standard gamma values (believe it or not I've seen
9383 * every one of these mentioned somewhere.)
9384 *
9385 * In the following list the most useful values are first!
9386 */
9387 static double
9388 gammas[]={2.2, 1.0, 2.2/1.45, 1.8, 1.5, 2.4, 2.5, 2.62, 2.9};
9389
9390 /* This records the command and arguments: */
9391 size_t cp = 0;
9392 char command[1024];
9393
9394 anon_context(&pm.this);
9395
9396 /* Add appropriate signal handlers, just the ANSI specified ones: */
9397 signal(SIGABRT, signal_handler);
9398 signal(SIGFPE, signal_handler);
9399 signal(SIGILL, signal_handler);
9400 signal(SIGINT, signal_handler);
9401 signal(SIGSEGV, signal_handler);
9402 signal(SIGTERM, signal_handler);
9403
9404#ifdef HAVE_FEENABLEEXCEPT
9405 /* Only required to enable FP exceptions on platforms where they start off
9406 * disabled; this is not necessary but if it is not done pngvalid will likely
9407 * end up ignoring FP conditions that other platforms fault.
9408 */
9409 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
9410#endif
9411
9412 modifier_init(&pm);
9413
9414 /* Preallocate the image buffer, because we know how big it needs to be,
9415 * note that, for testing purposes, it is deliberately mis-aligned by tag
9416 * bytes either side. All rows have an additional five bytes of padding for
9417 * overwrite checking.
9418 */
9419 store_ensure_image(&pm.this, NULL, 2, TRANSFORM_ROWMAX, TRANSFORM_HEIGHTMAX);
9420
9421 /* Don't give argv[0], it's normally some horrible libtool string: */
9422 cp = safecat(command, sizeof command, cp, "pngvalid");
9423
9424 /* Default to error on warning: */
9425 pm.this.treat_warnings_as_errors = 1;
9426
9427 /* Store the test gammas */
9428 pm.gammas = gammas;
9429 pm.ngammas = (sizeof gammas) / (sizeof gammas[0]);
9430 pm.ngamma_tests = 0; /* default to off */
9431
9432 /* And the test encodings */
9433 pm.encodings = test_encodings;
9434 pm.nencodings = (sizeof test_encodings) / (sizeof test_encodings[0]);
9435
9436 pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */
9437 /* The following allows results to pass if they correspond to anything in the
9438 * transformed range [input-.5,input+.5]; this is is required because of the
9439 * way libpng treates the 16_TO_8 flag when building the gamma tables.
9440 *
9441 * TODO: review this
9442 */
9443 pm.use_input_precision_16to8 = 1U;
9444
9445 /* Some default values (set the behavior for 'make check' here).
9446 * These values simply control the maximum error permitted in the gamma
9447 * transformations. The practial limits for human perception are described
9448 * below (the setting for maxpc16), however for 8 bit encodings it isn't
9449 * possible to meet the accepted capabilities of human vision - i.e. 8 bit
9450 * images can never be good enough, regardless of encoding.
9451 */
9452 pm.maxout8 = .1; /* Arithmetic error in *encoded* value */
9453 pm.maxabs8 = .00005; /* 1/20000 */
9454 pm.maxcalc8 = .004; /* +/-1 in 8 bits for compose errors */
9455 pm.maxpc8 = .499; /* I.e., .499% fractional error */
9456 pm.maxout16 = .499; /* Error in *encoded* value */
9457 pm.maxabs16 = .00005;/* 1/20000 */
9458 pm.maxcalc16 =.000015;/* +/-1 in 16 bits for compose errors */
9459
9460 /* NOTE: this is a reasonable perceptual limit. We assume that humans can
9461 * perceive light level differences of 1% over a 100:1 range, so we need to
9462 * maintain 1 in 10000 accuracy (in linear light space), which is what the
9463 * following guarantees. It also allows significantly higher errors at
9464 * higher 16 bit values, which is important for performance. The actual
9465 * maximum 16 bit error is about +/-1.9 in the fixed point implementation but
9466 * this is only allowed for values >38149 by the following:
9467 */
9468 pm.maxpc16 = .005; /* I.e., 1/200% - 1/20000 */
9469
9470 /* Now parse the command line options. */
9471 while (--argc >= 1)
9472 {
9473 int catmore = 0; /* Set if the argument has an argument. */
9474
9475 /* Record each argument for posterity: */
9476 cp = safecat(command, sizeof command, cp, " ");
9477 cp = safecat(command, sizeof command, cp, *++argv);
9478
9479 if (strcmp(*argv, "-v") == 0)
9480 pm.this.verbose = 1;
9481
9482 else if (strcmp(*argv, "-l") == 0)
9483 pm.log = 1;
9484
9485 else if (strcmp(*argv, "-q") == 0)
9486 summary = pm.this.verbose = pm.log = 0;
9487
9488 else if (strcmp(*argv, "-w") == 0)
9489 pm.this.treat_warnings_as_errors = 0;
9490
9491 else if (strcmp(*argv, "--speed") == 0)
9492 pm.this.speed = 1, pm.ngamma_tests = pm.ngammas, pm.test_standard = 0,
9493 summary = 0;
9494
9495 else if (strcmp(*argv, "--memory") == 0)
9496 memstats = 1;
9497
9498 else if (strcmp(*argv, "--size") == 0)
9499 pm.test_size = 1;
9500
9501 else if (strcmp(*argv, "--nosize") == 0)
9502 pm.test_size = 0;
9503
9504 else if (strcmp(*argv, "--standard") == 0)
9505 pm.test_standard = 1;
9506
9507 else if (strcmp(*argv, "--nostandard") == 0)
9508 pm.test_standard = 0;
9509
9510 else if (strcmp(*argv, "--transform") == 0)
9511 pm.test_transform = 1;
9512
9513 else if (strcmp(*argv, "--notransform") == 0)
9514 pm.test_transform = 0;
9515
9516#ifdef PNG_READ_TRANSFORMS_SUPPORTED
9517 else if (strncmp(*argv, "--transform-disable=",
9518 sizeof "--transform-disable") == 0)
9519 {
9520 pm.test_transform = 1;
9521 transform_disable(*argv + sizeof "--transform-disable");
9522 }
9523
9524 else if (strncmp(*argv, "--transform-enable=",
9525 sizeof "--transform-enable") == 0)
9526 {
9527 pm.test_transform = 1;
9528 transform_enable(*argv + sizeof "--transform-enable");
9529 }
9530#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
9531
9532 else if (strcmp(*argv, "--gamma") == 0)
9533 {
9534 /* Just do two gamma tests here (2.2 and linear) for speed: */
9535 pm.ngamma_tests = 2U;
9536 pm.test_gamma_threshold = 1;
9537 pm.test_gamma_transform = 1;
9538 pm.test_gamma_sbit = 1;
9539 pm.test_gamma_scale16 = 1;
9540 pm.test_gamma_background = 1;
9541 pm.test_gamma_alpha_mode = 1;
9542 }
9543
9544 else if (strcmp(*argv, "--nogamma") == 0)
9545 pm.ngamma_tests = 0;
9546
9547 else if (strcmp(*argv, "--gamma-threshold") == 0)
9548 pm.ngamma_tests = 2U, pm.test_gamma_threshold = 1;
9549
9550 else if (strcmp(*argv, "--nogamma-threshold") == 0)
9551 pm.test_gamma_threshold = 0;
9552
9553 else if (strcmp(*argv, "--gamma-transform") == 0)
9554 pm.ngamma_tests = 2U, pm.test_gamma_transform = 1;
9555
9556 else if (strcmp(*argv, "--nogamma-transform") == 0)
9557 pm.test_gamma_transform = 0;
9558
9559 else if (strcmp(*argv, "--gamma-sbit") == 0)
9560 pm.ngamma_tests = 2U, pm.test_gamma_sbit = 1;
9561
9562 else if (strcmp(*argv, "--nogamma-sbit") == 0)
9563 pm.test_gamma_sbit = 0;
9564
9565 else if (strcmp(*argv, "--gamma-16-to-8") == 0)
9566 pm.ngamma_tests = 2U, pm.test_gamma_scale16 = 1;
9567
9568 else if (strcmp(*argv, "--nogamma-16-to-8") == 0)
9569 pm.test_gamma_scale16 = 0;
9570
9571 else if (strcmp(*argv, "--gamma-background") == 0)
9572 pm.ngamma_tests = 2U, pm.test_gamma_background = 1;
9573
9574 else if (strcmp(*argv, "--nogamma-background") == 0)
9575 pm.test_gamma_background = 0;
9576
9577 else if (strcmp(*argv, "--gamma-alpha-mode") == 0)
9578 pm.ngamma_tests = 2U, pm.test_gamma_alpha_mode = 1;
9579
9580 else if (strcmp(*argv, "--nogamma-alpha-mode") == 0)
9581 pm.test_gamma_alpha_mode = 0;
9582
9583 else if (strcmp(*argv, "--expand16") == 0)
9584 pm.test_gamma_expand16 = 1;
9585
9586 else if (strcmp(*argv, "--noexpand16") == 0)
9587 pm.test_gamma_expand16 = 0;
9588
9589 else if (strcmp(*argv, "--more-gammas") == 0)
9590 pm.ngamma_tests = 3U;
9591
9592 else if (strcmp(*argv, "--all-gammas") == 0)
9593 pm.ngamma_tests = pm.ngammas;
9594
9595 else if (strcmp(*argv, "--progressive-read") == 0)
9596 pm.this.progressive = 1;
9597
9598 else if (strcmp(*argv, "--use-update-info") == 0)
9599 ++pm.use_update_info; /* Can call multiple times */
9600
9601 else if (strcmp(*argv, "--interlace") == 0)
9602 pm.interlace_type = PNG_INTERLACE_ADAM7;
9603
9604 else if (strcmp(*argv, "--use-input-precision") == 0)
9605 pm.use_input_precision = 1;
9606
9607 else if (strcmp(*argv, "--calculations-use-input-precision") == 0)
9608 pm.calculations_use_input_precision = 1;
9609
9610 else if (strcmp(*argv, "--assume-16-bit-calculations") == 0)
9611 pm.assume_16_bit_calculations = 1;
9612
9613 else if (strcmp(*argv, "--calculations-follow-bit-depth") == 0)
9614 pm.calculations_use_input_precision =
9615 pm.assume_16_bit_calculations = 0;
9616
9617 else if (strcmp(*argv, "--exhaustive") == 0)
9618 pm.test_exhaustive = 1;
9619
9620 else if (argc > 1 && strcmp(*argv, "--sbitlow") == 0)
9621 --argc, pm.sbitlow = (png_byte)atoi(*++argv), catmore = 1;
9622
9623 else if (argc > 1 && strcmp(*argv, "--touch") == 0)
9624 --argc, touch = *++argv, catmore = 1;
9625
9626 else if (argc > 1 && strncmp(*argv, "--max", 5) == 0)
9627 {
9628 --argc;
9629
9630 if (strcmp(5+*argv, "abs8") == 0)
9631 pm.maxabs8 = atof(*++argv);
9632
9633 else if (strcmp(5+*argv, "abs16") == 0)
9634 pm.maxabs16 = atof(*++argv);
9635
9636 else if (strcmp(5+*argv, "calc8") == 0)
9637 pm.maxcalc8 = atof(*++argv);
9638
9639 else if (strcmp(5+*argv, "calc16") == 0)
9640 pm.maxcalc16 = atof(*++argv);
9641
9642 else if (strcmp(5+*argv, "out8") == 0)
9643 pm.maxout8 = atof(*++argv);
9644
9645 else if (strcmp(5+*argv, "out16") == 0)
9646 pm.maxout16 = atof(*++argv);
9647
9648 else if (strcmp(5+*argv, "pc8") == 0)
9649 pm.maxpc8 = atof(*++argv);
9650
9651 else if (strcmp(5+*argv, "pc16") == 0)
9652 pm.maxpc16 = atof(*++argv);
9653
9654 else
9655 {
9656 fprintf(stderr, "pngvalid: %s: unknown 'max' option\n", *argv);
9657 exit(1);
9658 }
9659
9660 catmore = 1;
9661 }
9662
9663 else if (strcmp(*argv, "--log8") == 0)
9664 --argc, pm.log8 = atof(*++argv), catmore = 1;
9665
9666 else if (strcmp(*argv, "--log16") == 0)
9667 --argc, pm.log16 = atof(*++argv), catmore = 1;
9668
9669 else
9670 {
9671 fprintf(stderr, "pngvalid: %s: unknown argument\n", *argv);
9672 exit(1);
9673 }
9674
9675 if (catmore) /* consumed an extra *argv */
9676 {
9677 cp = safecat(command, sizeof command, cp, " ");
9678 cp = safecat(command, sizeof command, cp, *argv);
9679 }
9680 }
9681
9682 /* If pngvalid is run with no arguments default to a reasonable set of the
9683 * tests.
9684 */
9685 if (pm.test_standard == 0 && pm.test_size == 0 && pm.test_transform == 0 &&
9686 pm.ngamma_tests == 0)
9687 {
9688 /* Make this do all the tests done in the test shell scripts with the same
9689 * parameters, where possible. The limitation is that all the progressive
9690 * read and interlace stuff has to be done in separate runs, so only the
9691 * basic 'standard' and 'size' tests are done.
9692 */
9693 pm.test_standard = 1;
9694 pm.test_size = 1;
9695 pm.test_transform = 1;
9696 pm.ngamma_tests = 2U;
9697 }
9698
9699 if (pm.ngamma_tests > 0 &&
9700 pm.test_gamma_threshold == 0 && pm.test_gamma_transform == 0 &&
9701 pm.test_gamma_sbit == 0 && pm.test_gamma_scale16 == 0 &&
9702 pm.test_gamma_background == 0 && pm.test_gamma_alpha_mode == 0)
9703 {
9704 pm.test_gamma_threshold = 1;
9705 pm.test_gamma_transform = 1;
9706 pm.test_gamma_sbit = 1;
9707 pm.test_gamma_scale16 = 1;
9708 pm.test_gamma_background = 1;
9709 pm.test_gamma_alpha_mode = 1;
9710 }
9711
9712 else if (pm.ngamma_tests == 0)
9713 {
9714 /* Nothing to test so turn everything off: */
9715 pm.test_gamma_threshold = 0;
9716 pm.test_gamma_transform = 0;
9717 pm.test_gamma_sbit = 0;
9718 pm.test_gamma_scale16 = 0;
9719 pm.test_gamma_background = 0;
9720 pm.test_gamma_alpha_mode = 0;
9721 }
9722
9723 Try
9724 {
9725 /* Make useful base images */
9726 make_transform_images(&pm.this);
9727
9728 /* Perform the standard and gamma tests. */
9729 if (pm.test_standard)
9730 {
9731 perform_interlace_macro_validation();
9732 perform_formatting_test(&pm.this);
9733 perform_standard_test(&pm);
9734 perform_error_test(&pm);
9735 }
9736
9737 /* Various oddly sized images: */
9738 if (pm.test_size)
9739 {
9740 make_size_images(&pm.this);
9741 perform_size_test(&pm);
9742 }
9743
9744#ifdef PNG_READ_TRANSFORMS_SUPPORTED
9745 /* Combinatorial transforms: */
9746 if (pm.test_transform)
9747 perform_transform_test(&pm);
9748#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
9749
9750#ifdef PNG_READ_GAMMA_SUPPORTED
9751 if (pm.ngamma_tests > 0)
9752 perform_gamma_test(&pm, summary);
9753#endif
9754 }
9755
9756 Catch_anonymous
9757 {
9758 fprintf(stderr, "pngvalid: test aborted (probably failed in cleanup)\n");
9759 if (!pm.this.verbose)
9760 {
9761 if (pm.this.error[0] != 0)
9762 fprintf(stderr, "pngvalid: first error: %s\n", pm.this.error);
9763
9764 fprintf(stderr, "pngvalid: run with -v to see what happened\n");
9765 }
9766 exit(1);
9767 }
9768
9769 if (summary)
9770 {
9771 printf("%s: %s (%s point arithmetic)\n",
9772 (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
9773 pm.this.nwarnings)) ? "FAIL" : "PASS",
9774 command,
9775#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || PNG_LIBPNG_VER < 10500
9776 "floating"
9777#else
9778 "fixed"
9779#endif
9780 );
9781 }
9782
9783 if (memstats)
9784 {
9785 printf("Allocated memory statistics (in bytes):\n"
9786 "\tread %lu maximum single, %lu peak, %lu total\n"
9787 "\twrite %lu maximum single, %lu peak, %lu total\n",
9788 (unsigned long)pm.this.read_memory_pool.max_max,
9789 (unsigned long)pm.this.read_memory_pool.max_limit,
9790 (unsigned long)pm.this.read_memory_pool.max_total,
9791 (unsigned long)pm.this.write_memory_pool.max_max,
9792 (unsigned long)pm.this.write_memory_pool.max_limit,
9793 (unsigned long)pm.this.write_memory_pool.max_total);
9794 }
9795
9796 /* Do this here to provoke memory corruption errors in memory not directly
9797 * allocated by libpng - not a complete test, but better than nothing.
9798 */
9799 store_delete(&pm.this);
9800
9801 /* Error exit if there are any errors, and maybe if there are any
9802 * warnings.
9803 */
9804 if (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&
9805 pm.this.nwarnings))
9806 {
9807 if (!pm.this.verbose)
9808 fprintf(stderr, "pngvalid: %s\n", pm.this.error);
9809
9810 fprintf(stderr, "pngvalid: %d errors, %d warnings\n", pm.this.nerrors,
9811 pm.this.nwarnings);
9812
9813 exit(1);
9814 }
9815
9816 /* Success case. */
9817 if (touch != NULL)
9818 {
9819 FILE *fsuccess = fopen(touch, "wt");
9820
9821 if (fsuccess != NULL)
9822 {
9823 int error = 0;
9824 fprintf(fsuccess, "PNG validation succeeded\n");
9825 fflush(fsuccess);
9826 error = ferror(fsuccess);
9827
9828 if (fclose(fsuccess) || error)
9829 {
9830 fprintf(stderr, "%s: write failed\n", touch);
9831 exit(1);
9832 }
9833 }
9834 }
9835
9836 return 0;
9837}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/README
new file mode 100644
index 0000000..86583cc
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/README
@@ -0,0 +1,10 @@
1This demonstrates the use of PNG_USER_CONFIG, pngusr.h and pngusr.dfa
2
3The makefile builds a minimal read-only decoder with embedded libpng
4and zlib.
5
6Specify the location of the zlib source (1.2.1 or later) as ZLIBSRC
7on the make command line.
8
9If you prefer to use the shared libraries, go to contrib/pngminus
10and build the png2pnm application there.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/makefile b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/makefile
new file mode 100644
index 0000000..9692e0a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/makefile
@@ -0,0 +1,150 @@
1# Makefile for PngMinus (pngm2pnm)
2# Linux / Unix
3
4#CC=cc
5CC=gcc
6LD=$(CC)
7
8# If awk fails try
9# make AWK=nawk
10
11# If cpp fails try
12# make CPP=/lib/cpp
13
14RM=rm -f
15COPY=cp
16
17CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP -I. -O1
18
19C=.c
20O=.o
21L=.a
22E=
23
24# Where to find the source code:
25PNGSRC =../../..
26ZLIBSRC=$(PNGSRC)/../zlib
27PROGSRC=$(PNGSRC)/contrib/pngminus
28
29# Zlib (minimal inflate requirements - crc32 is used by libpng)
30# zutil can be eliminated if you provide your own zcalloc and zcfree
31ZSRCS = adler32$(C) crc32$(C) \
32 inffast$(C) inflate$(C) inftrees$(C) \
33 zutil$(C)
34
35# Standard headers
36ZH = zlib.h crc32.h inffast.h inffixed.h \
37 inflate.h inftrees.h zutil.h
38
39# Machine generated headers
40ZCONF = zconf.h
41
42# Headers callers use
43ZINC = zlib.h $(ZCONF)
44
45# Headers the Zlib source uses
46ZHDRS = $(ZH) $(ZCONF)
47
48ZOBJS = adler32$(O) crc32$(O) \
49 inffast$(O) inflate$(O) inftrees$(O) \
50 zutil$(O)
51
52# libpng
53PNGSRCS=png$(C) pngerror$(C) pngget$(C) pngmem$(C) \
54 pngread$(C) pngrio$(C) pngrtran$(C) pngrutil$(C) \
55 pngset$(C) pngtrans$(C)
56
57# Standard headers
58PNGH =png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h
59
60# Machine generated headers
61PNGCONF=pnglibconf.h
62
63# Headers callers use
64PNGINC= png.h pngconf.h pngusr.h $(PNGCONF)
65
66# Headers the PNG library uses
67PNGHDRS=$(PNGH) $(PNGCONF) pngusr.h
68
69PNGOBJS=png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
70 pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \
71 pngset$(O) pngtrans$(O)
72
73PROGSRCS= pngm2pnm$(C)
74PROGHDRS=
75PROGDOCS=
76PROGOBJS= pngm2pnm$(O)
77
78OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
79
80# implicit make rules -------------------------------------------------------
81
82# note: dependencies do not work on implicit rule lines
83.c$(O):
84 $(CC) -c $(CFLAGS) $<
85
86# dependencies
87
88all: pngm2pnm$(E)
89
90pngm2pnm$(E): $(OBJS)
91 $(LD) -o pngm2pnm$(E) $(OBJS)
92
93# The DFA_XTRA setting turns all libpng options off then
94# turns on those required for this minimal build.
95# The CPP_FLAGS setting causes pngusr.h to be included in
96# both the build of pnglibconf.h and, subsequently, when
97# building libpng itself.
98$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
99 $(PNGSRC)/scripts/pnglibconf.dfa \
100 $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
101 $(RM) pnglibconf.h pnglibconf.dfn
102 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
103 srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
104 DFA_XTRA="pngusr.dfa" $@
105
106clean:
107 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
108 srcdir=$(PNGSRC) clean
109 $(RM) pngm2pnm$(O)
110 $(RM) pngm2pnm$(E)
111 $(RM) $(OBJS)
112
113# distclean also removes the copied source and headers
114distclean: clean
115 $(RM) -r scripts # historical reasons
116 $(RM) $(PNGSRCS) $(PNGH)
117 $(RM) $(ZSRCS) $(ZH) $(ZCONF)
118 $(RM) $(PROGSRCS) $(PROGHDRS) $(PROGDOCS)
119
120# Header file dependencies:
121$(PROGOBJS): $(PROGHDRS) $(PNGINC) $(ZINC)
122$(PNGOBJS): $(PNGHDRS) $(ZINC)
123$(ZOBJS): $(ZHDRS)
124
125# Gather the source code from the respective directories
126$(PNGSRCS) $(PNGH): $(PNGSRC)/$@
127 $(RM) $@
128 $(COPY) $(PNGSRC)/$@ $@
129
130# No dependency on the ZLIBSRC target so that it only needs
131# to be specified once.
132$(ZSRCS) $(ZH):
133 $(RM) $@
134 $(COPY) $(ZLIBSRC)/$@ $@
135
136# The unconfigured zconf.h varies in name according to the
137# zlib release
138$(ZCONF):
139 $(RM) $@
140 @for f in zconf.h.in zconf.in.h zconf.h; do\
141 test -r $(ZLIBSRC)/$$f &&\
142 echo $(COPY) $(ZLIBSRC)/$$f $@ &&\
143 $(COPY) $(ZLIBSRC)/$$f $@ && exit 0;\
144 done; echo copy: $(ZLIBSRC)/zconf.h not found; exit 1
145
146pngm2pnm.c: $(PROGSRC)/png2pnm.c
147 $(RM) $@
148 $(COPY) $(PROGSRC)/png2pnm.c $@
149
150# End of makefile for pngm2pnm
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.dfa b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.dfa
new file mode 100644
index 0000000..8a66d64
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.dfa
@@ -0,0 +1,39 @@
1# pngminim/decoder/pngusr.dfa
2#
3# Copyright (c) 2010-2011 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# First all the build options off:
10
11everything = off
12
13# All that is required is some read code. This example switches
14# on the sequential read code (see ../preader for a progressive
15# read example).
16
17option SEQUENTIAL_READ on
18
19# You must choose fixed or floating point arithmetic:
20# option FLOATING_POINT on
21
22option FIXED_POINT on
23
24# You must chose the internal fixed point implementation or to
25# use the system floating point. The latter is considerably
26# smaller (by about 1kbyte on an x86 system):
27# option FLOATING_ARITHMETIC on
28
29option FLOATING_ARITHMETIC off
30
31# Your program will probably need other options. The example
32# program here, pngm2pnm, requires the following. Take a look
33# at pnglibconf.h to find out the full set of what has to be
34# enabled to make the following work.
35
36option SETJMP on
37option STDIO on
38option READ_EXPAND on
39option READ_STRIP_16_TO_8 on
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.h
new file mode 100644
index 0000000..2991c17
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/decoder/pngusr.h
@@ -0,0 +1,24 @@
1/* minrdpngconf.h: headers to make a minimal png-read-only library
2 *
3 * Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
4 *
5 * This code is released under the libpng license.
6 * For conditions of distribution and use, see the disclaimer
7 * and license in png.h
8 *
9 * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson
10 */
11
12#ifndef MINRDPNGCONF_H
13#define MINRDPNGCONF_H
14
15/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */
16
17/* List options to turn off features of the build that do not
18 * affect the API (so are not recorded in pnglibconf.h)
19 */
20
21#define PNG_NO_WARNINGS
22#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
23
24#endif /* MINRDPNGCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/README
new file mode 100644
index 0000000..f8a8b6d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/README
@@ -0,0 +1,10 @@
1This demonstrates the use of PNG_USER_CONFIG and pngusr.h
2
3The makefile builds a minimal write-only decoder with embedded libpng
4and zlib.
5
6Specify the location of the zlib source (1.2.1 or later) as ZLIBSRC
7on the make command line.
8
9If you prefer to use the shared libraries, go to contrib/pngminus
10and build the pnm2png application there.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/makefile b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/makefile
new file mode 100644
index 0000000..7374a6c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/makefile
@@ -0,0 +1,149 @@
1# Makefile for PngMinus (pnm2pngm)
2# Linux / Unix
3
4#CC=cc
5CC=gcc
6LD=$(CC)
7
8# If awk fails try
9# make AWK=nawk
10
11# If cpp fails try
12# make CPP=/lib/cpp
13
14RM=rm -f
15COPY=cp
16
17CFLAGS=-DPNG_USER_CONFIG -DNO_GZIP -I. -O1
18
19C=.c
20O=.o
21L=.a
22E=
23
24# Where to find the source code:
25PNGSRC =../../..
26ZLIBSRC=$(PNGSRC)/../zlib
27PROGSRC=$(PNGSRC)/contrib/pngminus
28
29# Zlib
30ZSRCS = adler32$(C) compress$(C) crc32$(C) deflate$(C) \
31 trees$(C) zutil$(C)
32
33# Standard headers
34#ZH = zlib.h crc32.h deflate.h trees.h zutil.h
35ZH = zlib.h crc32.h deflate.h trees.h zutil.h
36
37# Machine generated headers
38ZCONF = zconf.h
39
40# Headers callers use
41ZINC = zlib.h $(ZCONF)
42
43# Headers the Zlib source uses
44ZHDRS = $(ZH) $(ZCONF)
45
46# compress is not required; it is needed to link the zlib
47# code because deflate defines an unused API function deflateBound
48# which itself calls compressBound from compress.
49ZOBJS = adler32$(O) compress$(O) crc32$(O) deflate$(O) \
50 trees$(O) zutil$(O)
51
52# libpng
53PNGSRCS=png$(C) pngerror$(C) pngget$(C) pngmem$(C) \
54 pngset$(C) pngtrans$(C) pngwio$(C) pngwrite$(C) \
55 pngwtran$(C) pngwutil$(C)
56
57# Standard headers
58PNGH =png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h
59
60# Machine generated headers
61PNGCONF=pnglibconf.h
62
63# Headers callers use
64PNGINC= png.h pngconf.h pngusr.h $(PNGCONF)
65
66# Headers the PNG library uses
67PNGHDRS=$(PNGH) $(PNGCONF) pngusr.h
68
69PNGOBJS=png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
70 pngset$(O) pngtrans$(O) pngwio$(O) pngwrite$(O) \
71 pngwtran$(O) pngwutil$(O)
72
73PROGSRCS= pnm2pngm$(C)
74PROGHDRS=
75PROGDOCS=
76PROGOBJS= pnm2pngm$(O)
77
78OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
79
80# implicit make rules -------------------------------------------------------
81
82.c$(O):
83 $(CC) -c $(CFLAGS) $<
84
85# dependencies
86
87all: pnm2pngm$(E)
88
89pnm2pngm$(E): $(OBJS)
90 $(LD) -o pnm2pngm$(E) $(OBJS)
91
92# The DFA_XTRA setting turns all libpng options off then
93# turns on those required for this minimal build.
94# The CPP_FLAGS setting causes pngusr.h to be included in
95# both the build of pnglibconf.h and, subsequently, when
96# building libpng itself.
97$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
98 $(PNGSRC)/scripts/pnglibconf.dfa \
99 $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
100 $(RM) pnglibconf.h pnglibconf.dfn
101 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
102 srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
103 DFA_XTRA="pngusr.dfa" $@
104
105clean:
106 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
107 srcdir=$(PNGSRC) clean
108 $(RM) pnm2pngm$(O)
109 $(RM) pnm2pngm$(E)
110 $(RM) $(OBJS)
111
112# distclean also removes the copied source and headers
113distclean: clean
114 $(RM) -r scripts # historical reasons
115 $(RM) $(PNGSRCS) $(PNGH)
116 $(RM) $(ZSRCS) $(ZH) $(ZCONF)
117 $(RM) $(PROGSRCS) $(PROGHDRS) $(PROGDOCS)
118
119# Header file dependencies:
120$(PROGOBJS): $(PROGHDRS) $(PNGINC) $(ZINC)
121$(PNGOBJS): $(PNGHDRS) $(ZINC)
122$(ZOBJS): $(ZHDRS)
123
124# Gather the source code from the respective directories
125$(PNGSRCS) $(PNGH): $(PNGSRC)/$@
126 $(RM) $@
127 $(COPY) $(PNGSRC)/$@ $@
128
129# No dependency on the ZLIBSRC target so that it only needs
130# to be specified once.
131$(ZSRCS) $(ZH):
132 $(RM) $@
133 $(COPY) $(ZLIBSRC)/$@ $@
134
135# The unconfigured zconf.h varies in name according to the
136# zlib release
137$(ZCONF):
138 $(RM) $@
139 @for f in zconf.h.in zconf.in.h zconf.h; do\
140 test -r $(ZLIBSRC)/$$f &&\
141 echo $(COPY) $(ZLIBSRC)/$$f $@ &&\
142 $(COPY) $(ZLIBSRC)/$$f $@ && exit 0;\
143 done; echo copy: $(ZLIBSRC)/zconf.h not found; exit 1
144
145pnm2pngm.c: $(PROGSRC)/pnm2png.c
146 $(RM) $@
147 $(COPY) $(PROGSRC)/pnm2png.c $@
148
149# End of makefile for pnm2pngm
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.dfa b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.dfa
new file mode 100644
index 0000000..448f821
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.dfa
@@ -0,0 +1,35 @@
1# pngminim/encoder/pngusr.dfa
2#
3# Copyright (c) 2010-2011 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# First all the build options off:
10
11everything = off
12
13# Switch on the write code - this makes a minimalist encoder
14
15option WRITE on
16
17# You must choose fixed or floating point arithmetic:
18# option FLOATING_POINT on
19
20option FIXED_POINT on
21
22# You must chose the internal fixed point implementation or to
23# use the system floating point. The latter is considerably
24# smaller (by about 1kbyte on an x86 system):
25# option FLOATING_ARITHMETIC on
26
27option FLOATING_ARITHMETIC off
28
29# Your program will probably need other options. The example
30# program here, pnm2pngm, requires the following. Take a look
31# at pnglibconf.h to find out the full set of what has to be
32# enabled to make the following work.
33
34option SETJMP on
35option STDIO on
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.h
new file mode 100644
index 0000000..bafbf13
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/encoder/pngusr.h
@@ -0,0 +1,24 @@
1/* minwrpngconf.h: headers to make a minimal png-write-only library
2 *
3 * Copyright (c) 2007, 2010-2011 Glenn Randers-Pehrson
4 *
5 * This code is released under the libpng license.
6 * For conditions of distribution and use, see the disclaimer
7 * and license in png.h
8 *
9 * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson
10 */
11
12#ifndef MINWRPNGCONF_H
13#define MINWRPNGCONF_H
14
15/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */
16
17/* List options to turn off features of the build that do not
18 * affect the API (so are not recorded in pnglibconf.h)
19 */
20
21#define PNG_NO_WARNINGS
22#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
23
24#endif /* MINWRPNGCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/README
new file mode 100644
index 0000000..e40024e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/README
@@ -0,0 +1,15 @@
1This demonstrates the use of PNG_USER_CONFIG and pngusr.h
2
3The makefile builds a minimal read-only progressive decoder with
4embedded libpng, zlib and your system's X library.
5
6Specify the location of the zlib source (1.2.1 or later) as ZLIBSRC
7on the make command line.
8
9Edit makefile if required, to find your X library and include files,
10then
11
12 make ZLIBSRC=directory
13
14If you prefer to use the shared libraries, go to contrib/gregbook
15and build the rpng2-x application there.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/makefile b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/makefile
new file mode 100644
index 0000000..a367661
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/makefile
@@ -0,0 +1,165 @@
1# Makefile for PngMinus (rpng2)
2# Linux / Unix
3
4#CC=cc
5CC=gcc
6LD=$(CC)
7
8# If awk fails try
9# make AWK=nawk
10
11# If cpp fails try
12# make CPP=/lib/cpp
13
14RM=rm -f
15COPY=cp
16
17#XINC = -I/usr/include # old-style, stock X distributions
18#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX)
19
20#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
21#XLIB = -L/usr/openwin/lib -lX11
22
23XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.)
24XLIB = -L/usr/X11R6/lib -lX11
25#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64
26
27#XINC = -I/usr/local/include # FreeBSD
28#XLIB = -L/usr/local/lib -lX11
29
30#LIBS = $(XLIB)
31LIBS = $(XLIB) -lm #platforms that need libm
32
33CFLAGS=-DPNG_USER_CONFIG -DNO_GZCOMPRESS -DNO_GZIP -I. $(XINC) -O1
34
35C=.c
36O=.o
37L=.a
38E=
39
40# Where to find the source code:
41PNGSRC =../../..
42ZLIBSRC=$(PNGSRC)/../zlib
43PROGSRC=$(PNGSRC)/contrib/gregbook
44
45# Zlib (minimal inflate requirements - crc32 is used by libpng)
46# zutil can be eliminated if you provide your own zcalloc and zcfree
47ZSRCS = adler32$(C) crc32$(C) \
48 inffast$(C) inflate$(C) inftrees$(C) \
49 zutil$(C)
50
51# Standard headers
52ZH = zlib.h crc32.h inffast.h inffixed.h \
53 inflate.h inftrees.h zutil.h
54
55# Machine generated headers
56ZCONF = zconf.h
57
58# Headers callers use
59ZINC = zlib.h $(ZCONF)
60
61# Headers the Zlib source uses
62ZHDRS = $(ZH) $(ZCONF)
63
64ZOBJS = adler32$(O) crc32$(O) \
65 inffast$(O) inflate$(O) inftrees$(O) \
66 zutil$(O)
67
68# libpng
69PNGSRCS=png$(C) pngerror$(C) pngget$(C) pngmem$(C) \
70 pngpread$(C) pngread$(C) pngrio$(C) pngrtran$(C) pngrutil$(C) \
71 pngset$(C) pngtrans$(C)
72
73# Standard headers
74PNGH =png.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h
75
76# Machine generated headers
77PNGCONF=pnglibconf.h
78
79# Headers callers use
80PNGINC= png.h pngconf.h pngusr.h $(PNGCONF)
81
82# Headers the PNG library uses
83PNGHDRS=$(PNGH) $(PNGCONF) pngusr.h
84
85PNGOBJS=png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
86 pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \
87 pngset$(O) pngtrans$(O)
88
89PROGSRCS= rpng2-x$(C) readpng2$(C)
90PROGHDRS= readpng2.h
91PROGDOCS= COPYING LICENSE
92PROGOBJS= rpng2-x$(O) readpng2$(O)
93
94OBJS = $(PROGOBJS) $(PNGOBJS) $(ZOBJS)
95
96# implicit make rules -------------------------------------------------------
97
98.c$(O):
99 $(CC) -c $(CFLAGS) $<
100
101# dependencies
102
103all: $(PROGDOCS) rpng2-x$(E)
104
105rpng2-x$(E): $(OBJS)
106 $(LD) -o rpng2-x$(E) $(OBJS) $(LIBS)
107
108# The DFA_XTRA setting turns all libpng options off then
109# turns on those required for this minimal build.
110# The CPP_FLAGS setting causes pngusr.h to be included in
111# both the build of pnglibconf.h and, subsequently, when
112# building libpng itself.
113$(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak\
114 $(PNGSRC)/scripts/pnglibconf.dfa \
115 $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
116 $(RM) pnglibconf.h pnglibconf.dfn
117 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
118 srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG"\
119 DFA_XTRA="pngusr.dfa" $@
120
121clean:
122 $(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\
123 srcdir=$(PNGSRC) clean
124 $(RM) rpng2-x$(O)
125 $(RM) rpng2-x$(E)
126 $(RM) $(OBJS)
127
128# distclean also removes the copied source and headers
129distclean: clean
130 $(RM) -r scripts # historical reasons
131 $(RM) $(PNGSRCS) $(PNGH)
132 $(RM) $(ZSRCS) $(ZH) $(ZCONF)
133 $(RM) $(PROGSRCS) $(PROGHDRS) $(PROGDOCS)
134
135# Header file dependencies:
136$(PROGOBJS): $(PROGHDRS) $(PNGINC) $(ZINC)
137$(PNGOBJS): $(PNGHDRS) $(ZINC)
138$(ZOBJS): $(ZHDRS)
139
140# Gather the source code from the respective directories
141$(PNGSRCS) $(PNGH): $(PNGSRC)/$@
142 $(RM) $@
143 $(COPY) $(PNGSRC)/$@ $@
144
145# No dependency on the ZLIBSRC target so that it only needs
146# to be specified once.
147$(ZSRCS) $(ZH):
148 $(RM) $@
149 $(COPY) $(ZLIBSRC)/$@ $@
150
151# The unconfigured zconf.h varies in name according to the
152# zlib release
153$(ZCONF):
154 $(RM) $@
155 @for f in zconf.h.in zconf.in.h zconf.h; do\
156 test -r $(ZLIBSRC)/$$f &&\
157 echo $(COPY) $(ZLIBSRC)/$$f $@ &&\
158 $(COPY) $(ZLIBSRC)/$$f $@ && exit 0;\
159 done; echo copy: $(ZLIBSRC)/zconf.h not found; exit 1
160
161$(PROGSRCS) $(PROGHDRS) $(PROGDOCS): $(PROGSRC)/$@
162 $(RM) $@
163 $(COPY) $(PROGSRC)/$@ $@
164
165# End of makefile for rpng2-x
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.dfa b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.dfa
new file mode 100644
index 0000000..0c991d3
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.dfa
@@ -0,0 +1,40 @@
1# pngminim/preader/pngusr.dfa
2#
3# Copyright (c) 2010-2011 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# First all the build options off:
10
11everything = off
12
13# Just switch on the progressive read code
14
15option PROGRESSIVE_READ on
16
17# You may choose fixed or floating point APIs:
18# option FLOATING_POINT on
19
20option FIXED_POINT on
21
22# You must chose the internal fixed point implementation or to
23# use the system floating point. The latter is considerably
24# smaller (by about 1kbyte on an x86 system):
25
26option FLOATING_ARITHMETIC on
27# option FLOATING_ARITHMETIC off
28
29# Your program will probably need other options. The example
30# program here, rpng2-x, requires the following. Take a look
31# at pnglibconf.h to find out the full set of what has to be
32# enabled to make the following work.
33
34option SETJMP on
35option STDIO on
36option READ_bKGD on
37option READ_GAMMA on
38option READ_EXPAND on
39option READ_STRIP_16_TO_8 on
40option READ_GRAY_TO_RGB on
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.h
new file mode 100644
index 0000000..7db806f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminim/preader/pngusr.h
@@ -0,0 +1,24 @@
1/* minrdpngconf.h: headers to make a minimal png-read-only library
2 *
3 * Copyright (c) 2009, 2010-2011 Glenn Randers-Pehrson
4 *
5 * This code is released under the libpng license.
6 * For conditions of distribution and use, see the disclaimer
7 * and license in png.h
8 *
9 * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson
10 */
11
12#ifndef MINPRDPNGCONF_H
13#define MINPRDPNGCONF_H
14
15/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */
16
17/* List options to turn off features of the build that do not
18 * affect the API (so are not recorded in pnglibconf.h)
19 */
20
21#define PNG_NO_WARNINGS
22#define PNG_ALIGN_TYPE PNG_ALIGN_NONE
23
24#endif /* MINPRDPNGCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/README
new file mode 100644
index 0000000..b0516ec
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/README
@@ -0,0 +1,153 @@
1PngMinus
2--------
3(copyright Willem van Schaik, 1999)
4
5
6License
7-------
8
9Permission to use, copy, modify, and distribute this software and
10its documentation for any purpose and without fee is hereby granted,
11provided that the above copyright notice appear in all copies and
12that both that copyright notice and this permission notice appear in
13supporting documentation. This software is provided "as is" without
14express or implied warranty.
15
16
17Some history
18------------
19Soon after the creation of PNG in 1995, the need was felt for a set of
20pnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I
21(Willem van Schaik) started such a project. Luckily we discovered this
22and merged the two together into pnmtopng.tar.gz, which is available
23from a/o ftp://ftp.simplesystems.org/pub/libpng/png/.
24
25These two utilities have many, many options and make use of most of the
26features of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes
27the utilities quite complex and by now not anymore very maintainable.
28When we wrote these programs, libpng was still in an early stage.
29Therefore, lots of the functionality that we put in our software can now
30be done using transform-functions in libpng.
31
32Finally, to compile these programs, you need to have installed and
33compiled three libraries: libpng, zlib and netpbm. Especially the latter
34makes the whole setup a bit bulky. But that's unavoidable given the many
35features of pnmtopng.
36
37
38What now
39--------
40At this moment libpng is in a very stable state and can do much of the
41work done in pnmtopng. Also, pnmtopng needs to be upgraded to the new
42interface of libpng. Hence, it is time for a rewrite from the ground up
43of pnmtopng and pngtopnm. This will happen in the near future (stay
44tuned). The new package will get a different name to distinguish it from
45the old one: PngPlus.
46
47To experiment a bit with the new interface of libpng, I started off with
48a small prototype that contains only the basic functionality. It doesn't
49have any of the options to read or write special chunks and it will do
50no gamma correction. But this makes it also a simple program that is
51quite easy to understand and can serve well as a template for other
52software developments. (By now there are of course a couple of programs,
53like Greg Roelofs' rpng/wpng, that can be used just as good.)
54
55
56Can and can not
57---------------
58As this is the small brother of the future PngPlus, I called this fellow
59PngMinus. Because I started this development in good-old Turbo-C, I
60avoided the use the netpbm library, which requires DOS extenders. Again,
61another reason to call it PngMinus (minus netpbm :-). So, part of the
62program are some elementary routines to read / write pgm- and ppm-files.
63It does not read b&w pbm-files.
64
65The downside of this approach is that you can not use them on images
66that require blocks of memory bigger than 64k (the DOS version). For
67larger images you will get an out-of-memory error.
68
69As said before, PngMinus doesn't correct for gamma. When reading
70png-files you can do this just as well by piping the output of png2pnm
71to pnmgamma, one of the standard PbmPlus tools. This same scenario will
72most probably also be followed in the full-blown future PngPlus, with
73the addition of course of the possibility to create gamma-chunks when
74writing png-files.
75
76On the other hand it supports alpha-channels. When reading a png-image
77you can write the alpha-channel into a pgm-file. And when creating an
78RGB+A png-image, you just combine a ppm-file with a corresponding
79pgm-file containing the alpha-channel. When reading, transparency chunks
80are converted into an alpha-channel and from there on treated the same
81way.
82
83Finally you can opt for writing ascii or binary pgm- and ppm-files. When
84the bit-depth is 16, the format will always be ascii.
85
86
87Using it
88--------
89To distinguish them from pnmtopng and PngPlus, the utilities are named
90png2pnm and pnm2png (2 instead of to). The input- and output-files can
91be given as parameters or through redirection. Therefore the programs
92can be part of a pipe.
93
94To list the options type "png2pnm -h" or "pnm2png -h".
95
96
97Just like Scandinavian furniture
98--------------------------------
99You have to put it together yourself. I did test the software under
100MS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both
101cases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,
102however some older libpng versions have a bug in pngmem.c when using
103Turbo-C 3.0 (see below).
104
105You can build it using one of the two makefiles (make -f makefile.###)
106or use the batch/script files pngminus.bat / pngminus.sh. This assumes
107that you have built the libraries in ../libpng and ../zlib. Using Linux,
108make sure that you have built libpng with makefile.std and not
109makefile.linux (also called .lnx in earlier versions of libpng). The
110latter creates a .so shared-library, while the PngMinus makefile assumes
111a normal .a static library.
112
113If you create a ../pngsuite directory and then store the basn####.png
114files from PngSuite (http://www.schaik.com/pngsuite/) in there, you can
115test in one go the proper functioning of PngMinus, see png2pnm.bat and
116pnm2png.bat (or the .sh versions).
117
118
119Warranty
120-------
121Please, remember that this was just a small experiment to learn a few
122things. It will have many unforeseen features <vbg>. Who said bugs? Use
123it when you are in need for something simple or when you want to start
124developing your own stuff.
125
126
127The Turbo bug
128-------------
129** pngmem.old
130 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
131 hptr += 16L;
132** pngmem.c
133 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
134 hptr = hptr + 16L;
135**
136
137** pngmem.old
138 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
139 hptr += (png_uint_32)65536L;
140** pngmem.c
141 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
142 hptr = hptr + 65536L;
143**
144
145
146The end
147-------
148Willem van Schaik
149mailto:willem@schaik.com
150http://www.schaik.com/png/
151-------
152Oct 1999
153
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.std b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.std
new file mode 100644
index 0000000..a121032
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.std
@@ -0,0 +1,65 @@
1# Makefile for PngMinus (png2pnm and pnm2png)
2# Linux / Unix
3
4#CC=cc
5CC=gcc
6LD=$(CC)
7
8RM=rm -f
9
10#PNGPATH = /usr/local
11#PNGINC = -I$(PNGPATH)/include/libpng15
12#PNGLIB = -L$(PNGPATH)/lib -lpng15
13#PNGLIBS = $(PNGPATH)/lib/libpng15.a
14PNGINC = -I../..
15PNGLIB = -L../.. -lpng
16PNGLIBS = ../../libpng.a
17
18#ZPATH = /usr/local
19#ZINC = -I$(ZPATH)/include
20#ZLIB = -L$(ZPATH)/lib -lz
21#ZLIBS = $(ZPATH)/lib/libz.a
22ZINC = -I../../../zlib
23ZLIB = -L../../../zlib -lz
24ZLIBS = ../../../zlib/libz.a
25
26CFLAGS=$(PNGINC) $(ZINC)
27LDLIBS=$(PNGLIB) $(ZLIB)
28LDLIBSS=$(PNGLIBS) $(ZLIBS)
29C=.c
30O=.o
31L=.a
32E=
33
34# dependencies
35
36#all: png2pnm$(E) pnm2png$(E)
37all: png2pnm$(E) pnm2png$(E) png2pnm-static$(E) pnm2png-static$(E)
38
39png2pnm$(O): png2pnm$(C)
40 $(CC) -c $(CFLAGS) png2pnm$(C)
41
42png2pnm$(E): png2pnm$(O)
43 $(LD) $(LDFLAGS) -o png2pnm$(E) png2pnm$(O) $(LDLIBS) -lm
44
45png2pnm-static$(E): png2pnm$(O)
46 $(LD) $(LDFLAGS) -o png2pnm-static$(E) png2pnm$(O) $(LDLIBSS) -lm
47
48pnm2png$(O): pnm2png$(C)
49 $(CC) -c $(CFLAGS) pnm2png$(C)
50
51pnm2png$(E): pnm2png$(O)
52 $(LD) $(LDFLAGS) -o pnm2png$(E) pnm2png$(O) $(LDLIBS) -lm
53
54pnm2png-static$(E): pnm2png$(O)
55 $(LD) $(LDFLAGS) -o pnm2png-static$(E) pnm2png$(O) $(LDLIBSS) -lm
56
57clean:
58 $(RM) png2pnm$(O)
59 $(RM) pnm2png$(O)
60 $(RM) png2pnm$(E)
61 $(RM) pnm2png$(E)
62 $(RM) png2pnm-static$(E)
63 $(RM) pnm2png-static$(E)
64
65# End of makefile for png2pnm / pnm2png
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.tc3 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.tc3
new file mode 100644
index 0000000..01062cc
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makefile.tc3
@@ -0,0 +1,38 @@
1# Makefile for PngMinus (png2pnm and pnm2png)
2# TurboC++ 3.0
3
4CC=tcc -Ic:\tc3\inc
5LD=tcc -Lc:\tc3\lib
6LB=tlib
7RM=del
8CP=copy
9MODEL=l
10CCFLAGS=-O -m$(MODEL) -I..\libpng -I..\zlib
11LDFLAGS=-m$(MODEL) -L..\libpng -L..\zlib
12C=.c
13O=.obj
14L=.lib
15E=.exe
16
17# dependencies
18
19all: png2pnm$(E) pnm2png$(E)
20
21png2pnm$(O): png2pnm$(C)
22 $(CC) -c $(CCFLAGS) png2pnm$(C)
23
24png2pnm$(E): png2pnm$(O)
25 $(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L)
26
27pnm2png$(O): pnm2png$(C)
28 $(CC) -c $(CCFLAGS) pnm2png$(C)
29
30pnm2png$(E): pnm2png$(O)
31 $(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L)
32
33clean:
34 $(RM) *$(O)
35 $(RM) *$(E)
36
37# End of makefile for png2pnm / pnm2png
38
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makevms.com b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makevms.com
new file mode 100644
index 0000000..96c3147
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/makevms.com
@@ -0,0 +1,92 @@
1$!------------------------------------------------------------------------------
2$! make Contrib programs of libpng under OpenVMS
3$!
4$!
5$! Look for the compiler used
6$!
7$ zlibsrc = "[---.zlib]"
8$ ccopt="/include=(''zlibsrc',[--])"
9$ if f$getsyi("HW_MODEL").ge.1024
10$ then
11$ ccopt = "/prefix=all"+ccopt
12$ comp = "__decc__=1"
13$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
14$ else
15$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
16$ then
17$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
18$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
19$ then
20$ comp = "__gcc__=1"
21$ CC :== GCC
22$ else
23$ comp = "__vaxc__=1"
24$ endif
25$ else
26$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
27$ ccopt = "/decc/prefix=all"+ccopt
28$ comp = "__decc__=1"
29$ endif
30$ endif
31$ open/write lopt lib.opt
32$ write lopt "[--]libpng.olb/lib"
33$ write lopt "''zlibsrc'libz.olb/lib"
34$ close lopt
35$ open/write xopt x11.opt
36$ write xopt "sys$library:decw$xlibshr.exe/share"
37$ close xopt
38$ write sys$output "Compiling PNG contrib programs ..."
39$ write sys$output "Building pnm2png..."
40$ CALL MAKE pnm2png.OBJ "cc ''CCOPT' pnm2png" -
41 pnm2png.c
42$ call make pnm2png.exe -
43 "LINK pnm2png,lib.opt/opt" -
44 pnm2png.obj
45$ write sys$output "Building png2pnm..."
46$ CALL MAKE png2pnm.OBJ "cc ''CCOPT' png2pnm" -
47 png2pnm.c
48$ call make png2pnm.exe -
49 "LINK png2pnm,lib.opt/opt" -
50 png2pnm.obj
51$ exit
52$!
53$!
54$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
55$ V = 'F$Verify(0)
56$! P1 = What we are trying to make
57$! P2 = Command to make it
58$! P3 - P8 What it depends on
59$
60$ If F$Search(P1) .Eqs. "" Then Goto Makeit
61$ Time = F$CvTime(F$File(P1,"RDT"))
62$arg=3
63$Loop:
64$ Argument = P'arg
65$ If Argument .Eqs. "" Then Goto Exit
66$ El=0
67$Loop2:
68$ File = F$Element(El," ",Argument)
69$ If File .Eqs. " " Then Goto Endl
70$ AFile = ""
71$Loop3:
72$ OFile = AFile
73$ AFile = F$Search(File)
74$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
75$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
76$ Goto Loop3
77$NextEL:
78$ El = El + 1
79$ Goto Loop2
80$EndL:
81$ arg=arg+1
82$ If arg .Le. 8 Then Goto Loop
83$ Goto Exit
84$
85$Makeit:
86$ VV=F$VERIFY(0)
87$ write sys$output P2
88$ 'P2
89$ VV='F$Verify(VV)
90$Exit:
91$ If V Then Set Verify
92$ENDSUBROUTINE
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.bat b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.bat
new file mode 100644
index 0000000..85abe3c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.bat
@@ -0,0 +1,41 @@
1REM -- grayscale
2png2pnm.exe -noraw ..\pngsuite\basn0g01.png basn0g01.pgm
3png2pnm.exe -noraw ..\pngsuite\basn0g02.png basn0g02.pgm
4png2pnm.exe -noraw ..\pngsuite\basn0g04.png basn0g04.pgm
5png2pnm.exe -noraw ..\pngsuite\basn0g08.png basn0g08.pgm
6png2pnm.exe -noraw ..\pngsuite\basn0g16.png basn0g16.pgm
7REM -- full-color
8png2pnm.exe -noraw ..\pngsuite\basn2c08.png basn2c08.ppm
9png2pnm.exe -noraw ..\pngsuite\basn2c16.png basn2c16.ppm
10REM -- palletted
11png2pnm.exe -noraw ..\pngsuite\basn3p01.png basn3p01.ppm
12png2pnm.exe -noraw ..\pngsuite\basn3p02.png basn3p02.ppm
13png2pnm.exe -noraw ..\pngsuite\basn3p04.png basn3p04.ppm
14png2pnm.exe -noraw ..\pngsuite\basn3p08.png basn3p08.ppm
15REM -- gray with alpha-channel
16png2pnm.exe -noraw ..\pngsuite\basn4a08.png basn4a08.pgm
17png2pnm.exe -noraw ..\pngsuite\basn4a16.png basn4a16.pgm
18REM -- color with alpha-channel
19png2pnm.exe -noraw -alpha basn6a08.pgm ..\pngsuite\basn6a08.png basn6a08.ppm
20png2pnm.exe -noraw -alpha basn6a16.pgm ..\pngsuite\basn6a16.png basn6a16.ppm
21REM -- grayscale
22png2pnm.exe -raw ..\pngsuite\basn0g01.png rawn0g01.pgm
23png2pnm.exe -raw ..\pngsuite\basn0g02.png rawn0g02.pgm
24png2pnm.exe -raw ..\pngsuite\basn0g04.png rawn0g04.pgm
25png2pnm.exe -raw ..\pngsuite\basn0g08.png rawn0g08.pgm
26png2pnm.exe -raw ..\pngsuite\basn0g16.png rawn0g16.pgm
27REM -- full-color
28png2pnm.exe -raw ..\pngsuite\basn2c08.png rawn2c08.ppm
29png2pnm.exe -raw ..\pngsuite\basn2c16.png rawn2c16.ppm
30REM -- palletted
31png2pnm.exe -raw ..\pngsuite\basn3p01.png rawn3p01.ppm
32png2pnm.exe -raw ..\pngsuite\basn3p02.png rawn3p02.ppm
33png2pnm.exe -raw ..\pngsuite\basn3p04.png rawn3p04.ppm
34png2pnm.exe -raw ..\pngsuite\basn3p08.png rawn3p08.ppm
35REM -- gray with alpha-channel
36png2pnm.exe -raw ..\pngsuite\basn4a08.png rawn4a08.pgm
37png2pnm.exe -raw ..\pngsuite\basn4a16.png rawn4a16.pgm
38REM -- color with alpha-channel
39png2pnm.exe -noraw -alpha rawn6a08.pgm ..\pngsuite\basn6a08.png rawn6a08.ppm
40png2pnm.exe -noraw -alpha rawn6a16.pgm ..\pngsuite\basn6a16.png rawn6a16.ppm
41
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.c
new file mode 100644
index 0000000..ef28d90
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.c
@@ -0,0 +1,430 @@
1/*
2 * png2pnm.c --- conversion from PNG-file to PGM/PPM-file
3 * copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
4 *
5 * version 1.0 - 1999.10.15 - First version.
6 *
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear in
11 * supporting documentation. This software is provided "as is" without
12 * express or implied warranty.
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#ifdef __TURBOC__
18#include <mem.h>
19#include <fcntl.h>
20#endif
21
22#ifndef BOOL
23#define BOOL unsigned char
24#endif
25#ifndef TRUE
26#define TRUE (BOOL) 1
27#endif
28#ifndef FALSE
29#define FALSE (BOOL) 0
30#endif
31
32#ifdef __TURBOC__
33#define STDIN 0
34#define STDOUT 1
35#define STDERR 2
36#endif
37
38/* to make png2pnm verbose so we can find problems (needs to be before png.h) */
39#ifndef PNG_DEBUG
40#define PNG_DEBUG 0
41#endif
42
43#include "png.h"
44
45/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
46#ifndef png_jmpbuf
47# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
48#endif
49
50/* function prototypes */
51
52int main (int argc, char *argv[]);
53void usage ();
54BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha);
55
56/*
57 * main
58 */
59
60int main(int argc, char *argv[])
61{
62 FILE *fp_rd = stdin;
63 FILE *fp_wr = stdout;
64 FILE *fp_al = NULL;
65 BOOL raw = TRUE;
66 BOOL alpha = FALSE;
67 int argi;
68
69 for (argi = 1; argi < argc; argi++)
70 {
71 if (argv[argi][0] == '-')
72 {
73 switch (argv[argi][1])
74 {
75 case 'n':
76 raw = FALSE;
77 break;
78 case 'r':
79 raw = TRUE;
80 break;
81 case 'a':
82 alpha = TRUE;
83 argi++;
84 if ((fp_al = fopen (argv[argi], "wb")) == NULL)
85 {
86 fprintf (stderr, "PNM2PNG\n");
87 fprintf (stderr, "Error: can not create alpha-channel file %s\n", argv[argi]);
88 exit (1);
89 }
90 break;
91 case 'h':
92 case '?':
93 usage();
94 exit(0);
95 break;
96 default:
97 fprintf (stderr, "PNG2PNM\n");
98 fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
99 usage();
100 exit(1);
101 break;
102 } /* end switch */
103 }
104 else if (fp_rd == stdin)
105 {
106 if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
107 {
108 fprintf (stderr, "PNG2PNM\n");
109 fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
110 exit (1);
111 }
112 }
113 else if (fp_wr == stdout)
114 {
115 if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
116 {
117 fprintf (stderr, "PNG2PNM\n");
118 fprintf (stderr, "Error: can not create file %s\n", argv[argi]);
119 exit (1);
120 }
121 }
122 else
123 {
124 fprintf (stderr, "PNG2PNM\n");
125 fprintf (stderr, "Error: too many parameters\n");
126 usage();
127 exit(1);
128 }
129 } /* end for */
130
131#ifdef __TURBOC__
132 /* set stdin/stdout if required to binary */
133 if (fp_rd == stdin)
134 {
135 setmode (STDIN, O_BINARY);
136 }
137 if ((raw) && (fp_wr == stdout))
138 {
139 setmode (STDOUT, O_BINARY);
140 }
141#endif
142
143 /* call the conversion program itself */
144 if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)
145 {
146 fprintf (stderr, "PNG2PNM\n");
147 fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n");
148 exit(1);
149 }
150
151 /* close input file */
152 fclose (fp_rd);
153 /* close output file */
154 fclose (fp_wr);
155 /* close alpha file */
156 if (alpha)
157 fclose (fp_al);
158
159 return 0;
160}
161
162/*
163 * usage
164 */
165
166void usage()
167{
168 fprintf (stderr, "PNG2PNM\n");
169 fprintf (stderr, " by Willem van Schaik, 1999\n");
170#ifdef __TURBOC__
171 fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
172#else
173 fprintf (stderr, " for Linux (and Unix) compilers\n");
174#endif
175 fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n");
176 fprintf (stderr, " or: ... | png2pnm [options]\n");
177 fprintf (stderr, "Options:\n");
178 fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n");
179 fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n");
180 fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n");
181 fprintf (stderr, " -h | -? print this help-information\n");
182}
183
184/*
185 * png2pnm
186 */
187
188BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha)
189{
190 png_struct *png_ptr = NULL;
191 png_info *info_ptr = NULL;
192 png_byte buf[8];
193 png_byte *png_pixels = NULL;
194 png_byte **row_pointers = NULL;
195 png_byte *pix_ptr = NULL;
196 png_uint_32 row_bytes;
197
198 png_uint_32 width;
199 png_uint_32 height;
200 int bit_depth;
201 int channels;
202 int color_type;
203 int alpha_present;
204 int row, col;
205 int ret;
206 int i;
207 long dep_16;
208
209 /* read and check signature in PNG file */
210 ret = fread (buf, 1, 8, png_file);
211 if (ret != 8)
212 return FALSE;
213
214 ret = png_sig_cmp (buf, 0, 8);
215 if (ret)
216 return FALSE;
217
218 /* create png and info structures */
219
220 png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
221 NULL, NULL, NULL);
222 if (!png_ptr)
223 return FALSE; /* out of memory */
224
225 info_ptr = png_create_info_struct (png_ptr);
226 if (!info_ptr)
227 {
228 png_destroy_read_struct (&png_ptr, NULL, NULL);
229 return FALSE; /* out of memory */
230 }
231
232 if (setjmp (png_jmpbuf(png_ptr)))
233 {
234 png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
235 return FALSE;
236 }
237
238 /* set up the input control for C streams */
239 png_init_io (png_ptr, png_file);
240 png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */
241
242 /* read the file information */
243 png_read_info (png_ptr, info_ptr);
244
245 /* get size and bit-depth of the PNG-image */
246 png_get_IHDR (png_ptr, info_ptr,
247 &width, &height, &bit_depth, &color_type,
248 NULL, NULL, NULL);
249
250 /* set-up the transformations */
251
252 /* transform paletted images into full-color rgb */
253 if (color_type == PNG_COLOR_TYPE_PALETTE)
254 png_set_expand (png_ptr);
255 /* expand images to bit-depth 8 (only applicable for grayscale images) */
256 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
257 png_set_expand (png_ptr);
258 /* transform transparency maps into full alpha-channel */
259 if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
260 png_set_expand (png_ptr);
261
262#ifdef NJET
263 /* downgrade 16-bit images to 8 bit */
264 if (bit_depth == 16)
265 png_set_strip_16 (png_ptr);
266 /* transform grayscale images into full-color */
267 if (color_type == PNG_COLOR_TYPE_GRAY ||
268 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
269 png_set_gray_to_rgb (png_ptr);
270 /* only if file has a file gamma, we do a correction */
271 if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))
272 png_set_gamma (png_ptr, (double) 2.2, file_gamma);
273#endif
274
275 /* all transformations have been registered; now update info_ptr data,
276 * get rowbytes and channels, and allocate image memory */
277
278 png_read_update_info (png_ptr, info_ptr);
279
280 /* get the new color-type and bit-depth (after expansion/stripping) */
281 png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
282 NULL, NULL, NULL);
283
284 /* check for 16-bit files */
285 if (bit_depth == 16)
286 {
287 raw = FALSE;
288#ifdef __TURBOC__
289 pnm_file->flags &= ~((unsigned) _F_BIN);
290#endif
291 }
292
293 /* calculate new number of channels and store alpha-presence */
294 if (color_type == PNG_COLOR_TYPE_GRAY)
295 channels = 1;
296 else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
297 channels = 2;
298 else if (color_type == PNG_COLOR_TYPE_RGB)
299 channels = 3;
300 else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
301 channels = 4;
302 else
303 channels = 0; /* should never happen */
304 alpha_present = (channels - 1) % 2;
305
306 /* check if alpha is expected to be present in file */
307 if (alpha && !alpha_present)
308 {
309 fprintf (stderr, "PNG2PNM\n");
310 fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n");
311 exit (1);
312 }
313
314 /* row_bytes is the width x number of channels x (bit-depth / 8) */
315 row_bytes = png_get_rowbytes (png_ptr, info_ptr);
316
317 if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL) {
318 png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
319 return FALSE;
320 }
321
322 if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
323 {
324 png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
325 free (png_pixels);
326 png_pixels = NULL;
327 return FALSE;
328 }
329
330 /* set the individual row_pointers to point at the correct offsets */
331 for (i = 0; i < (height); i++)
332 row_pointers[i] = png_pixels + i * row_bytes;
333
334 /* now we can go ahead and just read the whole image */
335 png_read_image (png_ptr, row_pointers);
336
337 /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
338 png_read_end (png_ptr, info_ptr);
339
340 /* clean up after the read, and free any memory allocated - REQUIRED */
341 png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);
342
343 /* write header of PNM file */
344
345 if ((color_type == PNG_COLOR_TYPE_GRAY) ||
346 (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
347 {
348 fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2");
349 fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
350 fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
351 }
352 else if ((color_type == PNG_COLOR_TYPE_RGB) ||
353 (color_type == PNG_COLOR_TYPE_RGB_ALPHA))
354 {
355 fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3");
356 fprintf (pnm_file, "%d %d\n", (int) width, (int) height);
357 fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
358 }
359
360 /* write header of PGM file with alpha channel */
361
362 if ((alpha) &&
363 ((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||
364 (color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
365 {
366 fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2");
367 fprintf (alpha_file, "%d %d\n", (int) width, (int) height);
368 fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L));
369 }
370
371 /* write data to PNM file */
372 pix_ptr = png_pixels;
373
374 for (row = 0; row < height; row++)
375 {
376 for (col = 0; col < width; col++)
377 {
378 for (i = 0; i < (channels - alpha_present); i++)
379 {
380 if (raw)
381 fputc ((int) *pix_ptr++ , pnm_file);
382 else
383 if (bit_depth == 16){
384 dep_16 = (long) *pix_ptr++;
385 fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++));
386 }
387 else
388 fprintf (pnm_file, "%ld ", (long) *pix_ptr++);
389 }
390 if (alpha_present)
391 {
392 if (!alpha)
393 {
394 pix_ptr++; /* alpha */
395 if (bit_depth == 16)
396 pix_ptr++;
397 }
398 else /* output alpha-channel as pgm file */
399 {
400 if (raw)
401 fputc ((int) *pix_ptr++ , alpha_file);
402 else
403 if (bit_depth == 16){
404 dep_16 = (long) *pix_ptr++;
405 fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++);
406 }
407 else
408 fprintf (alpha_file, "%ld ", (long) *pix_ptr++);
409 }
410 } /* if alpha_present */
411
412 if (!raw)
413 if (col % 4 == 3)
414 fprintf (pnm_file, "\n");
415 } /* end for col */
416
417 if (!raw)
418 if (col % 4 != 0)
419 fprintf (pnm_file, "\n");
420 } /* end for row */
421
422 if (row_pointers != (unsigned char**) NULL)
423 free (row_pointers);
424 if (png_pixels != (unsigned char*) NULL)
425 free (png_pixels);
426
427 return TRUE;
428
429} /* end of source */
430
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.sh b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.sh
new file mode 100755
index 0000000..ee39664
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/png2pnm.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2# -- grayscale
3./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm
4./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm
5./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm
6./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm
7./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm
8# -- full-color
9./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm
10./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm
11# -- palletted
12./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm
13./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm
14./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm
15./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm
16# -- gray with alpha-channel
17./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm
18./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm
19# -- color with alpha-channel
20./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm
21./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm
22# -- grayscale
23./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm
24./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm
25./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm
26./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm
27./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm
28# -- full-color
29./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm
30./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm
31# -- palletted
32./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm
33./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm
34./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm
35./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm
36# -- gray with alpha-channel
37./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm
38./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm
39# -- color with alpha-channel
40./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm
41./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm
42
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.bat b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.bat
new file mode 100644
index 0000000..5f8d2d4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.bat
@@ -0,0 +1,4 @@
1make -f makefile.tc3
2call png2pnm.bat
3call pnm2png.bat
4
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.sh b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.sh
new file mode 100755
index 0000000..adcef55
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pngminus.sh
@@ -0,0 +1,5 @@
1#!/bin/sh
2make -f makefile.std
3sh png2pnm.sh
4sh pnm2png.sh
5
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.bat b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.bat
new file mode 100644
index 0000000..5b9977a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.bat
@@ -0,0 +1,41 @@
1REM -- grayscale
2pnm2png.exe basn0g01.pgm basn0g01.png
3pnm2png.exe basn0g02.pgm basn0g02.png
4pnm2png.exe basn0g04.pgm basn0g04.png
5pnm2png.exe basn0g08.pgm basn0g08.png
6pnm2png.exe basn0g16.pgm basn0g16.png
7REM -- full-color
8pnm2png.exe basn2c08.ppm basn2c08.png
9pnm2png.exe basn2c16.ppm basn2c16.png
10REM -- palletted
11pnm2png.exe basn3p01.ppm basn3p01.png
12pnm2png.exe basn3p02.ppm basn3p02.png
13pnm2png.exe basn3p04.ppm basn3p04.png
14pnm2png.exe basn3p08.ppm basn3p08.png
15REM -- gray with alpha-channel
16pnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
17pnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
18REM -- color with alpha-channel
19pnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
20pnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
21REM -- grayscale
22pnm2png.exe rawn0g01.pgm rawn0g01.png
23pnm2png.exe rawn0g02.pgm rawn0g02.png
24pnm2png.exe rawn0g04.pgm rawn0g04.png
25pnm2png.exe rawn0g08.pgm rawn0g08.png
26pnm2png.exe rawn0g16.pgm rawn0g16.png
27REM -- full-color
28pnm2png.exe rawn2c08.ppm rawn2c08.png
29pnm2png.exe rawn2c16.ppm rawn2c16.png
30REM -- palletted
31pnm2png.exe rawn3p01.ppm rawn3p01.png
32pnm2png.exe rawn3p02.ppm rawn3p02.png
33pnm2png.exe rawn3p04.ppm rawn3p04.png
34pnm2png.exe rawn3p08.ppm rawn3p08.png
35REM -- gray with alpha-channel
36pnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
37pnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
38REM -- color with alpha-channel
39pnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
40pnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
41
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.c
new file mode 100644
index 0000000..2f321cc
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.c
@@ -0,0 +1,533 @@
1/*
2 * pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file
3 * copyright (C) 1999 by Willem van Schaik <willem@schaik.com>
4 *
5 * version 1.0 - 1999.10.15 - First version.
6 *
7 * Permission to use, copy, modify, and distribute this software and
8 * its documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and
10 * that both that copyright notice and this permission notice appear in
11 * supporting documentation. This software is provided "as is" without
12 * express or implied warranty.
13 */
14
15#include <stdio.h>
16#include <stdlib.h>
17#ifdef __TURBOC__
18#include <mem.h>
19#include <fcntl.h>
20#endif
21
22#ifndef BOOL
23#define BOOL unsigned char
24#endif
25#ifndef TRUE
26#define TRUE (BOOL) 1
27#endif
28#ifndef FALSE
29#define FALSE (BOOL) 0
30#endif
31
32#define STDIN 0
33#define STDOUT 1
34#define STDERR 2
35
36/* to make pnm2png verbose so we can find problems (needs to be before png.h) */
37#ifndef PNG_DEBUG
38#define PNG_DEBUG 0
39#endif
40
41#include "png.h"
42
43/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
44#ifndef png_jmpbuf
45# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
46#endif
47
48/* function prototypes */
49
50int main (int argc, char *argv[]);
51void usage ();
52BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha);
53void get_token(FILE *pnm_file, char *token);
54png_uint_32 get_data (FILE *pnm_file, int depth);
55png_uint_32 get_value (FILE *pnm_file, int depth);
56
57/*
58 * main
59 */
60
61int main(int argc, char *argv[])
62{
63 FILE *fp_rd = stdin;
64 FILE *fp_al = NULL;
65 FILE *fp_wr = stdout;
66 BOOL interlace = FALSE;
67 BOOL alpha = FALSE;
68 int argi;
69
70 for (argi = 1; argi < argc; argi++)
71 {
72 if (argv[argi][0] == '-')
73 {
74 switch (argv[argi][1])
75 {
76 case 'i':
77 interlace = TRUE;
78 break;
79 case 'a':
80 alpha = TRUE;
81 argi++;
82 if ((fp_al = fopen (argv[argi], "rb")) == NULL)
83 {
84 fprintf (stderr, "PNM2PNG\n");
85 fprintf (stderr, "Error: alpha-channel file %s does not exist\n",
86 argv[argi]);
87 exit (1);
88 }
89 break;
90 case 'h':
91 case '?':
92 usage();
93 exit(0);
94 break;
95 default:
96 fprintf (stderr, "PNM2PNG\n");
97 fprintf (stderr, "Error: unknown option %s\n", argv[argi]);
98 usage();
99 exit(1);
100 break;
101 } /* end switch */
102 }
103 else if (fp_rd == stdin)
104 {
105 if ((fp_rd = fopen (argv[argi], "rb")) == NULL)
106 {
107 fprintf (stderr, "PNM2PNG\n");
108 fprintf (stderr, "Error: file %s does not exist\n", argv[argi]);
109 exit (1);
110 }
111 }
112 else if (fp_wr == stdout)
113 {
114 if ((fp_wr = fopen (argv[argi], "wb")) == NULL)
115 {
116 fprintf (stderr, "PNM2PNG\n");
117 fprintf (stderr, "Error: can not create PNG-file %s\n", argv[argi]);
118 exit (1);
119 }
120 }
121 else
122 {
123 fprintf (stderr, "PNM2PNG\n");
124 fprintf (stderr, "Error: too many parameters\n");
125 usage();
126 exit (1);
127 }
128 } /* end for */
129
130#ifdef __TURBOC__
131 /* set stdin/stdout to binary, we're reading the PNM always! in binary format */
132 if (fp_rd == stdin)
133 {
134 setmode (STDIN, O_BINARY);
135 }
136 if (fp_wr == stdout)
137 {
138 setmode (STDOUT, O_BINARY);
139 }
140#endif
141
142 /* call the conversion program itself */
143 if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)
144 {
145 fprintf (stderr, "PNM2PNG\n");
146 fprintf (stderr, "Error: unsuccessful converting to PNG-image\n");
147 exit (1);
148 }
149
150 /* close input file */
151 fclose (fp_rd);
152 /* close output file */
153 fclose (fp_wr);
154 /* close alpha file */
155 if (alpha)
156 fclose (fp_al);
157
158 return 0;
159}
160
161/*
162 * usage
163 */
164
165void usage()
166{
167 fprintf (stderr, "PNM2PNG\n");
168 fprintf (stderr, " by Willem van Schaik, 1999\n");
169#ifdef __TURBOC__
170 fprintf (stderr, " for Turbo-C and Borland-C compilers\n");
171#else
172 fprintf (stderr, " for Linux (and Unix) compilers\n");
173#endif
174 fprintf (stderr, "Usage: pnm2png [options] <file>.<pnm> [<file>.png]\n");
175 fprintf (stderr, " or: ... | pnm2png [options]\n");
176 fprintf (stderr, "Options:\n");
177 fprintf (stderr, " -i[nterlace] write png-file with interlacing on\n");
178 fprintf (stderr, " -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\n");
179 fprintf (stderr, " -h | -? print this help-information\n");
180}
181
182/*
183 * pnm2png
184 */
185
186BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace, BOOL alpha)
187{
188 png_struct *png_ptr = NULL;
189 png_info *info_ptr = NULL;
190 png_byte *png_pixels = NULL;
191 png_byte **row_pointers = NULL;
192 png_byte *pix_ptr = NULL;
193 png_uint_32 row_bytes;
194
195 char type_token[16];
196 char width_token[16];
197 char height_token[16];
198 char maxval_token[16];
199 int color_type;
200 png_uint_32 width, alpha_width;
201 png_uint_32 height, alpha_height;
202 png_uint_32 maxval;
203 int bit_depth = 0;
204 int channels;
205 int alpha_depth = 0;
206 int alpha_present;
207 int row, col;
208 BOOL raw, alpha_raw = FALSE;
209 png_uint_32 tmp16;
210 int i;
211
212 /* read header of PNM file */
213
214 get_token(pnm_file, type_token);
215 if (type_token[0] != 'P')
216 {
217 return FALSE;
218 }
219 else if ((type_token[1] == '1') || (type_token[1] == '4'))
220 {
221 raw = (type_token[1] == '4');
222 color_type = PNG_COLOR_TYPE_GRAY;
223 bit_depth = 1;
224 }
225 else if ((type_token[1] == '2') || (type_token[1] == '5'))
226 {
227 raw = (type_token[1] == '5');
228 color_type = PNG_COLOR_TYPE_GRAY;
229 get_token(pnm_file, width_token);
230 sscanf (width_token, "%lu", &width);
231 get_token(pnm_file, height_token);
232 sscanf (height_token, "%lu", &height);
233 get_token(pnm_file, maxval_token);
234 sscanf (maxval_token, "%lu", &maxval);
235 if (maxval <= 1)
236 bit_depth = 1;
237 else if (maxval <= 3)
238 bit_depth = 2;
239 else if (maxval <= 15)
240 bit_depth = 4;
241 else if (maxval <= 255)
242 bit_depth = 8;
243 else /* if (maxval <= 65535) */
244 bit_depth = 16;
245 }
246 else if ((type_token[1] == '3') || (type_token[1] == '6'))
247 {
248 raw = (type_token[1] == '6');
249 color_type = PNG_COLOR_TYPE_RGB;
250 get_token(pnm_file, width_token);
251 sscanf (width_token, "%lu", &width);
252 get_token(pnm_file, height_token);
253 sscanf (height_token, "%lu", &height);
254 get_token(pnm_file, maxval_token);
255 sscanf (maxval_token, "%lu", &maxval);
256 if (maxval <= 1)
257 bit_depth = 1;
258 else if (maxval <= 3)
259 bit_depth = 2;
260 else if (maxval <= 15)
261 bit_depth = 4;
262 else if (maxval <= 255)
263 bit_depth = 8;
264 else /* if (maxval <= 65535) */
265 bit_depth = 16;
266 }
267 else
268 {
269 return FALSE;
270 }
271
272 /* read header of PGM file with alpha channel */
273
274 if (alpha)
275 {
276 if (color_type == PNG_COLOR_TYPE_GRAY)
277 color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
278 if (color_type == PNG_COLOR_TYPE_RGB)
279 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
280
281 get_token(alpha_file, type_token);
282 if (type_token[0] != 'P')
283 {
284 return FALSE;
285 }
286 else if ((type_token[1] == '2') || (type_token[1] == '5'))
287 {
288 alpha_raw = (type_token[1] == '5');
289 get_token(alpha_file, width_token);
290 sscanf (width_token, "%lu", &alpha_width);
291 if (alpha_width != width)
292 return FALSE;
293 get_token(alpha_file, height_token);
294 sscanf (height_token, "%lu", &alpha_height);
295 if (alpha_height != height)
296 return FALSE;
297 get_token(alpha_file, maxval_token);
298 sscanf (maxval_token, "%lu", &maxval);
299 if (maxval <= 1)
300 alpha_depth = 1;
301 else if (maxval <= 3)
302 alpha_depth = 2;
303 else if (maxval <= 15)
304 alpha_depth = 4;
305 else if (maxval <= 255)
306 alpha_depth = 8;
307 else /* if (maxval <= 65535) */
308 alpha_depth = 16;
309 if (alpha_depth != bit_depth)
310 return FALSE;
311 }
312 else
313 {
314 return FALSE;
315 }
316 } /* end if alpha */
317
318 /* calculate the number of channels and store alpha-presence */
319 if (color_type == PNG_COLOR_TYPE_GRAY)
320 channels = 1;
321 else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
322 channels = 2;
323 else if (color_type == PNG_COLOR_TYPE_RGB)
324 channels = 3;
325 else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
326 channels = 4;
327 else
328 channels = 0; /* should not happen */
329
330 alpha_present = (channels - 1) % 2;
331
332 /* row_bytes is the width x number of channels x (bit-depth / 8) */
333 row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);
334
335 if ((png_pixels = (png_byte *) malloc (row_bytes * height * sizeof (png_byte))) == NULL)
336 return FALSE;
337
338 /* read data from PNM file */
339 pix_ptr = png_pixels;
340
341 for (row = 0; row < height; row++)
342 {
343 for (col = 0; col < width; col++)
344 {
345 for (i = 0; i < (channels - alpha_present); i++)
346 {
347 if (raw)
348 *pix_ptr++ = get_data (pnm_file, bit_depth);
349 else
350 if (bit_depth <= 8)
351 *pix_ptr++ = get_value (pnm_file, bit_depth);
352 else
353 {
354 tmp16 = get_value (pnm_file, bit_depth);
355 *pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);
356 pix_ptr++;
357 *pix_ptr = (png_byte) (tmp16 & 0xFF);
358 pix_ptr++;
359 }
360 }
361
362 if (alpha) /* read alpha-channel from pgm file */
363 {
364 if (alpha_raw)
365 *pix_ptr++ = get_data (alpha_file, alpha_depth);
366 else
367 if (alpha_depth <= 8)
368 *pix_ptr++ = get_value (alpha_file, bit_depth);
369 else
370 {
371 tmp16 = get_value (alpha_file, bit_depth);
372 *pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);
373 *pix_ptr++ = (png_byte) (tmp16 & 0xFF);
374 }
375 } /* if alpha */
376
377 } /* end for col */
378 } /* end for row */
379
380 /* prepare the standard PNG structures */
381 png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
382 if (!png_ptr)
383 {
384 return FALSE;
385 }
386 info_ptr = png_create_info_struct (png_ptr);
387 if (!info_ptr)
388 {
389 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
390 return FALSE;
391 }
392
393 /* setjmp() must be called in every function that calls a PNG-reading libpng function */
394 if (setjmp (png_jmpbuf(png_ptr)))
395 {
396 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
397 return FALSE;
398 }
399
400 /* initialize the png structure */
401 png_init_io (png_ptr, png_file);
402
403 /* we're going to write more or less the same PNG as the input file */
404 png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,
405 (!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,
406 PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
407
408 /* write the file header information */
409 png_write_info (png_ptr, info_ptr);
410
411 /* if needed we will allocate memory for an new array of row-pointers */
412 if (row_pointers == (unsigned char**) NULL)
413 {
414 if ((row_pointers = (png_byte **) malloc (height * sizeof (png_bytep))) == NULL)
415 {
416 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
417 return FALSE;
418 }
419 }
420
421 /* set the individual row_pointers to point at the correct offsets */
422 for (i = 0; i < (height); i++)
423 row_pointers[i] = png_pixels + i * row_bytes;
424
425 /* write out the entire image data in one call */
426 png_write_image (png_ptr, row_pointers);
427
428 /* write the additional chuncks to the PNG file (not really needed) */
429 png_write_end (png_ptr, info_ptr);
430
431 /* clean up after the write, and free any memory allocated */
432 png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
433
434 if (row_pointers != (unsigned char**) NULL)
435 free (row_pointers);
436 if (png_pixels != (unsigned char*) NULL)
437 free (png_pixels);
438
439 return TRUE;
440} /* end of pnm2png */
441
442/*
443 * get_token() - gets the first string after whitespace
444 */
445
446void get_token(FILE *pnm_file, char *token)
447{
448 int i = 0;
449
450 /* remove white-space */
451 do
452 {
453 token[i] = (unsigned char) fgetc (pnm_file);
454 }
455 while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
456
457 /* read string */
458 do
459 {
460 i++;
461 token[i] = (unsigned char) fgetc (pnm_file);
462 }
463 while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));
464
465 token[i] = '\0';
466
467 return;
468}
469
470/*
471 * get_data() - takes first byte and converts into next pixel value,
472 * taking as much bits as defined by bit-depth and
473 * using the bit-depth to fill up a byte (0Ah -> AAh)
474 */
475
476png_uint_32 get_data (FILE *pnm_file, int depth)
477{
478 static int bits_left = 0;
479 static int old_value = 0;
480 static int mask = 0;
481 int i;
482 png_uint_32 ret_value;
483
484 if (mask == 0)
485 for (i = 0; i < depth; i++)
486 mask = (mask >> 1) | 0x80;
487
488 if (bits_left <= 0)
489 {
490 old_value = fgetc (pnm_file);
491 bits_left = 8;
492 }
493
494 ret_value = old_value & mask;
495 for (i = 1; i < (8 / depth); i++)
496 ret_value = ret_value || (ret_value >> depth);
497
498 old_value = (old_value << depth) & 0xFF;
499 bits_left -= depth;
500
501 return ret_value;
502}
503
504/*
505 * get_value() - takes first (numeric) string and converts into number,
506 * using the bit-depth to fill up a byte (0Ah -> AAh)
507 */
508
509png_uint_32 get_value (FILE *pnm_file, int depth)
510{
511 static png_uint_32 mask = 0;
512 png_byte token[16];
513 png_uint_32 ret_value;
514 int i = 0;
515
516 if (mask == 0)
517 for (i = 0; i < depth; i++)
518 mask = (mask << 1) | 0x01;
519
520 get_token (pnm_file, (char *) token);
521 sscanf ((const char *) token, "%lu", &ret_value);
522
523 ret_value &= mask;
524
525 if (depth < 8)
526 for (i = 0; i < (8 / depth); i++)
527 ret_value = (ret_value << depth) || ret_value;
528
529 return ret_value;
530}
531
532/* end of source */
533
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.sh b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.sh
new file mode 100755
index 0000000..975f047
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngminus/pnm2png.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2# -- grayscale
3./pnm2png basn0g01.pgm basn0g01.png
4./pnm2png basn0g02.pgm basn0g02.png
5./pnm2png basn0g04.pgm basn0g04.png
6./pnm2png basn0g08.pgm basn0g08.png
7./pnm2png basn0g16.pgm basn0g16.png
8# -- full-color
9./pnm2png basn2c08.ppm basn2c08.png
10./pnm2png basn2c16.ppm basn2c16.png
11# -- palletted
12./pnm2png basn3p01.ppm basn3p01.png
13./pnm2png basn3p02.ppm basn3p02.png
14./pnm2png basn3p04.ppm basn3p04.png
15./pnm2png basn3p08.ppm basn3p08.png
16# -- gray with alpha-channel
17./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png
18./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png
19# -- color with alpha-channel
20./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png
21./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png
22# -- grayscale
23./pnm2png rawn0g01.pgm rawn0g01.png
24./pnm2png rawn0g02.pgm rawn0g02.png
25./pnm2png rawn0g04.pgm rawn0g04.png
26./pnm2png rawn0g08.pgm rawn0g08.png
27./pnm2png rawn0g16.pgm rawn0g16.png
28# -- full-color
29./pnm2png rawn2c08.ppm rawn2c08.png
30./pnm2png rawn2c16.ppm rawn2c16.png
31# -- palletted
32./pnm2png rawn3p01.ppm rawn3p01.png
33./pnm2png rawn3p02.ppm rawn3p02.png
34./pnm2png rawn3p04.ppm rawn3p04.png
35./pnm2png rawn3p08.ppm rawn3p08.png
36# -- gray with alpha-channel
37./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png
38./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png
39# -- color with alpha-channel
40./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png
41./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png
42
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g01.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g01.png
new file mode 100644
index 0000000..e31e1c7
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g01.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g02.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g02.png
new file mode 100644
index 0000000..68809dd
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g02.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g04.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g04.png
new file mode 100644
index 0000000..6fa089c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g04.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g08.png
new file mode 100644
index 0000000..bf522ee
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g16.png
new file mode 100644
index 0000000..318ebca
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn0g16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c08.png
new file mode 100644
index 0000000..21d2f91
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c16.png
new file mode 100644
index 0000000..1bd4a4d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn2c16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p01.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p01.png
new file mode 100644
index 0000000..a21db59
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p01.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p02.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p02.png
new file mode 100644
index 0000000..1d0ab61
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p02.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p04.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p04.png
new file mode 100644
index 0000000..6dc6eac
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p04.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p08.png
new file mode 100644
index 0000000..0e07f48
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a08.png
new file mode 100644
index 0000000..3bb0dd0
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a16.png
new file mode 100644
index 0000000..6dbee9f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn4a16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a08.png
new file mode 100644
index 0000000..6106230
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a16.png
new file mode 100644
index 0000000..a9bf3cb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/basn6a16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn1g04.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn1g04.png
new file mode 100644
index 0000000..39a7050
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn1g04.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn2c16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn2c16.png
new file mode 100644
index 0000000..dd3168e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn2c16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn3p08.png
new file mode 100644
index 0000000..0ede357
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbbn3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn2c16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn2c16.png
new file mode 100644
index 0000000..85cec39
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn2c16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn3p08.png
new file mode 100644
index 0000000..8cf2e6f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbgn3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbrn2c08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbrn2c08.png
new file mode 100644
index 0000000..5cca0d6
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbrn2c08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn1g16.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn1g16.png
new file mode 100644
index 0000000..99bdeed
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn1g16.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn3p08.png
new file mode 100644
index 0000000..eacab7a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbwn3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbyn3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbyn3p08.png
new file mode 100644
index 0000000..656db09
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftbyn3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n1g08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n1g08.png
new file mode 100644
index 0000000..333465f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n1g08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n2c08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n2c08.png
new file mode 100644
index 0000000..fc6e42c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n2c08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n3p08.png
new file mode 100644
index 0000000..69a69e58
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp0n3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp1n3p08.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp1n3p08.png
new file mode 100644
index 0000000..a6c9f35
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/pngsuite/ftp1n3p08.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.c
new file mode 100644
index 0000000..f3e440a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.c
@@ -0,0 +1,450 @@
1/*-------------------------------------
2 * PNGFILE.C -- Image File Functions
3 *-------------------------------------
4 *
5 * Copyright 2000, Willem van Schaik.
6 *
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
9 * and license in png.h
10 */
11
12#include <windows.h>
13#include <commdlg.h>
14#include <stdio.h>
15#include <stdlib.h>
16
17#include "png.h"
18#include "pngfile.h"
19#include "cexcept.h"
20
21define_exception_type(const char *);
22extern struct exception_context the_exception_context[1];
23struct exception_context the_exception_context[1];
24png_const_charp msg;
25
26static OPENFILENAME ofn;
27
28static png_structp png_ptr = NULL;
29static png_infop info_ptr = NULL;
30
31
32/* cexcept interface */
33
34static void
35png_cexcept_error(png_structp png_ptr, png_const_charp msg)
36{
37 if(png_ptr)
38 ;
39#ifdef PNG_CONSOLE_IO_SUPPORTED
40 fprintf(stderr, "libpng error: %s\n", msg);
41#endif
42 {
43 Throw msg;
44 }
45}
46
47/* Windows open-file functions */
48
49void PngFileInitialize (HWND hwnd)
50{
51 static TCHAR szFilter[] = TEXT ("PNG Files (*.PNG)\0*.png\0")
52 TEXT ("All Files (*.*)\0*.*\0\0");
53
54 ofn.lStructSize = sizeof (OPENFILENAME);
55 ofn.hwndOwner = hwnd;
56 ofn.hInstance = NULL;
57 ofn.lpstrFilter = szFilter;
58 ofn.lpstrCustomFilter = NULL;
59 ofn.nMaxCustFilter = 0;
60 ofn.nFilterIndex = 0;
61 ofn.lpstrFile = NULL; /* Set in Open and Close functions */
62 ofn.nMaxFile = MAX_PATH;
63 ofn.lpstrFileTitle = NULL; /* Set in Open and Close functions */
64 ofn.nMaxFileTitle = MAX_PATH;
65 ofn.lpstrInitialDir = NULL;
66 ofn.lpstrTitle = NULL;
67 ofn.Flags = 0; /* Set in Open and Close functions */
68 ofn.nFileOffset = 0;
69 ofn.nFileExtension = 0;
70 ofn.lpstrDefExt = TEXT ("png");
71 ofn.lCustData = 0;
72 ofn.lpfnHook = NULL;
73 ofn.lpTemplateName = NULL;
74}
75
76BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
77{
78 ofn.hwndOwner = hwnd;
79 ofn.lpstrFile = pstrFileName;
80 ofn.lpstrFileTitle = pstrTitleName;
81 ofn.Flags = OFN_HIDEREADONLY;
82
83 return GetOpenFileName (&ofn);
84}
85
86BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)
87{
88 ofn.hwndOwner = hwnd;
89 ofn.lpstrFile = pstrFileName;
90 ofn.lpstrFileTitle = pstrTitleName;
91 ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
92
93 return GetSaveFileName (&ofn);
94}
95
96/* PNG image handler functions */
97
98BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
99 int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)
100{
101 static FILE *pfFile;
102 png_byte pbSig[8];
103 int iBitDepth;
104 int iColorType;
105 double dGamma;
106 png_color_16 *pBackground;
107 png_uint_32 ulChannels;
108 png_uint_32 ulRowBytes;
109 png_byte *pbImageData = *ppbImageData;
110 static png_byte **ppbRowPointers = NULL;
111 int i;
112
113 /* open the PNG input file */
114
115 if (!pstrFileName)
116 {
117 *ppbImageData = pbImageData = NULL;
118 return FALSE;
119 }
120
121 if (!(pfFile = fopen(pstrFileName, "rb")))
122 {
123 *ppbImageData = pbImageData = NULL;
124 return FALSE;
125 }
126
127 /* first check the eight byte PNG signature */
128
129 fread(pbSig, 1, 8, pfFile);
130 if (png_sig_cmp(pbSig, 0, 8))
131 {
132 *ppbImageData = pbImageData = NULL;
133 return FALSE;
134 }
135
136 /* create the two png(-info) structures */
137
138 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,
139 (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
140 if (!png_ptr)
141 {
142 *ppbImageData = pbImageData = NULL;
143 return FALSE;
144 }
145
146 info_ptr = png_create_info_struct(png_ptr);
147 if (!info_ptr)
148 {
149 png_destroy_read_struct(&png_ptr, NULL, NULL);
150 *ppbImageData = pbImageData = NULL;
151 return FALSE;
152 }
153
154 Try
155 {
156
157 /* initialize the png structure */
158
159#ifdef PNG_STDIO_SUPPORTED
160 png_init_io(png_ptr, pfFile);
161#else
162 png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data);
163#endif
164
165 png_set_sig_bytes(png_ptr, 8);
166
167 /* read all PNG info up to image data */
168
169 png_read_info(png_ptr, info_ptr);
170
171 /* get width, height, bit-depth and color-type */
172
173 png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
174 &iColorType, NULL, NULL, NULL);
175
176 /* expand images of all color-type and bit-depth to 3x8-bit RGB */
177 /* let the library process alpha, transparency, background, etc. */
178
179#ifdef PNG_READ_16_TO_8_SUPPORTED
180 if (iBitDepth == 16)
181# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
182 png_set_scale_16(png_ptr);
183# else
184 png_set_strip_16(png_ptr);
185# endif
186#endif
187 if (iColorType == PNG_COLOR_TYPE_PALETTE)
188 png_set_expand(png_ptr);
189 if (iBitDepth < 8)
190 png_set_expand(png_ptr);
191 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
192 png_set_expand(png_ptr);
193 if (iColorType == PNG_COLOR_TYPE_GRAY ||
194 iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)
195 png_set_gray_to_rgb(png_ptr);
196
197 /* set the background color to draw transparent and alpha images over */
198 if (png_get_bKGD(png_ptr, info_ptr, &pBackground))
199 {
200 png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
201 pBkgColor->red = (byte) pBackground->red;
202 pBkgColor->green = (byte) pBackground->green;
203 pBkgColor->blue = (byte) pBackground->blue;
204 }
205 else
206 {
207 pBkgColor = NULL;
208 }
209
210 /* if required set gamma conversion */
211 if (png_get_gAMA(png_ptr, info_ptr, &dGamma))
212 png_set_gamma(png_ptr, (double) 2.2, dGamma);
213
214 /* after the transformations are registered, update info_ptr data */
215
216 png_read_update_info(png_ptr, info_ptr);
217
218 /* get again width, height and the new bit-depth and color-type */
219
220 png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,
221 &iColorType, NULL, NULL, NULL);
222
223
224 /* row_bytes is the width x number of channels */
225
226 ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);
227 ulChannels = png_get_channels(png_ptr, info_ptr);
228
229 *piChannels = ulChannels;
230
231 /* now we can allocate memory to store the image */
232
233 if (pbImageData)
234 {
235 free (pbImageData);
236 pbImageData = NULL;
237 }
238 if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight)
239 * sizeof(png_byte))) == NULL)
240 {
241 png_error(png_ptr, "Visual PNG: out of memory");
242 }
243 *ppbImageData = pbImageData;
244
245 /* and allocate memory for an array of row-pointers */
246
247 if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)
248 * sizeof(png_bytep))) == NULL)
249 {
250 png_error(png_ptr, "Visual PNG: out of memory");
251 }
252
253 /* set the individual row-pointers to point at the correct offsets */
254
255 for (i = 0; i < (*piHeight); i++)
256 ppbRowPointers[i] = pbImageData + i * ulRowBytes;
257
258 /* now we can go ahead and just read the whole image */
259
260 png_read_image(png_ptr, ppbRowPointers);
261
262 /* read the additional chunks in the PNG file (not really needed) */
263
264 png_read_end(png_ptr, NULL);
265
266 /* and we're done */
267
268 free (ppbRowPointers);
269 ppbRowPointers = NULL;
270
271 /* yepp, done */
272 }
273
274 Catch (msg)
275 {
276 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
277
278 *ppbImageData = pbImageData = NULL;
279
280 if(ppbRowPointers)
281 free (ppbRowPointers);
282
283 fclose(pfFile);
284
285 return FALSE;
286 }
287
288 fclose (pfFile);
289
290 return TRUE;
291}
292
293
294BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
295 int iWidth, int iHeight, png_color bkgColor)
296{
297 const int ciBitDepth = 8;
298 const int ciChannels = 3;
299
300 static FILE *pfFile;
301 png_uint_32 ulRowBytes;
302 static png_byte **ppbRowPointers = NULL;
303 int i;
304
305 /* open the PNG output file */
306
307 if (!pstrFileName)
308 return FALSE;
309
310 if (!(pfFile = fopen(pstrFileName, "wb")))
311 return FALSE;
312
313 /* prepare the standard PNG structures */
314
315 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,
316 (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);
317 if (!png_ptr)
318 {
319 fclose(pfFile);
320 return FALSE;
321 }
322
323 info_ptr = png_create_info_struct(png_ptr);
324 if (!info_ptr) {
325 fclose(pfFile);
326 png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
327 return FALSE;
328 }
329
330 Try
331 {
332 /* initialize the png structure */
333
334#ifdef PNG_STDIO_SUPPORTED
335 png_init_io(png_ptr, pfFile);
336#else
337 png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);
338#endif
339
340 /* we're going to write a very simple 3x8-bit RGB image */
341
342 png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth,
343 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
344 PNG_FILTER_TYPE_BASE);
345
346 /* write the file header information */
347
348 png_write_info(png_ptr, info_ptr);
349
350 /* swap the BGR pixels in the DiData structure to RGB */
351
352 png_set_bgr(png_ptr);
353
354 /* row_bytes is the width x number of channels */
355
356 ulRowBytes = iWidth * ciChannels;
357
358 /* we can allocate memory for an array of row-pointers */
359
360 if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL)
361 Throw "Visualpng: Out of memory";
362
363 /* set the individual row-pointers to point at the correct offsets */
364
365 for (i = 0; i < iHeight; i++)
366 ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2);
367
368 /* write out the entire image data in one call */
369
370 png_write_image (png_ptr, ppbRowPointers);
371
372 /* write the additional chunks to the PNG file (not really needed) */
373
374 png_write_end(png_ptr, info_ptr);
375
376 /* and we're done */
377
378 free (ppbRowPointers);
379 ppbRowPointers = NULL;
380
381 /* clean up after the write, and free any memory allocated */
382
383 png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
384
385 /* yepp, done */
386 }
387
388 Catch (msg)
389 {
390 png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
391
392 if(ppbRowPointers)
393 free (ppbRowPointers);
394
395 fclose(pfFile);
396
397 return FALSE;
398 }
399
400 fclose (pfFile);
401
402 return TRUE;
403}
404
405#ifndef PNG_STDIO_SUPPORTED
406
407static void
408png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
409{
410 png_size_t check;
411
412 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
413 * instead of an int, which is what fread() actually returns.
414 */
415 check = (png_size_t)fread(data, (png_size_t)1, length,
416 (FILE *)png_ptr->io_ptr);
417
418 if (check != length)
419 {
420 png_error(png_ptr, "Read Error");
421 }
422}
423
424static void
425png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
426{
427 png_uint_32 check;
428
429 check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
430 if (check != length)
431 {
432 png_error(png_ptr, "Write Error");
433 }
434}
435
436static void
437png_flush(png_structp png_ptr)
438{
439 FILE *io_ptr;
440 io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
441 if (io_ptr != NULL)
442 fflush(io_ptr);
443}
444
445#endif
446
447/*-----------------
448 * end of source
449 *-----------------
450 */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.h
new file mode 100644
index 0000000..66f8472
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/PngFile.h
@@ -0,0 +1,30 @@
1/*------------------------------------------*/
2/* PNGFILE.H -- Header File for pngfile.c*/
3/*------------------------------------------*/
4
5/* Copyright 2000, Willem van Schaik.*/
6
7/* This code is released under the libpng license.*/
8/* For conditions of distribution and use, see the disclaimer*/
9/* and license in png.h*/
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <windows.h>
15
16void PngFileInitialize (HWND hwnd) ;
17BOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;
18BOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;
19
20BOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,
21 int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor);
22BOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,
23 int iWidth, int iHeight, png_color BkgColor);
24
25#ifndef PNG_STDIO_SUPPORTED
26static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
27static void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
28static void png_flush(png_structp png_ptr);
29#endif
30
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/README.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/README.txt
new file mode 100644
index 0000000..7291bb2
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/README.txt
@@ -0,0 +1,61 @@
1Microsoft Developer Studio Build File, Format Version 6.00 for VisualPng
2------------------------------------------------------------------------
3
4Copyright 2000, Willem van Schaik.
5
6This code is released under the libpng license.
7For conditions of distribution and use, see the disclaimer
8and license in png.h
9
10As a PNG .dll demo VisualPng is finished. More features would only hinder
11the program's objective. However, further extensions (like support for other
12graphics formats) are in development. To get these, or for pre-compiled
13binaries, go to "http://www.schaik.com/png/visualpng.html".
14
15------------------------------------------------------------------------
16
17Assumes that
18
19 libpng DLLs and LIBs are in ..\..\projects\msvc\win32\libpng
20 zlib DLLs and LIBs are in ..\..\projects\msvc\win32\zlib
21 libpng header files are in ..\..\..\libpng
22 zlib header files are in ..\..\..\zlib
23 the pngsuite images are in ..\pngsuite
24
25To build:
26
271) On the main menu Select "Build|Set Active configuration".
28 Choose the configuration that corresponds to the library you want to test.
29 This library must have been built using the libpng MS project located in
30 the "..\..\mscv" subdirectory.
31
322) Select "Build|Clean"
33
343) Select "Build|Rebuild All"
35
364) After compiling and linking VisualPng will be started to view an image
37 from the PngSuite directory. Press Ctrl-N (and Ctrl-V) for other images.
38
39
40To install:
41
42When distributing VisualPng (or a further development) the following options
43are available:
44
451) Build the program with the configuration "Win32 LIB" and you only need to
46 include the executable from the ./lib directory in your distribution.
47
482) Build the program with the configuration "Win32 DLL" and you need to put
49 in your distribution the executable from the ./dll directory and the dll's
50 libpng1.dll, zlib.dll and msvcrt.dll. These need to be in the user's PATH.
51
52
53Willem van Schaik
54Calgary, June 6th 2000
55
56P.S. VisualPng was written based on preliminary work of:
57
58 - Simon-Pierre Cadieux
59 - Glenn Randers-Pehrson
60 - Greg Roelofs
61
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.c
new file mode 100644
index 0000000..e672ce0
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.c
@@ -0,0 +1,969 @@
1/*------------------------------------
2 * VisualPng.C -- Shows a PNG image
3 *------------------------------------
4 *
5 * Copyright 2000, Willem van Schaik.
6 *
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
9 * and license in png.h
10 */
11
12/* switches */
13
14/* defines */
15
16#define PROGNAME "VisualPng"
17#define LONGNAME "Win32 Viewer for PNG-files"
18#define VERSION "1.0 of 2000 June 07"
19
20/* constants */
21
22#define MARGIN 8
23
24/* standard includes */
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <windows.h>
30
31/* application includes */
32
33#include "png.h"
34#include "pngfile.h"
35#include "resource.h"
36
37/* macros */
38
39/* function prototypes */
40
41LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
42BOOL CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;
43
44BOOL CenterAbout (HWND hwndChild, HWND hwndParent);
45
46BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
47 int *pFileIndex);
48
49BOOL SearchPngList (TCHAR *pFileList, int FileCount, int *pFileIndex,
50 PTSTR pstrPrevName, PTSTR pstrNextName);
51
52BOOL LoadImageFile(HWND hwnd, PTSTR pstrPathName,
53 png_byte **ppbImage, int *pxImgSize, int *pyImgSize, int *piChannels,
54 png_color *pBkgColor);
55
56BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
57 BYTE **ppDiData, int cxWinSize, int cyWinSize,
58 BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
59 BOOL bStretched);
60
61BOOL InitBitmap (
62 BYTE *pDiData, int cxWinSize, int cyWinSize);
63
64BOOL FillBitmap (
65 BYTE *pDiData, int cxWinSize, int cyWinSize,
66 BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
67 BOOL bStretched);
68
69/* a few global variables */
70
71static char *szProgName = PROGNAME;
72static char *szAppName = LONGNAME;
73static char *szIconName = PROGNAME;
74static char szCmdFileName [MAX_PATH];
75
76/* MAIN routine */
77
78int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
79 PSTR szCmdLine, int iCmdShow)
80{
81 HACCEL hAccel;
82 HWND hwnd;
83 MSG msg;
84 WNDCLASS wndclass;
85 int ixBorders, iyBorders;
86
87 wndclass.style = CS_HREDRAW | CS_VREDRAW;
88 wndclass.lpfnWndProc = WndProc;
89 wndclass.cbClsExtra = 0;
90 wndclass.cbWndExtra = 0;
91 wndclass.hInstance = hInstance;
92 wndclass.hIcon = LoadIcon (hInstance, szIconName) ;
93 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
94 wndclass.hbrBackground = NULL; /* (HBRUSH) GetStockObject (GRAY_BRUSH); */
95 wndclass.lpszMenuName = szProgName;
96 wndclass.lpszClassName = szProgName;
97
98 if (!RegisterClass (&wndclass))
99 {
100 MessageBox (NULL, TEXT ("Error: this program requires Windows NT!"),
101 szProgName, MB_ICONERROR);
102 return 0;
103 }
104
105 /* if filename given on commandline, store it */
106 if ((szCmdLine != NULL) && (*szCmdLine != '\0'))
107 if (szCmdLine[0] == '"')
108 strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);
109 else
110 strcpy (szCmdFileName, szCmdLine);
111 else
112 strcpy (szCmdFileName, "");
113
114 /* calculate size of window-borders */
115 ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +
116 GetSystemMetrics (SM_CXDLGFRAME));
117 iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +
118 GetSystemMetrics (SM_CYDLGFRAME)) +
119 GetSystemMetrics (SM_CYCAPTION) +
120 GetSystemMetrics (SM_CYMENUSIZE) +
121 1; /* WvS: don't ask me why? */
122
123 hwnd = CreateWindow (szProgName, szAppName,
124 WS_OVERLAPPEDWINDOW,
125 CW_USEDEFAULT, CW_USEDEFAULT,
126 512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,
127/* CW_USEDEFAULT, CW_USEDEFAULT, */
128 NULL, NULL, hInstance, NULL);
129
130 ShowWindow (hwnd, iCmdShow);
131 UpdateWindow (hwnd);
132
133 hAccel = LoadAccelerators (hInstance, szProgName);
134
135 while (GetMessage (&msg, NULL, 0, 0))
136 {
137 if (!TranslateAccelerator (hwnd, hAccel, &msg))
138 {
139 TranslateMessage (&msg);
140 DispatchMessage (&msg);
141 }
142 }
143 return msg.wParam;
144}
145
146LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,
147 LPARAM lParam)
148{
149 static HINSTANCE hInstance ;
150 static HDC hdc;
151 static PAINTSTRUCT ps;
152 static HMENU hMenu;
153
154 static BITMAPFILEHEADER *pbmfh;
155 static BITMAPINFOHEADER *pbmih;
156 static BYTE *pbImage;
157 static int cxWinSize, cyWinSize;
158 static int cxImgSize, cyImgSize;
159 static int cImgChannels;
160 static png_color bkgColor = {127, 127, 127};
161
162 static BOOL bStretched = TRUE;
163
164 static BYTE *pDib = NULL;
165 static BYTE *pDiData = NULL;
166
167 static TCHAR szImgPathName [MAX_PATH];
168 static TCHAR szTitleName [MAX_PATH];
169
170 static TCHAR *pPngFileList = NULL;
171 static int iPngFileCount;
172 static int iPngFileIndex;
173
174 BOOL bOk;
175
176 switch (message)
177 {
178 case WM_CREATE:
179 hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
180 PngFileInitialize (hwnd);
181
182 strcpy (szImgPathName, "");
183
184 /* in case we process file given on command-line */
185
186 if (szCmdFileName[0] != '\0')
187 {
188 strcpy (szImgPathName, szCmdFileName);
189
190 /* read the other png-files in the directory for later */
191 /* next/previous commands */
192
193 BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
194 &iPngFileIndex);
195
196 /* load the image from file */
197
198 if (!LoadImageFile (hwnd, szImgPathName,
199 &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
200 return 0;
201
202 /* invalidate the client area for later update */
203
204 InvalidateRect (hwnd, NULL, TRUE);
205
206 /* display the PNG into the DIBitmap */
207
208 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
209 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
210 }
211
212 return 0;
213
214 case WM_SIZE:
215 cxWinSize = LOWORD (lParam);
216 cyWinSize = HIWORD (lParam);
217
218 /* invalidate the client area for later update */
219
220 InvalidateRect (hwnd, NULL, TRUE);
221
222 /* display the PNG into the DIBitmap */
223
224 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
225 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
226
227 return 0;
228
229 case WM_INITMENUPOPUP:
230 hMenu = GetMenu (hwnd);
231
232 if (pbImage)
233 EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_ENABLED);
234 else
235 EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_GRAYED);
236
237 return 0;
238
239 case WM_COMMAND:
240 hMenu = GetMenu (hwnd);
241
242 switch (LOWORD (wParam))
243 {
244 case IDM_FILE_OPEN:
245
246 /* show the File Open dialog box */
247
248 if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName))
249 return 0;
250
251 /* read the other png-files in the directory for later */
252 /* next/previous commands */
253
254 BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,
255 &iPngFileIndex);
256
257 /* load the image from file */
258
259 if (!LoadImageFile (hwnd, szImgPathName,
260 &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
261 return 0;
262
263 /* invalidate the client area for later update */
264
265 InvalidateRect (hwnd, NULL, TRUE);
266
267 /* display the PNG into the DIBitmap */
268
269 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
270 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
271
272 return 0;
273
274 case IDM_FILE_SAVE:
275
276 /* show the File Save dialog box */
277
278 if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName))
279 return 0;
280
281 /* save the PNG to a disk file */
282
283 SetCursor (LoadCursor (NULL, IDC_WAIT));
284 ShowCursor (TRUE);
285
286 bOk = PngSaveImage (szImgPathName, pDiData, cxWinSize, cyWinSize,
287 bkgColor);
288
289 ShowCursor (FALSE);
290 SetCursor (LoadCursor (NULL, IDC_ARROW));
291
292 if (!bOk)
293 MessageBox (hwnd, TEXT ("Error in saving the PNG image"),
294 szProgName, MB_ICONEXCLAMATION | MB_OK);
295 return 0;
296
297 case IDM_FILE_NEXT:
298
299 /* read next entry in the directory */
300
301 if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
302 NULL, szImgPathName))
303 {
304 if (strcmp (szImgPathName, "") == 0)
305 return 0;
306
307 /* load the image from file */
308
309 if (!LoadImageFile (hwnd, szImgPathName, &pbImage,
310 &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))
311 return 0;
312
313 /* invalidate the client area for later update */
314
315 InvalidateRect (hwnd, NULL, TRUE);
316
317 /* display the PNG into the DIBitmap */
318
319 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
320 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
321 }
322
323 return 0;
324
325 case IDM_FILE_PREVIOUS:
326
327 /* read previous entry in the directory */
328
329 if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,
330 szImgPathName, NULL))
331 {
332
333 if (strcmp (szImgPathName, "") == 0)
334 return 0;
335
336 /* load the image from file */
337
338 if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize,
339 &cyImgSize, &cImgChannels, &bkgColor))
340 return 0;
341
342 /* invalidate the client area for later update */
343
344 InvalidateRect (hwnd, NULL, TRUE);
345
346 /* display the PNG into the DIBitmap */
347
348 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
349 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
350 }
351
352 return 0;
353
354 case IDM_FILE_EXIT:
355
356 /* more cleanup needed... */
357
358 /* free image buffer */
359
360 if (pDib != NULL)
361 {
362 free (pDib);
363 pDib = NULL;
364 }
365
366 /* free file-list */
367
368 if (pPngFileList != NULL)
369 {
370 free (pPngFileList);
371 pPngFileList = NULL;
372 }
373
374 /* let's go ... */
375
376 exit (0);
377
378 return 0;
379
380 case IDM_OPTIONS_STRETCH:
381 bStretched = !bStretched;
382 if (bStretched)
383 CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_CHECKED);
384 else
385 CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED);
386
387 /* invalidate the client area for later update */
388
389 InvalidateRect (hwnd, NULL, TRUE);
390
391 /* display the PNG into the DIBitmap */
392
393 DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,
394 pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);
395
396 return 0;
397
398 case IDM_HELP_ABOUT:
399 DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc) ;
400 return 0;
401
402 } /* end switch */
403
404 break;
405
406 case WM_PAINT:
407 hdc = BeginPaint (hwnd, &ps);
408
409 if (pDib)
410 SetDIBitsToDevice (hdc, 0, 0, cxWinSize, cyWinSize, 0, 0,
411 0, cyWinSize, pDiData, (BITMAPINFO *) pDib, DIB_RGB_COLORS);
412
413 EndPaint (hwnd, &ps);
414 return 0;
415
416 case WM_DESTROY:
417 if (pbmfh)
418 {
419 free (pbmfh);
420 pbmfh = NULL;
421 }
422
423 PostQuitMessage (0);
424 return 0;
425 }
426
427 return DefWindowProc (hwnd, message, wParam, lParam);
428}
429
430BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,
431 WPARAM wParam, LPARAM lParam)
432{
433 switch (message)
434 {
435 case WM_INITDIALOG :
436 ShowWindow (hDlg, SW_HIDE);
437 CenterAbout (hDlg, GetWindow (hDlg, GW_OWNER));
438 ShowWindow (hDlg, SW_SHOW);
439 return TRUE ;
440
441 case WM_COMMAND :
442 switch (LOWORD (wParam))
443 {
444 case IDOK :
445 case IDCANCEL :
446 EndDialog (hDlg, 0) ;
447 return TRUE ;
448 }
449 break ;
450 }
451 return FALSE ;
452}
453
454/*---------------
455 * CenterAbout
456 *---------------
457 */
458BOOL CenterAbout (HWND hwndChild, HWND hwndParent)
459{
460 RECT rChild, rParent, rWorkArea;
461 int wChild, hChild, wParent, hParent;
462 int xNew, yNew;
463 BOOL bResult;
464
465 /* Get the Height and Width of the child window */
466 GetWindowRect (hwndChild, &rChild);
467 wChild = rChild.right - rChild.left;
468 hChild = rChild.bottom - rChild.top;
469
470 /* Get the Height and Width of the parent window */
471 GetWindowRect (hwndParent, &rParent);
472 wParent = rParent.right - rParent.left;
473 hParent = rParent.bottom - rParent.top;
474
475 /* Get the limits of the 'workarea' */
476 bResult = SystemParametersInfo(
477 SPI_GETWORKAREA, /* system parameter to query or set */
478 sizeof(RECT),
479 &rWorkArea,
480 0);
481 if (!bResult) {
482 rWorkArea.left = rWorkArea.top = 0;
483 rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);
484 rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);
485 }
486
487 /* Calculate new X position, then adjust for workarea */
488 xNew = rParent.left + ((wParent - wChild) /2);
489 if (xNew < rWorkArea.left) {
490 xNew = rWorkArea.left;
491 } else if ((xNew+wChild) > rWorkArea.right) {
492 xNew = rWorkArea.right - wChild;
493 }
494
495 /* Calculate new Y position, then adjust for workarea */
496 yNew = rParent.top + ((hParent - hChild) /2);
497 if (yNew < rWorkArea.top) {
498 yNew = rWorkArea.top;
499 } else if ((yNew+hChild) > rWorkArea.bottom) {
500 yNew = rWorkArea.bottom - hChild;
501 }
502
503 /* Set it, and return */
504 return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |
505 SWP_NOZORDER);
506}
507
508/*----------------
509 * BuildPngList
510 *----------------
511 */
512BOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,
513 int *pFileIndex)
514{
515 static TCHAR szImgPathName [MAX_PATH];
516 static TCHAR szImgFileName [MAX_PATH];
517 static TCHAR szImgFindName [MAX_PATH];
518
519 WIN32_FIND_DATA finddata;
520 HANDLE hFind;
521
522 static TCHAR szTmp [MAX_PATH];
523 BOOL bOk;
524 int i, ii;
525 int j, jj;
526
527 /* free previous file-list */
528
529 if (*ppFileList != NULL)
530 {
531 free (*ppFileList);
532 *ppFileList = NULL;
533 }
534
535 /* extract foldername, filename and search-name */
536
537 strcpy (szImgPathName, pstrPathName);
538 strcpy (szImgFileName, strrchr (pstrPathName, '\\') + 1);
539
540 strcpy (szImgFindName, szImgPathName);
541 *(strrchr (szImgFindName, '\\') + 1) = '\0';
542 strcat (szImgFindName, "*.png");
543
544 /* first cycle: count number of files in directory for memory allocation */
545
546 *pFileCount = 0;
547
548 hFind = FindFirstFile(szImgFindName, &finddata);
549 bOk = (hFind != (HANDLE) -1);
550
551 while (bOk)
552 {
553 *pFileCount += 1;
554 bOk = FindNextFile(hFind, &finddata);
555 }
556 FindClose(hFind);
557
558 /* allocation memory for file-list */
559
560 *ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);
561
562 /* second cycle: read directory and store filenames in file-list */
563
564 hFind = FindFirstFile(szImgFindName, &finddata);
565 bOk = (hFind != (HANDLE) -1);
566
567 i = 0;
568 ii = 0;
569 while (bOk)
570 {
571 strcpy (*ppFileList + ii, szImgPathName);
572 strcpy (strrchr(*ppFileList + ii, '\\') + 1, finddata.cFileName);
573
574 if (strcmp(pstrPathName, *ppFileList + ii) == 0)
575 *pFileIndex = i;
576
577 ii += MAX_PATH;
578 i++;
579
580 bOk = FindNextFile(hFind, &finddata);
581 }
582 FindClose(hFind);
583
584 /* finally we must sort the file-list */
585
586 for (i = 0; i < *pFileCount - 1; i++)
587 {
588 ii = i * MAX_PATH;
589 for (j = i+1; j < *pFileCount; j++)
590 {
591 jj = j * MAX_PATH;
592 if (strcmp (*ppFileList + ii, *ppFileList + jj) > 0)
593 {
594 strcpy (szTmp, *ppFileList + jj);
595 strcpy (*ppFileList + jj, *ppFileList + ii);
596 strcpy (*ppFileList + ii, szTmp);
597
598 /* check if this was the current image that we moved */
599
600 if (*pFileIndex == i)
601 *pFileIndex = j;
602 else
603 if (*pFileIndex == j)
604 *pFileIndex = i;
605 }
606 }
607 }
608
609 return TRUE;
610}
611
612/*----------------
613 * SearchPngList
614 *----------------
615 */
616
617BOOL SearchPngList (
618 TCHAR *pFileList, int FileCount, int *pFileIndex,
619 PTSTR pstrPrevName, PTSTR pstrNextName)
620{
621 if (FileCount > 0)
622 {
623 /* get previous entry */
624
625 if (pstrPrevName != NULL)
626 {
627 if (*pFileIndex > 0)
628 *pFileIndex -= 1;
629 else
630 *pFileIndex = FileCount - 1;
631
632 strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));
633 }
634
635 /* get next entry */
636
637 if (pstrNextName != NULL)
638 {
639 if (*pFileIndex < FileCount - 1)
640 *pFileIndex += 1;
641 else
642 *pFileIndex = 0;
643
644 strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH));
645 }
646
647 return TRUE;
648 }
649 else
650 {
651 return FALSE;
652 }
653}
654
655/*-----------------
656 * LoadImageFile
657 *-----------------
658 */
659
660BOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,
661 png_byte **ppbImage, int *pxImgSize, int *pyImgSize,
662 int *piChannels, png_color *pBkgColor)
663{
664 static TCHAR szTmp [MAX_PATH];
665
666 /* if there's an existing PNG, free the memory */
667
668 if (*ppbImage)
669 {
670 free (*ppbImage);
671 *ppbImage = NULL;
672 }
673
674 /* Load the entire PNG into memory */
675
676 SetCursor (LoadCursor (NULL, IDC_WAIT));
677 ShowCursor (TRUE);
678
679 PngLoadImage (pstrPathName, ppbImage, pxImgSize, pyImgSize, piChannels,
680 pBkgColor);
681
682 ShowCursor (FALSE);
683 SetCursor (LoadCursor (NULL, IDC_ARROW));
684
685 if (*ppbImage != NULL)
686 {
687 sprintf (szTmp, "VisualPng - %s", strrchr(pstrPathName, '\\') + 1);
688 SetWindowText (hwnd, szTmp);
689 }
690 else
691 {
692 MessageBox (hwnd, TEXT ("Error in loading the PNG image"),
693 szProgName, MB_ICONEXCLAMATION | MB_OK);
694 return FALSE;
695 }
696
697 return TRUE;
698}
699
700/*----------------
701 * DisplayImage
702 *----------------
703 */
704BOOL DisplayImage (HWND hwnd, BYTE **ppDib,
705 BYTE **ppDiData, int cxWinSize, int cyWinSize,
706 BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
707 BOOL bStretched)
708{
709 BYTE *pDib = *ppDib;
710 BYTE *pDiData = *ppDiData;
711 /* BITMAPFILEHEADER *pbmfh; */
712 BITMAPINFOHEADER *pbmih;
713 WORD wDIRowBytes;
714 png_color bkgBlack = {0, 0, 0};
715 png_color bkgGray = {127, 127, 127};
716 png_color bkgWhite = {255, 255, 255};
717
718 /* allocate memory for the Device Independant bitmap */
719
720 wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;
721
722 if (pDib)
723 {
724 free (pDib);
725 pDib = NULL;
726 }
727
728 if (!(pDib = (BYTE *) malloc (sizeof(BITMAPINFOHEADER) +
729 wDIRowBytes * cyWinSize)))
730 {
731 MessageBox (hwnd, TEXT ("Error in displaying the PNG image"),
732 szProgName, MB_ICONEXCLAMATION | MB_OK);
733 *ppDib = pDib = NULL;
734 return FALSE;
735 }
736 *ppDib = pDib;
737 memset (pDib, 0, sizeof(BITMAPINFOHEADER));
738
739 /* initialize the dib-structure */
740
741 pbmih = (BITMAPINFOHEADER *) pDib;
742 pbmih->biSize = sizeof(BITMAPINFOHEADER);
743 pbmih->biWidth = cxWinSize;
744 pbmih->biHeight = -((long) cyWinSize);
745 pbmih->biPlanes = 1;
746 pbmih->biBitCount = 24;
747 pbmih->biCompression = 0;
748 pDiData = pDib + sizeof(BITMAPINFOHEADER);
749 *ppDiData = pDiData;
750
751 /* first fill bitmap with gray and image border */
752
753 InitBitmap (pDiData, cxWinSize, cyWinSize);
754
755 /* then fill bitmap with image */
756
757 if (pbImage)
758 {
759 FillBitmap (
760 pDiData, cxWinSize, cyWinSize,
761 pbImage, cxImgSize, cyImgSize, cImgChannels,
762 bStretched);
763 }
764
765 return TRUE;
766}
767
768/*--------------
769 * InitBitmap
770 *--------------
771 */
772BOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)
773{
774 BYTE *dst;
775 int x, y, col;
776
777 /* initialize the background with gray */
778
779 dst = pDiData;
780 for (y = 0; y < cyWinSize; y++)
781 {
782 col = 0;
783 for (x = 0; x < cxWinSize; x++)
784 {
785 /* fill with GRAY */
786 *dst++ = 127;
787 *dst++ = 127;
788 *dst++ = 127;
789 col += 3;
790 }
791 /* rows start on 4 byte boundaries */
792 while ((col % 4) != 0)
793 {
794 dst++;
795 col++;
796 }
797 }
798
799 return TRUE;
800}
801
802/*--------------
803 * FillBitmap
804 *--------------
805 */
806BOOL FillBitmap (
807 BYTE *pDiData, int cxWinSize, int cyWinSize,
808 BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,
809 BOOL bStretched)
810{
811 BYTE *pStretchedImage;
812 BYTE *pImg;
813 BYTE *src, *dst;
814 BYTE r, g, b, a;
815 const int cDIChannels = 3;
816 WORD wImgRowBytes;
817 WORD wDIRowBytes;
818 int cxNewSize, cyNewSize;
819 int cxImgPos, cyImgPos;
820 int xImg, yImg;
821 int xWin, yWin;
822 int xOld, yOld;
823 int xNew, yNew;
824
825 if (bStretched)
826 {
827 cxNewSize = cxWinSize - 2 * MARGIN;
828 cyNewSize = cyWinSize - 2 * MARGIN;
829
830 /* stretch the image to it's window determined size */
831
832 /* the following two are mathematically the same, but the first
833 * has side-effects because of rounding
834 */
835/* if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) */
836 if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))
837 {
838 cyNewSize = cxNewSize * cyImgSize / cxImgSize;
839 cxImgPos = MARGIN;
840 cyImgPos = (cyWinSize - cyNewSize) / 2;
841 }
842 else
843 {
844 cxNewSize = cyNewSize * cxImgSize / cyImgSize;
845 cyImgPos = MARGIN;
846 cxImgPos = (cxWinSize - cxNewSize) / 2;
847 }
848
849 pStretchedImage = malloc (cImgChannels * cxNewSize * cyNewSize);
850 pImg = pStretchedImage;
851
852 for (yNew = 0; yNew < cyNewSize; yNew++)
853 {
854 yOld = yNew * cyImgSize / cyNewSize;
855 for (xNew = 0; xNew < cxNewSize; xNew++)
856 {
857 xOld = xNew * cxImgSize / cxNewSize;
858
859 r = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 0);
860 g = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 1);
861 b = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 2);
862 *pImg++ = r;
863 *pImg++ = g;
864 *pImg++ = b;
865 if (cImgChannels == 4)
866 {
867 a = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld)
868 + 3);
869 *pImg++ = a;
870 }
871 }
872 }
873
874 /* calculate row-bytes */
875
876 wImgRowBytes = cImgChannels * cxNewSize;
877 wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
878
879 /* copy image to screen */
880
881 for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)
882 {
883 if (yWin >= cyWinSize - cyImgPos)
884 break;
885 src = pStretchedImage + yImg * wImgRowBytes;
886 dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
887
888 for (xImg = 0, xWin = cxImgPos; xImg < cxNewSize; xImg++, xWin++)
889 {
890 if (xWin >= cxWinSize - cxImgPos)
891 break;
892 r = *src++;
893 g = *src++;
894 b = *src++;
895 *dst++ = b; /* note the reverse order */
896 *dst++ = g;
897 *dst++ = r;
898 if (cImgChannels == 4)
899 {
900 a = *src++;
901 }
902 }
903 }
904
905 /* free memory */
906
907 if (pStretchedImage != NULL)
908 {
909 free (pStretchedImage);
910 pStretchedImage = NULL;
911 }
912
913 }
914
915 /* process the image not-stretched */
916
917 else
918 {
919 /* calculate the central position */
920
921 cxImgPos = (cxWinSize - cxImgSize) / 2;
922 cyImgPos = (cyWinSize - cyImgSize) / 2;
923
924 /* check for image larger than window */
925
926 if (cxImgPos < MARGIN)
927 cxImgPos = MARGIN;
928 if (cyImgPos < MARGIN)
929 cyImgPos = MARGIN;
930
931 /* calculate both row-bytes */
932
933 wImgRowBytes = cImgChannels * cxImgSize;
934 wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;
935
936 /* copy image to screen */
937
938 for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)
939 {
940 if (yWin >= cyWinSize - MARGIN)
941 break;
942 src = pbImage + yImg * wImgRowBytes;
943 dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;
944
945 for (xImg = 0, xWin = cxImgPos; xImg < cxImgSize; xImg++, xWin++)
946 {
947 if (xWin >= cxWinSize - MARGIN)
948 break;
949 r = *src++;
950 g = *src++;
951 b = *src++;
952 *dst++ = b; /* note the reverse order */
953 *dst++ = g;
954 *dst++ = r;
955 if (cImgChannels == 4)
956 {
957 a = *src++;
958 }
959 }
960 }
961 }
962
963 return TRUE;
964}
965
966/*-----------------
967 * end of source
968 *-----------------
969 */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.ico b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.ico
new file mode 100644
index 0000000..68aa371
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.ico
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.png
new file mode 100644
index 0000000..c6aa80a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.rc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.rc
new file mode 100644
index 0000000..6e0623a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/VisualPng.rc
@@ -0,0 +1,152 @@
1//Microsoft Developer Studio generated resource script.
2//
3#include "resource.h"
4
5#define APSTUDIO_READONLY_SYMBOLS
6/////////////////////////////////////////////////////////////////////////////
7//
8// Generated from the TEXTINCLUDE 2 resource.
9//
10#include "afxres.h"
11
12/////////////////////////////////////////////////////////////////////////////
13#undef APSTUDIO_READONLY_SYMBOLS
14
15/////////////////////////////////////////////////////////////////////////////
16// English (U.S.) resources
17
18#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
19#ifdef _WIN32
20LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21#pragma code_page(1252)
22#endif //_WIN32
23
24#ifdef APSTUDIO_INVOKED
25/////////////////////////////////////////////////////////////////////////////
26//
27// TEXTINCLUDE
28//
29
301 TEXTINCLUDE DISCARDABLE
31BEGIN
32 "resource.h\0"
33END
34
352 TEXTINCLUDE DISCARDABLE
36BEGIN
37 "#include ""afxres.h""\r\n"
38 "\0"
39END
40
413 TEXTINCLUDE DISCARDABLE
42BEGIN
43 "\r\n"
44 "\0"
45END
46
47#endif // APSTUDIO_INVOKED
48
49
50/////////////////////////////////////////////////////////////////////////////
51//
52// Menu
53//
54
55VISUALPNG MENU DISCARDABLE
56BEGIN
57 POPUP "&File"
58 BEGIN
59 MENUITEM "&Open Image...\tCtrl+O", IDM_FILE_OPEN
60 MENUITEM "Save &As...", IDM_FILE_SAVE
61 MENUITEM SEPARATOR
62 MENUITEM "&Next Image\tCtrl+N", IDM_FILE_NEXT
63 MENUITEM "Pre&vious Image\tCtrl+V", IDM_FILE_PREVIOUS
64 MENUITEM SEPARATOR
65 MENUITEM "E&xit\tAlt+X", IDM_FILE_EXIT
66 END
67 POPUP "&Options"
68 BEGIN
69 MENUITEM "&Stretch", IDM_OPTIONS_STRETCH, CHECKED
70 END
71 POPUP "&Help"
72 BEGIN
73 MENUITEM "&About", IDM_HELP_ABOUT
74 END
75END
76
77
78/////////////////////////////////////////////////////////////////////////////
79//
80// Accelerator
81//
82
83VISUALPNG ACCELERATORS DISCARDABLE
84BEGIN
85 "N", IDM_FILE_NEXT, VIRTKEY, CONTROL, NOINVERT
86 "O", IDM_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
87 "P", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT
88 "V", IDM_FILE_PREVIOUS, VIRTKEY, CONTROL, NOINVERT
89 "X", IDM_FILE_EXIT, VIRTKEY, ALT, NOINVERT
90END
91
92
93/////////////////////////////////////////////////////////////////////////////
94//
95// Icon
96//
97
98// Icon with lowest ID value placed first to ensure application icon
99// remains consistent on all systems.
100VISUALPNG ICON DISCARDABLE "VisualPng.ico"
101
102/////////////////////////////////////////////////////////////////////////////
103//
104// Dialog
105//
106
107ABOUTBOX DIALOG DISCARDABLE 0, 0, 186, 94
108STYLE DS_MODALFRAME | WS_POPUP
109FONT 8, "MS Sans Serif"
110BEGIN
111 DEFPUSHBUTTON "OK",IDOK,68,67,50,14
112 CTEXT "VisualPng 1.0 - June 2000",IDC_STATIC,49,14,88,8
113 LTEXT "a PNG image viewer",IDC_STATIC,60,30,66,8
114 LTEXT "(c) Willem van Schaik, 2000",IDC_STATIC,48,52,90,8
115 LTEXT "to demonstrate the use of libpng in Visual C",
116 IDC_STATIC,25,38,136,8
117END
118
119
120/////////////////////////////////////////////////////////////////////////////
121//
122// DESIGNINFO
123//
124
125#ifdef APSTUDIO_INVOKED
126GUIDELINES DESIGNINFO DISCARDABLE
127BEGIN
128 "ABOUTBOX", DIALOG
129 BEGIN
130 LEFTMARGIN, 7
131 RIGHTMARGIN, 179
132 TOPMARGIN, 7
133 BOTTOMMARGIN, 87
134 END
135END
136#endif // APSTUDIO_INVOKED
137
138#endif // English (U.S.) resources
139/////////////////////////////////////////////////////////////////////////////
140
141
142
143#ifndef APSTUDIO_INVOKED
144/////////////////////////////////////////////////////////////////////////////
145//
146// Generated from the TEXTINCLUDE 3 resource.
147//
148
149
150/////////////////////////////////////////////////////////////////////////////
151#endif // not APSTUDIO_INVOKED
152
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/cexcept.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/cexcept.h
new file mode 100644
index 0000000..83c8bfe
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/cexcept.h
@@ -0,0 +1,248 @@
1/*===
2cexcept.h 2.0.1 (2008-Jul-19-Sat)
3http://www.nicemice.net/cexcept/
4Adam M. Costello
5http://www.nicemice.net/amc/
6
7An interface for exception-handling in ANSI C (C89 and subsequent ISO
8standards), developed jointly with Cosmin Truta.
9
10 Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.
11 This software may be modified only if its author and version
12 information is updated accurately, and may be redistributed
13 only if accompanied by this unaltered notice. Subject to those
14 restrictions, permission is granted to anyone to do anything
15 with this software. The copyright holders make no guarantees
16 regarding this software, and are not responsible for any damage
17 resulting from its use.
18
19The cexcept interface is not compatible with and cannot interact
20with system exceptions (like division by zero or memory segmentation
21violation), compiler-generated exceptions (like C++ exceptions), or
22other exception-handling interfaces.
23
24When using this interface across multiple .c files, do not include
25this header file directly. Instead, create a wrapper header file that
26includes this header file and then invokes the define_exception_type
27macro (see below). The .c files should then include that header file.
28
29The interface consists of one type, one well-known name, and six macros.
30
31
32define_exception_type(type_name);
33
34 This macro is used like an external declaration. It specifies
35 the type of object that gets copied from the exception thrower to
36 the exception catcher. The type_name can be any type that can be
37 assigned to, that is, a non-constant arithmetic type, struct, union,
38 or pointer. Examples:
39
40 define_exception_type(int);
41
42 enum exception { out_of_memory, bad_arguments, disk_full };
43 define_exception_type(enum exception);
44
45 struct exception { int code; const char *msg; };
46 define_exception_type(struct exception);
47
48 Because throwing an exception causes the object to be copied (not
49 just once, but twice), programmers may wish to consider size when
50 choosing the exception type.
51
52
53struct exception_context;
54
55 This type may be used after the define_exception_type() macro has
56 been invoked. A struct exception_context must be known to both
57 the thrower and the catcher. It is expected that there be one
58 context for each thread that uses exceptions. It would certainly
59 be dangerous for multiple threads to access the same context.
60 One thread can use multiple contexts, but that is likely to be
61 confusing and not typically useful. The application can allocate
62 this structure in any way it pleases--automatic, static, or dynamic.
63 The application programmer should pretend not to know the structure
64 members, which are subject to change.
65
66
67struct exception_context *the_exception_context;
68
69 The Try/Catch and Throw statements (described below) implicitly
70 refer to a context, using the name the_exception_context. It is
71 the application's responsibility to make sure that this name yields
72 the address of a mutable (non-constant) struct exception_context
73 wherever those statements are used. Subject to that constraint, the
74 application may declare a variable of this name anywhere it likes
75 (inside a function, in a parameter list, or externally), and may
76 use whatever storage class specifiers (static, extern, etc) or type
77 qualifiers (const, volatile, etc) it likes. Examples:
78
79 static struct exception_context
80 * const the_exception_context = &foo;
81
82 { struct exception_context *the_exception_context = bar; ... }
83
84 int blah(struct exception_context *the_exception_context, ...);
85
86 extern struct exception_context the_exception_context[1];
87
88 The last example illustrates a trick that avoids creating a pointer
89 object separate from the structure object.
90
91 The name could even be a macro, for example:
92
93 struct exception_context ec_array[numthreads];
94 #define the_exception_context (ec_array + thread_id)
95
96 Be aware that the_exception_context is used several times by the
97 Try/Catch/Throw macros, so it shouldn't be expensive or have side
98 effects. The expansion must be a drop-in replacement for an
99 identifier, so it's safest to put parentheses around it.
100
101
102void init_exception_context(struct exception_context *ec);
103
104 For context structures allocated statically (by an external
105 definition or using the "static" keyword), the implicit
106 initialization to all zeros is sufficient, but contexts allocated
107 by other means must be initialized using this macro before they
108 are used by a Try/Catch statement. It does no harm to initialize
109 a context more than once (by using this macro on a statically
110 allocated context, or using this macro twice on the same context),
111 but a context must not be re-initialized after it has been used by a
112 Try/Catch statement.
113
114
115Try statement
116Catch (expression) statement
117
118 The Try/Catch/Throw macros are capitalized in order to avoid
119 confusion with the C++ keywords, which have subtly different
120 semantics.
121
122 A Try/Catch statement has a syntax similar to an if/else statement,
123 except that the parenthesized expression goes after the second
124 keyword rather than the first. As with if/else, there are two
125 clauses, each of which may be a simple statement ending with a
126 semicolon or a brace-enclosed compound statement. But whereas
127 the else clause is optional, the Catch clause is required. The
128 expression must be a modifiable lvalue (something capable of being
129 assigned to) of the same type (disregarding type qualifiers) that
130 was passed to define_exception_type().
131
132 If a Throw that uses the same exception context as the Try/Catch is
133 executed within the Try clause (typically within a function called
134 by the Try clause), and the exception is not caught by a nested
135 Try/Catch statement, then a copy of the exception will be assigned
136 to the expression, and control will jump to the Catch clause. If no
137 such Throw is executed, then the assignment is not performed, and
138 the Catch clause is not executed.
139
140 The expression is not evaluated unless and until the exception is
141 caught, which is significant if it has side effects, for example:
142
143 Try foo();
144 Catch (p[++i].e) { ... }
145
146 IMPORTANT: Jumping into or out of a Try clause (for example via
147 return, break, continue, goto, longjmp) is forbidden--the compiler
148 will not complain, but bad things will happen at run-time. Jumping
149 into or out of a Catch clause is okay, and so is jumping around
150 inside a Try clause. In many cases where one is tempted to return
151 from a Try clause, it will suffice to use Throw, and then return
152 from the Catch clause. Another option is to set a flag variable and
153 use goto to jump to the end of the Try clause, then check the flag
154 after the Try/Catch statement.
155
156 IMPORTANT: The values of any non-volatile automatic variables
157 changed within the Try clause are undefined after an exception is
158 caught. Therefore, variables modified inside the Try block whose
159 values are needed later outside the Try block must either use static
160 storage or be declared with the "volatile" type qualifier.
161
162
163Throw expression;
164
165 A Throw statement is very much like a return statement, except that
166 the expression is required. Whereas return jumps back to the place
167 where the current function was called, Throw jumps back to the Catch
168 clause of the innermost enclosing Try clause. The expression must
169 be compatible with the type passed to define_exception_type(). The
170 exception must be caught, otherwise the program may crash.
171
172 Slight limitation: If the expression is a comma-expression, it must
173 be enclosed in parentheses.
174
175
176Try statement
177Catch_anonymous statement
178
179 When the value of the exception is not needed, a Try/Catch statement
180 can use Catch_anonymous instead of Catch (expression).
181
182
183Everything below this point is for the benefit of the compiler. The
184application programmer should pretend not to know any of it, because it
185is subject to change.
186
187===*/
188
189
190#ifndef CEXCEPT_H
191#define CEXCEPT_H
192
193
194#include <setjmp.h>
195
196#define define_exception_type(etype) \
197struct exception_context { \
198 jmp_buf *penv; \
199 int caught; \
200 volatile struct { etype etmp; } v; \
201}
202
203/* etmp must be volatile because the application might use automatic */
204/* storage for the_exception_context, and etmp is modified between */
205/* the calls to setjmp() and longjmp(). A wrapper struct is used to */
206/* avoid warnings about a duplicate volatile qualifier in case etype */
207/* already includes it. */
208
209#define init_exception_context(ec) ((void)((ec)->penv = 0))
210
211#define Try \
212 { \
213 jmp_buf *exception__prev, exception__env; \
214 exception__prev = the_exception_context->penv; \
215 the_exception_context->penv = &exception__env; \
216 if (setjmp(exception__env) == 0) { \
217 do
218
219#define exception__catch(action) \
220 while (the_exception_context->caught = 0, \
221 the_exception_context->caught); \
222 } \
223 else { \
224 the_exception_context->caught = 1; \
225 } \
226 the_exception_context->penv = exception__prev; \
227 } \
228 if (!the_exception_context->caught || action) { } \
229 else
230
231#define Catch(e) exception__catch(((e) = the_exception_context->v.etmp, 0))
232#define Catch_anonymous exception__catch(0)
233
234/* Try ends with do, and Catch begins with while(0) and ends with */
235/* else, to ensure that Try/Catch syntax is similar to if/else */
236/* syntax. */
237/* */
238/* The 0 in while(0) is expressed as x=0,x in order to appease */
239/* compilers that warn about constant expressions inside while(). */
240/* Most compilers should still recognize that the condition is always */
241/* false and avoid generating code for it. */
242
243#define Throw \
244 for (;; longjmp(*the_exception_context->penv, 1)) \
245 the_exception_context->v.etmp =
246
247
248#endif /* CEXCEPT_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/resource.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/resource.h
new file mode 100644
index 0000000..a06050a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/visupng/resource.h
@@ -0,0 +1,23 @@
1//{{NO_DEPENDENCIES}}
2// Microsoft Developer Studio generated include file.
3// Used by VisualPng.rc
4//
5#define IDM_FILE_OPEN 40001
6#define IDM_FILE_SAVE 40002
7#define IDM_FILE_NEXT 40003
8#define IDM_FILE_PREVIOUS 40004
9#define IDM_FILE_EXIT 40005
10#define IDM_OPTIONS_BACKGROUND 40006
11#define IDM_OPTIONS_STRETCH 40007
12#define IDM_HELP_ABOUT 40008
13
14// Next default values for new objects
15//
16#ifdef APSTUDIO_INVOKED
17#ifndef APSTUDIO_READONLY_SYMBOLS
18#define _APS_NEXT_RESOURCE_VALUE 113
19#define _APS_NEXT_COMMAND_VALUE 40009
20#define _APS_NEXT_CONTROL_VALUE 1001
21#define _APS_NEXT_SYMED_VALUE 101
22#endif
23#endif
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/example.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/example.c
new file mode 100644
index 0000000..eb850fe
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/example.c
@@ -0,0 +1,862 @@
1
2#if 0 /* in case someone actually tries to compile this */
3
4/* example.c - an example of using libpng
5 * Last changed in libpng 1.5.7 [December 15, 2011]
6 * Maintained 1998-2011 Glenn Randers-Pehrson
7 * Maintained 1996, 1997 Andreas Dilger
8 * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
9 */
10
11/* This is an example of how to use libpng to read and write PNG files.
12 * The file libpng-manual.txt is much more verbose then this. If you have not
13 * read it, do so first. This was designed to be a starting point of an
14 * implementation. This is not officially part of libpng, is hereby placed
15 * in the public domain, and therefore does not require a copyright notice.
16 * To the extent possible under law, the authors have waived all copyright and
17 * related or neighboring rights to this file.
18 *
19 * This file does not currently compile, because it is missing certain
20 * parts, like allocating memory to hold an image. You will have to
21 * supply these parts to get it to compile. For an example of a minimal
22 * working PNG reader/writer, see pngtest.c, included in this distribution;
23 * see also the programs in the contrib directory.
24 */
25
26#define _POSIX_SOURCE 1 /* libpng and zlib are POSIX-compliant. You may
27 * change this if your application uses non-POSIX
28 * extensions. */
29
30#include "png.h"
31
32 /* The png_jmpbuf() macro, used in error handling, became available in
33 * libpng version 1.0.6. If you want to be able to run your code with older
34 * versions of libpng, you must define the macro yourself (but only if it
35 * is not already defined by libpng!).
36 */
37
38#ifndef png_jmpbuf
39# define png_jmpbuf(png_ptr) ((png_ptr)->png_jmpbuf)
40#endif
41
42/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
43 * returns zero if the image is a PNG and nonzero if it isn't a PNG.
44 *
45 * The function check_if_png() shown here, but not used, returns nonzero (true)
46 * if the file can be opened and is a PNG, 0 (false) otherwise.
47 *
48 * If this call is successful, and you are going to keep the file open,
49 * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
50 * you have created the png_ptr, so that libpng knows your application
51 * has read that many bytes from the start of the file. Make sure you
52 * don't call png_set_sig_bytes() with more than 8 bytes read or give it
53 * an incorrect number of bytes read, or you will either have read too
54 * many bytes (your fault), or you are telling libpng to read the wrong
55 * number of magic bytes (also your fault).
56 *
57 * Many applications already read the first 2 or 4 bytes from the start
58 * of the image to determine the file type, so it would be easiest just
59 * to pass the bytes to png_sig_cmp() or even skip that if you know
60 * you have a PNG file, and call png_set_sig_bytes().
61 */
62#define PNG_BYTES_TO_CHECK 4
63int check_if_png(char *file_name, FILE **fp)
64{
65 char buf[PNG_BYTES_TO_CHECK];
66
67 /* Open the prospective PNG file. */
68 if ((*fp = fopen(file_name, "rb")) == NULL)
69 return 0;
70
71 /* Read in some of the signature bytes */
72 if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
73 return 0;
74
75 /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
76 Return nonzero (true) if they match */
77
78 return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
79}
80
81/* Read a PNG file. You may want to return an error code if the read
82 * fails (depending upon the failure). There are two "prototypes" given
83 * here - one where we are given the filename, and we need to open the
84 * file, and the other where we are given an open file (possibly with
85 * some or all of the magic bytes read - see comments above).
86 */
87#ifdef open_file /* prototype 1 */
88void read_png(char *file_name) /* We need to open the file */
89{
90 png_structp png_ptr;
91 png_infop info_ptr;
92 unsigned int sig_read = 0;
93 png_uint_32 width, height;
94 int bit_depth, color_type, interlace_type;
95 FILE *fp;
96
97 if ((fp = fopen(file_name, "rb")) == NULL)
98 return (ERROR);
99
100#else no_open_file /* prototype 2 */
101void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
102{
103 png_structp png_ptr;
104 png_infop info_ptr;
105 png_uint_32 width, height;
106 int bit_depth, color_type, interlace_type;
107#endif no_open_file /* Only use one prototype! */
108
109 /* Create and initialize the png_struct with the desired error handler
110 * functions. If you want to use the default stderr and longjump method,
111 * you can supply NULL for the last three parameters. We also supply the
112 * the compiler header file version, so that we know if the application
113 * was compiled with a compatible version of the library. REQUIRED
114 */
115 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
116 png_voidp user_error_ptr, user_error_fn, user_warning_fn);
117
118 if (png_ptr == NULL)
119 {
120 fclose(fp);
121 return (ERROR);
122 }
123
124 /* Allocate/initialize the memory for image information. REQUIRED. */
125 info_ptr = png_create_info_struct(png_ptr);
126 if (info_ptr == NULL)
127 {
128 fclose(fp);
129 png_destroy_read_struct(&png_ptr, NULL, NULL);
130 return (ERROR);
131 }
132
133 /* Set error handling if you are using the setjmp/longjmp method (this is
134 * the normal method of doing things with libpng). REQUIRED unless you
135 * set up your own error handlers in the png_create_read_struct() earlier.
136 */
137
138 if (setjmp(png_jmpbuf(png_ptr)))
139 {
140 /* Free all of the memory associated with the png_ptr and info_ptr */
141 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
142 fclose(fp);
143 /* If we get here, we had a problem reading the file */
144 return (ERROR);
145 }
146
147 /* One of the following I/O initialization methods is REQUIRED */
148#ifdef streams /* PNG file I/O method 1 */
149 /* Set up the input control if you are using standard C streams */
150 png_init_io(png_ptr, fp);
151
152#else no_streams /* PNG file I/O method 2 */
153 /* If you are using replacement read functions, instead of calling
154 * png_init_io() here you would call:
155 */
156 png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
157 /* where user_io_ptr is a structure you want available to the callbacks */
158#endif no_streams /* Use only one I/O method! */
159
160 /* If we have already read some of the signature */
161 png_set_sig_bytes(png_ptr, sig_read);
162
163#ifdef hilevel
164 /*
165 * If you have enough memory to read in the entire image at once,
166 * and you need to specify only transforms that can be controlled
167 * with one of the PNG_TRANSFORM_* bits (this presently excludes
168 * quantizing, filling, setting background, and doing gamma
169 * adjustment), then you can read the entire image (including
170 * pixels) into the info structure with this call:
171 */
172 png_read_png(png_ptr, info_ptr, png_transforms, NULL);
173
174#else
175 /* OK, you're doing it the hard way, with the lower-level functions */
176
177 /* The call to png_read_info() gives us all of the information from the
178 * PNG file before the first IDAT (image data chunk). REQUIRED
179 */
180 png_read_info(png_ptr, info_ptr);
181
182 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
183 &interlace_type, NULL, NULL);
184
185 /* Set up the data transformations you want. Note that these are all
186 * optional. Only call them if you want/need them. Many of the
187 * transformations only work on specific types of images, and many
188 * are mutually exclusive.
189 */
190
191 /* Tell libpng to strip 16 bit/color files down to 8 bits/color.
192 * Use accurate scaling if it's available, otherwise just chop off the
193 * low byte.
194 */
195#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
196 png_set_scale_16(png_ptr);
197#else
198 png_set_strip_16(png_ptr);
199#endif
200
201 /* Strip alpha bytes from the input data without combining with the
202 * background (not recommended).
203 */
204 png_set_strip_alpha(png_ptr);
205
206 /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
207 * byte into separate bytes (useful for paletted and grayscale images).
208 */
209 png_set_packing(png_ptr);
210
211 /* Change the order of packed pixels to least significant bit first
212 * (not useful if you are using png_set_packing). */
213 png_set_packswap(png_ptr);
214
215 /* Expand paletted colors into true RGB triplets */
216 if (color_type == PNG_COLOR_TYPE_PALETTE)
217 png_set_palette_to_rgb(png_ptr);
218
219 /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
220 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
221 png_set_expand_gray_1_2_4_to_8(png_ptr);
222
223 /* Expand paletted or RGB images with transparency to full alpha channels
224 * so the data will be available as RGBA quartets.
225 */
226 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
227 png_set_tRNS_to_alpha(png_ptr);
228
229 /* Set the background color to draw transparent and alpha images over.
230 * It is possible to set the red, green, and blue components directly
231 * for paletted images instead of supplying a palette index. Note that
232 * even if the PNG file supplies a background, you are not required to
233 * use it - you should use the (solid) application background if it has one.
234 */
235
236 png_color_16 my_background, *image_background;
237
238 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
239 png_set_background(png_ptr, image_background,
240 PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
241 else
242 png_set_background(png_ptr, &my_background,
243 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
244
245 /* Some suggestions as to how to get a screen gamma value
246 *
247 * Note that screen gamma is the display_exponent, which includes
248 * the CRT_exponent and any correction for viewing conditions
249 */
250 if (/* We have a user-defined screen gamma value */)
251 {
252 screen_gamma = user-defined screen_gamma;
253 }
254 /* This is one way that applications share the same screen gamma value */
255 else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
256 {
257 screen_gamma = atof(gamma_str);
258 }
259 /* If we don't have another value */
260 else
261 {
262 screen_gamma = 2.2; /* A good guess for a PC monitor in a dimly
263 lit room */
264 screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
265 }
266
267 /* Tell libpng to handle the gamma conversion for you. The final call
268 * is a good guess for PC generated images, but it should be configurable
269 * by the user at run time by the user. It is strongly suggested that
270 * your application support gamma correction.
271 */
272
273 int intent;
274
275 if (png_get_sRGB(png_ptr, info_ptr, &intent))
276 png_set_gamma(png_ptr, screen_gamma, 0.45455);
277 else
278 {
279 double image_gamma;
280 if (png_get_gAMA(png_ptr, info_ptr, &image_gamma))
281 png_set_gamma(png_ptr, screen_gamma, image_gamma);
282 else
283 png_set_gamma(png_ptr, screen_gamma, 0.45455);
284 }
285
286#ifdef PNG_READ_QUANTIZE_SUPPORTED
287 /* Quantize RGB files down to 8 bit palette or reduce palettes
288 * to the number of colors available on your screen.
289 */
290 if (color_type & PNG_COLOR_MASK_COLOR)
291 {
292 int num_palette;
293 png_colorp palette;
294
295 /* This reduces the image to the application supplied palette */
296 if (/* We have our own palette */)
297 {
298 /* An array of colors to which the image should be quantized */
299 png_color std_color_cube[MAX_SCREEN_COLORS];
300
301 png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
302 MAX_SCREEN_COLORS, NULL, 0);
303 }
304 /* This reduces the image to the palette supplied in the file */
305 else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette))
306 {
307 png_uint_16p histogram = NULL;
308
309 png_get_hIST(png_ptr, info_ptr, &histogram);
310
311 png_set_quantize(png_ptr, palette, num_palette,
312 max_screen_colors, histogram, 0);
313 }
314 }
315#endif /* PNG_READ_QUANTIZE_SUPPORTED */
316
317 /* Invert monochrome files to have 0 as white and 1 as black */
318 png_set_invert_mono(png_ptr);
319
320 /* If you want to shift the pixel values from the range [0,255] or
321 * [0,65535] to the original [0,7] or [0,31], or whatever range the
322 * colors were originally in:
323 */
324 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
325 {
326 png_color_8p sig_bit_p;
327
328 png_get_sBIT(png_ptr, info_ptr, &sig_bit_p);
329 png_set_shift(png_ptr, sig_bit_p);
330 }
331
332 /* Flip the RGB pixels to BGR (or RGBA to BGRA) */
333 if (color_type & PNG_COLOR_MASK_COLOR)
334 png_set_bgr(png_ptr);
335
336 /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
337 png_set_swap_alpha(png_ptr);
338
339 /* Swap bytes of 16 bit files to least significant byte first */
340 png_set_swap(png_ptr);
341
342 /* Add filler (or alpha) byte (before/after each RGB triplet) */
343 png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
344
345#ifdef PNG_READ_INTERLACING_SUPPORTED
346 /* Turn on interlace handling. REQUIRED if you are not using
347 * png_read_image(). To see how to handle interlacing passes,
348 * see the png_read_row() method below:
349 */
350 number_passes = png_set_interlace_handling(png_ptr);
351#else
352 number_passes = 1;
353#endif /* PNG_READ_INTERLACING_SUPPORTED */
354
355
356 /* Optional call to gamma correct and add the background to the palette
357 * and update info structure. REQUIRED if you are expecting libpng to
358 * update the palette for you (ie you selected such a transform above).
359 */
360 png_read_update_info(png_ptr, info_ptr);
361
362 /* Allocate the memory to hold the image using the fields of info_ptr. */
363
364 /* The easiest way to read the image: */
365 png_bytep row_pointers[height];
366
367 /* Clear the pointer array */
368 for (row = 0; row < height; row++)
369 row_pointers[row] = NULL;
370
371 for (row = 0; row < height; row++)
372 row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,
373 info_ptr));
374
375 /* Now it's time to read the image. One of these methods is REQUIRED */
376#ifdef entire /* Read the entire image in one go */
377 png_read_image(png_ptr, row_pointers);
378
379#else no_entire /* Read the image one or more scanlines at a time */
380 /* The other way to read images - deal with interlacing: */
381
382 for (pass = 0; pass < number_passes; pass++)
383 {
384#ifdef single /* Read the image a single row at a time */
385 for (y = 0; y < height; y++)
386 {
387 png_read_rows(png_ptr, &row_pointers[y], NULL, 1);
388 }
389
390#else no_single /* Read the image several rows at a time */
391 for (y = 0; y < height; y += number_of_rows)
392 {
393#ifdef sparkle /* Read the image using the "sparkle" effect. */
394 png_read_rows(png_ptr, &row_pointers[y], NULL,
395 number_of_rows);
396#else no_sparkle /* Read the image using the "rectangle" effect */
397 png_read_rows(png_ptr, NULL, &row_pointers[y],
398 number_of_rows);
399#endif no_sparkle /* Use only one of these two methods */
400 }
401
402 /* If you want to display the image after every pass, do so here */
403#endif no_single /* Use only one of these two methods */
404 }
405#endif no_entire /* Use only one of these two methods */
406
407 /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
408 png_read_end(png_ptr, info_ptr);
409#endif hilevel
410
411 /* At this point you have read the entire image */
412
413 /* Clean up after the read, and free any memory allocated - REQUIRED */
414 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
415
416 /* Close the file */
417 fclose(fp);
418
419 /* That's it */
420 return (OK);
421}
422
423/* Progressively read a file */
424
425int
426initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
427{
428 /* Create and initialize the png_struct with the desired error handler
429 * functions. If you want to use the default stderr and longjump method,
430 * you can supply NULL for the last three parameters. We also check that
431 * the library version is compatible in case we are using dynamically
432 * linked libraries.
433 */
434 *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
435 png_voidp user_error_ptr, user_error_fn, user_warning_fn);
436
437 if (*png_ptr == NULL)
438 {
439 *info_ptr = NULL;
440 return (ERROR);
441 }
442
443 *info_ptr = png_create_info_struct(png_ptr);
444
445 if (*info_ptr == NULL)
446 {
447 png_destroy_read_struct(png_ptr, info_ptr, NULL);
448 return (ERROR);
449 }
450
451 if (setjmp(png_jmpbuf((*png_ptr))))
452 {
453 png_destroy_read_struct(png_ptr, info_ptr, NULL);
454 return (ERROR);
455 }
456
457 /* This one's new. You will need to provide all three
458 * function callbacks, even if you aren't using them all.
459 * If you aren't using all functions, you can specify NULL
460 * parameters. Even when all three functions are NULL,
461 * you need to call png_set_progressive_read_fn().
462 * These functions shouldn't be dependent on global or
463 * static variables if you are decoding several images
464 * simultaneously. You should store stream specific data
465 * in a separate struct, given as the second parameter,
466 * and retrieve the pointer from inside the callbacks using
467 * the function png_get_progressive_ptr(png_ptr).
468 */
469 png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
470 info_callback, row_callback, end_callback);
471
472 return (OK);
473}
474
475int
476process_data(png_structp *png_ptr, png_infop *info_ptr,
477 png_bytep buffer, png_uint_32 length)
478{
479 if (setjmp(png_jmpbuf((*png_ptr))))
480 {
481 /* Free the png_ptr and info_ptr memory on error */
482 png_destroy_read_struct(png_ptr, info_ptr, NULL);
483 return (ERROR);
484 }
485
486 /* This one's new also. Simply give it chunks of data as
487 * they arrive from the data stream (in order, of course).
488 * On segmented machines, don't give it any more than 64K.
489 * The library seems to run fine with sizes of 4K, although
490 * you can give it much less if necessary (I assume you can
491 * give it chunks of 1 byte, but I haven't tried with less
492 * than 256 bytes yet). When this function returns, you may
493 * want to display any rows that were generated in the row
494 * callback, if you aren't already displaying them there.
495 */
496 png_process_data(*png_ptr, *info_ptr, buffer, length);
497 return (OK);
498}
499
500info_callback(png_structp png_ptr, png_infop info)
501{
502 /* Do any setup here, including setting any of the transformations
503 * mentioned in the Reading PNG files section. For now, you _must_
504 * call either png_start_read_image() or png_read_update_info()
505 * after all the transformations are set (even if you don't set
506 * any). You may start getting rows before png_process_data()
507 * returns, so this is your last chance to prepare for that.
508 */
509}
510
511row_callback(png_structp png_ptr, png_bytep new_row,
512 png_uint_32 row_num, int pass)
513{
514 /*
515 * This function is called for every row in the image. If the
516 * image is interlaced, and you turned on the interlace handler,
517 * this function will be called for every row in every pass.
518 *
519 * In this function you will receive a pointer to new row data from
520 * libpng called new_row that is to replace a corresponding row (of
521 * the same data format) in a buffer allocated by your application.
522 *
523 * The new row data pointer "new_row" may be NULL, indicating there is
524 * no new data to be replaced (in cases of interlace loading).
525 *
526 * If new_row is not NULL then you need to call
527 * png_progressive_combine_row() to replace the corresponding row as
528 * shown below:
529 */
530
531 /* Get pointer to corresponding row in our
532 * PNG read buffer.
533 */
534 png_bytep old_row = ((png_bytep *)our_data)[row_num];
535
536#ifdef PNG_READ_INTERLACING_SUPPORTED
537 /* If both rows are allocated then copy the new row
538 * data to the corresponding row data.
539 */
540 if ((old_row != NULL) && (new_row != NULL))
541 png_progressive_combine_row(png_ptr, old_row, new_row);
542
543 /*
544 * The rows and passes are called in order, so you don't really
545 * need the row_num and pass, but I'm supplying them because it
546 * may make your life easier.
547 *
548 * For the non-NULL rows of interlaced images, you must call
549 * png_progressive_combine_row() passing in the new row and the
550 * old row, as demonstrated above. You can call this function for
551 * NULL rows (it will just return) and for non-interlaced images
552 * (it just does the png_memcpy for you) if it will make the code
553 * easier. Thus, you can just do this for all cases:
554 */
555
556 png_progressive_combine_row(png_ptr, old_row, new_row);
557
558 /* where old_row is what was displayed for previous rows. Note
559 * that the first pass (pass == 0 really) will completely cover
560 * the old row, so the rows do not have to be initialized. After
561 * the first pass (and only for interlaced images), you will have
562 * to pass the current row as new_row, and the function will combine
563 * the old row and the new row.
564 */
565#endif /* PNG_READ_INTERLACING_SUPPORTED */
566}
567
568end_callback(png_structp png_ptr, png_infop info)
569{
570 /* This function is called when the whole image has been read,
571 * including any chunks after the image (up to and including
572 * the IEND). You will usually have the same info chunk as you
573 * had in the header, although some data may have been added
574 * to the comments and time fields.
575 *
576 * Most people won't do much here, perhaps setting a flag that
577 * marks the image as finished.
578 */
579}
580
581/* Write a png file */
582void write_png(char *file_name /* , ... other image information ... */)
583{
584 FILE *fp;
585 png_structp png_ptr;
586 png_infop info_ptr;
587 png_colorp palette;
588
589 /* Open the file */
590 fp = fopen(file_name, "wb");
591 if (fp == NULL)
592 return (ERROR);
593
594 /* Create and initialize the png_struct with the desired error handler
595 * functions. If you want to use the default stderr and longjump method,
596 * you can supply NULL for the last three parameters. We also check that
597 * the library version is compatible with the one used at compile time,
598 * in case we are using dynamically linked libraries. REQUIRED.
599 */
600 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
601 png_voidp user_error_ptr, user_error_fn, user_warning_fn);
602
603 if (png_ptr == NULL)
604 {
605 fclose(fp);
606 return (ERROR);
607 }
608
609 /* Allocate/initialize the image information data. REQUIRED */
610 info_ptr = png_create_info_struct(png_ptr);
611 if (info_ptr == NULL)
612 {
613 fclose(fp);
614 png_destroy_write_struct(&png_ptr, NULL);
615 return (ERROR);
616 }
617
618 /* Set error handling. REQUIRED if you aren't supplying your own
619 * error handling functions in the png_create_write_struct() call.
620 */
621 if (setjmp(png_jmpbuf(png_ptr)))
622 {
623 /* If we get here, we had a problem writing the file */
624 fclose(fp);
625 png_destroy_write_struct(&png_ptr, &info_ptr);
626 return (ERROR);
627 }
628
629 /* One of the following I/O initialization functions is REQUIRED */
630
631#ifdef streams /* I/O initialization method 1 */
632 /* Set up the output control if you are using standard C streams */
633 png_init_io(png_ptr, fp);
634
635#else no_streams /* I/O initialization method 2 */
636 /* If you are using replacement write functions, instead of calling
637 * png_init_io() here you would call
638 */
639 png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
640 user_IO_flush_function);
641 /* where user_io_ptr is a structure you want available to the callbacks */
642#endif no_streams /* Only use one initialization method */
643
644#ifdef hilevel
645 /* This is the easy way. Use it if you already have all the
646 * image info living in the structure. You could "|" many
647 * PNG_TRANSFORM flags into the png_transforms integer here.
648 */
649 png_write_png(png_ptr, info_ptr, png_transforms, NULL);
650
651#else
652 /* This is the hard way */
653
654 /* Set the image information here. Width and height are up to 2^31,
655 * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
656 * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
657 * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
658 * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
659 * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
660 * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
661 */
662 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
663 PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
664
665 /* Set the palette if there is one. REQUIRED for indexed-color images */
666 palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
667 * png_sizeof(png_color));
668 /* ... Set palette colors ... */
669 png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
670 /* You must not free palette here, because png_set_PLTE only makes a link to
671 * the palette that you malloced. Wait until you are about to destroy
672 * the png structure.
673 */
674
675 /* Optional significant bit (sBIT) chunk */
676 png_color_8 sig_bit;
677
678 /* If we are dealing with a grayscale image then */
679 sig_bit.gray = true_bit_depth;
680
681 /* Otherwise, if we are dealing with a color image then */
682 sig_bit.red = true_red_bit_depth;
683 sig_bit.green = true_green_bit_depth;
684 sig_bit.blue = true_blue_bit_depth;
685
686 /* If the image has an alpha channel then */
687 sig_bit.alpha = true_alpha_bit_depth;
688
689 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
690
691
692 /* Optional gamma chunk is strongly suggested if you have any guess
693 * as to the correct gamma of the image.
694 */
695 png_set_gAMA(png_ptr, info_ptr, gamma);
696
697 /* Optionally write comments into the image */
698 text_ptr[0].key = "Title";
699 text_ptr[0].text = "Mona Lisa";
700 text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
701 text_ptr[0].itxt_length = 0;
702 text_ptr[0].lang = NULL;
703 text_ptr[0].lang_key = NULL;
704 text_ptr[1].key = "Author";
705 text_ptr[1].text = "Leonardo DaVinci";
706 text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
707 text_ptr[1].itxt_length = 0;
708 text_ptr[1].lang = NULL;
709 text_ptr[1].lang_key = NULL;
710 text_ptr[2].key = "Description";
711 text_ptr[2].text = "<long text>";
712 text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
713 text_ptr[2].itxt_length = 0;
714 text_ptr[2].lang = NULL;
715 text_ptr[2].lang_key = NULL;
716 png_set_text(png_ptr, info_ptr, text_ptr, 3);
717
718 /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */
719
720 /* Note that if sRGB is present the gAMA and cHRM chunks must be ignored
721 * on read and, if your application chooses to write them, they must
722 * be written in accordance with the sRGB profile
723 */
724
725 /* Write the file header information. REQUIRED */
726 png_write_info(png_ptr, info_ptr);
727
728 /* If you want, you can write the info in two steps, in case you need to
729 * write your private chunk ahead of PLTE:
730 *
731 * png_write_info_before_PLTE(write_ptr, write_info_ptr);
732 * write_my_chunk();
733 * png_write_info(png_ptr, info_ptr);
734 *
735 * However, given the level of known- and unknown-chunk support in 1.2.0
736 * and up, this should no longer be necessary.
737 */
738
739 /* Once we write out the header, the compression type on the text
740 * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
741 * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
742 * at the end.
743 */
744
745 /* Set up the transformations you want. Note that these are
746 * all optional. Only call them if you want them.
747 */
748
749 /* Invert monochrome pixels */
750 png_set_invert_mono(png_ptr);
751
752 /* Shift the pixels up to a legal bit depth and fill in
753 * as appropriate to correctly scale the image.
754 */
755 png_set_shift(png_ptr, &sig_bit);
756
757 /* Pack pixels into bytes */
758 png_set_packing(png_ptr);
759
760 /* Swap location of alpha bytes from ARGB to RGBA */
761 png_set_swap_alpha(png_ptr);
762
763 /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
764 * RGB (4 channels -> 3 channels). The second parameter is not used.
765 */
766 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
767
768 /* Flip BGR pixels to RGB */
769 png_set_bgr(png_ptr);
770
771 /* Swap bytes of 16-bit files to most significant byte first */
772 png_set_swap(png_ptr);
773
774 /* Swap bits of 1, 2, 4 bit packed pixel formats */
775 png_set_packswap(png_ptr);
776
777 /* Turn on interlace handling if you are not using png_write_image() */
778 if (interlacing)
779 number_passes = png_set_interlace_handling(png_ptr);
780
781 else
782 number_passes = 1;
783
784 /* The easiest way to write the image (you may have a different memory
785 * layout, however, so choose what fits your needs best). You need to
786 * use the first method if you aren't handling interlacing yourself.
787 */
788 png_uint_32 k, height, width;
789 png_byte image[height][width*bytes_per_pixel];
790 png_bytep row_pointers[height];
791
792 if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
793 png_error (png_ptr, "Image is too tall to process in memory");
794
795 for (k = 0; k < height; k++)
796 row_pointers[k] = image + k*width*bytes_per_pixel;
797
798 /* One of the following output methods is REQUIRED */
799
800#ifdef entire /* Write out the entire image data in one call */
801 png_write_image(png_ptr, row_pointers);
802
803 /* The other way to write the image - deal with interlacing */
804
805#else no_entire /* Write out the image data by one or more scanlines */
806
807 /* The number of passes is either 1 for non-interlaced images,
808 * or 7 for interlaced images.
809 */
810 for (pass = 0; pass < number_passes; pass++)
811 {
812 /* Write a few rows at a time. */
813 png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows);
814
815 /* If you are only writing one row at a time, this works */
816 for (y = 0; y < height; y++)
817 png_write_rows(png_ptr, &row_pointers[y], 1);
818 }
819#endif no_entire /* Use only one output method */
820
821 /* You can write optional chunks like tEXt, zTXt, and tIME at the end
822 * as well. Shouldn't be necessary in 1.2.0 and up as all the public
823 * chunks are supported and you can use png_set_unknown_chunks() to
824 * register unknown chunks into the info structure to be written out.
825 */
826
827 /* It is REQUIRED to call this to finish writing the rest of the file */
828 png_write_end(png_ptr, info_ptr);
829#endif hilevel
830
831 /* If you png_malloced a palette, free it here (don't free info_ptr->palette,
832 * as recommended in versions 1.0.5m and earlier of this example; if
833 * libpng mallocs info_ptr->palette, libpng will free it). If you
834 * allocated it with malloc() instead of png_malloc(), use free() instead
835 * of png_free().
836 */
837 png_free(png_ptr, palette);
838 palette = NULL;
839
840 /* Similarly, if you png_malloced any data that you passed in with
841 * png_set_something(), such as a hist or trans array, free it here,
842 * when you can be sure that libpng is through with it.
843 */
844 png_free(png_ptr, trans);
845 trans = NULL;
846 /* Whenever you use png_free() it is a good idea to set the pointer to
847 * NULL in case your application inadvertently tries to png_free() it
848 * again. When png_free() sees a NULL it returns without action, thus
849 * avoiding the double-free security problem.
850 */
851
852 /* Clean up after the write, and free any memory allocated */
853 png_destroy_write_struct(&png_ptr, &info_ptr);
854
855 /* Close the file */
856 fclose(fp);
857
858 /* That's it */
859 return (OK);
860}
861
862#endif /* if 0 */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-config.in b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-config.in
new file mode 100644
index 0000000..199ad87
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-config.in
@@ -0,0 +1,127 @@
1#! /bin/sh
2
3# libpng-config
4# provides configuration info for libpng.
5
6# Copyright (C) 2002, 2004, 2006, 2007 Glenn Randers-Pehrson
7
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# Modeled after libxml-config.
13
14version="@PNGLIB_VERSION@"
15prefix="@prefix@"
16exec_prefix="@exec_prefix@"
17libdir="@libdir@"
18includedir="@includedir@/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@"
19libs="-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@"
20all_libs="-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ @LIBS@"
21I_opts="-I${includedir}"
22L_opts="-L${libdir}"
23R_opts=""
24cppflags=""
25ccopts=""
26ldopts=""
27
28usage()
29{
30 cat <<EOF
31Usage: $0 [OPTION] ...
32
33Known values for OPTION are:
34
35 --prefix print libpng prefix
36 --libdir print path to directory containing library
37 --libs print library linking information
38 --ccopts print compiler options
39 --cppflags print pre-processor flags
40 --cflags print preprocessor flags, I_opts, and compiler options
41 --I_opts print "-I" include options
42 --L_opts print linker "-L" flags for dynamic linking
43 --R_opts print dynamic linker "-R" or "-rpath" flags
44 --ldopts print linker options
45 --ldflags print linker flags (ldopts, L_opts, R_opts, and libs)
46 --static revise subsequent outputs for static linking
47 --help print this help and exit
48 --version print version information
49EOF
50
51 exit $1
52}
53
54if test $# -eq 0; then
55 usage 1
56fi
57
58while test $# -gt 0; do
59 case "$1" in
60
61 --prefix)
62 echo ${prefix}
63 ;;
64
65 --version)
66 echo ${version}
67 exit 0
68 ;;
69
70 --help)
71 usage 0
72 ;;
73
74 --ccopts)
75 echo ${ccopts}
76 ;;
77
78 --cppflags)
79 echo ${cppflags}
80 ;;
81
82 --cflags)
83 echo ${I_opts} ${cppflags} ${ccopts}
84 ;;
85
86 --libdir)
87 echo ${libdir}
88 ;;
89
90 --libs)
91 echo ${libs}
92 ;;
93
94 --I_opts)
95 echo ${I_opts}
96 ;;
97
98 --L_opts)
99 echo ${L_opts}
100 ;;
101
102 --R_opts)
103 echo ${R_opts}
104 ;;
105
106 --ldopts)
107 echo ${ldopts}
108 ;;
109
110 --ldflags)
111 echo ${ldopts} ${L_opts} ${R_opts} ${libs}
112 ;;
113
114 --static)
115 R_opts=""
116 libs=${all_libs}
117 ;;
118
119 *)
120 usage
121 exit 1
122 ;;
123 esac
124 shift
125done
126
127exit 0
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-manual.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-manual.txt
new file mode 100644
index 0000000..d560264
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng-manual.txt
@@ -0,0 +1,4628 @@
1libpng-manual.txt - A description on how to use and modify libpng
2
3 libpng version 1.5.9 - February 18, 2012
4 Updated and distributed by Glenn Randers-Pehrson
5 <glennrp at users.sourceforge.net>
6 Copyright (c) 1998-2011 Glenn Randers-Pehrson
7
8 This document is released under the libpng license.
9 For conditions of distribution and use, see the disclaimer
10 and license in png.h
11
12 Based on:
13
14 libpng versions 0.97, January 1998, through 1.5.9 - February 18, 2012
15 Updated and distributed by Glenn Randers-Pehrson
16 Copyright (c) 1998-2011 Glenn Randers-Pehrson
17
18 libpng 1.0 beta 6 version 0.96 May 28, 1997
19 Updated and distributed by Andreas Dilger
20 Copyright (c) 1996, 1997 Andreas Dilger
21
22 libpng 1.0 beta 2 - version 0.88 January 26, 1996
23 For conditions of distribution and use, see copyright
24 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
25 Schalnat, Group 42, Inc.
26
27 Updated/rewritten per request in the libpng FAQ
28 Copyright (c) 1995, 1996 Frank J. T. Wojcik
29 December 18, 1995 & January 20, 1996
30
31I. Introduction
32
33This file describes how to use and modify the PNG reference library
34(known as libpng) for your own use. There are five sections to this
35file: introduction, structures, reading, writing, and modification and
36configuration notes for various special platforms. In addition to this
37file, example.c is a good starting point for using the library, as
38it is heavily commented and should include everything most people
39will need. We assume that libpng is already installed; see the
40INSTALL file for instructions on how to install libpng.
41
42For examples of libpng usage, see the files "example.c", "pngtest.c",
43and the files in the "contrib" directory, all of which are included in
44the libpng distribution.
45
46Libpng was written as a companion to the PNG specification, as a way
47of reducing the amount of time and effort it takes to support the PNG
48file format in application programs.
49
50The PNG specification (second edition), November 2003, is available as
51a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
52<http://www.w3.org/TR/2003/REC-PNG-20031110/
53The W3C and ISO documents have identical technical content.
54
55The PNG-1.2 specification is available at
56<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
57to the PNG specification (second edition) but has some additional material.
58
59The PNG-1.0 specification is available
60as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
61W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
62
63Some additional chunks are described in the special-purpose public chunks
64documents at <http://www.libpng.org/pub/png/documents/>.
65
66Other information
67about PNG, and the latest version of libpng, can be found at the PNG home
68page, <http://www.libpng.org/pub/png/>.
69
70Most users will not have to modify the library significantly; advanced
71users may want to modify it more. All attempts were made to make it as
72complete as possible, while keeping the code easy to understand.
73Currently, this library only supports C. Support for other languages
74is being considered.
75
76Libpng has been designed to handle multiple sessions at one time,
77to be easily modifiable, to be portable to the vast majority of
78machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
79to use. The ultimate goal of libpng is to promote the acceptance of
80the PNG file format in whatever way possible. While there is still
81work to be done (see the TODO file), libpng should cover the
82majority of the needs of its users.
83
84Libpng uses zlib for its compression and decompression of PNG files.
85Further information about zlib, and the latest version of zlib, can
86be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
87The zlib compression utility is a general purpose utility that is
88useful for more than PNG files, and can be used without libpng.
89See the documentation delivered with zlib for more details.
90You can usually find the source files for the zlib utility wherever you
91find the libpng source files.
92
93Libpng is thread safe, provided the threads are using different
94instances of the structures. Each thread should have its own
95png_struct and png_info instances, and thus its own image.
96Libpng does not protect itself against two threads using the
97same instance of a structure.
98
99II. Structures
100
101There are two main structures that are important to libpng, png_struct
102and png_info. Both are internal structures that are no longer exposed
103in the libpng interface (as of libpng 1.5.0).
104
105The png_info structure is designed to provide information about the
106PNG file. At one time, the fields of png_info were intended to be
107directly accessible to the user. However, this tended to cause problems
108with applications using dynamically loaded libraries, and as a result
109a set of interface functions for png_info (the png_get_*() and png_set_*()
110functions) was developed, and direct access to the png_info fields was
111deprecated..
112
113The png_struct structure is the object used by the library to decode a
114single image. As of 1.5.0 this structure is also not exposed.
115
116Almost all libpng APIs require a pointer to a png_struct as the first argument.
117Many (in particular the png_set and png_get APIs) also require a pointer
118to png_info as the second argument. Some application visible macros
119defined in png.h designed for basic data access (reading and writing
120integers in the PNG format) don't take a png_info pointer, but it's almost
121always safe to assume that a (png_struct*) has to be passed to call an API
122function.
123
124You can have more than one png_info structure associated with an image,
125as illustrated in pngtest.c, one for information valid prior to the
126IDAT chunks and another (called "end_info" below) for things after them.
127
128The png.h header file is an invaluable reference for programming with libpng.
129And while I'm on the topic, make sure you include the libpng header file:
130
131#include <png.h>
132
133and also (as of libpng-1.5.0) the zlib header file, if you need it:
134
135#include <zlib.h>
136
137Types
138
139The png.h header file defines a number of integral types used by the
140APIs. Most of these are fairly obvious; for example types corresponding
141to integers of particular sizes and types for passing color values.
142
143One exception is how non-integral numbers are handled. For application
144convenience most APIs that take such numbers have C (double) arguments,
145however internally PNG, and libpng, use 32 bit signed integers and encode
146the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
147macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
148which is simply (png_int_32).
149
150All APIs that take (double) arguments also have a matching API that
151takes the corresponding fixed point integer arguments. The fixed point
152API has the same name as the floating point one with "_fixed" appended.
153The actual range of values permitted in the APIs is frequently less than
154the full range of (png_fixed_point) (-21474 to +21474). When APIs require
155a non-negative argument the type is recorded as png_uint_32 above. Consult
156the header file and the text below for more information.
157
158Special care must be take with sCAL chunk handling because the chunk itself
159uses non-integral values encoded as strings containing decimal floating point
160numbers. See the comments in the header file.
161
162Configuration
163
164The main header file function declarations are frequently protected by C
165preprocessing directives of the form:
166
167 #ifdef PNG_feature_SUPPORTED
168 declare-function
169 #endif
170 ...
171 #ifdef PNG_feature_SUPPORTED
172 use-function
173 #endif
174
175The library can be built without support for these APIs, although a
176standard build will have all implemented APIs. Application programs
177should check the feature macros before using an API for maximum
178portability. From libpng 1.5.0 the feature macros set during the build
179of libpng are recorded in the header file "pnglibconf.h" and this file
180is always included by png.h.
181
182If you don't need to change the library configuration from the default, skip to
183the next section ("Reading").
184
185Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
186of the build project files in the 'projects' directory simply copy
187scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
188systems do not permit easy auto-configuration of the library - they only
189support the default configuration.
190
191The easiest way to make minor changes to the libpng configuration when
192auto-configuration is supported is to add definitions to the command line
193using (typically) CPPFLAGS. For example:
194
195CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
196
197will change the internal libpng math implementation for gamma correction and
198other arithmetic calculations to fixed point, avoiding the need for fast
199floating point support. The result can be seen in the generated pnglibconf.h -
200make sure it contains the changed feature macro setting.
201
202If you need to make more extensive configuration changes - more than one or two
203feature macro settings - you can either add -DPNG_USER_CONFIG to the build
204command line and put a list of feature macro settings in pngusr.h or you can set
205DFA_XTRA (a makefile variable) to a file containing the same information in the
206form of 'option' settings.
207
208A. Changing pnglibconf.h
209
210A variety of methods exist to build libpng. Not all of these support
211reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
212rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
213
214Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
215pnglibconf.h and changing the lines defining the supported features, paying
216very close attention to the 'option' information in scripts/pnglibconf.dfa
217that describes those features and their requirements. This is easy to get
218wrong.
219
220B. Configuration using DFA_XTRA
221
222Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
223variant such as 'nawk' or 'gawk', is available. The configure build will
224automatically find an appropriate awk and build pnglibconf.h.
225The scripts/pnglibconf.mak file contains a set of make rules for doing the
226same thing if configure is not used, and many of the makefiles in the scripts
227directory use this approach.
228
229When rebuilding simply write a new file containing changed options and set
230DFA_XTRA to the name of this file. This causes the build to append the new file
231to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
232of the following forms:
233
234everything = off
235
236This turns all optional features off. Include it at the start of pngusr.dfa to
237make it easier to build a minimal configuration. You will need to turn at least
238some features on afterward to enable either reading or writing code, or both.
239
240option feature on
241option feature off
242
243Enable or disable a single feature. This will automatically enable other
244features required by a feature that is turned on or disable other features that
245require a feature which is turned off. Conflicting settings will cause an error
246message to be emitted by awk.
247
248setting feature default value
249
250Changes the default value of setting 'feature' to 'value'. There are a small
251number of settings listed at the top of pnglibconf.h, they are documented in the
252source code. Most of these values have performance implications for the library
253but most of them have no visible effect on the API. Some can also be overridden
254from the API.
255
256This method of building a customized pnglibconf.h is illustrated in
257contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
258pngusr.dfa in these directories.
259
260C. Configuration using PNG_USR_CONFIG
261
262If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
263pngusr.h will automatically be included before the options in
264scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
265macro definitions turning features on or off or setting settings.
266
267Apart from the global setting "everything = off" all the options listed above
268can be set using macros in pngusr.h:
269
270#define PNG_feature_SUPPORTED
271
272is equivalent to:
273
274option feature on
275
276#define PNG_NO_feature
277
278is equivalent to:
279
280option feature off
281
282#define PNG_feature value
283
284is equivalent to:
285
286setting feature default value
287
288Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
289pngusr file you supply override the contents of scripts/pnglibconf.dfa
290
291If confusing or incomprehensible behavior results it is possible to
292examine the intermediate file pnglibconf.dfn to find the full set of
293dependency information for each setting and option. Simply locate the
294feature in the file and read the C comments that precede it.
295
296This method is also illustrated in the contrib/pngminim/* makefiles and
297pngusr.h.
298
299III. Reading
300
301We'll now walk you through the possible functions to call when reading
302in a PNG file sequentially, briefly explaining the syntax and purpose
303of each one. See example.c and png.h for more detail. While
304progressive reading is covered in the next section, you will still
305need some of the functions discussed in this section to read a PNG
306file.
307
308Setup
309
310You will want to do the I/O initialization(*) before you get into libpng,
311so if it doesn't work, you don't have much to undo. Of course, you
312will also want to insure that you are, in fact, dealing with a PNG
313file. Libpng provides a simple check to see if a file is a PNG file.
314To use it, pass in the first 1 to 8 bytes of the file to the function
315png_sig_cmp(), and it will return 0 (false) if the bytes match the
316corresponding bytes of the PNG signature, or nonzero (true) otherwise.
317Of course, the more bytes you pass in, the greater the accuracy of the
318prediction.
319
320If you are intending to keep the file pointer open for use in libpng,
321you must ensure you don't read more than 8 bytes from the beginning
322of the file, and you also have to make a call to png_set_sig_bytes_read()
323with the number of bytes you read from the beginning. Libpng will
324then only check the bytes (if any) that your program didn't read.
325
326(*): If you are not using the standard I/O functions, you will need
327to replace them with custom functions. See the discussion under
328Customizing libpng.
329
330
331 FILE *fp = fopen(file_name, "rb");
332 if (!fp)
333 {
334 return (ERROR);
335 }
336
337 fread(header, 1, number, fp);
338 is_png = !png_sig_cmp(header, 0, number);
339
340 if (!is_png)
341 {
342 return (NOT_PNG);
343 }
344
345
346Next, png_struct and png_info need to be allocated and initialized. In
347order to ensure that the size of these structures is correct even with a
348dynamically linked libpng, there are functions to initialize and
349allocate the structures. We also pass the library version, optional
350pointers to error handling functions, and a pointer to a data struct for
351use by the error functions, if necessary (the pointer and functions can
352be NULL if the default error handlers are to be used). See the section
353on Changes to Libpng below regarding the old initialization functions.
354The structure allocation functions quietly return NULL if they fail to
355create the structure, so your application should check for that.
356
357 png_structp png_ptr = png_create_read_struct
358 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
359 user_error_fn, user_warning_fn);
360
361 if (!png_ptr)
362 return (ERROR);
363
364 png_infop info_ptr = png_create_info_struct(png_ptr);
365
366 if (!info_ptr)
367 {
368 png_destroy_read_struct(&png_ptr,
369 (png_infopp)NULL, (png_infopp)NULL);
370 return (ERROR);
371 }
372
373If you want to use your own memory allocation routines,
374use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
375png_create_read_struct_2() instead of png_create_read_struct():
376
377 png_structp png_ptr = png_create_read_struct_2
378 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
379 user_error_fn, user_warning_fn, (png_voidp)
380 user_mem_ptr, user_malloc_fn, user_free_fn);
381
382The error handling routines passed to png_create_read_struct()
383and the memory alloc/free routines passed to png_create_struct_2()
384are only necessary if you are not using the libpng supplied error
385handling and memory alloc/free functions.
386
387When libpng encounters an error, it expects to longjmp back
388to your routine. Therefore, you will need to call setjmp and pass
389your png_jmpbuf(png_ptr). If you read the file from different
390routines, you will need to update the longjmp buffer every time you enter
391a new routine that will call a png_*() function.
392
393See your documentation of setjmp/longjmp for your compiler for more
394information on setjmp/longjmp. See the discussion on libpng error
395handling in the Customizing Libpng section below for more information
396on the libpng error handling. If an error occurs, and libpng longjmp's
397back to your setjmp, you will want to call png_destroy_read_struct() to
398free any memory.
399
400 if (setjmp(png_jmpbuf(png_ptr)))
401 {
402 png_destroy_read_struct(&png_ptr, &info_ptr,
403 &end_info);
404 fclose(fp);
405 return (ERROR);
406 }
407
408Pass (png_infopp)NULL instead of &end_info if you didn't create
409an end_info structure.
410
411If you would rather avoid the complexity of setjmp/longjmp issues,
412you can compile libpng with PNG_NO_SETJMP, in which case
413errors will result in a call to PNG_ABORT() which defaults to abort().
414
415You can #define PNG_ABORT() to a function that does something
416more useful than abort(), as long as your function does not
417return.
418
419Now you need to set up the input code. The default for libpng is to
420use the C function fread(). If you use this, you will need to pass a
421valid FILE * in the function png_init_io(). Be sure that the file is
422opened in binary mode. If you wish to handle reading data in another
423way, you need not call the png_init_io() function, but you must then
424implement the libpng I/O methods discussed in the Customizing Libpng
425section below.
426
427 png_init_io(png_ptr, fp);
428
429If you had previously opened the file and read any of the signature from
430the beginning in order to see if this was a PNG file, you need to let
431libpng know that there are some bytes missing from the start of the file.
432
433 png_set_sig_bytes(png_ptr, number);
434
435You can change the zlib compression buffer size to be used while
436reading compressed data with
437
438 png_set_compression_buffer_size(png_ptr, buffer_size);
439
440where the default size is 8192 bytes. Note that the buffer size
441is changed immediately and the buffer is reallocated immediately,
442instead of setting a flag to be acted upon later.
443
444If you want CRC errors to be handled in a different manner than
445the default, use
446
447 png_set_crc_action(png_ptr, crit_action, ancil_action);
448
449The values for png_set_crc_action() say how libpng is to handle CRC errors in
450ancillary and critical chunks, and whether to use the data contained
451therein. Note that it is impossible to "discard" data in a critical
452chunk.
453
454Choices for (int) crit_action are
455 PNG_CRC_DEFAULT 0 error/quit
456 PNG_CRC_ERROR_QUIT 1 error/quit
457 PNG_CRC_WARN_USE 3 warn/use data
458 PNG_CRC_QUIET_USE 4 quiet/use data
459 PNG_CRC_NO_CHANGE 5 use the current value
460
461Choices for (int) ancil_action are
462 PNG_CRC_DEFAULT 0 error/quit
463 PNG_CRC_ERROR_QUIT 1 error/quit
464 PNG_CRC_WARN_DISCARD 2 warn/discard data
465 PNG_CRC_WARN_USE 3 warn/use data
466 PNG_CRC_QUIET_USE 4 quiet/use data
467 PNG_CRC_NO_CHANGE 5 use the current value
468
469Setting up callback code
470
471You can set up a callback function to handle any unknown chunks in the
472input stream. You must supply the function
473
474 read_chunk_callback(png_structp png_ptr,
475 png_unknown_chunkp chunk);
476 {
477 /* The unknown chunk structure contains your
478 chunk data, along with similar data for any other
479 unknown chunks: */
480
481 png_byte name[5];
482 png_byte *data;
483 png_size_t size;
484
485 /* Note that libpng has already taken care of
486 the CRC handling */
487
488 /* put your code here. Search for your chunk in the
489 unknown chunk structure, process it, and return one
490 of the following: */
491
492 return (-n); /* chunk had an error */
493 return (0); /* did not recognize */
494 return (n); /* success */
495 }
496
497(You can give your function another name that you like instead of
498"read_chunk_callback")
499
500To inform libpng about your function, use
501
502 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
503 read_chunk_callback);
504
505This names not only the callback function, but also a user pointer that
506you can retrieve with
507
508 png_get_user_chunk_ptr(png_ptr);
509
510If you call the png_set_read_user_chunk_fn() function, then all unknown
511chunks will be saved when read, in case your callback function will need
512one or more of them. This behavior can be changed with the
513png_set_keep_unknown_chunks() function, described below.
514
515At this point, you can set up a callback function that will be
516called after each row has been read, which you can use to control
517a progress meter or the like. It's demonstrated in pngtest.c.
518You must supply a function
519
520 void read_row_callback(png_structp png_ptr,
521 png_uint_32 row, int pass);
522 {
523 /* put your code here */
524 }
525
526(You can give it another name that you like instead of "read_row_callback")
527
528To inform libpng about your function, use
529
530 png_set_read_status_fn(png_ptr, read_row_callback);
531
532When this function is called the row has already been completely processed and
533the 'row' and 'pass' refer to the next row to be handled. For the
534non-interlaced case the row that was just handled is simply one less than the
535passed in row number, and pass will always be 0. For the interlaced case the
536same applies unless the row value is 0, in which case the row just handled was
537the last one from one of the preceding passes. Because interlacing may skip a
538pass you cannot be sure that the preceding pass is just 'pass-1', if you really
539need to know what the last pass is record (row,pass) from the callback and use
540the last recorded value each time.
541
542As with the user transform you can find the output row using the
543PNG_ROW_FROM_PASS_ROW macro.
544
545Unknown-chunk handling
546
547Now you get to set the way the library processes unknown chunks in the
548input PNG stream. Both known and unknown chunks will be read. Normal
549behavior is that known chunks will be parsed into information in
550various info_ptr members while unknown chunks will be discarded. This
551behavior can be wasteful if your application will never use some known
552chunk types. To change this, you can call:
553
554 png_set_keep_unknown_chunks(png_ptr, keep,
555 chunk_list, num_chunks);
556 keep - 0: default unknown chunk handling
557 1: ignore; do not keep
558 2: keep only if safe-to-copy
559 3: keep even if unsafe-to-copy
560
561 You can use these definitions:
562 PNG_HANDLE_CHUNK_AS_DEFAULT 0
563 PNG_HANDLE_CHUNK_NEVER 1
564 PNG_HANDLE_CHUNK_IF_SAFE 2
565 PNG_HANDLE_CHUNK_ALWAYS 3
566
567 chunk_list - list of chunks affected (a byte string,
568 five bytes per chunk, NULL or '\0' if
569 num_chunks is 0)
570
571 num_chunks - number of chunks affected; if 0, all
572 unknown chunks are affected. If nonzero,
573 only the chunks in the list are affected
574
575Unknown chunks declared in this way will be saved as raw data onto a
576list of png_unknown_chunk structures. If a chunk that is normally
577known to libpng is named in the list, it will be handled as unknown,
578according to the "keep" directive. If a chunk is named in successive
579instances of png_set_keep_unknown_chunks(), the final instance will
580take precedence. The IHDR and IEND chunks should not be named in
581chunk_list; if they are, libpng will process them normally anyway.
582If you know that your application will never make use of some particular
583chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
584
585Here is an example of the usage of png_set_keep_unknown_chunks(),
586where the private "vpAg" chunk will later be processed by a user chunk
587callback function:
588
589 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
590
591 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
592 png_byte unused_chunks[]=
593 {
594 104, 73, 83, 84, (png_byte) '\0', /* hIST */
595 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
596 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
597 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
598 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
599 116, 73, 77, 69, (png_byte) '\0', /* tIME */
600 };
601 #endif
602
603 ...
604
605 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
606 /* ignore all unknown chunks: */
607 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
608
609 /* except for vpAg: */
610 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
611
612 /* also ignore unused known chunks: */
613 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
614 (int)sizeof(unused_chunks)/5);
615 #endif
616
617User limits
618
619The PNG specification allows the width and height of an image to be as
620large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
621Since very few applications really need to process such large images,
622we have imposed an arbitrary 1-million limit on rows and columns.
623Larger images will be rejected immediately with a png_error() call. If
624you wish to change this limit, you can use
625
626 png_set_user_limits(png_ptr, width_max, height_max);
627
628to set your own limits, or use width_max = height_max = 0x7fffffffL
629to allow all valid dimensions (libpng may reject some very large images
630anyway because of potential buffer overflow conditions).
631
632You should put this statement after you create the PNG structure and
633before calling png_read_info(), png_read_png(), or png_process_data().
634
635When writing a PNG datastream, put this statement before calling
636png_write_info() or png_write_png().
637
638If you need to retrieve the limits that are being applied, use
639
640 width_max = png_get_user_width_max(png_ptr);
641 height_max = png_get_user_height_max(png_ptr);
642
643The PNG specification sets no limit on the number of ancillary chunks
644allowed in a PNG datastream. You can impose a limit on the total number
645of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
646
647 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
648
649where 0x7fffffffL means unlimited. You can retrieve this limit with
650
651 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
652
653This limit also applies to the number of buffers that can be allocated
654by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
655
656You can also set a limit on the amount of memory that a compressed chunk
657other than IDAT can occupy, with
658
659 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
660
661and you can retrieve the limit with
662
663 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
664
665Any chunks that would cause either of these limits to be exceeded will
666be ignored.
667
668Information about your system
669
670If you intend to display the PNG or to incorporate it in other image data you
671need to tell libpng information about your display or drawing surface so that
672libpng can convert the values in the image to match the display.
673
674From libpng-1.5.4 this information can be set before reading the PNG file
675header. In earlier versions png_set_gamma() existed but behaved incorrectly if
676called before the PNG file header had been read and png_set_alpha_mode() did not
677exist.
678
679If you need to support versions prior to libpng-1.5.4 test the version number
680as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
681described in the appropriate manual page.
682
683You give libpng the encoding expected by your system expressed as a 'gamma'
684value. You can also specify a default encoding for the PNG file in
685case the required information is missing from the file. By default libpng
686assumes that the PNG data matches your system, to keep this default call:
687
688 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
689
690or you can use the fixed point equivalent:
691
692 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
693
694If you don't know the gamma for your system it is probably 2.2 - a good
695approximation to the IEC standard for display systems (sRGB). If images are
696too contrasty or washed out you got the value wrong - check your system
697documentation!
698
699Many systems permit the system gamma to be changed via a lookup table in the
700display driver, a few systems, including older Macs, change the response by
701default. As of 1.5.4 three special values are available to handle common
702situations:
703
704 PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
705 standard. This matches almost all systems.
706 PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
707 Apple Macintosh system with the default settings.
708 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
709 system expects data with no gamma encoding.
710
711You would use the linear (unencoded) value if you need to process the pixel
712values further because this avoids the need to decode and reencode each
713component value whenever arithmetic is performed. A lot of graphics software
714uses linear values for this reason, often with higher precision component values
715to preserve overall accuracy.
716
717The second thing you may need to tell libpng about is how your system handles
718alpha channel information. Some, but not all, PNG files contain an alpha
719channel. To display these files correctly you need to compose the data onto a
720suitable background, as described in the PNG specification.
721
722Libpng only supports composing onto a single color (using png_set_background;
723see below). Otherwise you must do the composition yourself and, in this case,
724you may need to call png_set_alpha_mode:
725
726#if PNG_LIBPNG_VER >= 10504
727 png_set_alpha_mode(png_ptr, mode, screen_gamma);
728#else
729 png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
730#endif
731
732The screen_gamma value is the same as the argument to png_set_gamma; however,
733how it affects the output depends on the mode. png_set_alpha_mode() sets the
734file gamma default to 1/screen_gamma, so normally you don't need to call
735png_set_gamma. If you need different defaults call png_set_gamma() before
736png_set_alpha_mode() - if you call it after it will override the settings made
737by png_set_alpha_mode().
738
739The mode is as follows:
740
741 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
742green and blue, or gray, components are gamma encoded color
743values and are not premultiplied by the alpha value. The
744alpha value is a linear measure of the contribution of the
745pixel to the corresponding final output pixel.
746
747You should normally use this format if you intend to perform
748color correction on the color values; most, maybe all, color
749correction software has no handling for the alpha channel and,
750anyway, the math to handle pre-multiplied component values is
751unnecessarily complex.
752
753Before you do any arithmetic on the component values you need
754to remove the gamma encoding and multiply out the alpha
755channel. See the PNG specification for more detail. It is
756important to note that when an image with an alpha channel is
757scaled, linear encoded, pre-multiplied component values must
758be used!
759
760The remaining modes assume you don't need to do any further color correction or
761that if you do, your color correction software knows all about alpha (it
762probably doesn't!)
763
764 PNG_ALPHA_STANDARD: The data libpng produces
765is encoded in the standard way
766assumed by most correctly written graphics software.
767The gamma encoding will be removed by libpng and the
768linear component values will be pre-multiplied by the
769alpha channel.
770
771With this format the final image must be re-encoded to
772match the display gamma before the image is displayed.
773If your system doesn't do that, yet still seems to
774perform arithmetic on the pixels without decoding them,
775it is broken - check out the modes below.
776
777With PNG_ALPHA_STANDARD libpng always produces linear
778component values, whatever screen_gamma you supply. The
779screen_gamma value is, however, used as a default for
780the file gamma if the PNG file has no gamma information.
781
782If you call png_set_gamma() after png_set_alpha_mode() you
783will override the linear encoding. Instead the
784pre-multiplied pixel values will be gamma encoded but
785the alpha channel will still be linear. This may
786actually match the requirements of some broken software,
787but it is unlikely.
788
789While linear 8-bit data is often used it has
790insufficient precision for any image with a reasonable
791dynamic range. To avoid problems, and if your software
792supports it, use png_set_expand_16() to force all
793components to 16 bits.
794
795 PNG_ALPHA_OPTIMIZED: This mode is the same
796as PNG_ALPHA_STANDARD except that
797completely opaque pixels are gamma encoded according to
798the screen_gamma value. Pixels with alpha less than 1.0
799will still have linear components.
800
801Use this format if you have control over your
802compositing software and do don't do other arithmetic
803(such as scaling) on the data you get from libpng. Your
804compositing software can simply copy opaque pixels to
805the output but still has linear values for the
806non-opaque pixels.
807
808In normal compositing, where the alpha channel encodes
809partial pixel coverage (as opposed to broad area
810translucency), the inaccuracies of the 8-bit
811representation of non-opaque pixels are irrelevant.
812
813You can also try this format if your software is broken;
814it might look better.
815
816 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
817however, all component values,
818including the alpha channel are gamma encoded. This is
819an appropriate format to try if your software, or more
820likely hardware, is totally broken, i.e., if it performs
821linear arithmetic directly on gamma encoded values.
822
823In most cases of broken software or hardware the bug in the final display
824manifests as a subtle halo around composited parts of the image. You may not
825even perceive this as a halo; the composited part of the image may simply appear
826separate from the background, as though it had been cut out of paper and pasted
827on afterward.
828
829If you don't have to deal with bugs in software or hardware, or if you can fix
830them, there are three recommended ways of using png_set_alpha_mode():
831
832 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
833 screen_gamma);
834
835You can do color correction on the result (libpng does not currently
836support color correction internally). When you handle the alpha channel
837you need to undo the gamma encoding and multiply out the alpha.
838
839 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
840 screen_gamma);
841 png_set_expand_16(png_ptr);
842
843If you are using the high level interface, don't call png_set_expand_16();
844instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
845
846With this mode you can't do color correction, but you can do arithmetic,
847including composition and scaling, on the data without further processing.
848
849 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
850 screen_gamma);
851
852You can avoid the expansion to 16-bit components with this mode, but you
853lose the ability to scale the image or perform other linear arithmetic.
854All you can do is compose the result onto a matching output. Since this
855mode is libpng-specific you also need to write your own composition
856software.
857
858If you don't need, or can't handle, the alpha channel you can call
859png_set_background() to remove it by compositing against a fixed color. Don't
860call png_set_strip_alpha() to do this - it will leave spurious pixel values in
861transparent parts of this image.
862
863 png_set_background(png_ptr, &background_color,
864 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
865
866The background_color is an RGB or grayscale value according to the data format
867libpng will produce for you. Because you don't yet know the format of the PNG
868file, if you call png_set_background at this point you must arrange for the
869format produced by libpng to always have 8-bit or 16-bit components and then
870store the color as an 8-bit or 16-bit color as appropriate. The color contains
871separate gray and RGB component values, so you can let libpng produce gray or
872RGB output according to the input format, but low bit depth grayscale images
873must always be converted to at least 8-bit format. (Even though low bit depth
874grayscale images can't have an alpha channel they can have a transparent
875color!)
876
877You set the transforms you need later, either as flags to the high level
878interface or libpng API calls for the low level interface. For reference the
879settings and API calls required are:
880
8818-bit values:
882 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
883 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
884
885 If you must get exactly the same inaccurate results
886 produced by default in versions prior to libpng-1.5.4,
887 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
888 instead.
889
89016-bit values:
891 PNG_TRANSFORM_EXPAND_16
892 png_set_expand_16(png_ptr);
893
894In either case palette image data will be expanded to RGB. If you just want
895color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
896to the list.
897
898Calling png_set_background before the PNG file header is read will not work
899prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
900errors it is therefore much safer to call png_set_background after the head has
901been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
902used with the high level interface.
903
904The high-level read interface
905
906At this point there are two ways to proceed; through the high-level
907read interface, or through a sequence of low-level read operations.
908You can use the high-level interface if (a) you are willing to read
909the entire image into memory, and (b) the input transformations
910you want to do are limited to the following set:
911
912 PNG_TRANSFORM_IDENTITY No transformation
913 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
914 8-bit accurately
915 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
916 8-bit less accurately
917 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
918 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
919 samples to bytes
920 PNG_TRANSFORM_PACKSWAP Change order of packed
921 pixels to LSB first
922 PNG_TRANSFORM_EXPAND Perform set_expand()
923 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
924 PNG_TRANSFORM_SHIFT Normalize pixels to the
925 sBIT depth
926 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
927 to BGRA
928 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
929 to AG
930 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
931 to transparency
932 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
933 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
934 to RGB (or GA to RGBA)
935 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
936
937(This excludes setting a background color, doing gamma transformation,
938quantizing, and setting filler.) If this is the case, simply do this:
939
940 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
941
942where png_transforms is an integer containing the bitwise OR of some
943set of transformation flags. This call is equivalent to png_read_info(),
944followed the set of transformations indicated by the transform mask,
945then png_read_image(), and finally png_read_end().
946
947(The final parameter of this call is not yet used. Someday it might point
948to transformation parameters required by some future input transform.)
949
950You must use png_transforms and not call any png_set_transform() functions
951when you use png_read_png().
952
953After you have called png_read_png(), you can retrieve the image data
954with
955
956 row_pointers = png_get_rows(png_ptr, info_ptr);
957
958where row_pointers is an array of pointers to the pixel data for each row:
959
960 png_bytep row_pointers[height];
961
962If you know your image size and pixel size ahead of time, you can allocate
963row_pointers prior to calling png_read_png() with
964
965 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
966 png_error (png_ptr,
967 "Image is too tall to process in memory");
968
969 if (width > PNG_UINT_32_MAX/pixel_size)
970 png_error (png_ptr,
971 "Image is too wide to process in memory");
972
973 row_pointers = png_malloc(png_ptr,
974 height*png_sizeof(png_bytep));
975
976 for (int i=0; i<height, i++)
977 row_pointers[i]=NULL; /* security precaution */
978
979 for (int i=0; i<height, i++)
980 row_pointers[i]=png_malloc(png_ptr,
981 width*pixel_size);
982
983 png_set_rows(png_ptr, info_ptr, &row_pointers);
984
985Alternatively you could allocate your image in one big block and define
986row_pointers[i] to point into the proper places in your block.
987
988If you use png_set_rows(), the application is responsible for freeing
989row_pointers (and row_pointers[i], if they were separately allocated).
990
991If you don't allocate row_pointers ahead of time, png_read_png() will
992do it, and it'll be free'ed by libpng when you call png_destroy_*().
993
994The low-level read interface
995
996If you are going the low-level route, you are now ready to read all
997the file information up to the actual image data. You do this with a
998call to png_read_info().
999
1000 png_read_info(png_ptr, info_ptr);
1001
1002This will process all chunks up to but not including the image data.
1003
1004This also copies some of the data from the PNG file into the decode structure
1005for use in later transformations. Important information copied in is:
1006
10071) The PNG file gamma from the gAMA chunk. This overwrites the default value
1008provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1009
10102) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
1011damages the information provided by an earlier call to png_set_background
1012resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
1013
10143) The number of significant bits in each component value. Libpng uses this to
1015optimize gamma handling by reducing the internal lookup table sizes.
1016
10174) The transparent color information from a tRNS chunk. This can be modified by
1018a later call to png_set_tRNS.
1019
1020Querying the info structure
1021
1022Functions are used to get the information from the info_ptr once it
1023has been read. Note that these fields may not be completely filled
1024in until png_read_end() has read the chunk data following the image.
1025
1026 png_get_IHDR(png_ptr, info_ptr, &width, &height,
1027 &bit_depth, &color_type, &interlace_type,
1028 &compression_type, &filter_method);
1029
1030 width - holds the width of the image
1031 in pixels (up to 2^31).
1032
1033 height - holds the height of the image
1034 in pixels (up to 2^31).
1035
1036 bit_depth - holds the bit depth of one of the
1037 image channels. (valid values are
1038 1, 2, 4, 8, 16 and depend also on
1039 the color_type. See also
1040 significant bits (sBIT) below).
1041
1042 color_type - describes which color/alpha channels
1043 are present.
1044 PNG_COLOR_TYPE_GRAY
1045 (bit depths 1, 2, 4, 8, 16)
1046 PNG_COLOR_TYPE_GRAY_ALPHA
1047 (bit depths 8, 16)
1048 PNG_COLOR_TYPE_PALETTE
1049 (bit depths 1, 2, 4, 8)
1050 PNG_COLOR_TYPE_RGB
1051 (bit_depths 8, 16)
1052 PNG_COLOR_TYPE_RGB_ALPHA
1053 (bit_depths 8, 16)
1054
1055 PNG_COLOR_MASK_PALETTE
1056 PNG_COLOR_MASK_COLOR
1057 PNG_COLOR_MASK_ALPHA
1058
1059 interlace_type - (PNG_INTERLACE_NONE or
1060 PNG_INTERLACE_ADAM7)
1061
1062 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
1063 for PNG 1.0)
1064
1065 filter_method - (must be PNG_FILTER_TYPE_BASE
1066 for PNG 1.0, and can also be
1067 PNG_INTRAPIXEL_DIFFERENCING if
1068 the PNG datastream is embedded in
1069 a MNG-1.0 datastream)
1070
1071 Any or all of interlace_type, compression_type, or
1072 filter_method can be NULL if you are
1073 not interested in their values.
1074
1075 Note that png_get_IHDR() returns 32-bit data into
1076 the application's width and height variables.
1077 This is an unsafe situation if these are 16-bit
1078 variables. In such situations, the
1079 png_get_image_width() and png_get_image_height()
1080 functions described below are safer.
1081
1082 width = png_get_image_width(png_ptr,
1083 info_ptr);
1084
1085 height = png_get_image_height(png_ptr,
1086 info_ptr);
1087
1088 bit_depth = png_get_bit_depth(png_ptr,
1089 info_ptr);
1090
1091 color_type = png_get_color_type(png_ptr,
1092 info_ptr);
1093
1094 interlace_type = png_get_interlace_type(png_ptr,
1095 info_ptr);
1096
1097 compression_type = png_get_compression_type(png_ptr,
1098 info_ptr);
1099
1100 filter_method = png_get_filter_type(png_ptr,
1101 info_ptr);
1102
1103 channels = png_get_channels(png_ptr, info_ptr);
1104
1105 channels - number of channels of info for the
1106 color type (valid values are 1 (GRAY,
1107 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
1108 4 (RGB_ALPHA or RGB + filler byte))
1109
1110 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
1111
1112 rowbytes - number of bytes needed to hold a row
1113
1114 signature = png_get_signature(png_ptr, info_ptr);
1115
1116 signature - holds the signature read from the
1117 file (if any). The data is kept in
1118 the same offset it would be if the
1119 whole signature were read (i.e. if an
1120 application had already read in 4
1121 bytes of signature before starting
1122 libpng, the remaining 4 bytes would
1123 be in signature[4] through signature[7]
1124 (see png_set_sig_bytes())).
1125
1126These are also important, but their validity depends on whether the chunk
1127has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
1128png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
1129data has been read, or zero if it is missing. The parameters to the
1130png_get_<chunk> are set directly if they are simple data types, or a
1131pointer into the info_ptr is returned for any complex types.
1132
1133 png_get_PLTE(png_ptr, info_ptr, &palette,
1134 &num_palette);
1135
1136 palette - the palette for the file
1137 (array of png_color)
1138
1139 num_palette - number of entries in the palette
1140
1141 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
1142 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
1143
1144 file_gamma - the gamma at which the file is
1145 written (PNG_INFO_gAMA)
1146
1147 int_file_gamma - 100,000 times the gamma at which the
1148 file is written
1149
1150 png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, &red_y,
1151 &green_x, &green_y, &blue_x, &blue_y)
1152 png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X,
1153 &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z)
1154 png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y,
1155 &int_red_x, &int_red_y, &int_green_x, &int_green_y,
1156 &int_blue_x, &int_blue_y)
1157 png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
1158 &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z,
1159 &int_blue_X, &int_blue_Y, &int_blue_Z)
1160
1161 {white,red,green,blue}_{x,y}
1162 A color space encoding specified using the chromaticities
1163 of the end points and the white point. (PNG_INFO_cHRM)
1164
1165 {red,green,blue}_{X,Y,Z}
1166 A color space encoding specified using the encoding end
1167 points - the CIE tristimulus specification of the intended
1168 color of the red, green and blue channels in the PNG RGB
1169 data. The white point is simply the sum of the three end
1170 points. (PNG_INFO_cHRM)
1171
1172 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
1173
1174 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
1175 The presence of the sRGB chunk
1176 means that the pixel data is in the
1177 sRGB color space. This chunk also
1178 implies specific values of gAMA and
1179 cHRM.
1180
1181 png_get_iCCP(png_ptr, info_ptr, &name,
1182 &compression_type, &profile, &proflen);
1183
1184 name - The profile name.
1185
1186 compression_type - The compression type; always
1187 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
1188 You may give NULL to this argument to
1189 ignore it.
1190
1191 profile - International Color Consortium color
1192 profile data. May contain NULs.
1193
1194 proflen - length of profile data in bytes.
1195
1196 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1197
1198 sig_bit - the number of significant bits for
1199 (PNG_INFO_sBIT) each of the gray,
1200 red, green, and blue channels,
1201 whichever are appropriate for the
1202 given color type (png_color_16)
1203
1204 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
1205 &num_trans, &trans_color);
1206
1207 trans_alpha - array of alpha (transparency)
1208 entries for palette (PNG_INFO_tRNS)
1209
1210 num_trans - number of transparent entries
1211 (PNG_INFO_tRNS)
1212
1213 trans_color - graylevel or color sample values of
1214 the single transparent color for
1215 non-paletted images (PNG_INFO_tRNS)
1216
1217 png_get_hIST(png_ptr, info_ptr, &hist);
1218 (PNG_INFO_hIST)
1219
1220 hist - histogram of palette (array of
1221 png_uint_16)
1222
1223 png_get_tIME(png_ptr, info_ptr, &mod_time);
1224
1225 mod_time - time image was last modified
1226 (PNG_VALID_tIME)
1227
1228 png_get_bKGD(png_ptr, info_ptr, &background);
1229
1230 background - background color (of type
1231 png_color_16p) (PNG_VALID_bKGD)
1232 valid 16-bit red, green and blue
1233 values, regardless of color_type
1234
1235 num_comments = png_get_text(png_ptr, info_ptr,
1236 &text_ptr, &num_text);
1237
1238 num_comments - number of comments
1239
1240 text_ptr - array of png_text holding image
1241 comments
1242
1243 text_ptr[i].compression - type of compression used
1244 on "text" PNG_TEXT_COMPRESSION_NONE
1245 PNG_TEXT_COMPRESSION_zTXt
1246 PNG_ITXT_COMPRESSION_NONE
1247 PNG_ITXT_COMPRESSION_zTXt
1248
1249 text_ptr[i].key - keyword for comment. Must contain
1250 1-79 characters.
1251
1252 text_ptr[i].text - text comments for current
1253 keyword. Can be empty.
1254
1255 text_ptr[i].text_length - length of text string,
1256 after decompression, 0 for iTXt
1257
1258 text_ptr[i].itxt_length - length of itxt string,
1259 after decompression, 0 for tEXt/zTXt
1260
1261 text_ptr[i].lang - language of comment (empty
1262 string for unknown).
1263
1264 text_ptr[i].lang_key - keyword in UTF-8
1265 (empty string for unknown).
1266
1267 Note that the itxt_length, lang, and lang_key
1268 members of the text_ptr structure only exist when the
1269 library is built with iTXt chunk support. Prior to
1270 libpng-1.4.0 the library was built by default without
1271 iTXt support. Also note that when iTXt is supported,
1272 they contain NULL pointers when the "compression"
1273 field contains PNG_TEXT_COMPRESSION_NONE or
1274 PNG_TEXT_COMPRESSION_zTXt.
1275
1276 num_text - number of comments (same as
1277 num_comments; you can put NULL here
1278 to avoid the duplication)
1279
1280 Note while png_set_text() will accept text, language,
1281 and translated keywords that can be NULL pointers, the
1282 structure returned by png_get_text will always contain
1283 regular zero-terminated C strings. They might be
1284 empty strings but they will never be NULL pointers.
1285
1286 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
1287 &palette_ptr);
1288
1289 num_spalettes - number of sPLT chunks read.
1290
1291 palette_ptr - array of palette structures holding
1292 contents of one or more sPLT chunks
1293 read.
1294
1295 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
1296 &unit_type);
1297
1298 offset_x - positive offset from the left edge
1299 of the screen (can be negative)
1300
1301 offset_y - positive offset from the top edge
1302 of the screen (can be negative)
1303
1304 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
1305
1306 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
1307 &unit_type);
1308
1309 res_x - pixels/unit physical resolution in
1310 x direction
1311
1312 res_y - pixels/unit physical resolution in
1313 x direction
1314
1315 unit_type - PNG_RESOLUTION_UNKNOWN,
1316 PNG_RESOLUTION_METER
1317
1318 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
1319 &height)
1320
1321 unit - physical scale units (an integer)
1322
1323 width - width of a pixel in physical scale units
1324
1325 height - height of a pixel in physical scale units
1326 (width and height are doubles)
1327
1328 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
1329 &height)
1330
1331 unit - physical scale units (an integer)
1332
1333 width - width of a pixel in physical scale units
1334 (expressed as a string)
1335
1336 height - height of a pixel in physical scale units
1337 (width and height are strings like "2.54")
1338
1339 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
1340 info_ptr, &unknowns)
1341
1342 unknowns - array of png_unknown_chunk
1343 structures holding unknown chunks
1344
1345 unknowns[i].name - name of unknown chunk
1346
1347 unknowns[i].data - data of unknown chunk
1348
1349 unknowns[i].size - size of unknown chunk's data
1350
1351 unknowns[i].location - position of chunk in file
1352
1353 The value of "i" corresponds to the order in which the
1354 chunks were read from the PNG file or inserted with the
1355 png_set_unknown_chunks() function.
1356
1357 The value of "location" is a bitwise "or" of
1358
1359 PNG_HAVE_IHDR (0x01)
1360 PNG_HAVE_PLTE (0x02)
1361 PNG_AFTER_IDAT (0x08)
1362
1363The data from the pHYs chunk can be retrieved in several convenient
1364forms:
1365
1366 res_x = png_get_x_pixels_per_meter(png_ptr,
1367 info_ptr)
1368
1369 res_y = png_get_y_pixels_per_meter(png_ptr,
1370 info_ptr)
1371
1372 res_x_and_y = png_get_pixels_per_meter(png_ptr,
1373 info_ptr)
1374
1375 res_x = png_get_x_pixels_per_inch(png_ptr,
1376 info_ptr)
1377
1378 res_y = png_get_y_pixels_per_inch(png_ptr,
1379 info_ptr)
1380
1381 res_x_and_y = png_get_pixels_per_inch(png_ptr,
1382 info_ptr)
1383
1384 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
1385 info_ptr)
1386
1387 Each of these returns 0 [signifying "unknown"] if
1388 the data is not present or if res_x is 0;
1389 res_x_and_y is 0 if res_x != res_y
1390
1391 Note that because of the way the resolutions are
1392 stored internally, the inch conversions won't
1393 come out to exactly even number. For example,
1394 72 dpi is stored as 0.28346 pixels/meter, and
1395 when this is retrieved it is 71.9988 dpi, so
1396 be sure to round the returned value appropriately
1397 if you want to display a reasonable-looking result.
1398
1399The data from the oFFs chunk can be retrieved in several convenient
1400forms:
1401
1402 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
1403
1404 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
1405
1406 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
1407
1408 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
1409
1410 Each of these returns 0 [signifying "unknown" if both
1411 x and y are 0] if the data is not present or if the
1412 chunk is present but the unit is the pixel. The
1413 remark about inexact inch conversions applies here
1414 as well, because a value in inches can't always be
1415 converted to microns and back without some loss
1416 of precision.
1417
1418For more information, see the
1419PNG specification for chunk contents. Be careful with trusting
1420rowbytes, as some of the transformations could increase the space
1421needed to hold a row (expand, filler, gray_to_rgb, etc.).
1422See png_read_update_info(), below.
1423
1424A quick word about text_ptr and num_text. PNG stores comments in
1425keyword/text pairs, one pair per chunk, with no limit on the number
1426of text chunks, and a 2^31 byte limit on their size. While there are
1427suggested keywords, there is no requirement to restrict the use to these
1428strings. It is strongly suggested that keywords and text be sensible
1429to humans (that's the point), so don't use abbreviations. Non-printing
1430symbols are not allowed. See the PNG specification for more details.
1431There is also no requirement to have text after the keyword.
1432
1433Keywords should be limited to 79 Latin-1 characters without leading or
1434trailing spaces, but non-consecutive spaces are allowed within the
1435keyword. It is possible to have the same keyword any number of times.
1436The text_ptr is an array of png_text structures, each holding a
1437pointer to a language string, a pointer to a keyword and a pointer to
1438a text string. The text string, language code, and translated
1439keyword may be empty or NULL pointers. The keyword/text
1440pairs are put into the array in the order that they are received.
1441However, some or all of the text chunks may be after the image, so, to
1442make sure you have read all the text chunks, don't mess with these
1443until after you read the stuff after the image. This will be
1444mentioned again below in the discussion that goes with png_read_end().
1445
1446Input transformations
1447
1448After you've read the header information, you can set up the library
1449to handle any special transformations of the image data. The various
1450ways to transform the data will be described in the order that they
1451should occur. This is important, as some of these change the color
1452type and/or bit depth of the data, and some others only work on
1453certain color types and bit depths.
1454
1455Transformations you request are ignored if they don't have any meaning for a
1456particular input data format. However some transformations can have an effect
1457as a result of a previous transformation. If you specify a contradictory set of
1458transformations, for example both adding and removing the alpha channel, you
1459cannot predict the final result.
1460
1461The color used for the transparency values should be supplied in the same
1462format/depth as the current image data. It is stored in the same format/depth
1463as the image data in a tRNS chunk, so this is what libpng expects for this data.
1464
1465The color used for the background value depends on the need_expand argument as
1466described below.
1467
1468Data will be decoded into the supplied row buffers packed into bytes
1469unless the library has been told to transform it into another format.
1470For example, 4 bit/pixel paletted or grayscale data will be returned
14712 pixels/byte with the leftmost pixel in the high-order bits of the
1472byte, unless png_set_packing() is called. 8-bit RGB data will be stored
1473in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
1474is called to insert filler bytes, either before or after each RGB triplet.
147516-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
1476byte of the color value first, unless png_set_scale_16() is called to
1477transform it to regular RGB RGB triplets, or png_set_filler() or
1478png_set_add alpha() is called to insert filler bytes, either before or
1479after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
1480be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
1481or png_set_scale_16().
1482
1483The following code transforms grayscale images of less than 8 to 8 bits,
1484changes paletted images to RGB, and adds a full alpha channel if there is
1485transparency information in a tRNS chunk. This is most useful on
1486grayscale images with bit depths of 2 or 4 or if there is a multiple-image
1487viewing application that wishes to treat all images in the same way.
1488
1489 if (color_type == PNG_COLOR_TYPE_PALETTE)
1490 png_set_palette_to_rgb(png_ptr);
1491
1492 if (png_get_valid(png_ptr, info_ptr,
1493 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
1494
1495 if (color_type == PNG_COLOR_TYPE_GRAY &&
1496 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
1497
1498The first two functions are actually aliases for png_set_expand(), added
1499in libpng version 1.0.4, with the function names expanded to improve code
1500readability. In some future version they may actually do different
1501things.
1502
1503As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
1504added. It expands the sample depth without changing tRNS to alpha.
1505
1506As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
1507png_set_expand(); however, the resultant channels have 16 bits rather than 8.
1508Use this when the output color or gray channels are made linear to avoid fairly
1509severe accuracy loss.
1510
1511 if (bit_depth < 16)
1512 png_set_expand_16(png_ptr);
1513
1514PNG can have files with 16 bits per channel. If you only can handle
15158 bits per channel, this will strip the pixels down to 8-bit.
1516
1517 if (bit_depth == 16)
1518#if PNG_LIBPNG_VER >= 10504
1519 png_set_scale_16(png_ptr);
1520#else
1521 png_set_strip_16(png_ptr);
1522#endif
1523
1524(The more accurate "png_set_scale_16()" API became available in libpng version
15251.5.4).
1526
1527If you need to process the alpha channel on the image separately from the image
1528data (for example if you convert it to a bitmap mask) it is possible to have
1529libpng strip the channel leaving just RGB or gray data:
1530
1531 if (color_type & PNG_COLOR_MASK_ALPHA)
1532 png_set_strip_alpha(png_ptr);
1533
1534If you strip the alpha channel you need to find some other way of dealing with
1535the information. If, instead, you want to convert the image to an opaque
1536version with no alpha channel use png_set_background; see below.
1537
1538As of libpng version 1.5.2, almost all useful expansions are supported, the
1539major ommissions are conversion of grayscale to indexed images (which can be
1540done trivially in the application) and conversion of indexed to grayscale (which
1541can be done by a trivial manipulation of the palette.)
1542
1543In the following table, the 01 means grayscale with depth<8, 31 means
1544indexed with depth<8, other numerals represent the color type, "T" means
1545the tRNS chunk is present, A means an alpha channel is present, and O
1546means tRNS or alpha is present but all pixels in the image are opaque.
1547
1548 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
1549 TO
1550 01 - [G] - - - - - - - - - - - - -
1551 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
1552 0 1 G + . . G G G G G G B B GB GB
1553 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
1554 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
1555 2 C P C C C + . . C - - CB CB B B
1556 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
1557 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
1558 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
1559 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
1560 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
1561 4A lA G A T T GA GT GT GA GT GT + BA G GBA
1562 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
1563 6A CA PA CA C C A T tT PA P P C CBA + BA
1564 6O CA PBA CA C C A tT T PA P P CBA C BA +
1565
1566Within the matrix,
1567 "+" identifies entries where 'from' and 'to' are the same.
1568 "-" means the transformation is not supported.
1569 "." means nothing is necessary (a tRNS chunk can just be ignored).
1570 "t" means the transformation is obtained by png_set_tRNS.
1571 "A" means the transformation is obtained by png_set_add_alpha().
1572 "X" means the transformation is obtained by png_set_expand().
1573 "1" means the transformation is obtained by
1574 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() if there
1575 is no transparency in the original or the final format).
1576 "C" means the transformation is obtained by png_set_gray_to_rgb().
1577 "G" means the transformation is obtained by png_set_rgb_to_gray().
1578 "P" means the transformation is obtained by
1579 png_set_expand_palette_to_rgb().
1580 "p" means the transformation is obtained by png_set_packing().
1581 "Q" means the transformation is obtained by png_set_quantize().
1582 "T" means the transformation is obtained by png_set_tRNS_to_alpha().
1583 "B" means the transformation is obtained by png_set_background(), or
1584 png_strip_alpha().
1585
1586When an entry has multiple transforms listed all are required to cause the
1587right overall transformation. When two transforms are separated by a comma
1588either will do the job. When transforms are enclosed in [] the transform should
1589do the job but this is currently unimplemented - a different format will result
1590if the suggested transformations are used.
1591
1592In PNG files, the alpha channel in an image
1593is the level of opacity. If you need the alpha channel in an image to
1594be the level of transparency instead of opacity, you can invert the
1595alpha channel (or the tRNS chunk data) after it's read, so that 0 is
1596fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
1597images) is fully transparent, with
1598
1599 png_set_invert_alpha(png_ptr);
1600
1601PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
1602they can, resulting in, for example, 8 pixels per byte for 1 bit
1603files. This code expands to 1 pixel per byte without changing the
1604values of the pixels:
1605
1606 if (bit_depth < 8)
1607 png_set_packing(png_ptr);
1608
1609PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
1610stored in a PNG image have been "scaled" or "shifted" up to the next
1611higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
1612to 8 bits/sample in the range [0, 255]). However, it is also possible
1613to convert the PNG pixel data back to the original bit depth of the
1614image. This call reduces the pixels back down to the original bit depth:
1615
1616 png_color_8p sig_bit;
1617
1618 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
1619 png_set_shift(png_ptr, sig_bit);
1620
1621PNG files store 3-color pixels in red, green, blue order. This code
1622changes the storage of the pixels to blue, green, red:
1623
1624 if (color_type == PNG_COLOR_TYPE_RGB ||
1625 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1626 png_set_bgr(png_ptr);
1627
1628PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
1629into 4 or 8 bytes for windowing systems that need them in this format:
1630
1631 if (color_type == PNG_COLOR_TYPE_RGB)
1632 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
1633
1634where "filler" is the 8 or 16-bit number to fill with, and the location is
1635either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
1636you want the filler before the RGB or after. This transformation
1637does not affect images that already have full alpha channels. To add an
1638opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
1639will generate RGBA pixels.
1640
1641Note that png_set_filler() does not change the color type. If you want
1642to do that, you can add a true alpha channel with
1643
1644 if (color_type == PNG_COLOR_TYPE_RGB ||
1645 color_type == PNG_COLOR_TYPE_GRAY)
1646 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
1647
1648where "filler" contains the alpha value to assign to each pixel.
1649This function was added in libpng-1.2.7.
1650
1651If you are reading an image with an alpha channel, and you need the
1652data as ARGB instead of the normal PNG format RGBA:
1653
1654 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1655 png_set_swap_alpha(png_ptr);
1656
1657For some uses, you may want a grayscale image to be represented as
1658RGB. This code will do that conversion:
1659
1660 if (color_type == PNG_COLOR_TYPE_GRAY ||
1661 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1662 png_set_gray_to_rgb(png_ptr);
1663
1664Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
1665with alpha.
1666
1667 if (color_type == PNG_COLOR_TYPE_RGB ||
1668 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
1669 png_set_rgb_to_gray(png_ptr, error_action, double red_weight,
1670 double green_weight);
1671
1672 error_action = 1: silently do the conversion
1673
1674 error_action = 2: issue a warning if the original
1675 image has any pixel where
1676 red != green or red != blue
1677
1678 error_action = 3: issue an error and abort the
1679 conversion if the original
1680 image has any pixel where
1681 red != green or red != blue
1682
1683 red_weight: weight of red component
1684
1685 green_weight: weight of green component
1686 If either weight is negative, default
1687 weights are used.
1688
1689In the corresponding fixed point API the red_weight and green_weight values are
1690simply scaled by 100,000:
1691
1692 png_set_rgb_to_gray(png_ptr, error_action, png_fixed_point red_weight,
1693 png_fixed_point green_weight);
1694
1695If you have set error_action = 1 or 2, you can
1696later check whether the image really was gray, after processing
1697the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
1698It will return a png_byte that is zero if the image was gray or
16991 if there were any non-gray pixels. Background and sBIT data
1700will be silently converted to grayscale, using the green channel
1701data for sBIT, regardless of the error_action setting.
1702
1703The default values come from the PNG file cHRM chunk if present; otherwise, the
1704defaults correspond to the ITU-R recommendation 709, and also the sRGB color
1705space, as recommended in the Charles Poynton's Colour FAQ,
1706<http://www.poynton.com/>, in section 9:
1707
1708 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
1709
1710 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
1711
1712Previous versions of this document, 1998 through 2002, recommended a slightly
1713different formula:
1714
1715 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
1716
1717Libpng uses an integer approximation:
1718
1719 Y = (6968 * R + 23434 * G + 2366 * B)/32768
1720
1721The calculation is done in a linear colorspace, if the image gamma
1722can be determined.
1723
1724The png_set_background() function has been described already; it tells libpng to
1725composite images with alpha or simple transparency against the supplied
1726background color. For compatibility with versions of libpng earlier than
1727libpng-1.5.4 it is recommended that you call the function after reading the file
1728header, even if you don't want to use the color in a bKGD chunk, if one exists.
1729
1730If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
1731you may use this color, or supply another color more suitable for
1732the current display (e.g., the background color from a web page). You
1733need to tell libpng how the color is represented, both the format of the
1734component values in the color (the number of bits) and the gamma encoding of the
1735color. The function takes two arguments, background_gamma_mode and need_expand
1736to convey this information, however only two combinations are likely to be
1737useful:
1738
1739 png_color_16 my_background;
1740 png_color_16p image_background;
1741
1742 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
1743 png_set_background(png_ptr, image_background,
1744 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
1745 else
1746 png_set_background(png_ptr, &my_background,
1747 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
1748
1749The second call was described above - my_background is in the format of the
1750final, display, output produced by libpng. Because you now know the format of
1751the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
1752output and to retain palette images (the palette colors will be modified
1753appropriately and the tRNS chunk removed.) However, if you are doing this,
1754take great care not to ask for transformations without checking first that
1755they apply!
1756
1757In the first call the background color has the original bit depth and color type
1758of the PNG file. So, for palette images the color is supplied as a palette
1759index and for low bit greyscale images the color is a reduced bit value in
1760image_background->gray.
1761
1762If you didn't call png_set_gamma() before reading the file header, for example
1763if you need your code to remain compatible with older versions of libpng prior
1764to libpng-1.5.4, this is the place to call it.
1765
1766Do not call it if you called png_set_alpha_mode(); doing so will damage the
1767settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
1768supported then you can certainly do png_set_gamma() before reading the PNG
1769header.)
1770
1771This API unconditionally sets the screen and file gamma values, so it will
1772override the value in the PNG file unless it is called before the PNG file
1773reading starts. For this reason you must always call it with the PNG file
1774value when you call it in this position:
1775
1776 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
1777 png_set_gamma(png_ptr, screen_gamma, file_gamma);
1778
1779 else
1780 png_set_gamma(png_ptr, screen_gamma, 0.45455);
1781
1782If you need to reduce an RGB file to a paletted file, or if a paletted
1783file has more entries then will fit on your screen, png_set_quantize()
1784will do that. Note that this is a simple match quantization that merely
1785finds the closest color available. This should work fairly well with
1786optimized palettes, but fairly badly with linear color cubes. If you
1787pass a palette that is larger than maximum_colors, the file will
1788reduce the number of colors in the palette so it will fit into
1789maximum_colors. If there is a histogram, libpng will use it to make
1790more intelligent choices when reducing the palette. If there is no
1791histogram, it may not do as good a job.
1792
1793 if (color_type & PNG_COLOR_MASK_COLOR)
1794 {
1795 if (png_get_valid(png_ptr, info_ptr,
1796 PNG_INFO_PLTE))
1797 {
1798 png_uint_16p histogram = NULL;
1799
1800 png_get_hIST(png_ptr, info_ptr,
1801 &histogram);
1802 png_set_quantize(png_ptr, palette, num_palette,
1803 max_screen_colors, histogram, 1);
1804 }
1805
1806 else
1807 {
1808 png_color std_color_cube[MAX_SCREEN_COLORS] =
1809 { ... colors ... };
1810
1811 png_set_quantize(png_ptr, std_color_cube,
1812 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
1813 NULL,0);
1814 }
1815 }
1816
1817PNG files describe monochrome as black being zero and white being one.
1818The following code will reverse this (make black be one and white be
1819zero):
1820
1821 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
1822 png_set_invert_mono(png_ptr);
1823
1824This function can also be used to invert grayscale and gray-alpha images:
1825
1826 if (color_type == PNG_COLOR_TYPE_GRAY ||
1827 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
1828 png_set_invert_mono(png_ptr);
1829
1830PNG files store 16-bit pixels in network byte order (big-endian,
1831ie. most significant bits first). This code changes the storage to the
1832other way (little-endian, i.e. least significant bits first, the
1833way PCs store them):
1834
1835 if (bit_depth == 16)
1836 png_set_swap(png_ptr);
1837
1838If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
1839need to change the order the pixels are packed into bytes, you can use:
1840
1841 if (bit_depth < 8)
1842 png_set_packswap(png_ptr);
1843
1844Finally, you can write your own transformation function if none of
1845the existing ones meets your needs. This is done by setting a callback
1846with
1847
1848 png_set_read_user_transform_fn(png_ptr,
1849 read_transform_fn);
1850
1851You must supply the function
1852
1853 void read_transform_fn(png_structp png_ptr, png_row_infop
1854 row_info, png_bytep data)
1855
1856See pngtest.c for a working example. Your function will be called
1857after all of the other transformations have been processed. Take care with
1858interlaced images if you do the interlace yourself - the width of the row is the
1859width in 'row_info', not the overall image width.
1860
1861If supported, libpng provides two information routines that you can use to find
1862where you are in processing the image:
1863
1864 png_get_current_pass_number(png_structp png_ptr);
1865 png_get_current_row_number(png_structp png_ptr);
1866
1867Don't try using these outside a transform callback - firstly they are only
1868supported if user transforms are supported, secondly they may well return
1869unexpected results unless the row is actually being processed at the moment they
1870are called.
1871
1872With interlaced
1873images the value returned is the row in the input sub-image image. Use
1874PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
1875find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
1876
1877The discussion of interlace handling above contains more information on how to
1878use these values.
1879
1880You can also set up a pointer to a user structure for use by your
1881callback function, and you can inform libpng that your transform
1882function will change the number of channels or bit depth with the
1883function
1884
1885 png_set_user_transform_info(png_ptr, user_ptr,
1886 user_depth, user_channels);
1887
1888The user's application, not libpng, is responsible for allocating and
1889freeing any memory required for the user structure.
1890
1891You can retrieve the pointer via the function
1892png_get_user_transform_ptr(). For example:
1893
1894 voidp read_user_transform_ptr =
1895 png_get_user_transform_ptr(png_ptr);
1896
1897The last thing to handle is interlacing; this is covered in detail below,
1898but you must call the function here if you want libpng to handle expansion
1899of the interlaced image.
1900
1901 number_of_passes = png_set_interlace_handling(png_ptr);
1902
1903After setting the transformations, libpng can update your png_info
1904structure to reflect any transformations you've requested with this
1905call.
1906
1907 png_read_update_info(png_ptr, info_ptr);
1908
1909This is most useful to update the info structure's rowbytes
1910field so you can use it to allocate your image memory. This function
1911will also update your palette with the correct screen_gamma and
1912background if these have been given with the calls above. You may
1913only call png_read_update_info() once with a particular info_ptr.
1914
1915After you call png_read_update_info(), you can allocate any
1916memory you need to hold the image. The row data is simply
1917raw byte data for all forms of images. As the actual allocation
1918varies among applications, no example will be given. If you
1919are allocating one large chunk, you will need to build an
1920array of pointers to each row, as it will be needed for some
1921of the functions below.
1922
1923Remember: Before you call png_read_update_info(), the png_get_*()
1924functions return the values corresponding to the original PNG image.
1925After you call png_read_update_info the values refer to the image
1926that libpng will output. Consequently you must call all the png_set_
1927functions before you call png_read_update_info(). This is particularly
1928important for png_set_interlace_handling() - if you are going to call
1929png_read_update_info() you must call png_set_interlace_handling() before
1930it unless you want to receive interlaced output.
1931
1932Reading image data
1933
1934After you've allocated memory, you can read the image data.
1935The simplest way to do this is in one function call. If you are
1936allocating enough memory to hold the whole image, you can just
1937call png_read_image() and libpng will read in all the image data
1938and put it in the memory area supplied. You will need to pass in
1939an array of pointers to each row.
1940
1941This function automatically handles interlacing, so you don't
1942need to call png_set_interlace_handling() (unless you call
1943png_read_update_info()) or call this function multiple times, or any
1944of that other stuff necessary with png_read_rows().
1945
1946 png_read_image(png_ptr, row_pointers);
1947
1948where row_pointers is:
1949
1950 png_bytep row_pointers[height];
1951
1952You can point to void or char or whatever you use for pixels.
1953
1954If you don't want to read in the whole image at once, you can
1955use png_read_rows() instead. If there is no interlacing (check
1956interlace_type == PNG_INTERLACE_NONE), this is simple:
1957
1958 png_read_rows(png_ptr, row_pointers, NULL,
1959 number_of_rows);
1960
1961where row_pointers is the same as in the png_read_image() call.
1962
1963If you are doing this just one row at a time, you can do this with
1964a single row_pointer instead of an array of row_pointers:
1965
1966 png_bytep row_pointer = row;
1967 png_read_row(png_ptr, row_pointer, NULL);
1968
1969If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
1970get somewhat harder. The only current (PNG Specification version 1.2)
1971interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
1972a somewhat complicated 2D interlace scheme, known as Adam7, that
1973breaks down an image into seven smaller images of varying size, based
1974on an 8x8 grid. This number is defined (from libpng 1.5) as
1975PNG_INTERLACE_ADAM7_PASSES in png.h
1976
1977libpng can fill out those images or it can give them to you "as is".
1978It is almost always better to have libpng handle the interlacing for you.
1979If you want the images filled out, there are two ways to do that. The one
1980mentioned in the PNG specification is to expand each pixel to cover
1981those pixels that have not been read yet (the "rectangle" method).
1982This results in a blocky image for the first pass, which gradually
1983smooths out as more pixels are read. The other method is the "sparkle"
1984method, where pixels are drawn only in their final locations, with the
1985rest of the image remaining whatever colors they were initialized to
1986before the start of the read. The first method usually looks better,
1987but tends to be slower, as there are more pixels to put in the rows.
1988
1989If, as is likely, you want libpng to expand the images, call this before
1990calling png_start_read_image() or png_read_update_info():
1991
1992 if (interlace_type == PNG_INTERLACE_ADAM7)
1993 number_of_passes
1994 = png_set_interlace_handling(png_ptr);
1995
1996This will return the number of passes needed. Currently, this is seven,
1997but may change if another interlace type is added. This function can be
1998called even if the file is not interlaced, where it will return one pass.
1999You then need to read the whole image 'number_of_passes' times. Each time
2000will distribute the pixels from the current pass to the correct place in
2001the output image, so you need to supply the same rows to png_read_rows in
2002each pass.
2003
2004If you are not going to display the image after each pass, but are
2005going to wait until the entire image is read in, use the sparkle
2006effect. This effect is faster and the end result of either method
2007is exactly the same. If you are planning on displaying the image
2008after each pass, the "rectangle" effect is generally considered the
2009better looking one.
2010
2011If you only want the "sparkle" effect, just call png_read_rows() as
2012normal, with the third parameter NULL. Make sure you make pass over
2013the image number_of_passes times, and you don't change the data in the
2014rows between calls. You can change the locations of the data, just
2015not the data. Each pass only writes the pixels appropriate for that
2016pass, and assumes the data from previous passes is still valid.
2017
2018 png_read_rows(png_ptr, row_pointers, NULL,
2019 number_of_rows);
2020
2021If you only want the first effect (the rectangles), do the same as
2022before except pass the row buffer in the third parameter, and leave
2023the second parameter NULL.
2024
2025 png_read_rows(png_ptr, NULL, row_pointers,
2026 number_of_rows);
2027
2028If you don't want libpng to handle the interlacing details, just call
2029png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
2030Each of the images is a valid image by itself, however you will almost
2031certainly need to distribute the pixels from each sub-image to the
2032correct place. This is where everything gets very tricky.
2033
2034If you want to retrieve the separate images you must pass the correct
2035number of rows to each successive call of png_read_rows(). The calculation
2036gets pretty complicated for small images, where some sub-images may
2037not even exist because either their width or height ends up zero.
2038libpng provides two macros to help you in 1.5 and later versions:
2039
2040 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
2041 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
2042
2043Respectively these tell you the width and height of the sub-image
2044corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
2045this can be confusing because the specification refers to the same passes
2046as 1 to 7! Be careful, you must check both the width and height before
2047calling png_read_rows() and not call it for that pass if either is zero.
2048
2049You can, of course, read each sub-image row by row. If you want to
2050produce optimal code to make a pixel-by-pixel transformation of an
2051interlaced image this is the best approach; read each row of each pass,
2052transform it, and write it out to a new interlaced image.
2053
2054If you want to de-interlace the image yourself libpng provides further
2055macros to help that tell you where to place the pixels in the output image.
2056Because the interlacing scheme is rectangular - sub-image pixels are always
2057arranged on a rectangular grid - all you need to know for each pass is the
2058starting column and row in the output image of the first pixel plus the
2059spacing between each pixel. As of libpng 1.5 there are four macros to
2060retrieve this information:
2061
2062 png_uint_32 x = PNG_PASS_START_COL(pass);
2063 png_uint_32 y = PNG_PASS_START_ROW(pass);
2064 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
2065 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
2066
2067These allow you to write the obvious loop:
2068
2069 png_uint_32 input_y = 0;
2070 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
2071
2072 while (output_y < output_image_height)
2073 {
2074 png_uint_32 input_x = 0;
2075 png_uint_32 output_x = PNG_PASS_START_COL(pass);
2076
2077 while (output_x < output_image_width)
2078 {
2079 image[output_y][output_x] =
2080 subimage[pass][input_y][input_x++];
2081
2082 output_x += xStep;
2083 }
2084
2085 ++input_y;
2086 output_y += yStep;
2087 }
2088
2089Notice that the steps between successive output rows and columns are
2090returned as shifts. This is possible because the pixels in the subimages
2091are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
2092image. In practice you may need to directly calculate the output coordinate
2093given an input coordinate. libpng provides two further macros for this
2094purpose:
2095
2096 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
2097 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
2098
2099Finally a pair of macros are provided to tell you if a particular image
2100row or column appears in a given pass:
2101
2102 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
2103 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
2104
2105Bear in mind that you will probably also need to check the width and height
2106of the pass in addition to the above to be sure the pass even exists!
2107
2108With any luck you are convinced by now that you don't want to do your own
2109interlace handling. In reality normally the only good reason for doing this
2110is if you are processing PNG files on a pixel-by-pixel basis and don't want
2111to load the whole file into memory when it is interlaced.
2112
2113libpng includes a test program, pngvalid, that illustrates reading and
2114writing of interlaced images. If you can't get interlacing to work in your
2115code and don't want to leave it to libpng (the recommended approach), see
2116how pngvalid.c does it.
2117
2118Finishing a sequential read
2119
2120After you are finished reading the image through the
2121low-level interface, you can finish reading the file. If you are
2122interested in comments or time, which may be stored either before or
2123after the image data, you should pass the separate png_info struct if
2124you want to keep the comments from before and after the image
2125separate.
2126
2127 png_infop end_info = png_create_info_struct(png_ptr);
2128
2129 if (!end_info)
2130 {
2131 png_destroy_read_struct(&png_ptr, &info_ptr,
2132 (png_infopp)NULL);
2133 return (ERROR);
2134 }
2135
2136 png_read_end(png_ptr, end_info);
2137
2138If you are not interested, you should still call png_read_end()
2139but you can pass NULL, avoiding the need to create an end_info structure.
2140
2141 png_read_end(png_ptr, (png_infop)NULL);
2142
2143If you don't call png_read_end(), then your file pointer will be
2144left pointing to the first chunk after the last IDAT, which is probably
2145not what you want if you expect to read something beyond the end of
2146the PNG datastream.
2147
2148When you are done, you can free all memory allocated by libpng like this:
2149
2150 png_destroy_read_struct(&png_ptr, &info_ptr,
2151 &end_info);
2152
2153or, if you didn't create an end_info structure,
2154
2155 png_destroy_read_struct(&png_ptr, &info_ptr,
2156 (png_infopp)NULL);
2157
2158It is also possible to individually free the info_ptr members that
2159point to libpng-allocated storage with the following function:
2160
2161 png_free_data(png_ptr, info_ptr, mask, seq)
2162
2163 mask - identifies data to be freed, a mask
2164 containing the bitwise OR of one or
2165 more of
2166 PNG_FREE_PLTE, PNG_FREE_TRNS,
2167 PNG_FREE_HIST, PNG_FREE_ICCP,
2168 PNG_FREE_PCAL, PNG_FREE_ROWS,
2169 PNG_FREE_SCAL, PNG_FREE_SPLT,
2170 PNG_FREE_TEXT, PNG_FREE_UNKN,
2171 or simply PNG_FREE_ALL
2172
2173 seq - sequence number of item to be freed
2174 (-1 for all items)
2175
2176This function may be safely called when the relevant storage has
2177already been freed, or has not yet been allocated, or was allocated
2178by the user and not by libpng, and will in those cases do nothing.
2179The "seq" parameter is ignored if only one item of the selected data
2180type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
2181are allowed for the data type identified in the mask, such as text or
2182sPLT, only the n'th item in the structure is freed, where n is "seq".
2183
2184The default behavior is only to free data that was allocated internally
2185by libpng. This can be changed, so that libpng will not free the data,
2186or so that it will free data that was allocated by the user with png_malloc()
2187or png_zalloc() and passed in via a png_set_*() function, with
2188
2189 png_data_freer(png_ptr, info_ptr, freer, mask)
2190
2191 freer - one of
2192 PNG_DESTROY_WILL_FREE_DATA
2193 PNG_SET_WILL_FREE_DATA
2194 PNG_USER_WILL_FREE_DATA
2195
2196 mask - which data elements are affected
2197 same choices as in png_free_data()
2198
2199This function only affects data that has already been allocated.
2200You can call this function after reading the PNG data but before calling
2201any png_set_*() functions, to control whether the user or the png_set_*()
2202function is responsible for freeing any existing data that might be present,
2203and again after the png_set_*() functions to control whether the user
2204or png_destroy_*() is supposed to free the data. When the user assumes
2205responsibility for libpng-allocated data, the application must use
2206png_free() to free it, and when the user transfers responsibility to libpng
2207for data that the user has allocated, the user must have used png_malloc()
2208or png_zalloc() to allocate it.
2209
2210If you allocated your row_pointers in a single block, as suggested above in
2211the description of the high level read interface, you must not transfer
2212responsibility for freeing it to the png_set_rows or png_read_destroy function,
2213because they would also try to free the individual row_pointers[i].
2214
2215If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
2216separately, do not transfer responsibility for freeing text_ptr to libpng,
2217because when libpng fills a png_text structure it combines these members with
2218the key member, and png_free_data() will free only text_ptr.key. Similarly,
2219if you transfer responsibility for free'ing text_ptr from libpng to your
2220application, your application must not separately free those members.
2221
2222The png_free_data() function will turn off the "valid" flag for anything
2223it frees. If you need to turn the flag off for a chunk that was freed by
2224your application instead of by libpng, you can use
2225
2226 png_set_invalid(png_ptr, info_ptr, mask);
2227
2228 mask - identifies the chunks to be made invalid,
2229 containing the bitwise OR of one or
2230 more of
2231 PNG_INFO_gAMA, PNG_INFO_sBIT,
2232 PNG_INFO_cHRM, PNG_INFO_PLTE,
2233 PNG_INFO_tRNS, PNG_INFO_bKGD,
2234 PNG_INFO_hIST, PNG_INFO_pHYs,
2235 PNG_INFO_oFFs, PNG_INFO_tIME,
2236 PNG_INFO_pCAL, PNG_INFO_sRGB,
2237 PNG_INFO_iCCP, PNG_INFO_sPLT,
2238 PNG_INFO_sCAL, PNG_INFO_IDAT
2239
2240For a more compact example of reading a PNG image, see the file example.c.
2241
2242Reading PNG files progressively
2243
2244The progressive reader is slightly different then the non-progressive
2245reader. Instead of calling png_read_info(), png_read_rows(), and
2246png_read_end(), you make one call to png_process_data(), which calls
2247callbacks when it has the info, a row, or the end of the image. You
2248set up these callbacks with png_set_progressive_read_fn(). You don't
2249have to worry about the input/output functions of libpng, as you are
2250giving the library the data directly in png_process_data(). I will
2251assume that you have read the section on reading PNG files above,
2252so I will only highlight the differences (although I will show
2253all of the code).
2254
2255png_structp png_ptr;
2256png_infop info_ptr;
2257
2258 /* An example code fragment of how you would
2259 initialize the progressive reader in your
2260 application. */
2261 int
2262 initialize_png_reader()
2263 {
2264 png_ptr = png_create_read_struct
2265 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2266 user_error_fn, user_warning_fn);
2267
2268 if (!png_ptr)
2269 return (ERROR);
2270
2271 info_ptr = png_create_info_struct(png_ptr);
2272
2273 if (!info_ptr)
2274 {
2275 png_destroy_read_struct(&png_ptr,
2276 (png_infopp)NULL, (png_infopp)NULL);
2277 return (ERROR);
2278 }
2279
2280 if (setjmp(png_jmpbuf(png_ptr)))
2281 {
2282 png_destroy_read_struct(&png_ptr, &info_ptr,
2283 (png_infopp)NULL);
2284 return (ERROR);
2285 }
2286
2287 /* This one's new. You can provide functions
2288 to be called when the header info is valid,
2289 when each row is completed, and when the image
2290 is finished. If you aren't using all functions,
2291 you can specify NULL parameters. Even when all
2292 three functions are NULL, you need to call
2293 png_set_progressive_read_fn(). You can use
2294 any struct as the user_ptr (cast to a void pointer
2295 for the function call), and retrieve the pointer
2296 from inside the callbacks using the function
2297
2298 png_get_progressive_ptr(png_ptr);
2299
2300 which will return a void pointer, which you have
2301 to cast appropriately.
2302 */
2303 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
2304 info_callback, row_callback, end_callback);
2305
2306 return 0;
2307 }
2308
2309 /* A code fragment that you call as you receive blocks
2310 of data */
2311 int
2312 process_data(png_bytep buffer, png_uint_32 length)
2313 {
2314 if (setjmp(png_jmpbuf(png_ptr)))
2315 {
2316 png_destroy_read_struct(&png_ptr, &info_ptr,
2317 (png_infopp)NULL);
2318 return (ERROR);
2319 }
2320
2321 /* This one's new also. Simply give it a chunk
2322 of data from the file stream (in order, of
2323 course). On machines with segmented memory
2324 models machines, don't give it any more than
2325 64K. The library seems to run fine with sizes
2326 of 4K. Although you can give it much less if
2327 necessary (I assume you can give it chunks of
2328 1 byte, I haven't tried less then 256 bytes
2329 yet). When this function returns, you may
2330 want to display any rows that were generated
2331 in the row callback if you don't already do
2332 so there.
2333 */
2334 png_process_data(png_ptr, info_ptr, buffer, length);
2335
2336 /* At this point you can call png_process_data_skip if
2337 you want to handle data the library will skip yourself;
2338 it simply returns the number of bytes to skip (and stops
2339 libpng skipping that number of bytes on the next
2340 png_process_data call).
2341 return 0;
2342 }
2343
2344 /* This function is called (as set by
2345 png_set_progressive_read_fn() above) when enough data
2346 has been supplied so all of the header has been
2347 read.
2348 */
2349 void
2350 info_callback(png_structp png_ptr, png_infop info)
2351 {
2352 /* Do any setup here, including setting any of
2353 the transformations mentioned in the Reading
2354 PNG files section. For now, you _must_ call
2355 either png_start_read_image() or
2356 png_read_update_info() after all the
2357 transformations are set (even if you don't set
2358 any). You may start getting rows before
2359 png_process_data() returns, so this is your
2360 last chance to prepare for that.
2361
2362 This is where you turn on interlace handling,
2363 assuming you don't want to do it yourself.
2364
2365 If you need to you can stop the processing of
2366 your original input data at this point by calling
2367 png_process_data_pause. This returns the number
2368 of unprocessed bytes from the last png_process_data
2369 call - it is up to you to ensure that the next call
2370 sees these bytes again. If you don't want to bother
2371 with this you can get libpng to cache the unread
2372 bytes by setting the 'save' parameter (see png.h) but
2373 then libpng will have to copy the data internally.
2374 */
2375 }
2376
2377 /* This function is called when each row of image
2378 data is complete */
2379 void
2380 row_callback(png_structp png_ptr, png_bytep new_row,
2381 png_uint_32 row_num, int pass)
2382 {
2383 /* If the image is interlaced, and you turned
2384 on the interlace handler, this function will
2385 be called for every row in every pass. Some
2386 of these rows will not be changed from the
2387 previous pass. When the row is not changed,
2388 the new_row variable will be NULL. The rows
2389 and passes are called in order, so you don't
2390 really need the row_num and pass, but I'm
2391 supplying them because it may make your life
2392 easier.
2393
2394 If you did not turn on interlace handling then
2395 the callback is called for each row of each
2396 sub-image when the image is interlaced. In this
2397 case 'row_num' is the row in the sub-image, not
2398 the row in the output image as it is in all other
2399 cases.
2400
2401 For the non-NULL rows of interlaced images when
2402 you have switched on libpng interlace handling,
2403 you must call png_progressive_combine_row()
2404 passing in the row and the old row. You can
2405 call this function for NULL rows (it will just
2406 return) and for non-interlaced images (it just
2407 does the memcpy for you) if it will make the
2408 code easier. Thus, you can just do this for
2409 all cases if you switch on interlace handling;
2410 */
2411
2412 png_progressive_combine_row(png_ptr, old_row,
2413 new_row);
2414
2415 /* where old_row is what was displayed for
2416 previously for the row. Note that the first
2417 pass (pass == 0, really) will completely cover
2418 the old row, so the rows do not have to be
2419 initialized. After the first pass (and only
2420 for interlaced images), you will have to pass
2421 the current row, and the function will combine
2422 the old row and the new row.
2423
2424 You can also call png_process_data_pause in this
2425 callback - see above.
2426 */
2427 }
2428
2429 void
2430 end_callback(png_structp png_ptr, png_infop info)
2431 {
2432 /* This function is called after the whole image
2433 has been read, including any chunks after the
2434 image (up to and including the IEND). You
2435 will usually have the same info chunk as you
2436 had in the header, although some data may have
2437 been added to the comments and time fields.
2438
2439 Most people won't do much here, perhaps setting
2440 a flag that marks the image as finished.
2441 */
2442 }
2443
2444
2445
2446IV. Writing
2447
2448Much of this is very similar to reading. However, everything of
2449importance is repeated here, so you won't have to constantly look
2450back up in the reading section to understand writing.
2451
2452Setup
2453
2454You will want to do the I/O initialization before you get into libpng,
2455so if it doesn't work, you don't have anything to undo. If you are not
2456using the standard I/O functions, you will need to replace them with
2457custom writing functions. See the discussion under Customizing libpng.
2458
2459 FILE *fp = fopen(file_name, "wb");
2460
2461 if (!fp)
2462 return (ERROR);
2463
2464Next, png_struct and png_info need to be allocated and initialized.
2465As these can be both relatively large, you may not want to store these
2466on the stack, unless you have stack space to spare. Of course, you
2467will want to check if they return NULL. If you are also reading,
2468you won't want to name your read structure and your write structure
2469both "png_ptr"; you can call them anything you like, such as
2470"read_ptr" and "write_ptr". Look at pngtest.c, for example.
2471
2472 png_structp png_ptr = png_create_write_struct
2473 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2474 user_error_fn, user_warning_fn);
2475
2476 if (!png_ptr)
2477 return (ERROR);
2478
2479 png_infop info_ptr = png_create_info_struct(png_ptr);
2480 if (!info_ptr)
2481 {
2482 png_destroy_write_struct(&png_ptr,
2483 (png_infopp)NULL);
2484 return (ERROR);
2485 }
2486
2487If you want to use your own memory allocation routines,
2488define PNG_USER_MEM_SUPPORTED and use
2489png_create_write_struct_2() instead of png_create_write_struct():
2490
2491 png_structp png_ptr = png_create_write_struct_2
2492 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
2493 user_error_fn, user_warning_fn, (png_voidp)
2494 user_mem_ptr, user_malloc_fn, user_free_fn);
2495
2496After you have these structures, you will need to set up the
2497error handling. When libpng encounters an error, it expects to
2498longjmp() back to your routine. Therefore, you will need to call
2499setjmp() and pass the png_jmpbuf(png_ptr). If you
2500write the file from different routines, you will need to update
2501the png_jmpbuf(png_ptr) every time you enter a new routine that will
2502call a png_*() function. See your documentation of setjmp/longjmp
2503for your compiler for more information on setjmp/longjmp. See
2504the discussion on libpng error handling in the Customizing Libpng
2505section below for more information on the libpng error handling.
2506
2507 if (setjmp(png_jmpbuf(png_ptr)))
2508 {
2509 png_destroy_write_struct(&png_ptr, &info_ptr);
2510 fclose(fp);
2511 return (ERROR);
2512 }
2513 ...
2514 return;
2515
2516If you would rather avoid the complexity of setjmp/longjmp issues,
2517you can compile libpng with PNG_NO_SETJMP, in which case
2518errors will result in a call to PNG_ABORT() which defaults to abort().
2519
2520You can #define PNG_ABORT() to a function that does something
2521more useful than abort(), as long as your function does not
2522return.
2523
2524Now you need to set up the output code. The default for libpng is to
2525use the C function fwrite(). If you use this, you will need to pass a
2526valid FILE * in the function png_init_io(). Be sure that the file is
2527opened in binary mode. Again, if you wish to handle writing data in
2528another way, see the discussion on libpng I/O handling in the Customizing
2529Libpng section below.
2530
2531 png_init_io(png_ptr, fp);
2532
2533If you are embedding your PNG into a datastream such as MNG, and don't
2534want libpng to write the 8-byte signature, or if you have already
2535written the signature in your application, use
2536
2537 png_set_sig_bytes(png_ptr, 8);
2538
2539to inform libpng that it should not write a signature.
2540
2541Write callbacks
2542
2543At this point, you can set up a callback function that will be
2544called after each row has been written, which you can use to control
2545a progress meter or the like. It's demonstrated in pngtest.c.
2546You must supply a function
2547
2548 void write_row_callback(png_structp png_ptr, png_uint_32 row,
2549 int pass);
2550 {
2551 /* put your code here */
2552 }
2553
2554(You can give it another name that you like instead of "write_row_callback")
2555
2556To inform libpng about your function, use
2557
2558 png_set_write_status_fn(png_ptr, write_row_callback);
2559
2560When this function is called the row has already been completely processed and
2561it has also been written out. The 'row' and 'pass' refer to the next row to be
2562handled. For the
2563non-interlaced case the row that was just handled is simply one less than the
2564passed in row number, and pass will always be 0. For the interlaced case the
2565same applies unless the row value is 0, in which case the row just handled was
2566the last one from one of the preceding passes. Because interlacing may skip a
2567pass you cannot be sure that the preceding pass is just 'pass-1', if you really
2568need to know what the last pass is record (row,pass) from the callback and use
2569the last recorded value each time.
2570
2571As with the user transform you can find the output row using the
2572PNG_ROW_FROM_PASS_ROW macro.
2573
2574You now have the option of modifying how the compression library will
2575run. The following functions are mainly for testing, but may be useful
2576in some cases, like if you need to write PNG files extremely fast and
2577are willing to give up some compression, or if you want to get the
2578maximum possible compression at the expense of slower writing. If you
2579have no special needs in this area, let the library do what it wants by
2580not calling this function at all, as it has been tuned to deliver a good
2581speed/compression ratio. The second parameter to png_set_filter() is
2582the filter method, for which the only valid values are 0 (as of the
2583July 1999 PNG specification, version 1.2) or 64 (if you are writing
2584a PNG datastream that is to be embedded in a MNG datastream). The third
2585parameter is a flag that indicates which filter type(s) are to be tested
2586for each scanline. See the PNG specification for details on the specific
2587filter types.
2588
2589
2590 /* turn on or off filtering, and/or choose
2591 specific filters. You can use either a single
2592 PNG_FILTER_VALUE_NAME or the bitwise OR of one
2593 or more PNG_FILTER_NAME masks.
2594 */
2595 png_set_filter(png_ptr, 0,
2596 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
2597 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
2598 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
2599 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
2600 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
2601 PNG_ALL_FILTERS);
2602
2603If an application wants to start and stop using particular filters during
2604compression, it should start out with all of the filters (to ensure that
2605the previous row of pixels will be stored in case it's needed later),
2606and then add and remove them after the start of compression.
2607
2608If you are writing a PNG datastream that is to be embedded in a MNG
2609datastream, the second parameter can be either 0 or 64.
2610
2611The png_set_compression_*() functions interface to the zlib compression
2612library, and should mostly be ignored unless you really know what you are
2613doing. The only generally useful call is png_set_compression_level()
2614which changes how much time zlib spends on trying to compress the image
2615data. See the Compression Library (zlib.h and algorithm.txt, distributed
2616with zlib) for details on the compression levels.
2617
2618 #include zlib.h
2619
2620 /* Set the zlib compression level */
2621 png_set_compression_level(png_ptr,
2622 Z_BEST_COMPRESSION);
2623
2624 /* Set other zlib parameters for compressing IDAT */
2625 png_set_compression_mem_level(png_ptr, 8);
2626 png_set_compression_strategy(png_ptr,
2627 Z_DEFAULT_STRATEGY);
2628 png_set_compression_window_bits(png_ptr, 15);
2629 png_set_compression_method(png_ptr, 8);
2630 png_set_compression_buffer_size(png_ptr, 8192)
2631
2632 /* Set zlib parameters for text compression
2633 * If you don't call these, the parameters
2634 * fall back on those defined for IDAT chunks
2635 */
2636 png_set_text_compression_mem_level(png_ptr, 8);
2637 png_set_text_compression_strategy(png_ptr,
2638 Z_DEFAULT_STRATEGY);
2639 png_set_text_compression_window_bits(png_ptr, 15);
2640 png_set_text_compression_method(png_ptr, 8);
2641
2642Setting the contents of info for output
2643
2644You now need to fill in the png_info structure with all the data you
2645wish to write before the actual image. Note that the only thing you
2646are allowed to write after the image is the text chunks and the time
2647chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
2648the latest PNG specification for more information on that. If you
2649wish to write them before the image, fill them in now, and flag that
2650data as being valid. If you want to wait until after the data, don't
2651fill them until png_write_end(). For all the fields in png_info and
2652their data types, see png.h. For explanations of what the fields
2653contain, see the PNG specification.
2654
2655Some of the more important parts of the png_info are:
2656
2657 png_set_IHDR(png_ptr, info_ptr, width, height,
2658 bit_depth, color_type, interlace_type,
2659 compression_type, filter_method)
2660
2661 width - holds the width of the image
2662 in pixels (up to 2^31).
2663
2664 height - holds the height of the image
2665 in pixels (up to 2^31).
2666
2667 bit_depth - holds the bit depth of one of the
2668 image channels.
2669 (valid values are 1, 2, 4, 8, 16
2670 and depend also on the
2671 color_type. See also significant
2672 bits (sBIT) below).
2673
2674 color_type - describes which color/alpha
2675 channels are present.
2676 PNG_COLOR_TYPE_GRAY
2677 (bit depths 1, 2, 4, 8, 16)
2678 PNG_COLOR_TYPE_GRAY_ALPHA
2679 (bit depths 8, 16)
2680 PNG_COLOR_TYPE_PALETTE
2681 (bit depths 1, 2, 4, 8)
2682 PNG_COLOR_TYPE_RGB
2683 (bit_depths 8, 16)
2684 PNG_COLOR_TYPE_RGB_ALPHA
2685 (bit_depths 8, 16)
2686
2687 PNG_COLOR_MASK_PALETTE
2688 PNG_COLOR_MASK_COLOR
2689 PNG_COLOR_MASK_ALPHA
2690
2691 interlace_type - PNG_INTERLACE_NONE or
2692 PNG_INTERLACE_ADAM7
2693
2694 compression_type - (must be
2695 PNG_COMPRESSION_TYPE_DEFAULT)
2696
2697 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
2698 or, if you are writing a PNG to
2699 be embedded in a MNG datastream,
2700 can also be
2701 PNG_INTRAPIXEL_DIFFERENCING)
2702
2703If you call png_set_IHDR(), the call must appear before any of the
2704other png_set_*() functions, because they might require access to some of
2705the IHDR settings. The remaining png_set_*() functions can be called
2706in any order.
2707
2708If you wish, you can reset the compression_type, interlace_type, or
2709filter_method later by calling png_set_IHDR() again; if you do this, the
2710width, height, bit_depth, and color_type must be the same in each call.
2711
2712 png_set_PLTE(png_ptr, info_ptr, palette,
2713 num_palette);
2714
2715 palette - the palette for the file
2716 (array of png_color)
2717 num_palette - number of entries in the palette
2718
2719 png_set_gAMA(png_ptr, info_ptr, file_gamma);
2720 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
2721
2722 file_gamma - the gamma at which the image was
2723 created (PNG_INFO_gAMA)
2724
2725 int_file_gamma - 100,000 times the gamma at which
2726 the image was created
2727
2728 png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y,
2729 green_x, green_y, blue_x, blue_y)
2730 png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
2731 green_Y, green_Z, blue_X, blue_Y, blue_Z)
2732 png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
2733 int_red_x, int_red_y, int_green_x, int_green_y,
2734 int_blue_x, int_blue_y)
2735 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
2736 int_red_Z, int_green_X, int_green_Y, int_green_Z,
2737 int_blue_X, int_blue_Y, int_blue_Z)
2738
2739 {white,red,green,blue}_{x,y}
2740 A color space encoding specified using the chromaticities
2741 of the end points and the white point.
2742
2743 {red,green,blue}_{X,Y,Z}
2744 A color space encoding specified using the encoding end
2745 points - the CIE tristimulus specification of the intended
2746 color of the red, green and blue channels in the PNG RGB
2747 data. The white point is simply the sum of the three end
2748 points.
2749
2750 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
2751
2752 srgb_intent - the rendering intent
2753 (PNG_INFO_sRGB) The presence of
2754 the sRGB chunk means that the pixel
2755 data is in the sRGB color space.
2756 This chunk also implies specific
2757 values of gAMA and cHRM. Rendering
2758 intent is the CSS-1 property that
2759 has been defined by the International
2760 Color Consortium
2761 (http://www.color.org).
2762 It can be one of
2763 PNG_sRGB_INTENT_SATURATION,
2764 PNG_sRGB_INTENT_PERCEPTUAL,
2765 PNG_sRGB_INTENT_ABSOLUTE, or
2766 PNG_sRGB_INTENT_RELATIVE.
2767
2768
2769 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
2770 srgb_intent);
2771
2772 srgb_intent - the rendering intent
2773 (PNG_INFO_sRGB) The presence of the
2774 sRGB chunk means that the pixel
2775 data is in the sRGB color space.
2776 This function also causes gAMA and
2777 cHRM chunks with the specific values
2778 that are consistent with sRGB to be
2779 written.
2780
2781 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
2782 profile, proflen);
2783
2784 name - The profile name.
2785
2786 compression_type - The compression type; always
2787 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2788 You may give NULL to this argument to
2789 ignore it.
2790
2791 profile - International Color Consortium color
2792 profile data. May contain NULs.
2793
2794 proflen - length of profile data in bytes.
2795
2796 png_set_sBIT(png_ptr, info_ptr, sig_bit);
2797
2798 sig_bit - the number of significant bits for
2799 (PNG_INFO_sBIT) each of the gray, red,
2800 green, and blue channels, whichever are
2801 appropriate for the given color type
2802 (png_color_16)
2803
2804 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
2805 num_trans, trans_color);
2806
2807 trans_alpha - array of alpha (transparency)
2808 entries for palette (PNG_INFO_tRNS)
2809
2810 num_trans - number of transparent entries
2811 (PNG_INFO_tRNS)
2812
2813 trans_color - graylevel or color sample values
2814 (in order red, green, blue) of the
2815 single transparent color for
2816 non-paletted images (PNG_INFO_tRNS)
2817
2818 png_set_hIST(png_ptr, info_ptr, hist);
2819
2820 hist - histogram of palette (array of
2821 png_uint_16) (PNG_INFO_hIST)
2822
2823 png_set_tIME(png_ptr, info_ptr, mod_time);
2824
2825 mod_time - time image was last modified
2826 (PNG_VALID_tIME)
2827
2828 png_set_bKGD(png_ptr, info_ptr, background);
2829
2830 background - background color (of type
2831 png_color_16p) (PNG_VALID_bKGD)
2832
2833 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
2834
2835 text_ptr - array of png_text holding image
2836 comments
2837
2838 text_ptr[i].compression - type of compression used
2839 on "text" PNG_TEXT_COMPRESSION_NONE
2840 PNG_TEXT_COMPRESSION_zTXt
2841 PNG_ITXT_COMPRESSION_NONE
2842 PNG_ITXT_COMPRESSION_zTXt
2843 text_ptr[i].key - keyword for comment. Must contain
2844 1-79 characters.
2845 text_ptr[i].text - text comments for current
2846 keyword. Can be NULL or empty.
2847 text_ptr[i].text_length - length of text string,
2848 after decompression, 0 for iTXt
2849 text_ptr[i].itxt_length - length of itxt string,
2850 after decompression, 0 for tEXt/zTXt
2851 text_ptr[i].lang - language of comment (NULL or
2852 empty for unknown).
2853 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
2854 or empty for unknown).
2855
2856 Note that the itxt_length, lang, and lang_key
2857 members of the text_ptr structure only exist when the
2858 library is built with iTXt chunk support. Prior to
2859 libpng-1.4.0 the library was built by default without
2860 iTXt support. Also note that when iTXt is supported,
2861 they contain NULL pointers when the "compression"
2862 field contains PNG_TEXT_COMPRESSION_NONE or
2863 PNG_TEXT_COMPRESSION_zTXt.
2864
2865 num_text - number of comments
2866
2867 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
2868 num_spalettes);
2869
2870 palette_ptr - array of png_sPLT_struct structures
2871 to be added to the list of palettes
2872 in the info structure.
2873 num_spalettes - number of palette structures to be
2874 added.
2875
2876 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
2877 unit_type);
2878
2879 offset_x - positive offset from the left
2880 edge of the screen
2881
2882 offset_y - positive offset from the top
2883 edge of the screen
2884
2885 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2886
2887 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
2888 unit_type);
2889
2890 res_x - pixels/unit physical resolution
2891 in x direction
2892
2893 res_y - pixels/unit physical resolution
2894 in y direction
2895
2896 unit_type - PNG_RESOLUTION_UNKNOWN,
2897 PNG_RESOLUTION_METER
2898
2899 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
2900
2901 unit - physical scale units (an integer)
2902
2903 width - width of a pixel in physical scale units
2904
2905 height - height of a pixel in physical scale units
2906 (width and height are doubles)
2907
2908 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
2909
2910 unit - physical scale units (an integer)
2911
2912 width - width of a pixel in physical scale units
2913 expressed as a string
2914
2915 height - height of a pixel in physical scale units
2916 (width and height are strings like "2.54")
2917
2918 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
2919 num_unknowns)
2920
2921 unknowns - array of png_unknown_chunk
2922 structures holding unknown chunks
2923 unknowns[i].name - name of unknown chunk
2924 unknowns[i].data - data of unknown chunk
2925 unknowns[i].size - size of unknown chunk's data
2926 unknowns[i].location - position to write chunk in file
2927 0: do not write chunk
2928 PNG_HAVE_IHDR: before PLTE
2929 PNG_HAVE_PLTE: before IDAT
2930 PNG_AFTER_IDAT: after IDAT
2931
2932The "location" member is set automatically according to
2933what part of the output file has already been written.
2934You can change its value after calling png_set_unknown_chunks()
2935as demonstrated in pngtest.c. Within each of the "locations",
2936the chunks are sequenced according to their position in the
2937structure (that is, the value of "i", which is the order in which
2938the chunk was either read from the input file or defined with
2939png_set_unknown_chunks).
2940
2941A quick word about text and num_text. text is an array of png_text
2942structures. num_text is the number of valid structures in the array.
2943Each png_text structure holds a language code, a keyword, a text value,
2944and a compression type.
2945
2946The compression types have the same valid numbers as the compression
2947types of the image data. Currently, the only valid number is zero.
2948However, you can store text either compressed or uncompressed, unlike
2949images, which always have to be compressed. So if you don't want the
2950text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
2951Because tEXt and zTXt chunks don't have a language field, if you
2952specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
2953any language code or translated keyword will not be written out.
2954
2955Until text gets around a few hundred bytes, it is not worth compressing it.
2956After the text has been written out to the file, the compression type
2957is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
2958so that it isn't written out again at the end (in case you are calling
2959png_write_end() with the same struct).
2960
2961The keywords that are given in the PNG Specification are:
2962
2963 Title Short (one line) title or
2964 caption for image
2965
2966 Author Name of image's creator
2967
2968 Description Description of image (possibly long)
2969
2970 Copyright Copyright notice
2971
2972 Creation Time Time of original image creation
2973 (usually RFC 1123 format, see below)
2974
2975 Software Software used to create the image
2976
2977 Disclaimer Legal disclaimer
2978
2979 Warning Warning of nature of content
2980
2981 Source Device used to create the image
2982
2983 Comment Miscellaneous comment; conversion
2984 from other image format
2985
2986The keyword-text pairs work like this. Keywords should be short
2987simple descriptions of what the comment is about. Some typical
2988keywords are found in the PNG specification, as is some recommendations
2989on keywords. You can repeat keywords in a file. You can even write
2990some text before the image and some after. For example, you may want
2991to put a description of the image before the image, but leave the
2992disclaimer until after, so viewers working over modem connections
2993don't have to wait for the disclaimer to go over the modem before
2994they start seeing the image. Finally, keywords should be full
2995words, not abbreviations. Keywords and text are in the ISO 8859-1
2996(Latin-1) character set (a superset of regular ASCII) and can not
2997contain NUL characters, and should not contain control or other
2998unprintable characters. To make the comments widely readable, stick
2999with basic ASCII, and avoid machine specific character set extensions
3000like the IBM-PC character set. The keyword must be present, but
3001you can leave off the text string on non-compressed pairs.
3002Compressed pairs must have a text string, as only the text string
3003is compressed anyway, so the compression would be meaningless.
3004
3005PNG supports modification time via the png_time structure. Two
3006conversion routines are provided, png_convert_from_time_t() for
3007time_t and png_convert_from_struct_tm() for struct tm. The
3008time_t routine uses gmtime(). You don't have to use either of
3009these, but if you wish to fill in the png_time structure directly,
3010you should provide the time in universal time (GMT) if possible
3011instead of your local time. Note that the year number is the full
3012year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
3013that months start with 1.
3014
3015If you want to store the time of the original image creation, you should
3016use a plain tEXt chunk with the "Creation Time" keyword. This is
3017necessary because the "creation time" of a PNG image is somewhat vague,
3018depending on whether you mean the PNG file, the time the image was
3019created in a non-PNG format, a still photo from which the image was
3020scanned, or possibly the subject matter itself. In order to facilitate
3021machine-readable dates, it is recommended that the "Creation Time"
3022tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
3023although this isn't a requirement. Unlike the tIME chunk, the
3024"Creation Time" tEXt chunk is not expected to be automatically changed
3025by the software. To facilitate the use of RFC 1123 dates, a function
3026png_convert_to_rfc1123(png_timep) is provided to convert from PNG
3027time to an RFC 1123 format string.
3028
3029Writing unknown chunks
3030
3031You can use the png_set_unknown_chunks function to queue up chunks
3032for writing. You give it a chunk name, raw data, and a size; that's
3033all there is to it. The chunks will be written by the next following
3034png_write_info_before_PLTE, png_write_info, or png_write_end function.
3035Any chunks previously read into the info structure's unknown-chunk
3036list will also be written out in a sequence that satisfies the PNG
3037specification's ordering rules.
3038
3039The high-level write interface
3040
3041At this point there are two ways to proceed; through the high-level
3042write interface, or through a sequence of low-level write operations.
3043You can use the high-level interface if your image data is present
3044in the info structure. All defined output
3045transformations are permitted, enabled by the following masks.
3046
3047 PNG_TRANSFORM_IDENTITY No transformation
3048 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
3049 PNG_TRANSFORM_PACKSWAP Change order of packed
3050 pixels to LSB first
3051 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
3052 PNG_TRANSFORM_SHIFT Normalize pixels to the
3053 sBIT depth
3054 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
3055 to BGRA
3056 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
3057 to AG
3058 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
3059 to transparency
3060 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
3061 PNG_TRANSFORM_STRIP_FILLER Strip out filler
3062 bytes (deprecated).
3063 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
3064 filler bytes
3065 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
3066 filler bytes
3067
3068If you have valid image data in the info structure (you can use
3069png_set_rows() to put image data in the info structure), simply do this:
3070
3071 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
3072
3073where png_transforms is an integer containing the bitwise OR of some set of
3074transformation flags. This call is equivalent to png_write_info(),
3075followed the set of transformations indicated by the transform mask,
3076then png_write_image(), and finally png_write_end().
3077
3078(The final parameter of this call is not yet used. Someday it might point
3079to transformation parameters required by some future output transform.)
3080
3081You must use png_transforms and not call any png_set_transform() functions
3082when you use png_write_png().
3083
3084The low-level write interface
3085
3086If you are going the low-level route instead, you are now ready to
3087write all the file information up to the actual image data. You do
3088this with a call to png_write_info().
3089
3090 png_write_info(png_ptr, info_ptr);
3091
3092Note that there is one transformation you may need to do before
3093png_write_info(). In PNG files, the alpha channel in an image is the
3094level of opacity. If your data is supplied as a level of transparency,
3095you can invert the alpha channel before you write it, so that 0 is
3096fully transparent and 255 (in 8-bit or paletted images) or 65535
3097(in 16-bit images) is fully opaque, with
3098
3099 png_set_invert_alpha(png_ptr);
3100
3101This must appear before png_write_info() instead of later with the
3102other transformations because in the case of paletted images the tRNS
3103chunk data has to be inverted before the tRNS chunk is written. If
3104your image is not a paletted image, the tRNS data (which in such cases
3105represents a single color to be rendered as transparent) won't need to
3106be changed, and you can safely do this transformation after your
3107png_write_info() call.
3108
3109If you need to write a private chunk that you want to appear before
3110the PLTE chunk when PLTE is present, you can write the PNG info in
3111two steps, and insert code to write your own chunk between them:
3112
3113 png_write_info_before_PLTE(png_ptr, info_ptr);
3114 png_set_unknown_chunks(png_ptr, info_ptr, ...);
3115 png_write_info(png_ptr, info_ptr);
3116
3117After you've written the file information, you can set up the library
3118to handle any special transformations of the image data. The various
3119ways to transform the data will be described in the order that they
3120should occur. This is important, as some of these change the color
3121type and/or bit depth of the data, and some others only work on
3122certain color types and bit depths. Even though each transformation
3123checks to see if it has data that it can do something with, you should
3124make sure to only enable a transformation if it will be valid for the
3125data. For example, don't swap red and blue on grayscale data.
3126
3127PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
3128the library to strip input data that has 4 or 8 bytes per pixel down
3129to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
3130bytes per pixel).
3131
3132 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
3133
3134where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
3135PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
3136is stored XRGB or RGBX.
3137
3138PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
3139they can, resulting in, for example, 8 pixels per byte for 1 bit files.
3140If the data is supplied at 1 pixel per byte, use this code, which will
3141correctly pack the pixels into a single byte:
3142
3143 png_set_packing(png_ptr);
3144
3145PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
3146data is of another bit depth, you can write an sBIT chunk into the
3147file so that decoders can recover the original data if desired.
3148
3149 /* Set the true bit depth of the image data */
3150 if (color_type & PNG_COLOR_MASK_COLOR)
3151 {
3152 sig_bit.red = true_bit_depth;
3153 sig_bit.green = true_bit_depth;
3154 sig_bit.blue = true_bit_depth;
3155 }
3156
3157 else
3158 {
3159 sig_bit.gray = true_bit_depth;
3160 }
3161
3162 if (color_type & PNG_COLOR_MASK_ALPHA)
3163 {
3164 sig_bit.alpha = true_bit_depth;
3165 }
3166
3167 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
3168
3169If the data is stored in the row buffer in a bit depth other than
3170one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
3171this will scale the values to appear to be the correct bit depth as
3172is required by PNG.
3173
3174 png_set_shift(png_ptr, &sig_bit);
3175
3176PNG files store 16-bit pixels in network byte order (big-endian,
3177ie. most significant bits first). This code would be used if they are
3178supplied the other way (little-endian, i.e. least significant bits
3179first, the way PCs store them):
3180
3181 if (bit_depth > 8)
3182 png_set_swap(png_ptr);
3183
3184If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
3185need to change the order the pixels are packed into bytes, you can use:
3186
3187 if (bit_depth < 8)
3188 png_set_packswap(png_ptr);
3189
3190PNG files store 3 color pixels in red, green, blue order. This code
3191would be used if they are supplied as blue, green, red:
3192
3193 png_set_bgr(png_ptr);
3194
3195PNG files describe monochrome as black being zero and white being
3196one. This code would be used if the pixels are supplied with this reversed
3197(black being one and white being zero):
3198
3199 png_set_invert_mono(png_ptr);
3200
3201Finally, you can write your own transformation function if none of
3202the existing ones meets your needs. This is done by setting a callback
3203with
3204
3205 png_set_write_user_transform_fn(png_ptr,
3206 write_transform_fn);
3207
3208You must supply the function
3209
3210 void write_transform_fn(png_structp png_ptr, png_row_infop
3211 row_info, png_bytep data)
3212
3213See pngtest.c for a working example. Your function will be called
3214before any of the other transformations are processed. If supported
3215libpng also supplies an information routine that may be called from
3216your callback:
3217
3218 png_get_current_row_number(png_ptr);
3219 png_get_current_pass_number(png_ptr);
3220
3221This returns the current row passed to the transform. With interlaced
3222images the value returned is the row in the input sub-image image. Use
3223PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
3224find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
3225
3226The discussion of interlace handling above contains more information on how to
3227use these values.
3228
3229You can also set up a pointer to a user structure for use by your
3230callback function.
3231
3232 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
3233
3234The user_channels and user_depth parameters of this function are ignored
3235when writing; you can set them to zero as shown.
3236
3237You can retrieve the pointer via the function png_get_user_transform_ptr().
3238For example:
3239
3240 voidp write_user_transform_ptr =
3241 png_get_user_transform_ptr(png_ptr);
3242
3243It is possible to have libpng flush any pending output, either manually,
3244or automatically after a certain number of lines have been written. To
3245flush the output stream a single time call:
3246
3247 png_write_flush(png_ptr);
3248
3249and to have libpng flush the output stream periodically after a certain
3250number of scanlines have been written, call:
3251
3252 png_set_flush(png_ptr, nrows);
3253
3254Note that the distance between rows is from the last time png_write_flush()
3255was called, or the first row of the image if it has never been called.
3256So if you write 50 lines, and then png_set_flush 25, it will flush the
3257output on the next scanline, and every 25 lines thereafter, unless
3258png_write_flush() is called before 25 more lines have been written.
3259If nrows is too small (less than about 10 lines for a 640 pixel wide
3260RGB image) the image compression may decrease noticeably (although this
3261may be acceptable for real-time applications). Infrequent flushing will
3262only degrade the compression performance by a few percent over images
3263that do not use flushing.
3264
3265Writing the image data
3266
3267That's it for the transformations. Now you can write the image data.
3268The simplest way to do this is in one function call. If you have the
3269whole image in memory, you can just call png_write_image() and libpng
3270will write the image. You will need to pass in an array of pointers to
3271each row. This function automatically handles interlacing, so you don't
3272need to call png_set_interlace_handling() or call this function multiple
3273times, or any of that other stuff necessary with png_write_rows().
3274
3275 png_write_image(png_ptr, row_pointers);
3276
3277where row_pointers is:
3278
3279 png_byte *row_pointers[height];
3280
3281You can point to void or char or whatever you use for pixels.
3282
3283If you don't want to write the whole image at once, you can
3284use png_write_rows() instead. If the file is not interlaced,
3285this is simple:
3286
3287 png_write_rows(png_ptr, row_pointers,
3288 number_of_rows);
3289
3290row_pointers is the same as in the png_write_image() call.
3291
3292If you are just writing one row at a time, you can do this with
3293a single row_pointer instead of an array of row_pointers:
3294
3295 png_bytep row_pointer = row;
3296
3297 png_write_row(png_ptr, row_pointer);
3298
3299When the file is interlaced, things can get a good deal more complicated.
3300The only currently (as of the PNG Specification version 1.2, dated July
33011999) defined interlacing scheme for PNG files is the "Adam7" interlace
3302scheme, that breaks down an image into seven smaller images of varying
3303size. libpng will build these images for you, or you can do them
3304yourself. If you want to build them yourself, see the PNG specification
3305for details of which pixels to write when.
3306
3307If you don't want libpng to handle the interlacing details, just
3308use png_set_interlace_handling() and call png_write_rows() the
3309correct number of times to write all the sub-images
3310(png_set_interlace_handling() returns the number of sub-images.)
3311
3312If you want libpng to build the sub-images, call this before you start
3313writing any rows:
3314
3315 number_of_passes = png_set_interlace_handling(png_ptr);
3316
3317This will return the number of passes needed. Currently, this is seven,
3318but may change if another interlace type is added.
3319
3320Then write the complete image number_of_passes times.
3321
3322 png_write_rows(png_ptr, row_pointers, number_of_rows);
3323
3324Think carefully before you write an interlaced image. Typically code that
3325reads such images reads all the image data into memory, uncompressed, before
3326doing any processing. Only code that can display an image on the fly can
3327take advantage of the interlacing and even then the image has to be exactly
3328the correct size for the output device, because scaling an image requires
3329adjacent pixels and these are not available until all the passes have been
3330read.
3331
3332If you do write an interlaced image you will hardly ever need to handle
3333the interlacing yourself. Call png_set_interlace_handling() and use the
3334approach described above.
3335
3336The only time it is conceivable that you will really need to write an
3337interlaced image pass-by-pass is when you have read one pass by pass and
3338made some pixel-by-pixel transformation to it, as described in the read
3339code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
3340to determine the size of each sub-image in turn and simply write the rows
3341you obtained from the read code.
3342
3343Finishing a sequential write
3344
3345After you are finished writing the image, you should finish writing
3346the file. If you are interested in writing comments or time, you should
3347pass an appropriately filled png_info pointer. If you are not interested,
3348you can pass NULL.
3349
3350 png_write_end(png_ptr, info_ptr);
3351
3352When you are done, you can free all memory used by libpng like this:
3353
3354 png_destroy_write_struct(&png_ptr, &info_ptr);
3355
3356It is also possible to individually free the info_ptr members that
3357point to libpng-allocated storage with the following function:
3358
3359 png_free_data(png_ptr, info_ptr, mask, seq)
3360
3361 mask - identifies data to be freed, a mask
3362 containing the bitwise OR of one or
3363 more of
3364 PNG_FREE_PLTE, PNG_FREE_TRNS,
3365 PNG_FREE_HIST, PNG_FREE_ICCP,
3366 PNG_FREE_PCAL, PNG_FREE_ROWS,
3367 PNG_FREE_SCAL, PNG_FREE_SPLT,
3368 PNG_FREE_TEXT, PNG_FREE_UNKN,
3369 or simply PNG_FREE_ALL
3370
3371 seq - sequence number of item to be freed
3372 (-1 for all items)
3373
3374This function may be safely called when the relevant storage has
3375already been freed, or has not yet been allocated, or was allocated
3376by the user and not by libpng, and will in those cases do nothing.
3377The "seq" parameter is ignored if only one item of the selected data
3378type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3379are allowed for the data type identified in the mask, such as text or
3380sPLT, only the n'th item in the structure is freed, where n is "seq".
3381
3382If you allocated data such as a palette that you passed in to libpng
3383with png_set_*, you must not free it until just before the call to
3384png_destroy_write_struct().
3385
3386The default behavior is only to free data that was allocated internally
3387by libpng. This can be changed, so that libpng will not free the data,
3388or so that it will free data that was allocated by the user with png_malloc()
3389or png_zalloc() and passed in via a png_set_*() function, with
3390
3391 png_data_freer(png_ptr, info_ptr, freer, mask)
3392
3393 freer - one of
3394 PNG_DESTROY_WILL_FREE_DATA
3395 PNG_SET_WILL_FREE_DATA
3396 PNG_USER_WILL_FREE_DATA
3397
3398 mask - which data elements are affected
3399 same choices as in png_free_data()
3400
3401For example, to transfer responsibility for some data from a read structure
3402to a write structure, you could use
3403
3404 png_data_freer(read_ptr, read_info_ptr,
3405 PNG_USER_WILL_FREE_DATA,
3406 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3407
3408 png_data_freer(write_ptr, write_info_ptr,
3409 PNG_DESTROY_WILL_FREE_DATA,
3410 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
3411
3412thereby briefly reassigning responsibility for freeing to the user but
3413immediately afterwards reassigning it once more to the write_destroy
3414function. Having done this, it would then be safe to destroy the read
3415structure and continue to use the PLTE, tRNS, and hIST data in the write
3416structure.
3417
3418This function only affects data that has already been allocated.
3419You can call this function before calling after the png_set_*() functions
3420to control whether the user or png_destroy_*() is supposed to free the data.
3421When the user assumes responsibility for libpng-allocated data, the
3422application must use
3423png_free() to free it, and when the user transfers responsibility to libpng
3424for data that the user has allocated, the user must have used png_malloc()
3425or png_zalloc() to allocate it.
3426
3427If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3428separately, do not transfer responsibility for freeing text_ptr to libpng,
3429because when libpng fills a png_text structure it combines these members with
3430the key member, and png_free_data() will free only text_ptr.key. Similarly,
3431if you transfer responsibility for free'ing text_ptr from libpng to your
3432application, your application must not separately free those members.
3433For a more compact example of writing a PNG image, see the file example.c.
3434
3435V. Modifying/Customizing libpng:
3436
3437There are two issues here. The first is changing how libpng does
3438standard things like memory allocation, input/output, and error handling.
3439The second deals with more complicated things like adding new chunks,
3440adding new transformations, and generally changing how libpng works.
3441Both of those are compile-time issues; that is, they are generally
3442determined at the time the code is written, and there is rarely a need
3443to provide the user with a means of changing them.
3444
3445Memory allocation, input/output, and error handling
3446
3447All of the memory allocation, input/output, and error handling in libpng
3448goes through callbacks that are user-settable. The default routines are
3449in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
3450these functions, call the appropriate png_set_*_fn() function.
3451
3452Memory allocation is done through the functions png_malloc(), png_calloc(),
3453and png_free(). These currently just call the standard C functions.
3454png_calloc() calls png_malloc() and then clears the newly
3455allocated memory to zero. There is limited support for certain systems
3456with segmented memory architectures and the types of pointers declared by
3457png.h match this; you will have to use appropriate pointers in your
3458application. Since it is
3459unlikely that the method of handling memory allocation on a platform
3460will change between applications, these functions must be modified in
3461the library at compile time. If you prefer to use a different method
3462of allocating and freeing data, you can use png_create_read_struct_2() or
3463png_create_write_struct_2() to register your own functions as described
3464above. These functions also provide a void pointer that can be retrieved
3465via
3466
3467 mem_ptr=png_get_mem_ptr(png_ptr);
3468
3469Your replacement memory functions must have prototypes as follows:
3470
3471 png_voidp malloc_fn(png_structp png_ptr,
3472 png_alloc_size_t size);
3473
3474 void free_fn(png_structp png_ptr, png_voidp ptr);
3475
3476Your malloc_fn() must return NULL in case of failure. The png_malloc()
3477function will normally call png_error() if it receives a NULL from the
3478system memory allocator or from your replacement malloc_fn().
3479
3480Your free_fn() will never be called with a NULL ptr, since libpng's
3481png_free() checks for NULL before calling free_fn().
3482
3483Input/Output in libpng is done through png_read() and png_write(),
3484which currently just call fread() and fwrite(). The FILE * is stored in
3485png_struct and is initialized via png_init_io(). If you wish to change
3486the method of I/O, the library supplies callbacks that you can set
3487through the function png_set_read_fn() and png_set_write_fn() at run
3488time, instead of calling the png_init_io() function. These functions
3489also provide a void pointer that can be retrieved via the function
3490png_get_io_ptr(). For example:
3491
3492 png_set_read_fn(png_structp read_ptr,
3493 voidp read_io_ptr, png_rw_ptr read_data_fn)
3494
3495 png_set_write_fn(png_structp write_ptr,
3496 voidp write_io_ptr, png_rw_ptr write_data_fn,
3497 png_flush_ptr output_flush_fn);
3498
3499 voidp read_io_ptr = png_get_io_ptr(read_ptr);
3500 voidp write_io_ptr = png_get_io_ptr(write_ptr);
3501
3502The replacement I/O functions must have prototypes as follows:
3503
3504 void user_read_data(png_structp png_ptr,
3505 png_bytep data, png_size_t length);
3506
3507 void user_write_data(png_structp png_ptr,
3508 png_bytep data, png_size_t length);
3509
3510 void user_flush_data(png_structp png_ptr);
3511
3512The user_read_data() function is responsible for detecting and
3513handling end-of-data errors.
3514
3515Supplying NULL for the read, write, or flush functions sets them back
3516to using the default C stream functions, which expect the io_ptr to
3517point to a standard *FILE structure. It is probably a mistake
3518to use NULL for one of write_data_fn and output_flush_fn but not both
3519of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
3520It is an error to read from a write stream, and vice versa.
3521
3522Error handling in libpng is done through png_error() and png_warning().
3523Errors handled through png_error() are fatal, meaning that png_error()
3524should never return to its caller. Currently, this is handled via
3525setjmp() and longjmp() (unless you have compiled libpng with
3526PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
3527but you could change this to do things like exit() if you should wish,
3528as long as your function does not return.
3529
3530On non-fatal errors, png_warning() is called
3531to print a warning message, and then control returns to the calling code.
3532By default png_error() and png_warning() print a message on stderr via
3533fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
3534(because you don't want the messages) or PNG_NO_STDIO defined (because
3535fprintf() isn't available). If you wish to change the behavior of the error
3536functions, you will need to set up your own message callbacks. These
3537functions are normally supplied at the time that the png_struct is created.
3538It is also possible to redirect errors and warnings to your own replacement
3539functions after png_create_*_struct() has been called by calling:
3540
3541 png_set_error_fn(png_structp png_ptr,
3542 png_voidp error_ptr, png_error_ptr error_fn,
3543 png_error_ptr warning_fn);
3544
3545 png_voidp error_ptr = png_get_error_ptr(png_ptr);
3546
3547If NULL is supplied for either error_fn or warning_fn, then the libpng
3548default function will be used, calling fprintf() and/or longjmp() if a
3549problem is encountered. The replacement error functions should have
3550parameters as follows:
3551
3552 void user_error_fn(png_structp png_ptr,
3553 png_const_charp error_msg);
3554
3555 void user_warning_fn(png_structp png_ptr,
3556 png_const_charp warning_msg);
3557
3558The motivation behind using setjmp() and longjmp() is the C++ throw and
3559catch exception handling methods. This makes the code much easier to write,
3560as there is no need to check every return code of every function call.
3561However, there are some uncertainties about the status of local variables
3562after a longjmp, so the user may want to be careful about doing anything
3563after setjmp returns non-zero besides returning itself. Consult your
3564compiler documentation for more details. For an alternative approach, you
3565may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
3566which is illustrated in pngvalid.c and in contrib/visupng.
3567
3568Custom chunks
3569
3570If you need to read or write custom chunks, you may need to get deeper
3571into the libpng code. The library now has mechanisms for storing
3572and writing chunks of unknown type; you can even declare callbacks
3573for custom chunks. However, this may not be good enough if the
3574library code itself needs to know about interactions between your
3575chunk and existing `intrinsic' chunks.
3576
3577If you need to write a new intrinsic chunk, first read the PNG
3578specification. Acquire a first level of understanding of how it works.
3579Pay particular attention to the sections that describe chunk names,
3580and look at how other chunks were designed, so you can do things
3581similarly. Second, check out the sections of libpng that read and
3582write chunks. Try to find a chunk that is similar to yours and use
3583it as a template. More details can be found in the comments inside
3584the code. It is best to handle private or unknown chunks in a generic method,
3585via callback functions, instead of by modifying libpng functions. This
3586is illustrated in pngtest.c, which uses a callback function to handle a
3587private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
3588libpng.
3589
3590If you wish to write your own transformation for the data, look through
3591the part of the code that does the transformations, and check out some of
3592the simpler ones to get an idea of how they work. Try to find a similar
3593transformation to the one you want to add and copy off of it. More details
3594can be found in the comments inside the code itself.
3595
3596Configuring for 16-bit platforms
3597
3598You will want to look into zconf.h to tell zlib (and thus libpng) that
3599it cannot allocate more then 64K at a time. Even if you can, the memory
3600won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
3601
3602Configuring for DOS
3603
3604For DOS users who only have access to the lower 640K, you will
3605have to limit zlib's memory usage via a png_set_compression_mem_level()
3606call. See zlib.h or zconf.h in the zlib library for more information.
3607
3608Configuring for Medium Model
3609
3610Libpng's support for medium model has been tested on most of the popular
3611compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
3612defined, and FAR gets defined to far in pngconf.h, and you should be
3613all set. Everything in the library (except for zlib's structure) is
3614expecting far data. You must use the typedefs with the p or pp on
3615the end for pointers (or at least look at them and be careful). Make
3616note that the rows of data are defined as png_bytepp, which is
3617an "unsigned char far * far *".
3618
3619Configuring for gui/windowing platforms:
3620
3621You will need to write new error and warning functions that use the GUI
3622interface, as described previously, and set them to be the error and
3623warning functions at the time that png_create_*_struct() is called,
3624in order to have them available during the structure initialization.
3625They can be changed later via png_set_error_fn(). On some compilers,
3626you may also have to change the memory allocators (png_malloc, etc.).
3627
3628Configuring for compiler xxx:
3629
3630All includes for libpng are in pngconf.h. If you need to add, change
3631or delete an include, this is the place to do it.
3632The includes that are not needed outside libpng are placed in pngpriv.h,
3633which is only used by the routines inside libpng itself.
3634The files in libpng proper only include pngpriv.h and png.h, which
3635in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
3636As of libpng-1.5.0, pngpriv.h also includes three other private header
3637files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
3638that previously appeared in the public headers.
3639
3640Configuring zlib:
3641
3642There are special functions to configure the compression. Perhaps the
3643most useful one changes the compression level, which currently uses
3644input compression values in the range 0 - 9. The library normally
3645uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
3646have shown that for a large majority of images, compression values in
3647the range 3-6 compress nearly as well as higher levels, and do so much
3648faster. For online applications it may be desirable to have maximum speed
3649(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
3650specify no compression (Z_NO_COMPRESSION = 0), but this would create
3651files larger than just storing the raw bitmap. You can specify the
3652compression level by calling:
3653
3654 #include zlib.h
3655 png_set_compression_level(png_ptr, level);
3656
3657Another useful one is to reduce the memory level used by the library.
3658The memory level defaults to 8, but it can be lowered if you are
3659short on memory (running DOS, for example, where you only have 640K).
3660Note that the memory level does have an effect on compression; among
3661other things, lower levels will result in sections of incompressible
3662data being emitted in smaller stored blocks, with a correspondingly
3663larger relative overhead of up to 15% in the worst case.
3664
3665 #include zlib.h
3666 png_set_compression_mem_level(png_ptr, level);
3667
3668The other functions are for configuring zlib. They are not recommended
3669for normal use and may result in writing an invalid PNG file. See
3670zlib.h for more information on what these mean.
3671
3672 #include zlib.h
3673 png_set_compression_strategy(png_ptr,
3674 strategy);
3675
3676 png_set_compression_window_bits(png_ptr,
3677 window_bits);
3678
3679 png_set_compression_method(png_ptr, method);
3680
3681 png_set_compression_buffer_size(png_ptr, size);
3682
3683As of libpng version 1.5.4, additional APIs became
3684available to set these separately for non-IDAT
3685compressed chunks such as zTXt, iTXt, and iCCP:
3686
3687 #include zlib.h
3688 #if PNG_LIBPNG_VER <= 10504
3689 png_set_text_compression_level(png_ptr, level);
3690
3691 png_set_text_compression_mem_level(png_ptr, level);
3692
3693 png_set_text_compression_strategy(png_ptr,
3694 strategy);
3695
3696 png_set_text_compression_window_bits(png_ptr,
3697 window_bits);
3698
3699 png_set_text_compression_method(png_ptr, method);
3700 #endif
3701
3702Controlling row filtering
3703
3704If you want to control whether libpng uses filtering or not, which
3705filters are used, and how it goes about picking row filters, you
3706can call one of these functions. The selection and configuration
3707of row filters can have a significant impact on the size and
3708encoding speed and a somewhat lesser impact on the decoding speed
3709of an image. Filtering is enabled by default for RGB and grayscale
3710images (with and without alpha), but not for paletted images nor
3711for any images with bit depths less than 8 bits/pixel.
3712
3713The 'method' parameter sets the main filtering method, which is
3714currently only '0' in the PNG 1.2 specification. The 'filters'
3715parameter sets which filter(s), if any, should be used for each
3716scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
3717to turn filtering on and off, respectively.
3718
3719Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
3720PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
3721ORed together with '|' to specify one or more filters to use.
3722These filters are described in more detail in the PNG specification.
3723If you intend to change the filter type during the course of writing
3724the image, you should start with flags set for all of the filters
3725you intend to use so that libpng can initialize its internal
3726structures appropriately for all of the filter types. (Note that this
3727means the first row must always be adaptively filtered, because libpng
3728currently does not allocate the filter buffers until png_write_row()
3729is called for the first time.)
3730
3731 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
3732 PNG_FILTER_UP | PNG_FILTER_AVG |
3733 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
3734
3735 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
3736 filters);
3737 The second parameter can also be
3738 PNG_INTRAPIXEL_DIFFERENCING if you are
3739 writing a PNG to be embedded in a MNG
3740 datastream. This parameter must be the
3741 same as the value of filter_method used
3742 in png_set_IHDR().
3743
3744It is also possible to influence how libpng chooses from among the
3745available filters. This is done in one or both of two ways - by
3746telling it how important it is to keep the same filter for successive
3747rows, and by telling it the relative computational costs of the filters.
3748
3749 double weights[3] = {1.5, 1.3, 1.1},
3750 costs[PNG_FILTER_VALUE_LAST] =
3751 {1.0, 1.3, 1.3, 1.5, 1.7};
3752
3753 png_set_filter_heuristics(png_ptr,
3754 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
3755 weights, costs);
3756
3757The weights are multiplying factors that indicate to libpng that the
3758row filter should be the same for successive rows unless another row filter
3759is that many times better than the previous filter. In the above example,
3760if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
3761"sum of absolute differences" 1.5 x 1.3 times higher than other filters
3762and still be chosen, while the NONE filter could have a sum 1.1 times
3763higher than other filters and still be chosen. Unspecified weights are
3764taken to be 1.0, and the specified weights should probably be declining
3765like those above in order to emphasize recent filters over older filters.
3766
3767The filter costs specify for each filter type a relative decoding cost
3768to be considered when selecting row filters. This means that filters
3769with higher costs are less likely to be chosen over filters with lower
3770costs, unless their "sum of absolute differences" is that much smaller.
3771The costs do not necessarily reflect the exact computational speeds of
3772the various filters, since this would unduly influence the final image
3773size.
3774
3775Note that the numbers above were invented purely for this example and
3776are given only to help explain the function usage. Little testing has
3777been done to find optimum values for either the costs or the weights.
3778
3779Removing unwanted object code
3780
3781There are a bunch of #define's in pngconf.h that control what parts of
3782libpng are compiled. All the defines end in _SUPPORTED. If you are
3783never going to use a capability, you can change the #define to #undef
3784before recompiling libpng and save yourself code and data space, or
3785you can turn off individual capabilities with defines that begin with
3786PNG_NO_.
3787
3788In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
3789
3790You can also turn all of the transforms and ancillary chunk capabilities
3791off en masse with compiler directives that define
3792PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
3793or all four,
3794along with directives to turn on any of the capabilities that you do
3795want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
3796transformations but still leave the library fully capable of reading
3797and writing PNG files with all known public chunks. Use of the
3798PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
3799that is incapable of reading or writing ancillary chunks. If you are
3800not using the progressive reading capability, you can turn that off
3801with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
3802capability, which you'll still have).
3803
3804All the reading and writing specific code are in separate files, so the
3805linker should only grab the files it needs. However, if you want to
3806make sure, or if you are building a stand alone library, all the
3807reading files start with "pngr" and all the writing files start with "pngw".
3808The files that don't match either (like png.c, pngtrans.c, etc.)
3809are used for both reading and writing, and always need to be included.
3810The progressive reader is in pngpread.c
3811
3812If you are creating or distributing a dynamically linked library (a .so
3813or DLL file), you should not remove or disable any parts of the library,
3814as this will cause applications linked with different versions of the
3815library to fail if they call functions not available in your library.
3816The size of the library itself should not be an issue, because only
3817those sections that are actually used will be loaded into memory.
3818
3819Requesting debug printout
3820
3821The macro definition PNG_DEBUG can be used to request debugging
3822printout. Set it to an integer value in the range 0 to 3. Higher
3823numbers result in increasing amounts of debugging information. The
3824information is printed to the "stderr" file, unless another file
3825name is specified in the PNG_DEBUG_FILE macro definition.
3826
3827When PNG_DEBUG > 0, the following functions (macros) become available:
3828
3829 png_debug(level, message)
3830 png_debug1(level, message, p1)
3831 png_debug2(level, message, p1, p2)
3832
3833in which "level" is compared to PNG_DEBUG to decide whether to print
3834the message, "message" is the formatted string to be printed,
3835and p1 and p2 are parameters that are to be embedded in the string
3836according to printf-style formatting directives. For example,
3837
3838 png_debug1(2, "foo=%d\n", foo);
3839
3840is expanded to
3841
3842 if (PNG_DEBUG > 2)
3843 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
3844
3845When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
3846can still use PNG_DEBUG to control your own debugging:
3847
3848 #ifdef PNG_DEBUG
3849 fprintf(stderr, ...
3850 #endif
3851
3852When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
3853having level = 0 will be printed. There aren't any such statements in
3854this version of libpng, but if you insert some they will be printed.
3855
3856VI. MNG support
3857
3858The MNG specification (available at http://www.libpng.org/pub/mng) allows
3859certain extensions to PNG for PNG images that are embedded in MNG datastreams.
3860Libpng can support some of these extensions. To enable them, use the
3861png_permit_mng_features() function:
3862
3863 feature_set = png_permit_mng_features(png_ptr, mask)
3864
3865 mask is a png_uint_32 containing the bitwise OR of the
3866 features you want to enable. These include
3867 PNG_FLAG_MNG_EMPTY_PLTE
3868 PNG_FLAG_MNG_FILTER_64
3869 PNG_ALL_MNG_FEATURES
3870
3871 feature_set is a png_uint_32 that is the bitwise AND of
3872 your mask with the set of MNG features that is
3873 supported by the version of libpng that you are using.
3874
3875It is an error to use this function when reading or writing a standalone
3876PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
3877in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
3878and the MHDR and MEND chunks. Libpng does not provide support for these
3879or any other MNG chunks; your application must provide its own support for
3880them. You may wish to consider using libmng (available at
3881http://www.libmng.com) instead.
3882
3883VII. Changes to Libpng from version 0.88
3884
3885It should be noted that versions of libpng later than 0.96 are not
3886distributed by the original libpng author, Guy Schalnat, nor by
3887Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
3888distributed versions 0.89 through 0.96, but rather by another member
3889of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
3890still alive and well, but they have moved on to other things.
3891
3892The old libpng functions png_read_init(), png_write_init(),
3893png_info_init(), png_read_destroy(), and png_write_destroy() have been
3894moved to PNG_INTERNAL in version 0.95 to discourage their use. These
3895functions will be removed from libpng version 1.4.0.
3896
3897The preferred method of creating and initializing the libpng structures is
3898via the png_create_read_struct(), png_create_write_struct(), and
3899png_create_info_struct() because they isolate the size of the structures
3900from the application, allow version error checking, and also allow the
3901use of custom error handling routines during the initialization, which
3902the old functions do not. The functions png_read_destroy() and
3903png_write_destroy() do not actually free the memory that libpng
3904allocated for these structs, but just reset the data structures, so they
3905can be used instead of png_destroy_read_struct() and
3906png_destroy_write_struct() if you feel there is too much system overhead
3907allocating and freeing the png_struct for each image read.
3908
3909Setting the error callbacks via png_set_message_fn() before
3910png_read_init() as was suggested in libpng-0.88 is no longer supported
3911because this caused applications that do not use custom error functions
3912to fail if the png_ptr was not initialized to zero. It is still possible
3913to set the error callbacks AFTER png_read_init(), or to change them with
3914png_set_error_fn(), which is essentially the same function, but with a new
3915name to force compilation errors with applications that try to use the old
3916method.
3917
3918Starting with version 1.0.7, you can find out which version of the library
3919you are using at run-time:
3920
3921 png_uint_32 libpng_vn = png_access_version_number();
3922
3923The number libpng_vn is constructed from the major version, minor
3924version with leading zero, and release number with leading zero,
3925(e.g., libpng_vn for version 1.0.7 is 10007).
3926
3927Note that this function does not take a png_ptr, so you can call it
3928before you've created one.
3929
3930You can also check which version of png.h you used when compiling your
3931application:
3932
3933 png_uint_32 application_vn = PNG_LIBPNG_VER;
3934
3935VIII. Changes to Libpng from version 1.0.x to 1.2.x
3936
3937Support for user memory management was enabled by default. To
3938accomplish this, the functions png_create_read_struct_2(),
3939png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
3940png_malloc_default(), and png_free_default() were added.
3941
3942Support for the iTXt chunk has been enabled by default as of
3943version 1.2.41.
3944
3945Support for certain MNG features was enabled.
3946
3947Support for numbered error messages was added. However, we never got
3948around to actually numbering the error messages. The function
3949png_set_strip_error_numbers() was added (Note: the prototype for this
3950function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
3951builds of libpng-1.2.15. It was restored in libpng-1.2.36).
3952
3953The png_malloc_warn() function was added at libpng-1.2.3. This issues
3954a png_warning and returns NULL instead of aborting when it fails to
3955acquire the requested memory allocation.
3956
3957Support for setting user limits on image width and height was enabled
3958by default. The functions png_set_user_limits(), png_get_user_width_max(),
3959and png_get_user_height_max() were added at libpng-1.2.6.
3960
3961The png_set_add_alpha() function was added at libpng-1.2.7.
3962
3963The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
3964Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
3965tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
3966deprecated.
3967
3968A number of macro definitions in support of runtime selection of
3969assembler code features (especially Intel MMX code support) were
3970added at libpng-1.2.0:
3971
3972 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
3973 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
3974 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
3975 PNG_ASM_FLAG_MMX_READ_INTERLACE
3976 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
3977 PNG_ASM_FLAG_MMX_READ_FILTER_UP
3978 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
3979 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
3980 PNG_ASM_FLAGS_INITIALIZED
3981 PNG_MMX_READ_FLAGS
3982 PNG_MMX_FLAGS
3983 PNG_MMX_WRITE_FLAGS
3984 PNG_MMX_FLAGS
3985
3986We added the following functions in support of runtime
3987selection of assembler code features:
3988
3989 png_get_mmx_flagmask()
3990 png_set_mmx_thresholds()
3991 png_get_asm_flags()
3992 png_get_mmx_bitdepth_threshold()
3993 png_get_mmx_rowbytes_threshold()
3994 png_set_asm_flags()
3995
3996We replaced all of these functions with simple stubs in libpng-1.2.20,
3997when the Intel assembler code was removed due to a licensing issue.
3998
3999These macros are deprecated:
4000
4001 PNG_READ_TRANSFORMS_NOT_SUPPORTED
4002 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4003 PNG_NO_SEQUENTIAL_READ_SUPPORTED
4004 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4005 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4006 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4007
4008They have been replaced, respectively, by:
4009
4010 PNG_NO_READ_TRANSFORMS
4011 PNG_NO_PROGRESSIVE_READ
4012 PNG_NO_SEQUENTIAL_READ
4013 PNG_NO_WRITE_TRANSFORMS
4014 PNG_NO_READ_ANCILLARY_CHUNKS
4015 PNG_NO_WRITE_ANCILLARY_CHUNKS
4016
4017PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4018deprecated since libpng-1.0.16 and libpng-1.2.6.
4019
4020The function
4021 png_check_sig(sig, num)
4022was replaced with
4023 !png_sig_cmp(sig, 0, num)
4024It has been deprecated since libpng-0.90.
4025
4026The function
4027 png_set_gray_1_2_4_to_8()
4028which also expands tRNS to alpha was replaced with
4029 png_set_expand_gray_1_2_4_to_8()
4030which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
4031
4032IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
4033
4034Private libpng prototypes and macro definitions were moved from
4035png.h and pngconf.h into a new pngpriv.h header file.
4036
4037Functions png_set_benign_errors(), png_benign_error(), and
4038png_chunk_benign_error() were added.
4039
4040Support for setting the maximum amount of memory that the application
4041will allocate for reading chunks was added, as a security measure.
4042The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
4043were added to the library.
4044
4045We implemented support for I/O states by adding png_ptr member io_state
4046and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
4047
4048We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
4049input transforms.
4050
4051Checking for and reporting of errors in the IHDR chunk is more thorough.
4052
4053Support for global arrays was removed, to improve thread safety.
4054
4055Some obsolete/deprecated macros and functions have been removed.
4056
4057Typecasted NULL definitions such as
4058 #define png_voidp_NULL (png_voidp)NULL
4059were eliminated. If you used these in your application, just use
4060NULL instead.
4061
4062The png_struct and info_struct members "trans" and "trans_values" were
4063changed to "trans_alpha" and "trans_color", respectively.
4064
4065The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
4066were removed.
4067
4068The PNG_1_0_X and PNG_1_2_X macros were eliminated.
4069
4070The PNG_LEGACY_SUPPORTED macro was eliminated.
4071
4072Many WIN32_WCE #ifdefs were removed.
4073
4074The functions png_read_init(info_ptr), png_write_init(info_ptr),
4075png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
4076have been removed. They have been deprecated since libpng-0.95.
4077
4078The png_permit_empty_plte() was removed. It has been deprecated
4079since libpng-1.0.9. Use png_permit_mng_features() instead.
4080
4081We removed the obsolete stub functions png_get_mmx_flagmask(),
4082png_set_mmx_thresholds(), png_get_asm_flags(),
4083png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
4084png_set_asm_flags(), and png_mmx_supported()
4085
4086We removed the obsolete png_check_sig(), png_memcpy_check(), and
4087png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
4088and memset(), respectively.
4089
4090The function png_set_gray_1_2_4_to_8() was removed. It has been
4091deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
4092png_set_expand_gray_1_2_4_to_8() because the former function also
4093expanded any tRNS chunk to an alpha channel.
4094
4095Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
4096were added and are used by default instead of the corresponding
4097functions. Unfortunately,
4098from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
4099function) incorrectly returned a value of type png_uint_32.
4100
4101We changed the prototype for png_malloc() from
4102 png_malloc(png_structp png_ptr, png_uint_32 size)
4103to
4104 png_malloc(png_structp png_ptr, png_alloc_size_t size)
4105
4106This also applies to the prototype for the user replacement malloc_fn().
4107
4108The png_calloc() function was added and is used in place of
4109of "png_malloc(); memset();" except in the case in png_read_png()
4110where the array consists of pointers; in this case a "for" loop is used
4111after the png_malloc() to set the pointers to NULL, to give robust.
4112behavior in case the application runs out of memory part-way through
4113the process.
4114
4115We changed the prototypes of png_get_compression_buffer_size() and
4116png_set_compression_buffer_size() to work with png_size_t instead of
4117png_uint_32.
4118
4119Support for numbered error messages was removed by default, since we
4120never got around to actually numbering the error messages. The function
4121png_set_strip_error_numbers() was removed from the library by default.
4122
4123The png_zalloc() and png_zfree() functions are no longer exported.
4124The png_zalloc() function no longer zeroes out the memory that it
4125allocates.
4126
4127Support for dithering was disabled by default in libpng-1.4.0, because
4128it has not been well tested and doesn't actually "dither".
4129The code was not
4130removed, however, and could be enabled by building libpng with
4131PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
4132was reenabled, but the function was renamed png_set_quantize() to
4133reflect more accurately what it actually does. At the same time,
4134the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
4135PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
4136was renamed to PNG_READ_QUANTIZE_SUPPORTED.
4137
4138We removed the trailing '.' from the warning and error messages.
4139
4140X. Changes to Libpng from version 1.4.x to 1.5.x
4141
4142From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
4143function) incorrectly returned a value of type png_uint_32.
4144
4145A. Changes that affect users of libpng
4146
4147There are no substantial API changes between the non-deprecated parts of
4148the 1.4.5 API and the 1.5.0 API, however the ability to directly access
4149the main libpng control structures, png_struct and png_info, deprecated
4150in earlier versions of libpng, has been completely removed from
4151libpng 1.5.
4152
4153We no longer include zlib.h in png.h. Applications that need access
4154to information in zlib.h will need to add the '#include "zlib.h"'
4155directive. It does not matter whether it is placed prior to or after
4156the '"#include png.h"' directive.
4157
4158We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
4159png_memcmp(), png_sprintf, and png_memcpy() macros into a private
4160header file (pngpriv.h) that is not accessible to applications.
4161
4162In png_get_iCCP, the type of "profile" was changed from png_charpp
4163to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
4164
4165There are changes of form in png.h, including new and changed macros to
4166declare parts of the API. Some API functions with arguments that are
4167pointers to data not modified within the function have been corrected to
4168declare these arguments with PNG_CONST.
4169
4170Much of the internal use of C macros to control the library build has also
4171changed and some of this is visible in the exported header files, in
4172particular the use of macros to control data and API elements visible
4173during application compilation may require significant revision to
4174application code. (It is extremely rare for an application to do this.)
4175
4176Any program that compiled against libpng 1.4 and did not use deprecated
4177features or access internal library structures should compile and work
4178against libpng 1.5, except for the change in the prototype for
4179png_get_iCCP() and png_set_iCCP() API functions mentioned above.
4180
4181libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
4182interlaced images. The macros return the number of rows and columns in
4183each pass and information that can be used to de-interlace and (if
4184absolutely necessary) interlace an image.
4185
4186libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
4187the application-provided png_longjmp_ptr on the internal, but application
4188initialized, longjmp buffer. It is provided as a convenience to avoid
4189the need to use the png_jmpbuf macro, which had the unnecessary side
4190effect of resetting the internal png_longjmp_ptr value.
4191
4192libpng 1.5.0 includes a complete fixed point API. By default this is
4193present along with the corresponding floating point API. In general the
4194fixed point API is faster and smaller than the floating point one because
4195the PNG file format used fixed point, not floating point. This applies
4196even if the library uses floating point in internal calculations. A new
4197macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
4198uses floating point arithmetic (the default) or fixed point arithmetic
4199internally for performance critical calculations such as gamma correction.
4200In some cases, the gamma calculations may produce slightly different
4201results. This has changed the results in png_rgb_to_gray and in alpha
4202composition (png_set_background for example). This applies even if the
4203original image was already linear (gamma == 1.0) and, therefore, it is
4204not necessary to linearize the image. This is because libpng has *not*
4205been changed to optimize that case correctly, yet.
4206
4207Fixed point support for the sCAL chunk comes with an important caveat;
4208the sCAL specification uses a decimal encoding of floating point values
4209and the accuracy of PNG fixed point values is insufficient for
4210representation of these values. Consequently a "string" API
4211(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
4212arbitrary sCAL chunks in the absence of either the floating point API or
4213internal floating point calculations.
4214
4215Applications no longer need to include the optional distribution header
4216file pngusr.h or define the corresponding macros during application
4217build in order to see the correct variant of the libpng API. From 1.5.0
4218application code can check for the corresponding _SUPPORTED macro:
4219
4220#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
4221 /* code that uses the inch conversion APIs. */
4222#endif
4223
4224This macro will only be defined if the inch conversion functions have been
4225compiled into libpng. The full set of macros, and whether or not support
4226has been compiled in, are available in the header file pnglibconf.h.
4227This header file is specific to the libpng build. Notice that prior to
42281.5.0 the _SUPPORTED macros would always have the default definition unless
4229reset by pngusr.h or by explicit settings on the compiler command line.
4230These settings may produce compiler warnings or errors in 1.5.0 because
4231of macro redefinition.
4232
4233From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
4234function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
4235is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
4236did not exist.)
4237
4238Applications can now choose whether to use these macros or to call the
4239corresponding function by defining PNG_USE_READ_MACROS or
4240PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
4241only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
4242will lead to a link failure.
4243
4244Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
4245when compressing the IDAT data and textual data such as zTXt and iCCP.
4246In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
4247We added five png_set_text_*() functions for setting the parameters to
4248use with textual data.
4249
4250Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
4251option was off by default, and slightly inaccurate scaling occurred.
4252This option can no longer be turned off, and the choice of accurate
4253or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
4254API for accurate scaling or the old png_set_strip_16_to_8() API for simple
4255chopping.
4256
4257Prior to libpng-1.5.4, the png_set_user_limits() function could only be
4258used to reduce the width and height limits from the value of
4259PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
4260that it could be used to override them. Now this function will reduce or
4261increase the limits.
4262
4263B. Changes to the build and configuration of libpng
4264
4265Details of internal changes to the library code can be found in the CHANGES
4266file and in the GIT repository logs. These will be of no concern to the vast
4267majority of library users or builders, however the few who configure libpng
4268to a non-default feature set may need to change how this is done.
4269
4270There should be no need for library builders to alter build scripts if
4271these use the distributed build support - configure or the makefiles -
4272however users of the makefiles may care to update their build scripts
4273to build pnglibconf.h where the corresponding makefile does not do so.
4274
4275Building libpng with a non-default configuration has changed completely.
4276The old method using pngusr.h should still work correctly even though the
4277way pngusr.h is used in the build has been changed; however, library
4278builders will probably want to examine the changes to take advantage of
4279new capabilities and to simplify their build system.
4280
4281B.1 Specific changes to library configuration capabilities
4282
4283The library now supports a complete fixed point implementation and can
4284thus be used on systems that have no floating point support or very
4285limited or slow support. Previously gamma correction, an essential part
4286of complete PNG support, required reasonably fast floating point.
4287
4288As part of this the choice of internal implementation has been made
4289independent of the choice of fixed versus floating point APIs and all the
4290missing fixed point APIs have been implemented.
4291
4292The exact mechanism used to control attributes of API functions has
4293changed. A single set of operating system independent macro definitions
4294is used and operating system specific directives are defined in
4295pnglibconf.h
4296
4297As part of this the mechanism used to choose procedure call standards on
4298those systems that allow a choice has been changed. At present this only
4299affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
4300running on Intel processors. As before, PNGAPI is defined where required
4301to control the exported API functions; however, two new macros, PNGCBAPI
4302and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
4303(PNGCAPI) for functions that must match a C library prototype (currently
4304only png_longjmp_ptr, which must match the C longjmp function.) The new
4305approach is documented in pngconf.h
4306
4307Despite these changes, libpng 1.5.0 only supports the native C function
4308calling standard on those platforms tested so far (__cdecl on Microsoft
4309Windows). This is because the support requirements for alternative
4310calling conventions seem to no longer exist. Developers who find it
4311necessary to set PNG_API_RULE to 1 should advise the mailing list
4312(png-mng-implement) of this and library builders who use Openwatcom and
4313therefore set PNG_API_RULE to 2 should also contact the mailing list.
4314
4315A new test program, pngvalid, is provided in addition to pngtest.
4316pngvalid validates the arithmetic accuracy of the gamma correction
4317calculations and includes a number of validations of the file format.
4318A subset of the full range of tests is run when "make check" is done
4319(in the 'configure' build.) pngvalid also allows total allocated memory
4320usage to be evaluated and performs additional memory overwrite validation.
4321
4322Many changes to individual feature macros have been made. The following
4323are the changes most likely to be noticed by library builders who
4324configure libpng:
4325
43261) All feature macros now have consistent naming:
4327
4328#define PNG_NO_feature turns the feature off
4329#define PNG_feature_SUPPORTED turns the feature on
4330
4331pnglibconf.h contains one line for each feature macro which is either:
4332
4333#define PNG_feature_SUPPORTED
4334
4335if the feature is supported or:
4336
4337/*#undef PNG_feature_SUPPORTED*/
4338
4339if it is not. Library code consistently checks for the 'SUPPORTED' macro.
4340It does not, and libpng applications should not, check for the 'NO' macro
4341which will not normally be defined even if the feature is not supported.
4342The 'NO' macros are only used internally for setting or not setting the
4343corresponding 'SUPPORTED' macros.
4344
4345Compatibility with the old names is provided as follows:
4346
4347PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
4348
4349And the following definitions disable the corresponding feature:
4350
4351PNG_SETJMP_NOT_SUPPORTED disables SETJMP
4352PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
4353PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
4354PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
4355PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
4356PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
4357
4358Library builders should remove use of the above, inconsistent, names.
4359
43602) Warning and error message formatting was previously conditional on
4361the STDIO feature. The library has been changed to use the
4362CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
4363the library no longer uses the printf(3) functions, even though the
4364default read/write implementations use (FILE) style stdio.h functions.
4365
43663) Three feature macros now control the fixed/floating point decisions:
4367
4368PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
4369
4370PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
4371practice these are normally required internally anyway (because the PNG
4372file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
4373merely stops the function from being exported.
4374
4375PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
4376point implementation or the fixed point one. Typically the fixed point
4377implementation is larger and slower than the floating point implementation
4378on a system that supports floating point, however it may be faster on a
4379system which lacks floating point hardware and therefore uses a software
4380emulation.
4381
43824) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
4383functions to read and write ints to be disabled independently of
4384PNG_USE_READ_MACROS, which allows libpng to be built with the functions
4385even though the default is to use the macros - this allows applications
4386to choose at app buildtime whether or not to use macros (previously
4387impossible because the functions weren't in the default build.)
4388
4389B.2 Changes to the configuration mechanism
4390
4391Prior to libpng-1.5.0 library builders who needed to configure libpng
4392had either to modify the exported pngconf.h header file to add system
4393specific configuration or had to write feature selection macros into
4394pngusr.h and cause this to be included into pngconf.h by defining
4395PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
4396application built without PNG_USER_CONFIG defined would see the
4397unmodified, default, libpng API and thus would probably fail to link.
4398
4399These mechanisms still work in the configure build and in any makefile
4400build that builds pnglibconf.h, although the feature selection macros
4401have changed somewhat as described above. In 1.5.0, however, pngusr.h is
4402processed only once, when the exported header file pnglibconf.h is built.
4403pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
4404build of pnglibconf.h and it is never included in an application build.
4405
4406The rarely used alternative of adding a list of feature macros to the
4407CFLAGS setting in the build also still works, however the macros will be
4408copied to pnglibconf.h and this may produce macro redefinition warnings
4409when the individual C files are compiled.
4410
4411All configuration now only works if pnglibconf.h is built from
4412scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
4413(the original author of awk) maintains C source code of that awk and this
4414and all known later implementations (often called by subtly different
4415names - nawk and gawk for example) are adequate to build pnglibconf.h.
4416The Sun Microsystems (now Oracle) program 'awk' is an earlier version
4417and does not work; this may also apply to other systems that have a
4418functioning awk called 'nawk'.
4419
4420Configuration options are now documented in scripts/pnglibconf.dfa. This
4421file also includes dependency information that ensures a configuration is
4422consistent; that is, if a feature is switched off dependent features are
4423also removed. As a recommended alternative to using feature macros in
4424pngusr.h a system builder may also define equivalent options in pngusr.dfa
4425(or, indeed, any file) and add that to the configuration by setting
4426DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
4427how to do this, and a case where pngusr.h is still required.
4428
4429XI. Detecting libpng
4430
4431The png_get_io_ptr() function has been present since libpng-0.88, has never
4432changed, and is unaffected by conditional compilation macros. It is the
4433best choice for use in configure scripts for detecting the presence of any
4434libpng version since 0.88. In an autoconf "configure.in" you could use
4435
4436 AC_CHECK_LIB(png, png_get_io_ptr, ...
4437
4438XII. Source code repository
4439
4440Since about February 2009, version 1.2.34, libpng has been under "git" source
4441control. The git repository was built from old libpng-x.y.z.tar.gz files
4442going back to version 0.70. You can access the git repository (read only)
4443at
4444
4445 git://libpng.git.sourceforge.net/gitroot/libpng
4446
4447or you can browse it via "gitweb" at
4448
4449 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
4450
4451Patches can be sent to glennrp at users.sourceforge.net or to
4452png-mng-implement at lists.sourceforge.net or you can upload them to
4453the libpng bug tracker at
4454
4455 http://libpng.sourceforge.net
4456
4457We also accept patches built from the tar or zip distributions, and
4458simple verbal discriptions of bug fixes, reported either to the
4459SourceForge bug tracker, to the png-mng-implement at lists.sf.net
4460mailing list, or directly to glennrp.
4461
4462XIII. Coding style
4463
4464Our coding style is similar to the "Allman" style, with curly
4465braces on separate lines:
4466
4467 if (condition)
4468 {
4469 action;
4470 }
4471
4472 else if (another condition)
4473 {
4474 another action;
4475 }
4476
4477The braces can be omitted from simple one-line actions:
4478
4479 if (condition)
4480 return (0);
4481
4482We use 3-space indentation, except for continued statements which
4483are usually indented the same as the first line of the statement
4484plus four more spaces.
4485
4486For macro definitions we use 2-space indentation, always leaving the "#"
4487in the first column.
4488
4489 #ifndef PNG_NO_FEATURE
4490 # ifndef PNG_FEATURE_SUPPORTED
4491 # define PNG_FEATURE_SUPPORTED
4492 # endif
4493 #endif
4494
4495Comments appear with the leading "/*" at the same indentation as
4496the statement that follows the comment:
4497
4498 /* Single-line comment */
4499 statement;
4500
4501 /* This is a multiple-line
4502 * comment.
4503 */
4504 statement;
4505
4506Very short comments can be placed after the end of the statement
4507to which they pertain:
4508
4509 statement; /* comment */
4510
4511We don't use C++ style ("//") comments. We have, however,
4512used them in the past in some now-abandoned MMX assembler
4513code.
4514
4515Functions and their curly braces are not indented, and
4516exported functions are marked with PNGAPI:
4517
4518 /* This is a public function that is visible to
4519 * application programmers. It does thus-and-so.
4520 */
4521 void PNGAPI
4522 png_exported_function(png_ptr, png_info, foo)
4523 {
4524 body;
4525 }
4526
4527The prototypes for all exported functions appear in png.h,
4528above the comment that says
4529
4530 /* Maintainer: Put new public prototypes here ... */
4531
4532We mark all non-exported functions with "/* PRIVATE */"":
4533
4534 void /* PRIVATE */
4535 png_non_exported_function(png_ptr, png_info, foo)
4536 {
4537 body;
4538 }
4539
4540The prototypes for non-exported functions (except for those in
4541pngtest) appear in
4542pngpriv.h
4543above the comment that says
4544
4545 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
4546
4547To avoid polluting the global namespace, the names of all exported
4548functions and variables begin with "png_", and all publicly visible C
4549preprocessor macros begin with "PNG_". We request that applications that
4550use libpng *not* begin any of their own symbols with either of these strings.
4551
4552We put a space after each comma and after each semicolon
4553in "for" statements, and we put spaces before and after each
4554C binary operator and after "for" or "while", and before
4555"?". We don't put a space between a typecast and the expression
4556being cast, nor do we put one between a function name and the
4557left parenthesis that follows it:
4558
4559 for (i = 2; i > 0; --i)
4560 y[i] = a(x) + (int)b;
4561
4562We prefer #ifdef and #ifndef to #if defined() and if !defined()
4563when there is only one macro being tested.
4564
4565We prefer to express integers that are used as bit masks in hex format,
4566with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
4567
4568We do not use the TAB character for indentation in the C sources.
4569
4570Lines do not exceed 80 characters.
4571
4572Other rules can be inferred by inspecting the libpng source.
4573
4574XIV. Y2K Compliance in libpng
4575
4576February 18, 2012
4577
4578Since the PNG Development group is an ad-hoc body, we can't make
4579an official declaration.
4580
4581This is your unofficial assurance that libpng from version 0.71 and
4582upward through 1.5.9 are Y2K compliant. It is my belief that earlier
4583versions were also Y2K compliant.
4584
4585Libpng only has three year fields. One is a 2-byte unsigned integer that
4586will hold years up to 65535. The other two hold the date in text
4587format, and will hold years up to 9999.
4588
4589The integer is
4590 "png_uint_16 year" in png_time_struct.
4591
4592The strings are
4593 "png_charp time_buffer" in png_struct and
4594 "near_time_buffer", which is a local character string in png.c.
4595
4596There are seven time-related functions:
4597
4598 png_convert_to_rfc_1123() in png.c
4599 (formerly png_convert_to_rfc_1152() in error)
4600 png_convert_from_struct_tm() in pngwrite.c, called
4601 in pngwrite.c
4602 png_convert_from_time_t() in pngwrite.c
4603 png_get_tIME() in pngget.c
4604 png_handle_tIME() in pngrutil.c, called in pngread.c
4605 png_set_tIME() in pngset.c
4606 png_write_tIME() in pngwutil.c, called in pngwrite.c
4607
4608All appear to handle dates properly in a Y2K environment. The
4609png_convert_from_time_t() function calls gmtime() to convert from system
4610clock time, which returns (year - 1900), which we properly convert to
4611the full 4-digit year. There is a possibility that applications using
4612libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
4613function, or that they are incorrectly passing only a 2-digit year
4614instead of "year - 1900" into the png_convert_from_struct_tm() function,
4615but this is not under our control. The libpng documentation has always
4616stated that it works with 4-digit years, and the APIs have been
4617documented as such.
4618
4619The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
4620integer to hold the year, and can hold years as large as 65535.
4621
4622zlib, upon which libpng depends, is also Y2K compliant. It contains
4623no date-related code.
4624
4625
4626 Glenn Randers-Pehrson
4627 libpng maintainer
4628 PNG Development Group
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.3 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.3
new file mode 100644
index 0000000..1d72ab4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.3
@@ -0,0 +1,5952 @@
1.TH LIBPNG 3 "February 18, 2012"
2.SH NAME
3libpng \- Portable Network Graphics (PNG) Reference Library 1.5.9
4.SH SYNOPSIS
5\fI\fB
6
7\fB#include <png.h>\fP
8
9\fI\fB
10
11\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
12
13\fI\fB
14
15\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
16
17\fI\fB
18
19\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
20
21\fI\fB
22
23\fBpng_voidp png_calloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
24
25\fI\fB
26
27\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
28
29\fI\fB
30
31\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
32
33\fI\fB
34
35\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
36
37\fI\fB
38
39\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
40
41\fI\fB
42
43\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
44
45\fI\fB
46
47\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
48
49\fI\fB
50
51\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
52
53\fI\fB
54
55\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
56
57\fI\fB
58
59\fBpng_structp png_create_read_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
60
61\fI\fB
62
63\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
64
65\fI\fB
66
67\fBpng_structp png_create_write_struct_2 (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
68
69\fI\fB
70
71\fBvoid png_data_freer (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIfreer\fP\fB, png_uint_32 \fImask)\fP\fB);\fP
72
73\fI\fB
74
75\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
76
77\fI\fB
78
79\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
80
81\fI\fB
82
83\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
84
85\fI\fB
86
87\fBvoid png_err (png_structp \fIpng_ptr\fP\fB);\fP
88
89\fI\fB
90
91\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
92
93\fI\fB
94
95\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
96
97\fI\fB
98
99\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
100
101\fI\fB
102
103\fBvoid png_free_default (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
104
105\fI\fB
106
107\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
108
109\fI\fB
110
111\fBpng_byte png_get_bit_depth (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
112
113\fI\fB
114
115\fBpng_uint_32 png_get_bKGD (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
116
117\fI\fB
118
119\fBpng_byte png_get_channels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
120
121\fI\fB
122
123\fBpng_uint_32 png_get_cHRM (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
124
125\fI\fB
126
127\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
128
129\fI\fB
130
131\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \fIpng_ptr,
132
133\fBpng_const_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*red_X\fP\fB, double \fP\fI*red_Y\fP\fB, double \fI*red_Z,
134
135\fBdouble \fP\fI*green_X\fP\fB, double \fP\fI*green_Y\fP\fB, double \fP\fI*green_Z\fP\fB, double \fI*blue_X,
136
137\fBdouble \fP\fI*blue_Y\fP\fB, double \fI*blue_Z\fP\fB);\fP
138
139\fI\fB
140
141\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fI*int_red_X\fP\fB, png_fixed_point \fP\fI*int_red_Y\fP\fB, png_fixed_point \fP\fI*int_red_Z\fP\fB, png_fixed_point \fP\fI*int_green_X\fP\fB, png_fixed_point \fP\fI*int_green_Y\fP\fB, png_fixed_point \fP\fI*int_green_Z\fP\fB, png_fixed_point \fP\fI*int_blue_X\fP\fB, png_fixed_point \fP\fI*int_blue_Y\fP\fB, png_fixed_point \fI*int_blue_Z\fP\fB);\fP
142
143\fI\fB
144
145\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \fIpng_ptr\fP\fB);\fP
146
147\fI\fB
148
149\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \fIpng_ptr\fP\fB);\fP
150
151\fI\fB
152
153\fBpng_byte png_get_color_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
154
155\fI\fB
156
157\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \fIpng_ptr\fP\fB);\fP
158
159\fI\fB
160
161\fBpng_byte png_get_compression_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
162
163\fI\fB
164
165\fBpng_byte png_get_copyright (png_const_structp \fIpng_ptr\fP\fB);\fP
166
167\fI\fB
168
169\fBpng_uint_32 png_get_current_row_number \fI(png_const_structp\fP\fB);\fP
170
171\fI\fB
172
173\fBpng_byte png_get_current_pass_number \fI(png_const_structp\fP\fB);\fP
174
175\fI\fB
176
177\fBpng_voidp png_get_error_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
178
179\fI\fB
180
181\fBpng_byte png_get_filter_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
182
183\fI\fB
184
185\fBpng_uint_32 png_get_gAMA (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
186
187\fI\fB
188
189\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
190
191\fI\fB
192
193\fBpng_byte png_get_header_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
194
195\fI\fB
196
197\fBpng_byte png_get_header_version (png_const_structp \fIpng_ptr\fP\fB);\fP
198
199\fI\fB
200
201\fBpng_uint_32 png_get_hIST (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
202
203\fI\fB
204
205\fBpng_uint_32 png_get_iCCP (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_bytepp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
206
207\fI\fB
208
209\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
210
211\fI\fB
212
213\fBpng_uint_32 png_get_image_height (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
214
215\fI\fB
216
217\fBpng_uint_32 png_get_image_width (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
218
219\fI\fB
220
221\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
222
223\fI\fB
224
225\fBpng_byte png_get_interlace_type (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
226
227\fI\fB
228
229\fBpng_const_bytep png_get_io_chunk_name (png_structp \fIpng_ptr\fP\fB);\fP
230
231\fI\fB
232
233\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \fIpng_ptr\fP\fB);\fP
234
235\fI\fB
236
237\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
238
239\fI\fB
240
241\fBpng_uint_32 png_get_io_state (png_structp \fIpng_ptr\fP\fB);\fP
242
243\fI\fB
244
245\fBpng_byte png_get_libpng_ver (png_const_structp \fIpng_ptr\fP\fB);\fP
246
247\fI\fB
248
249\fBpng_voidp png_get_mem_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
250
251\fI\fB
252
253\fBpng_uint_32 png_get_oFFs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
254
255\fI\fB
256
257\fBpng_uint_32 png_get_pCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
258
259\fI\fB
260
261\fBpng_uint_32 png_get_pHYs (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
262
263\fI\fB
264
265\fBfloat png_get_pixel_aspect_ratio (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
266
267\fI\fB
268
269\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
270
271\fI\fB
272
273\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
274
275\fI\fB
276
277\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
278
279\fI\fB
280
281\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
282
283\fI\fB
284
285\fBpng_voidp png_get_progressive_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
286
287\fI\fB
288
289\fBpng_uint_32 png_get_PLTE (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
290
291\fI\fB
292
293\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \fIpng_ptr)
294
295\fBpng_uint_32 png_get_rowbytes (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
296
297\fI\fB
298
299\fBpng_bytepp png_get_rows (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
300
301\fI\fB
302
303\fBpng_uint_32 png_get_sBIT (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
304
305\fI\fB
306
307\fBvoid png_get_sCAL (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, double* \fP\fIwidth\fP\fB, double* \fIheight\fP\fB);\fP
308
309\fI\fB
310
311\fBvoid png_get_sCAL_fixed (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_fixed_pointp \fP\fIwidth\fP\fB, png_fixed_pointp \fIheight\fP\fB);\fP
312
313\fI\fB
314
315\fBvoid png_get_sCAL_s (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int* \fP\fIunit\fP\fB, png_charpp \fP\fIwidth\fP\fB, png_charpp \fIheight\fP\fB);\fP
316
317\fI\fB
318
319\fBpng_bytep png_get_signature (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
320
321\fI\fB
322
323\fBpng_uint_32 png_get_sPLT (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
324
325\fI\fB
326
327\fBpng_uint_32 png_get_sRGB (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, int \fI*file_srgb_intent\fP\fB);\fP
328
329\fI\fB
330
331\fBpng_uint_32 png_get_text (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
332
333\fI\fB
334
335\fBpng_uint_32 png_get_tIME (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
336
337\fI\fB
338
339\fBpng_uint_32 png_get_tRNS (png_const_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans_alpha\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_color\fP\fB);\fP
340
341\fI\fB
342
343\fB/* This function is really an inline macro. \fI*/
344
345\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
346
347\fI\fB
348
349\fBpng_uint_32 png_get_uint_31 (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIbuf\fP\fB);\fP
350
351\fI\fB
352
353\fB/* This function is really an inline macro. \fI*/
354
355\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
356
357\fI\fB
358
359\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
360
361\fI\fB
362
363\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
364
365\fI\fB
366
367\fBpng_uint_32 png_get_user_height_max (png_const_structp \fIpng_ptr\fP\fB);\fP
368
369\fI\fB
370
371\fBpng_voidp png_get_user_transform_ptr (png_const_structp \fIpng_ptr\fP\fB);\fP
372
373\fI\fB
374
375\fBpng_uint_32 png_get_user_width_max (png_const_structp \fIpng_ptr\fP\fB);\fP
376
377\fI\fB
378
379\fBpng_uint_32 png_get_valid (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
380
381\fI\fB
382
383\fBfloat png_get_x_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
384
385\fI\fB
386
387\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
388
389\fI\fB
390
391\fBpng_int_32 png_get_x_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
392
393\fI\fB
394
395\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
396
397\fI\fB
398
399\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
400
401\fI\fB
402
403\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
404
405\fI\fB
406
407\fBfloat png_get_y_offset_inches (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
408
409\fI\fB
410
411\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
412
413\fI\fB
414
415\fBpng_int_32 png_get_y_offset_microns (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
416
417\fI\fB
418
419\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
420
421\fI\fB
422
423\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
424
425\fI\fB
426
427\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \fP\fIpng_ptr\fP\fB, png_const_infop \fIinfo_ptr\fP\fB);\fP
428
429\fI\fB
430
431\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
432
433\fI\fB
434
435\fBvoid png_info_init_3 (png_infopp \fP\fIinfo_ptr\fP\fB, png_size_t \fIpng_info_struct_size\fP\fB);\fP
436
437\fI\fB
438
439\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
440
441\fI\fB
442
443\fBvoid png_longjmp (png_structp \fP\fIpng_ptr\fP\fB, int \fIval\fP\fB);\fP
444
445\fI\fB
446
447\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
448
449\fI\fB
450
451\fBpng_voidp png_malloc_default (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
452
453\fI\fB
454
455\fBpng_voidp png_malloc_warn (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
456
457\fI\fB
458
459\fBpng_uint_32 png_permit_mng_features (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fImng_features_permitted\fP\fB);\fP
460
461\fI\fB
462
463\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
464
465\fI\fB
466
467\fBpng_size_t png_process_data_pause \fP\fI(png_structp\fP\fB, int \fIsave\fP\fB);\fP
468
469\fI\fB
470
471\fBpng_uint_32 png_process_data_skip \fI(png_structp\fP\fB);\fP
472
473\fI\fB
474
475\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
476
477\fI\fB
478
479\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
480
481\fI\fB
482
483\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
484
485\fI\fB
486
487\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
488
489\fI\fB
490
491\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
492
493\fI\fB
494
495\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
496
497\fI\fB
498
499\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
500
501\fI\fB
502
503\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
504
505\fI\fB
506
507\fBint png_reset_zstream (png_structp \fIpng_ptr\fP\fB);\fP
508
509\fI\fB
510
511\fBvoid png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
512
513\fI\fB
514
515\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
516
517\fI\fB
518
519\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
520
521\fI\fB
522
523\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
524
525\fI\fB
526
527\fBvoid png_set_alpha_mode (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, double \fIoutput_gamma\fP\fB);\fP
528
529\fI\fB
530
531\fBvoid png_set_alpha_mode_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImode\fP\fB, png_fixed_point \fIoutput_gamma\fP\fB);\fP
532
533\fI\fB
534
535\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP
536
537\fI\fB
538
539\fBvoid png_set_background_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, png_uint_32 \fIbackground_gamma\fP\fB);\fP
540
541\fI\fB
542
543\fBvoid png_set_benign_errors (png_structp \fP\fIpng_ptr\fP\fB, int \fIallowed\fP\fB);\fP
544
545\fI\fB
546
547\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
548
549\fI\fB
550
551\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP
552
553\fI\fB
554
555\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
556
557\fI\fB
558
559\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
560
561\fI\fB
562
563\fBvoid png_set_cHRM_XYZ (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIred_X\fP\fB, double \fP\fIred_Y\fP\fB, double \fP\fIred_Z\fP\fB, double \fP\fIgreen_X\fP\fB, double \fIgreen_Y,
564
565\fBdouble \fP\fIgreen_Z\fP\fB, double \fP\fIblue_X\fP\fB, double \fP\fIblue_Y\fP\fB, double \fIblue_Z\fP\fB);\fP
566
567\fI\fB
568
569\fBvoid png_set_cHRM_XYZ_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_fixed_point \fP\fIint_red_X\fP\fB, png_fixed_point \fP\fIint_red_Y\fP\fB, png_fixed_point \fP\fIint_red_Z\fP\fB, png_fixed_point \fP\fIint_green_X\fP\fB, png_fixed_point \fP\fIint_green_Y\fP\fB, png_fixed_point \fP\fIint_green_Z\fP\fB, png_fixed_point \fP\fIint_blue_X\fP\fB, png_fixed_point \fP\fIint_blue_Y\fP\fB, png_fixed_point \fIint_blue_Z\fP\fB);\fP
570
571\fI\fB
572
573\fBvoid png_set_chunk_cache_max (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIuser_chunk_cache_max\fP\fB);\fP
574
575\fI\fB
576
577\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
578
579\fI\fB
580
581\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
582
583\fI\fB
584
585\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
586
587\fI\fB
588
589\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
590
591\fI\fB
592
593\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
594
595\fI\fB
596
597\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
598
599\fI\fB
600
601\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
602
603\fI\fB
604
605\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
606
607\fI\fB
608
609\fBvoid png_set_expand_16 (png_structp \fIpng_ptr\fP\fB);\fP
610
611\fI\fB
612
613\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
614
615\fI\fB
616
617\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
618
619\fI\fB
620
621\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
622
623\fI\fB
624
625\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP
626
627\fI\fB
628
629\fBvoid png_set_filter_heuristics_fixed (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_fixed_point_p \fP\fIfilter_weights\fP\fB, png_fixed_point_p \fIfilter_costs\fP\fB);\fP
630
631\fI\fB
632
633\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
634
635\fI\fB
636
637\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
638
639\fI\fB
640
641\fBvoid png_set_gamma_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIscreen_gamma\fP\fB, png_uint_32 \fIdefault_file_gamma\fP\fB);\fP
642
643\fI\fB
644
645\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
646
647\fI\fB
648
649\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP
650
651\fI\fB
652
653\fBvoid png_set_gray_1_2_4_to_8 (png_structp \fIpng_ptr\fP\fB);\fP
654
655\fI\fB
656
657\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
658
659\fI\fB
660
661\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP
662
663\fI\fB
664
665\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_const_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_const_bytep \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
666
667\fI\fB
668
669\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
670
671\fI\fB
672
673\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
674
675\fI\fB
676
677\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
678
679\fI\fB
680
681\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
682
683\fI\fB
684
685\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
686
687\fI\fB
688
689\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP
690
691\fI\fB
692
693\fBjmp_buf* png_set_longjmp_fn (png_structp \fP\fIpng_ptr\fP\fB, png_longjmp_ptr \fP\fIlongjmp_fn\fP\fB, size_t \fIjmp_buf_size\fP\fB);\fP
694
695\fI\fB
696
697\fBvoid png_set_chunk_malloc_max (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIuser_chunk_cache_max\fP\fB);\fP
698
699\fI\fB
700
701\fBvoid png_set_compression_buffer_size (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
702
703\fI\fB
704
705\fBvoid png_set_mem_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
706
707\fI\fB
708
709\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
710
711\fI\fB
712
713\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
714
715\fI\fB
716
717\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
718
719\fI\fB
720
721\fBvoid png_set_palette_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
722
723\fI\fB
724
725\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
726
727\fI\fB
728
729\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP
730
731\fI\fB
732
733\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP
734
735\fI\fB
736
737\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
738
739\fI\fB
740
741\fBvoid png_set_quantize (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_quantize\fP\fB);\fP
742
743\fI\fB
744
745\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP
746
747\fI\fB
748
749\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
750
751\fI\fB
752
753\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP
754
755\fI\fB
756
757\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP
758
759\fI\fB
760
761\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP
762
763\fI\fB
764
765\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_uint_32 \fP\fIred\fP\fB, png_uint_32 \fIgreen\fP\fB);\fP
766
767\fI\fB
768
769\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP
770
771\fI\fB
772
773\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
774
775\fI\fB
776
777\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
778
779\fI\fB
780
781\fBvoid png_set_sCAL_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_fixed_point \fP\fIwidth\fP\fB, png_fixed_point \fIheight\fP\fB);\fP
782
783\fI\fB
784
785\fBvoid png_set_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
786
787\fI\fB
788
789\fBvoid png_set_scale_16 (png_structp \fIpng_ptr\fP\fB);\fP
790
791\fI\fB
792
793\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
794
795\fI\fB
796
797\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
798
799\fI\fB
800
801\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
802
803\fI\fB
804
805\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
806
807\fI\fB
808
809\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIsrgb_intent\fP\fB);\fP
810
811\fI\fB
812
813\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
814
815\fI\fB
816
817\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
818
819\fI\fB
820
821\fBvoid png_set_strip_error_numbers (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIstrip_mode\fP\fB);\fP
822
823\fI\fB
824
825\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
826
827\fI\fB
828
829\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
830
831\fI\fB
832
833\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
834
835\fI\fB
836
837\fBvoid png_set_text_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
838
839\fI\fB
840
841\fBvoid png_set_text_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
842
843\fI\fB
844
845\fBvoid png_set_text_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
846
847\fI\fB
848
849\fBvoid png_set_text_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
850
851\fI\fB
852
853\fBvoid \fP\fIpng_set_text_compression_method\fP\fB, (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod)\fP\fB);\fP
854
855\fI\fB
856
857\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
858
859\fI\fB
860
861\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans_alpha\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_color\fP\fB);\fP
862
863\fI\fB
864
865\fBvoid png_set_tRNS_to_alpha (png_structp \fIpng_ptr\fP\fB);\fP
866
867\fI\fB
868
869\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP
870
871\fI\fB
872
873\fBvoid png_set_unknown_chunk_location (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
874
875\fI\fB
876
877\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
878
879\fI\fB
880
881\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP
882
883\fI\fB
884
885\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP
886
887\fI\fB
888
889\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
890
891\fI\fB
892
893\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP
894
895\fI\fB
896
897\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
898
899\fI\fB
900
901\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
902
903\fI\fB
904
905\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
906
907\fI\fB
908
909\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
910
911\fI\fB
912
913\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
914
915\fI\fB
916
917\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
918
919\fI\fB
920
921\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
922
923\fI\fB
924
925\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
926
927\fI\fB
928
929\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
930
931\fI\fB
932
933\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
934
935\fI\fB
936
937\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
938
939\fI\fB
940
941\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
942
943\fI\fB
944
945\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
946
947\fI\fB
948
949\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
950
951\fI\fB
952
953\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
954
955\fI\fB
956
957\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
958
959\fI\fB
960
961\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
962
963\fI\fB
964
965\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
966
967\fI\fB
968
969.SH DESCRIPTION
970The
971.I libpng
972library supports encoding, decoding, and various manipulations of
973the Portable Network Graphics (PNG) format image files. It uses the
974.IR zlib(3)
975compression library.
976Following is a copy of the libpng-manual.txt file that accompanies libpng.
977.SH LIBPNG.TXT
978libpng-manual.txt - A description on how to use and modify libpng
979
980 libpng version 1.5.9 - February 18, 2012
981 Updated and distributed by Glenn Randers-Pehrson
982 <glennrp at users.sourceforge.net>
983 Copyright (c) 1998-2011 Glenn Randers-Pehrson
984
985 This document is released under the libpng license.
986 For conditions of distribution and use, see the disclaimer
987 and license in png.h
988
989 Based on:
990
991 libpng versions 0.97, January 1998, through 1.5.9 - February 18, 2012
992 Updated and distributed by Glenn Randers-Pehrson
993 Copyright (c) 1998-2011 Glenn Randers-Pehrson
994
995 libpng 1.0 beta 6 version 0.96 May 28, 1997
996 Updated and distributed by Andreas Dilger
997 Copyright (c) 1996, 1997 Andreas Dilger
998
999 libpng 1.0 beta 2 - version 0.88 January 26, 1996
1000 For conditions of distribution and use, see copyright
1001 notice in png.h. Copyright (c) 1995, 1996 Guy Eric
1002 Schalnat, Group 42, Inc.
1003
1004 Updated/rewritten per request in the libpng FAQ
1005 Copyright (c) 1995, 1996 Frank J. T. Wojcik
1006 December 18, 1995 & January 20, 1996
1007
1008.SH I. Introduction
1009
1010This file describes how to use and modify the PNG reference library
1011(known as libpng) for your own use. There are five sections to this
1012file: introduction, structures, reading, writing, and modification and
1013configuration notes for various special platforms. In addition to this
1014file, example.c is a good starting point for using the library, as
1015it is heavily commented and should include everything most people
1016will need. We assume that libpng is already installed; see the
1017INSTALL file for instructions on how to install libpng.
1018
1019For examples of libpng usage, see the files "example.c", "pngtest.c",
1020and the files in the "contrib" directory, all of which are included in
1021the libpng distribution.
1022
1023Libpng was written as a companion to the PNG specification, as a way
1024of reducing the amount of time and effort it takes to support the PNG
1025file format in application programs.
1026
1027The PNG specification (second edition), November 2003, is available as
1028a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
1029<http://www.w3.org/TR/2003/REC-PNG-20031110/
1030The W3C and ISO documents have identical technical content.
1031
1032The PNG-1.2 specification is available at
1033<http://www.libpng.org/pub/png/documents/>. It is technically equivalent
1034to the PNG specification (second edition) but has some additional material.
1035
1036The PNG-1.0 specification is available
1037as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
1038W3C Recommendation <http://www.w3.org/TR/REC.png.html>.
1039
1040Some additional chunks are described in the special-purpose public chunks
1041documents at <http://www.libpng.org/pub/png/documents/>.
1042
1043Other information
1044about PNG, and the latest version of libpng, can be found at the PNG home
1045page, <http://www.libpng.org/pub/png/>.
1046
1047Most users will not have to modify the library significantly; advanced
1048users may want to modify it more. All attempts were made to make it as
1049complete as possible, while keeping the code easy to understand.
1050Currently, this library only supports C. Support for other languages
1051is being considered.
1052
1053Libpng has been designed to handle multiple sessions at one time,
1054to be easily modifiable, to be portable to the vast majority of
1055machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
1056to use. The ultimate goal of libpng is to promote the acceptance of
1057the PNG file format in whatever way possible. While there is still
1058work to be done (see the TODO file), libpng should cover the
1059majority of the needs of its users.
1060
1061Libpng uses zlib for its compression and decompression of PNG files.
1062Further information about zlib, and the latest version of zlib, can
1063be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
1064The zlib compression utility is a general purpose utility that is
1065useful for more than PNG files, and can be used without libpng.
1066See the documentation delivered with zlib for more details.
1067You can usually find the source files for the zlib utility wherever you
1068find the libpng source files.
1069
1070Libpng is thread safe, provided the threads are using different
1071instances of the structures. Each thread should have its own
1072png_struct and png_info instances, and thus its own image.
1073Libpng does not protect itself against two threads using the
1074same instance of a structure.
1075
1076.SH II. Structures
1077
1078There are two main structures that are important to libpng, png_struct
1079and png_info. Both are internal structures that are no longer exposed
1080in the libpng interface (as of libpng 1.5.0).
1081
1082The png_info structure is designed to provide information about the
1083PNG file. At one time, the fields of png_info were intended to be
1084directly accessible to the user. However, this tended to cause problems
1085with applications using dynamically loaded libraries, and as a result
1086a set of interface functions for png_info (the png_get_*() and png_set_*()
1087functions) was developed, and direct access to the png_info fields was
1088deprecated..
1089
1090The png_struct structure is the object used by the library to decode a
1091single image. As of 1.5.0 this structure is also not exposed.
1092
1093Almost all libpng APIs require a pointer to a png_struct as the first argument.
1094Many (in particular the png_set and png_get APIs) also require a pointer
1095to png_info as the second argument. Some application visible macros
1096defined in png.h designed for basic data access (reading and writing
1097integers in the PNG format) don't take a png_info pointer, but it's almost
1098always safe to assume that a (png_struct*) has to be passed to call an API
1099function.
1100
1101You can have more than one png_info structure associated with an image,
1102as illustrated in pngtest.c, one for information valid prior to the
1103IDAT chunks and another (called "end_info" below) for things after them.
1104
1105The png.h header file is an invaluable reference for programming with libpng.
1106And while I'm on the topic, make sure you include the libpng header file:
1107
1108#include <png.h>
1109
1110and also (as of libpng-1.5.0) the zlib header file, if you need it:
1111
1112#include <zlib.h>
1113
1114.SS Types
1115
1116The png.h header file defines a number of integral types used by the
1117APIs. Most of these are fairly obvious; for example types corresponding
1118to integers of particular sizes and types for passing color values.
1119
1120One exception is how non-integral numbers are handled. For application
1121convenience most APIs that take such numbers have C (double) arguments,
1122however internally PNG, and libpng, use 32 bit signed integers and encode
1123the value by multiplying by 100,000. As of libpng 1.5.0 a convenience
1124macro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)
1125which is simply (png_int_32).
1126
1127All APIs that take (double) arguments also have a matching API that
1128takes the corresponding fixed point integer arguments. The fixed point
1129API has the same name as the floating point one with "_fixed" appended.
1130The actual range of values permitted in the APIs is frequently less than
1131the full range of (png_fixed_point) (-21474 to +21474). When APIs require
1132a non-negative argument the type is recorded as png_uint_32 above. Consult
1133the header file and the text below for more information.
1134
1135Special care must be take with sCAL chunk handling because the chunk itself
1136uses non-integral values encoded as strings containing decimal floating point
1137numbers. See the comments in the header file.
1138
1139.SS Configuration
1140
1141The main header file function declarations are frequently protected by C
1142preprocessing directives of the form:
1143
1144 #ifdef PNG_feature_SUPPORTED
1145 declare-function
1146 #endif
1147 ...
1148 #ifdef PNG_feature_SUPPORTED
1149 use-function
1150 #endif
1151
1152The library can be built without support for these APIs, although a
1153standard build will have all implemented APIs. Application programs
1154should check the feature macros before using an API for maximum
1155portability. From libpng 1.5.0 the feature macros set during the build
1156of libpng are recorded in the header file "pnglibconf.h" and this file
1157is always included by png.h.
1158
1159If you don't need to change the library configuration from the default, skip to
1160the next section ("Reading").
1161
1162Notice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all
1163of the build project files in the 'projects' directory simply copy
1164scripts/pnglibconf.h.prebuilt to pnglibconf.h. This means that these build
1165systems do not permit easy auto-configuration of the library - they only
1166support the default configuration.
1167
1168The easiest way to make minor changes to the libpng configuration when
1169auto-configuration is supported is to add definitions to the command line
1170using (typically) CPPFLAGS. For example:
1171
1172CPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC
1173
1174will change the internal libpng math implementation for gamma correction and
1175other arithmetic calculations to fixed point, avoiding the need for fast
1176floating point support. The result can be seen in the generated pnglibconf.h -
1177make sure it contains the changed feature macro setting.
1178
1179If you need to make more extensive configuration changes - more than one or two
1180feature macro settings - you can either add -DPNG_USER_CONFIG to the build
1181command line and put a list of feature macro settings in pngusr.h or you can set
1182DFA_XTRA (a makefile variable) to a file containing the same information in the
1183form of 'option' settings.
1184
1185A. Changing pnglibconf.h
1186
1187A variety of methods exist to build libpng. Not all of these support
1188reconfiguration of pnglibconf.h. To reconfigure pnglibconf.h it must either be
1189rebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.
1190
1191Hand editing is achieved by copying scripts/pnglibconf.h.prebuilt to
1192pnglibconf.h and changing the lines defining the supported features, paying
1193very close attention to the 'option' information in scripts/pnglibconf.dfa
1194that describes those features and their requirements. This is easy to get
1195wrong.
1196
1197B. Configuration using DFA_XTRA
1198
1199Rebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later
1200variant such as 'nawk' or 'gawk', is available. The configure build will
1201automatically find an appropriate awk and build pnglibconf.h.
1202The scripts/pnglibconf.mak file contains a set of make rules for doing the
1203same thing if configure is not used, and many of the makefiles in the scripts
1204directory use this approach.
1205
1206When rebuilding simply write a new file containing changed options and set
1207DFA_XTRA to the name of this file. This causes the build to append the new file
1208to the end of scripts/pnglibconf.dfa. The pngusr.dfa file should contain lines
1209of the following forms:
1210
1211everything = off
1212
1213This turns all optional features off. Include it at the start of pngusr.dfa to
1214make it easier to build a minimal configuration. You will need to turn at least
1215some features on afterward to enable either reading or writing code, or both.
1216
1217option feature on
1218option feature off
1219
1220Enable or disable a single feature. This will automatically enable other
1221features required by a feature that is turned on or disable other features that
1222require a feature which is turned off. Conflicting settings will cause an error
1223message to be emitted by awk.
1224
1225setting feature default value
1226
1227Changes the default value of setting 'feature' to 'value'. There are a small
1228number of settings listed at the top of pnglibconf.h, they are documented in the
1229source code. Most of these values have performance implications for the library
1230but most of them have no visible effect on the API. Some can also be overridden
1231from the API.
1232
1233This method of building a customized pnglibconf.h is illustrated in
1234contrib/pngminim/*. See the "$(PNGCONF):" target in the makefile and
1235pngusr.dfa in these directories.
1236
1237C. Configuration using PNG_USR_CONFIG
1238
1239If -DPNG_USR_CONFIG is added to the CFLAGS when pnglibconf.h is built the file
1240pngusr.h will automatically be included before the options in
1241scripts/pnglibconf.dfa are processed. Your pngusr.h file should contain only
1242macro definitions turning features on or off or setting settings.
1243
1244Apart from the global setting "everything = off" all the options listed above
1245can be set using macros in pngusr.h:
1246
1247#define PNG_feature_SUPPORTED
1248
1249is equivalent to:
1250
1251option feature on
1252
1253#define PNG_NO_feature
1254
1255is equivalent to:
1256
1257option feature off
1258
1259#define PNG_feature value
1260
1261is equivalent to:
1262
1263setting feature default value
1264
1265Notice that in both cases, pngusr.dfa and pngusr.h, the contents of the
1266pngusr file you supply override the contents of scripts/pnglibconf.dfa
1267
1268If confusing or incomprehensible behavior results it is possible to
1269examine the intermediate file pnglibconf.dfn to find the full set of
1270dependency information for each setting and option. Simply locate the
1271feature in the file and read the C comments that precede it.
1272
1273This method is also illustrated in the contrib/pngminim/* makefiles and
1274pngusr.h.
1275
1276.SH III. Reading
1277
1278We'll now walk you through the possible functions to call when reading
1279in a PNG file sequentially, briefly explaining the syntax and purpose
1280of each one. See example.c and png.h for more detail. While
1281progressive reading is covered in the next section, you will still
1282need some of the functions discussed in this section to read a PNG
1283file.
1284
1285.SS Setup
1286
1287You will want to do the I/O initialization(*) before you get into libpng,
1288so if it doesn't work, you don't have much to undo. Of course, you
1289will also want to insure that you are, in fact, dealing with a PNG
1290file. Libpng provides a simple check to see if a file is a PNG file.
1291To use it, pass in the first 1 to 8 bytes of the file to the function
1292png_sig_cmp(), and it will return 0 (false) if the bytes match the
1293corresponding bytes of the PNG signature, or nonzero (true) otherwise.
1294Of course, the more bytes you pass in, the greater the accuracy of the
1295prediction.
1296
1297If you are intending to keep the file pointer open for use in libpng,
1298you must ensure you don't read more than 8 bytes from the beginning
1299of the file, and you also have to make a call to png_set_sig_bytes_read()
1300with the number of bytes you read from the beginning. Libpng will
1301then only check the bytes (if any) that your program didn't read.
1302
1303(*): If you are not using the standard I/O functions, you will need
1304to replace them with custom functions. See the discussion under
1305Customizing libpng.
1306
1307
1308 FILE *fp = fopen(file_name, "rb");
1309 if (!fp)
1310 {
1311 return (ERROR);
1312 }
1313
1314 fread(header, 1, number, fp);
1315 is_png = !png_sig_cmp(header, 0, number);
1316
1317 if (!is_png)
1318 {
1319 return (NOT_PNG);
1320 }
1321
1322
1323Next, png_struct and png_info need to be allocated and initialized. In
1324order to ensure that the size of these structures is correct even with a
1325dynamically linked libpng, there are functions to initialize and
1326allocate the structures. We also pass the library version, optional
1327pointers to error handling functions, and a pointer to a data struct for
1328use by the error functions, if necessary (the pointer and functions can
1329be NULL if the default error handlers are to be used). See the section
1330on Changes to Libpng below regarding the old initialization functions.
1331The structure allocation functions quietly return NULL if they fail to
1332create the structure, so your application should check for that.
1333
1334 png_structp png_ptr = png_create_read_struct
1335 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1336 user_error_fn, user_warning_fn);
1337
1338 if (!png_ptr)
1339 return (ERROR);
1340
1341 png_infop info_ptr = png_create_info_struct(png_ptr);
1342
1343 if (!info_ptr)
1344 {
1345 png_destroy_read_struct(&png_ptr,
1346 (png_infopp)NULL, (png_infopp)NULL);
1347 return (ERROR);
1348 }
1349
1350If you want to use your own memory allocation routines,
1351use a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use
1352png_create_read_struct_2() instead of png_create_read_struct():
1353
1354 png_structp png_ptr = png_create_read_struct_2
1355 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
1356 user_error_fn, user_warning_fn, (png_voidp)
1357 user_mem_ptr, user_malloc_fn, user_free_fn);
1358
1359The error handling routines passed to png_create_read_struct()
1360and the memory alloc/free routines passed to png_create_struct_2()
1361are only necessary if you are not using the libpng supplied error
1362handling and memory alloc/free functions.
1363
1364When libpng encounters an error, it expects to longjmp back
1365to your routine. Therefore, you will need to call setjmp and pass
1366your png_jmpbuf(png_ptr). If you read the file from different
1367routines, you will need to update the longjmp buffer every time you enter
1368a new routine that will call a png_*() function.
1369
1370See your documentation of setjmp/longjmp for your compiler for more
1371information on setjmp/longjmp. See the discussion on libpng error
1372handling in the Customizing Libpng section below for more information
1373on the libpng error handling. If an error occurs, and libpng longjmp's
1374back to your setjmp, you will want to call png_destroy_read_struct() to
1375free any memory.
1376
1377 if (setjmp(png_jmpbuf(png_ptr)))
1378 {
1379 png_destroy_read_struct(&png_ptr, &info_ptr,
1380 &end_info);
1381 fclose(fp);
1382 return (ERROR);
1383 }
1384
1385Pass (png_infopp)NULL instead of &end_info if you didn't create
1386an end_info structure.
1387
1388If you would rather avoid the complexity of setjmp/longjmp issues,
1389you can compile libpng with PNG_NO_SETJMP, in which case
1390errors will result in a call to PNG_ABORT() which defaults to abort().
1391
1392You can #define PNG_ABORT() to a function that does something
1393more useful than abort(), as long as your function does not
1394return.
1395
1396Now you need to set up the input code. The default for libpng is to
1397use the C function fread(). If you use this, you will need to pass a
1398valid FILE * in the function png_init_io(). Be sure that the file is
1399opened in binary mode. If you wish to handle reading data in another
1400way, you need not call the png_init_io() function, but you must then
1401implement the libpng I/O methods discussed in the Customizing Libpng
1402section below.
1403
1404 png_init_io(png_ptr, fp);
1405
1406If you had previously opened the file and read any of the signature from
1407the beginning in order to see if this was a PNG file, you need to let
1408libpng know that there are some bytes missing from the start of the file.
1409
1410 png_set_sig_bytes(png_ptr, number);
1411
1412You can change the zlib compression buffer size to be used while
1413reading compressed data with
1414
1415 png_set_compression_buffer_size(png_ptr, buffer_size);
1416
1417where the default size is 8192 bytes. Note that the buffer size
1418is changed immediately and the buffer is reallocated immediately,
1419instead of setting a flag to be acted upon later.
1420
1421If you want CRC errors to be handled in a different manner than
1422the default, use
1423
1424 png_set_crc_action(png_ptr, crit_action, ancil_action);
1425
1426The values for png_set_crc_action() say how libpng is to handle CRC errors in
1427ancillary and critical chunks, and whether to use the data contained
1428therein. Note that it is impossible to "discard" data in a critical
1429chunk.
1430
1431Choices for (int) crit_action are
1432 PNG_CRC_DEFAULT 0 error/quit
1433 PNG_CRC_ERROR_QUIT 1 error/quit
1434 PNG_CRC_WARN_USE 3 warn/use data
1435 PNG_CRC_QUIET_USE 4 quiet/use data
1436 PNG_CRC_NO_CHANGE 5 use the current value
1437
1438Choices for (int) ancil_action are
1439 PNG_CRC_DEFAULT 0 error/quit
1440 PNG_CRC_ERROR_QUIT 1 error/quit
1441 PNG_CRC_WARN_DISCARD 2 warn/discard data
1442 PNG_CRC_WARN_USE 3 warn/use data
1443 PNG_CRC_QUIET_USE 4 quiet/use data
1444 PNG_CRC_NO_CHANGE 5 use the current value
1445
1446.SS Setting up callback code
1447
1448You can set up a callback function to handle any unknown chunks in the
1449input stream. You must supply the function
1450
1451 read_chunk_callback(png_structp png_ptr,
1452 png_unknown_chunkp chunk);
1453 {
1454 /* The unknown chunk structure contains your
1455 chunk data, along with similar data for any other
1456 unknown chunks: */
1457
1458 png_byte name[5];
1459 png_byte *data;
1460 png_size_t size;
1461
1462 /* Note that libpng has already taken care of
1463 the CRC handling */
1464
1465 /* put your code here. Search for your chunk in the
1466 unknown chunk structure, process it, and return one
1467 of the following: */
1468
1469 return (-n); /* chunk had an error */
1470 return (0); /* did not recognize */
1471 return (n); /* success */
1472 }
1473
1474(You can give your function another name that you like instead of
1475"read_chunk_callback")
1476
1477To inform libpng about your function, use
1478
1479 png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
1480 read_chunk_callback);
1481
1482This names not only the callback function, but also a user pointer that
1483you can retrieve with
1484
1485 png_get_user_chunk_ptr(png_ptr);
1486
1487If you call the png_set_read_user_chunk_fn() function, then all unknown
1488chunks will be saved when read, in case your callback function will need
1489one or more of them. This behavior can be changed with the
1490png_set_keep_unknown_chunks() function, described below.
1491
1492At this point, you can set up a callback function that will be
1493called after each row has been read, which you can use to control
1494a progress meter or the like. It's demonstrated in pngtest.c.
1495You must supply a function
1496
1497 void read_row_callback(png_structp png_ptr,
1498 png_uint_32 row, int pass);
1499 {
1500 /* put your code here */
1501 }
1502
1503(You can give it another name that you like instead of "read_row_callback")
1504
1505To inform libpng about your function, use
1506
1507 png_set_read_status_fn(png_ptr, read_row_callback);
1508
1509When this function is called the row has already been completely processed and
1510the 'row' and 'pass' refer to the next row to be handled. For the
1511non-interlaced case the row that was just handled is simply one less than the
1512passed in row number, and pass will always be 0. For the interlaced case the
1513same applies unless the row value is 0, in which case the row just handled was
1514the last one from one of the preceding passes. Because interlacing may skip a
1515pass you cannot be sure that the preceding pass is just 'pass-1', if you really
1516need to know what the last pass is record (row,pass) from the callback and use
1517the last recorded value each time.
1518
1519As with the user transform you can find the output row using the
1520PNG_ROW_FROM_PASS_ROW macro.
1521
1522.SS Unknown-chunk handling
1523
1524Now you get to set the way the library processes unknown chunks in the
1525input PNG stream. Both known and unknown chunks will be read. Normal
1526behavior is that known chunks will be parsed into information in
1527various info_ptr members while unknown chunks will be discarded. This
1528behavior can be wasteful if your application will never use some known
1529chunk types. To change this, you can call:
1530
1531 png_set_keep_unknown_chunks(png_ptr, keep,
1532 chunk_list, num_chunks);
1533 keep - 0: default unknown chunk handling
1534 1: ignore; do not keep
1535 2: keep only if safe-to-copy
1536 3: keep even if unsafe-to-copy
1537
1538 You can use these definitions:
1539 PNG_HANDLE_CHUNK_AS_DEFAULT 0
1540 PNG_HANDLE_CHUNK_NEVER 1
1541 PNG_HANDLE_CHUNK_IF_SAFE 2
1542 PNG_HANDLE_CHUNK_ALWAYS 3
1543
1544 chunk_list - list of chunks affected (a byte string,
1545 five bytes per chunk, NULL or '\0' if
1546 num_chunks is 0)
1547
1548 num_chunks - number of chunks affected; if 0, all
1549 unknown chunks are affected. If nonzero,
1550 only the chunks in the list are affected
1551
1552Unknown chunks declared in this way will be saved as raw data onto a
1553list of png_unknown_chunk structures. If a chunk that is normally
1554known to libpng is named in the list, it will be handled as unknown,
1555according to the "keep" directive. If a chunk is named in successive
1556instances of png_set_keep_unknown_chunks(), the final instance will
1557take precedence. The IHDR and IEND chunks should not be named in
1558chunk_list; if they are, libpng will process them normally anyway.
1559If you know that your application will never make use of some particular
1560chunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.
1561
1562Here is an example of the usage of png_set_keep_unknown_chunks(),
1563where the private "vpAg" chunk will later be processed by a user chunk
1564callback function:
1565
1566 png_byte vpAg[5]={118, 112, 65, 103, (png_byte) '\0'};
1567
1568 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1569 png_byte unused_chunks[]=
1570 {
1571 104, 73, 83, 84, (png_byte) '\0', /* hIST */
1572 105, 84, 88, 116, (png_byte) '\0', /* iTXt */
1573 112, 67, 65, 76, (png_byte) '\0', /* pCAL */
1574 115, 67, 65, 76, (png_byte) '\0', /* sCAL */
1575 115, 80, 76, 84, (png_byte) '\0', /* sPLT */
1576 116, 73, 77, 69, (png_byte) '\0', /* tIME */
1577 };
1578 #endif
1579
1580 ...
1581
1582 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1583 /* ignore all unknown chunks: */
1584 png_set_keep_unknown_chunks(read_ptr, 1, NULL, 0);
1585
1586 /* except for vpAg: */
1587 png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);
1588
1589 /* also ignore unused known chunks: */
1590 png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,
1591 (int)sizeof(unused_chunks)/5);
1592 #endif
1593
1594.SS User limits
1595
1596The PNG specification allows the width and height of an image to be as
1597large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
1598Since very few applications really need to process such large images,
1599we have imposed an arbitrary 1-million limit on rows and columns.
1600Larger images will be rejected immediately with a png_error() call. If
1601you wish to change this limit, you can use
1602
1603 png_set_user_limits(png_ptr, width_max, height_max);
1604
1605to set your own limits, or use width_max = height_max = 0x7fffffffL
1606to allow all valid dimensions (libpng may reject some very large images
1607anyway because of potential buffer overflow conditions).
1608
1609You should put this statement after you create the PNG structure and
1610before calling png_read_info(), png_read_png(), or png_process_data().
1611
1612When writing a PNG datastream, put this statement before calling
1613png_write_info() or png_write_png().
1614
1615If you need to retrieve the limits that are being applied, use
1616
1617 width_max = png_get_user_width_max(png_ptr);
1618 height_max = png_get_user_height_max(png_ptr);
1619
1620The PNG specification sets no limit on the number of ancillary chunks
1621allowed in a PNG datastream. You can impose a limit on the total number
1622of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
1623
1624 png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
1625
1626where 0x7fffffffL means unlimited. You can retrieve this limit with
1627
1628 chunk_cache_max = png_get_chunk_cache_max(png_ptr);
1629
1630This limit also applies to the number of buffers that can be allocated
1631by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
1632
1633You can also set a limit on the amount of memory that a compressed chunk
1634other than IDAT can occupy, with
1635
1636 png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);
1637
1638and you can retrieve the limit with
1639
1640 chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);
1641
1642Any chunks that would cause either of these limits to be exceeded will
1643be ignored.
1644
1645.SS Information about your system
1646
1647If you intend to display the PNG or to incorporate it in other image data you
1648need to tell libpng information about your display or drawing surface so that
1649libpng can convert the values in the image to match the display.
1650
1651From libpng-1.5.4 this information can be set before reading the PNG file
1652header. In earlier versions png_set_gamma() existed but behaved incorrectly if
1653called before the PNG file header had been read and png_set_alpha_mode() did not
1654exist.
1655
1656If you need to support versions prior to libpng-1.5.4 test the version number
1657as illustrated below using "PNG_LIBPNG_VER >= 10504" and follow the procedures
1658described in the appropriate manual page.
1659
1660You give libpng the encoding expected by your system expressed as a 'gamma'
1661value. You can also specify a default encoding for the PNG file in
1662case the required information is missing from the file. By default libpng
1663assumes that the PNG data matches your system, to keep this default call:
1664
1665 png_set_gamma(png_ptr, screen_gamma, 1/screen_gamma/*file gamma*/);
1666
1667or you can use the fixed point equivalent:
1668
1669 png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma, PNG_FP_1/screen_gamma);
1670
1671If you don't know the gamma for your system it is probably 2.2 - a good
1672approximation to the IEC standard for display systems (sRGB). If images are
1673too contrasty or washed out you got the value wrong - check your system
1674documentation!
1675
1676Many systems permit the system gamma to be changed via a lookup table in the
1677display driver, a few systems, including older Macs, change the response by
1678default. As of 1.5.4 three special values are available to handle common
1679situations:
1680
1681 PNG_DEFAULT_sRGB: Indicates that the system conforms to the IEC 61966-2-1
1682 standard. This matches almost all systems.
1683 PNG_GAMMA_MAC_18: Indicates that the system is an older (pre Mac OS 10.6)
1684 Apple Macintosh system with the default settings.
1685 PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates that the
1686 system expects data with no gamma encoding.
1687
1688You would use the linear (unencoded) value if you need to process the pixel
1689values further because this avoids the need to decode and reencode each
1690component value whenever arithmetic is performed. A lot of graphics software
1691uses linear values for this reason, often with higher precision component values
1692to preserve overall accuracy.
1693
1694The second thing you may need to tell libpng about is how your system handles
1695alpha channel information. Some, but not all, PNG files contain an alpha
1696channel. To display these files correctly you need to compose the data onto a
1697suitable background, as described in the PNG specification.
1698
1699Libpng only supports composing onto a single color (using png_set_background;
1700see below). Otherwise you must do the composition yourself and, in this case,
1701you may need to call png_set_alpha_mode:
1702
1703#if PNG_LIBPNG_VER >= 10504
1704 png_set_alpha_mode(png_ptr, mode, screen_gamma);
1705#else
1706 png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);
1707#endif
1708
1709The screen_gamma value is the same as the argument to png_set_gamma; however,
1710how it affects the output depends on the mode. png_set_alpha_mode() sets the
1711file gamma default to 1/screen_gamma, so normally you don't need to call
1712png_set_gamma. If you need different defaults call png_set_gamma() before
1713png_set_alpha_mode() - if you call it after it will override the settings made
1714by png_set_alpha_mode().
1715
1716The mode is as follows:
1717
1718 PNG_ALPHA_PNG: The data is encoded according to the PNG specification. Red,
1719green and blue, or gray, components are gamma encoded color
1720values and are not premultiplied by the alpha value. The
1721alpha value is a linear measure of the contribution of the
1722pixel to the corresponding final output pixel.
1723
1724You should normally use this format if you intend to perform
1725color correction on the color values; most, maybe all, color
1726correction software has no handling for the alpha channel and,
1727anyway, the math to handle pre-multiplied component values is
1728unnecessarily complex.
1729
1730Before you do any arithmetic on the component values you need
1731to remove the gamma encoding and multiply out the alpha
1732channel. See the PNG specification for more detail. It is
1733important to note that when an image with an alpha channel is
1734scaled, linear encoded, pre-multiplied component values must
1735be used!
1736
1737The remaining modes assume you don't need to do any further color correction or
1738that if you do, your color correction software knows all about alpha (it
1739probably doesn't!)
1740
1741 PNG_ALPHA_STANDARD: The data libpng produces
1742is encoded in the standard way
1743assumed by most correctly written graphics software.
1744The gamma encoding will be removed by libpng and the
1745linear component values will be pre-multiplied by the
1746alpha channel.
1747
1748With this format the final image must be re-encoded to
1749match the display gamma before the image is displayed.
1750If your system doesn't do that, yet still seems to
1751perform arithmetic on the pixels without decoding them,
1752it is broken - check out the modes below.
1753
1754With PNG_ALPHA_STANDARD libpng always produces linear
1755component values, whatever screen_gamma you supply. The
1756screen_gamma value is, however, used as a default for
1757the file gamma if the PNG file has no gamma information.
1758
1759If you call png_set_gamma() after png_set_alpha_mode() you
1760will override the linear encoding. Instead the
1761pre-multiplied pixel values will be gamma encoded but
1762the alpha channel will still be linear. This may
1763actually match the requirements of some broken software,
1764but it is unlikely.
1765
1766While linear 8-bit data is often used it has
1767insufficient precision for any image with a reasonable
1768dynamic range. To avoid problems, and if your software
1769supports it, use png_set_expand_16() to force all
1770components to 16 bits.
1771
1772 PNG_ALPHA_OPTIMIZED: This mode is the same
1773as PNG_ALPHA_STANDARD except that
1774completely opaque pixels are gamma encoded according to
1775the screen_gamma value. Pixels with alpha less than 1.0
1776will still have linear components.
1777
1778Use this format if you have control over your
1779compositing software and do don't do other arithmetic
1780(such as scaling) on the data you get from libpng. Your
1781compositing software can simply copy opaque pixels to
1782the output but still has linear values for the
1783non-opaque pixels.
1784
1785In normal compositing, where the alpha channel encodes
1786partial pixel coverage (as opposed to broad area
1787translucency), the inaccuracies of the 8-bit
1788representation of non-opaque pixels are irrelevant.
1789
1790You can also try this format if your software is broken;
1791it might look better.
1792
1793 PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD;
1794however, all component values,
1795including the alpha channel are gamma encoded. This is
1796an appropriate format to try if your software, or more
1797likely hardware, is totally broken, i.e., if it performs
1798linear arithmetic directly on gamma encoded values.
1799
1800In most cases of broken software or hardware the bug in the final display
1801manifests as a subtle halo around composited parts of the image. You may not
1802even perceive this as a halo; the composited part of the image may simply appear
1803separate from the background, as though it had been cut out of paper and pasted
1804on afterward.
1805
1806If you don't have to deal with bugs in software or hardware, or if you can fix
1807them, there are three recommended ways of using png_set_alpha_mode():
1808
1809 png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,
1810 screen_gamma);
1811
1812You can do color correction on the result (libpng does not currently
1813support color correction internally). When you handle the alpha channel
1814you need to undo the gamma encoding and multiply out the alpha.
1815
1816 png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,
1817 screen_gamma);
1818 png_set_expand_16(png_ptr);
1819
1820If you are using the high level interface, don't call png_set_expand_16();
1821instead pass PNG_TRANSFORM_EXPAND_16 to the interface.
1822
1823With this mode you can't do color correction, but you can do arithmetic,
1824including composition and scaling, on the data without further processing.
1825
1826 png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,
1827 screen_gamma);
1828
1829You can avoid the expansion to 16-bit components with this mode, but you
1830lose the ability to scale the image or perform other linear arithmetic.
1831All you can do is compose the result onto a matching output. Since this
1832mode is libpng-specific you also need to write your own composition
1833software.
1834
1835If you don't need, or can't handle, the alpha channel you can call
1836png_set_background() to remove it by compositing against a fixed color. Don't
1837call png_set_strip_alpha() to do this - it will leave spurious pixel values in
1838transparent parts of this image.
1839
1840 png_set_background(png_ptr, &background_color,
1841 PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);
1842
1843The background_color is an RGB or grayscale value according to the data format
1844libpng will produce for you. Because you don't yet know the format of the PNG
1845file, if you call png_set_background at this point you must arrange for the
1846format produced by libpng to always have 8-bit or 16-bit components and then
1847store the color as an 8-bit or 16-bit color as appropriate. The color contains
1848separate gray and RGB component values, so you can let libpng produce gray or
1849RGB output according to the input format, but low bit depth grayscale images
1850must always be converted to at least 8-bit format. (Even though low bit depth
1851grayscale images can't have an alpha channel they can have a transparent
1852color!)
1853
1854You set the transforms you need later, either as flags to the high level
1855interface or libpng API calls for the low level interface. For reference the
1856settings and API calls required are:
1857
18588-bit values:
1859 PNG_TRANSFORM_SCALE_16 | PNG_EXPAND
1860 png_set_expand(png_ptr); png_set_scale_16(png_ptr);
1861
1862 If you must get exactly the same inaccurate results
1863 produced by default in versions prior to libpng-1.5.4,
1864 use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)
1865 instead.
1866
186716-bit values:
1868 PNG_TRANSFORM_EXPAND_16
1869 png_set_expand_16(png_ptr);
1870
1871In either case palette image data will be expanded to RGB. If you just want
1872color data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)
1873to the list.
1874
1875Calling png_set_background before the PNG file header is read will not work
1876prior to libpng-1.5.4. Because the failure may result in unexpected warnings or
1877errors it is therefore much safer to call png_set_background after the head has
1878been read. Unfortunately this means that prior to libpng-1.5.4 it cannot be
1879used with the high level interface.
1880
1881.SS The high-level read interface
1882
1883At this point there are two ways to proceed; through the high-level
1884read interface, or through a sequence of low-level read operations.
1885You can use the high-level interface if (a) you are willing to read
1886the entire image into memory, and (b) the input transformations
1887you want to do are limited to the following set:
1888
1889 PNG_TRANSFORM_IDENTITY No transformation
1890 PNG_TRANSFORM_SCALE_16 Strip 16-bit samples to
1891 8-bit accurately
1892 PNG_TRANSFORM_STRIP_16 Chop 16-bit samples to
1893 8-bit less accurately
1894 PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
1895 PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
1896 samples to bytes
1897 PNG_TRANSFORM_PACKSWAP Change order of packed
1898 pixels to LSB first
1899 PNG_TRANSFORM_EXPAND Perform set_expand()
1900 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
1901 PNG_TRANSFORM_SHIFT Normalize pixels to the
1902 sBIT depth
1903 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
1904 to BGRA
1905 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
1906 to AG
1907 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
1908 to transparency
1909 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
1910 PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
1911 to RGB (or GA to RGBA)
1912 PNG_TRANSFORM_EXPAND_16 Expand samples to 16 bits
1913
1914(This excludes setting a background color, doing gamma transformation,
1915quantizing, and setting filler.) If this is the case, simply do this:
1916
1917 png_read_png(png_ptr, info_ptr, png_transforms, NULL)
1918
1919where png_transforms is an integer containing the bitwise OR of some
1920set of transformation flags. This call is equivalent to png_read_info(),
1921followed the set of transformations indicated by the transform mask,
1922then png_read_image(), and finally png_read_end().
1923
1924(The final parameter of this call is not yet used. Someday it might point
1925to transformation parameters required by some future input transform.)
1926
1927You must use png_transforms and not call any png_set_transform() functions
1928when you use png_read_png().
1929
1930After you have called png_read_png(), you can retrieve the image data
1931with
1932
1933 row_pointers = png_get_rows(png_ptr, info_ptr);
1934
1935where row_pointers is an array of pointers to the pixel data for each row:
1936
1937 png_bytep row_pointers[height];
1938
1939If you know your image size and pixel size ahead of time, you can allocate
1940row_pointers prior to calling png_read_png() with
1941
1942 if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
1943 png_error (png_ptr,
1944 "Image is too tall to process in memory");
1945
1946 if (width > PNG_UINT_32_MAX/pixel_size)
1947 png_error (png_ptr,
1948 "Image is too wide to process in memory");
1949
1950 row_pointers = png_malloc(png_ptr,
1951 height*png_sizeof(png_bytep));
1952
1953 for (int i=0; i<height, i++)
1954 row_pointers[i]=NULL; /* security precaution */
1955
1956 for (int i=0; i<height, i++)
1957 row_pointers[i]=png_malloc(png_ptr,
1958 width*pixel_size);
1959
1960 png_set_rows(png_ptr, info_ptr, &row_pointers);
1961
1962Alternatively you could allocate your image in one big block and define
1963row_pointers[i] to point into the proper places in your block.
1964
1965If you use png_set_rows(), the application is responsible for freeing
1966row_pointers (and row_pointers[i], if they were separately allocated).
1967
1968If you don't allocate row_pointers ahead of time, png_read_png() will
1969do it, and it'll be free'ed by libpng when you call png_destroy_*().
1970
1971.SS The low-level read interface
1972
1973If you are going the low-level route, you are now ready to read all
1974the file information up to the actual image data. You do this with a
1975call to png_read_info().
1976
1977 png_read_info(png_ptr, info_ptr);
1978
1979This will process all chunks up to but not including the image data.
1980
1981This also copies some of the data from the PNG file into the decode structure
1982for use in later transformations. Important information copied in is:
1983
19841) The PNG file gamma from the gAMA chunk. This overwrites the default value
1985provided by an earlier call to png_set_gamma or png_set_alpha_mode.
1986
19872) Prior to libpng-1.5.4 the background color from a bKGd chunk. This
1988damages the information provided by an earlier call to png_set_background
1989resulting in unexpected behavior. Libpng-1.5.4 no longer does this.
1990
19913) The number of significant bits in each component value. Libpng uses this to
1992optimize gamma handling by reducing the internal lookup table sizes.
1993
19944) The transparent color information from a tRNS chunk. This can be modified by
1995a later call to png_set_tRNS.
1996
1997.SS Querying the info structure
1998
1999Functions are used to get the information from the info_ptr once it
2000has been read. Note that these fields may not be completely filled
2001in until png_read_end() has read the chunk data following the image.
2002
2003 png_get_IHDR(png_ptr, info_ptr, &width, &height,
2004 &bit_depth, &color_type, &interlace_type,
2005 &compression_type, &filter_method);
2006
2007 width - holds the width of the image
2008 in pixels (up to 2^31).
2009
2010 height - holds the height of the image
2011 in pixels (up to 2^31).
2012
2013 bit_depth - holds the bit depth of one of the
2014 image channels. (valid values are
2015 1, 2, 4, 8, 16 and depend also on
2016 the color_type. See also
2017 significant bits (sBIT) below).
2018
2019 color_type - describes which color/alpha channels
2020 are present.
2021 PNG_COLOR_TYPE_GRAY
2022 (bit depths 1, 2, 4, 8, 16)
2023 PNG_COLOR_TYPE_GRAY_ALPHA
2024 (bit depths 8, 16)
2025 PNG_COLOR_TYPE_PALETTE
2026 (bit depths 1, 2, 4, 8)
2027 PNG_COLOR_TYPE_RGB
2028 (bit_depths 8, 16)
2029 PNG_COLOR_TYPE_RGB_ALPHA
2030 (bit_depths 8, 16)
2031
2032 PNG_COLOR_MASK_PALETTE
2033 PNG_COLOR_MASK_COLOR
2034 PNG_COLOR_MASK_ALPHA
2035
2036 interlace_type - (PNG_INTERLACE_NONE or
2037 PNG_INTERLACE_ADAM7)
2038
2039 compression_type - (must be PNG_COMPRESSION_TYPE_BASE
2040 for PNG 1.0)
2041
2042 filter_method - (must be PNG_FILTER_TYPE_BASE
2043 for PNG 1.0, and can also be
2044 PNG_INTRAPIXEL_DIFFERENCING if
2045 the PNG datastream is embedded in
2046 a MNG-1.0 datastream)
2047
2048 Any or all of interlace_type, compression_type, or
2049 filter_method can be NULL if you are
2050 not interested in their values.
2051
2052 Note that png_get_IHDR() returns 32-bit data into
2053 the application's width and height variables.
2054 This is an unsafe situation if these are 16-bit
2055 variables. In such situations, the
2056 png_get_image_width() and png_get_image_height()
2057 functions described below are safer.
2058
2059 width = png_get_image_width(png_ptr,
2060 info_ptr);
2061
2062 height = png_get_image_height(png_ptr,
2063 info_ptr);
2064
2065 bit_depth = png_get_bit_depth(png_ptr,
2066 info_ptr);
2067
2068 color_type = png_get_color_type(png_ptr,
2069 info_ptr);
2070
2071 interlace_type = png_get_interlace_type(png_ptr,
2072 info_ptr);
2073
2074 compression_type = png_get_compression_type(png_ptr,
2075 info_ptr);
2076
2077 filter_method = png_get_filter_type(png_ptr,
2078 info_ptr);
2079
2080 channels = png_get_channels(png_ptr, info_ptr);
2081
2082 channels - number of channels of info for the
2083 color type (valid values are 1 (GRAY,
2084 PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
2085 4 (RGB_ALPHA or RGB + filler byte))
2086
2087 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
2088
2089 rowbytes - number of bytes needed to hold a row
2090
2091 signature = png_get_signature(png_ptr, info_ptr);
2092
2093 signature - holds the signature read from the
2094 file (if any). The data is kept in
2095 the same offset it would be if the
2096 whole signature were read (i.e. if an
2097 application had already read in 4
2098 bytes of signature before starting
2099 libpng, the remaining 4 bytes would
2100 be in signature[4] through signature[7]
2101 (see png_set_sig_bytes())).
2102
2103These are also important, but their validity depends on whether the chunk
2104has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
2105png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
2106data has been read, or zero if it is missing. The parameters to the
2107png_get_<chunk> are set directly if they are simple data types, or a
2108pointer into the info_ptr is returned for any complex types.
2109
2110 png_get_PLTE(png_ptr, info_ptr, &palette,
2111 &num_palette);
2112
2113 palette - the palette for the file
2114 (array of png_color)
2115
2116 num_palette - number of entries in the palette
2117
2118 png_get_gAMA(png_ptr, info_ptr, &file_gamma);
2119 png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);
2120
2121 file_gamma - the gamma at which the file is
2122 written (PNG_INFO_gAMA)
2123
2124 int_file_gamma - 100,000 times the gamma at which the
2125 file is written
2126
2127 png_get_cHRM(png_ptr, info_ptr, &white_x, &white_y, &red_x, &red_y,
2128 &green_x, &green_y, &blue_x, &blue_y)
2129 png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z, &green_X,
2130 &green_Y, &green_Z, &blue_X, &blue_Y, &blue_Z)
2131 png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x, &int_white_y,
2132 &int_red_x, &int_red_y, &int_green_x, &int_green_y,
2133 &int_blue_x, &int_blue_y)
2134 png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,
2135 &int_red_Z, &int_green_X, &int_green_Y, &int_green_Z,
2136 &int_blue_X, &int_blue_Y, &int_blue_Z)
2137
2138 {white,red,green,blue}_{x,y}
2139 A color space encoding specified using the chromaticities
2140 of the end points and the white point. (PNG_INFO_cHRM)
2141
2142 {red,green,blue}_{X,Y,Z}
2143 A color space encoding specified using the encoding end
2144 points - the CIE tristimulus specification of the intended
2145 color of the red, green and blue channels in the PNG RGB
2146 data. The white point is simply the sum of the three end
2147 points. (PNG_INFO_cHRM)
2148
2149 png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
2150
2151 file_srgb_intent - the rendering intent (PNG_INFO_sRGB)
2152 The presence of the sRGB chunk
2153 means that the pixel data is in the
2154 sRGB color space. This chunk also
2155 implies specific values of gAMA and
2156 cHRM.
2157
2158 png_get_iCCP(png_ptr, info_ptr, &name,
2159 &compression_type, &profile, &proflen);
2160
2161 name - The profile name.
2162
2163 compression_type - The compression type; always
2164 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
2165 You may give NULL to this argument to
2166 ignore it.
2167
2168 profile - International Color Consortium color
2169 profile data. May contain NULs.
2170
2171 proflen - length of profile data in bytes.
2172
2173 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
2174
2175 sig_bit - the number of significant bits for
2176 (PNG_INFO_sBIT) each of the gray,
2177 red, green, and blue channels,
2178 whichever are appropriate for the
2179 given color type (png_color_16)
2180
2181 png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
2182 &num_trans, &trans_color);
2183
2184 trans_alpha - array of alpha (transparency)
2185 entries for palette (PNG_INFO_tRNS)
2186
2187 num_trans - number of transparent entries
2188 (PNG_INFO_tRNS)
2189
2190 trans_color - graylevel or color sample values of
2191 the single transparent color for
2192 non-paletted images (PNG_INFO_tRNS)
2193
2194 png_get_hIST(png_ptr, info_ptr, &hist);
2195 (PNG_INFO_hIST)
2196
2197 hist - histogram of palette (array of
2198 png_uint_16)
2199
2200 png_get_tIME(png_ptr, info_ptr, &mod_time);
2201
2202 mod_time - time image was last modified
2203 (PNG_VALID_tIME)
2204
2205 png_get_bKGD(png_ptr, info_ptr, &background);
2206
2207 background - background color (of type
2208 png_color_16p) (PNG_VALID_bKGD)
2209 valid 16-bit red, green and blue
2210 values, regardless of color_type
2211
2212 num_comments = png_get_text(png_ptr, info_ptr,
2213 &text_ptr, &num_text);
2214
2215 num_comments - number of comments
2216
2217 text_ptr - array of png_text holding image
2218 comments
2219
2220 text_ptr[i].compression - type of compression used
2221 on "text" PNG_TEXT_COMPRESSION_NONE
2222 PNG_TEXT_COMPRESSION_zTXt
2223 PNG_ITXT_COMPRESSION_NONE
2224 PNG_ITXT_COMPRESSION_zTXt
2225
2226 text_ptr[i].key - keyword for comment. Must contain
2227 1-79 characters.
2228
2229 text_ptr[i].text - text comments for current
2230 keyword. Can be empty.
2231
2232 text_ptr[i].text_length - length of text string,
2233 after decompression, 0 for iTXt
2234
2235 text_ptr[i].itxt_length - length of itxt string,
2236 after decompression, 0 for tEXt/zTXt
2237
2238 text_ptr[i].lang - language of comment (empty
2239 string for unknown).
2240
2241 text_ptr[i].lang_key - keyword in UTF-8
2242 (empty string for unknown).
2243
2244 Note that the itxt_length, lang, and lang_key
2245 members of the text_ptr structure only exist when the
2246 library is built with iTXt chunk support. Prior to
2247 libpng-1.4.0 the library was built by default without
2248 iTXt support. Also note that when iTXt is supported,
2249 they contain NULL pointers when the "compression"
2250 field contains PNG_TEXT_COMPRESSION_NONE or
2251 PNG_TEXT_COMPRESSION_zTXt.
2252
2253 num_text - number of comments (same as
2254 num_comments; you can put NULL here
2255 to avoid the duplication)
2256
2257 Note while png_set_text() will accept text, language,
2258 and translated keywords that can be NULL pointers, the
2259 structure returned by png_get_text will always contain
2260 regular zero-terminated C strings. They might be
2261 empty strings but they will never be NULL pointers.
2262
2263 num_spalettes = png_get_sPLT(png_ptr, info_ptr,
2264 &palette_ptr);
2265
2266 num_spalettes - number of sPLT chunks read.
2267
2268 palette_ptr - array of palette structures holding
2269 contents of one or more sPLT chunks
2270 read.
2271
2272 png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
2273 &unit_type);
2274
2275 offset_x - positive offset from the left edge
2276 of the screen (can be negative)
2277
2278 offset_y - positive offset from the top edge
2279 of the screen (can be negative)
2280
2281 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
2282
2283 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
2284 &unit_type);
2285
2286 res_x - pixels/unit physical resolution in
2287 x direction
2288
2289 res_y - pixels/unit physical resolution in
2290 x direction
2291
2292 unit_type - PNG_RESOLUTION_UNKNOWN,
2293 PNG_RESOLUTION_METER
2294
2295 png_get_sCAL(png_ptr, info_ptr, &unit, &width,
2296 &height)
2297
2298 unit - physical scale units (an integer)
2299
2300 width - width of a pixel in physical scale units
2301
2302 height - height of a pixel in physical scale units
2303 (width and height are doubles)
2304
2305 png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
2306 &height)
2307
2308 unit - physical scale units (an integer)
2309
2310 width - width of a pixel in physical scale units
2311 (expressed as a string)
2312
2313 height - height of a pixel in physical scale units
2314 (width and height are strings like "2.54")
2315
2316 num_unknown_chunks = png_get_unknown_chunks(png_ptr,
2317 info_ptr, &unknowns)
2318
2319 unknowns - array of png_unknown_chunk
2320 structures holding unknown chunks
2321
2322 unknowns[i].name - name of unknown chunk
2323
2324 unknowns[i].data - data of unknown chunk
2325
2326 unknowns[i].size - size of unknown chunk's data
2327
2328 unknowns[i].location - position of chunk in file
2329
2330 The value of "i" corresponds to the order in which the
2331 chunks were read from the PNG file or inserted with the
2332 png_set_unknown_chunks() function.
2333
2334 The value of "location" is a bitwise "or" of
2335
2336 PNG_HAVE_IHDR (0x01)
2337 PNG_HAVE_PLTE (0x02)
2338 PNG_AFTER_IDAT (0x08)
2339
2340The data from the pHYs chunk can be retrieved in several convenient
2341forms:
2342
2343 res_x = png_get_x_pixels_per_meter(png_ptr,
2344 info_ptr)
2345
2346 res_y = png_get_y_pixels_per_meter(png_ptr,
2347 info_ptr)
2348
2349 res_x_and_y = png_get_pixels_per_meter(png_ptr,
2350 info_ptr)
2351
2352 res_x = png_get_x_pixels_per_inch(png_ptr,
2353 info_ptr)
2354
2355 res_y = png_get_y_pixels_per_inch(png_ptr,
2356 info_ptr)
2357
2358 res_x_and_y = png_get_pixels_per_inch(png_ptr,
2359 info_ptr)
2360
2361 aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
2362 info_ptr)
2363
2364 Each of these returns 0 [signifying "unknown"] if
2365 the data is not present or if res_x is 0;
2366 res_x_and_y is 0 if res_x != res_y
2367
2368 Note that because of the way the resolutions are
2369 stored internally, the inch conversions won't
2370 come out to exactly even number. For example,
2371 72 dpi is stored as 0.28346 pixels/meter, and
2372 when this is retrieved it is 71.9988 dpi, so
2373 be sure to round the returned value appropriately
2374 if you want to display a reasonable-looking result.
2375
2376The data from the oFFs chunk can be retrieved in several convenient
2377forms:
2378
2379 x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
2380
2381 y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
2382
2383 x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
2384
2385 y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
2386
2387 Each of these returns 0 [signifying "unknown" if both
2388 x and y are 0] if the data is not present or if the
2389 chunk is present but the unit is the pixel. The
2390 remark about inexact inch conversions applies here
2391 as well, because a value in inches can't always be
2392 converted to microns and back without some loss
2393 of precision.
2394
2395For more information, see the
2396PNG specification for chunk contents. Be careful with trusting
2397rowbytes, as some of the transformations could increase the space
2398needed to hold a row (expand, filler, gray_to_rgb, etc.).
2399See png_read_update_info(), below.
2400
2401A quick word about text_ptr and num_text. PNG stores comments in
2402keyword/text pairs, one pair per chunk, with no limit on the number
2403of text chunks, and a 2^31 byte limit on their size. While there are
2404suggested keywords, there is no requirement to restrict the use to these
2405strings. It is strongly suggested that keywords and text be sensible
2406to humans (that's the point), so don't use abbreviations. Non-printing
2407symbols are not allowed. See the PNG specification for more details.
2408There is also no requirement to have text after the keyword.
2409
2410Keywords should be limited to 79 Latin-1 characters without leading or
2411trailing spaces, but non-consecutive spaces are allowed within the
2412keyword. It is possible to have the same keyword any number of times.
2413The text_ptr is an array of png_text structures, each holding a
2414pointer to a language string, a pointer to a keyword and a pointer to
2415a text string. The text string, language code, and translated
2416keyword may be empty or NULL pointers. The keyword/text
2417pairs are put into the array in the order that they are received.
2418However, some or all of the text chunks may be after the image, so, to
2419make sure you have read all the text chunks, don't mess with these
2420until after you read the stuff after the image. This will be
2421mentioned again below in the discussion that goes with png_read_end().
2422
2423.SS Input transformations
2424
2425After you've read the header information, you can set up the library
2426to handle any special transformations of the image data. The various
2427ways to transform the data will be described in the order that they
2428should occur. This is important, as some of these change the color
2429type and/or bit depth of the data, and some others only work on
2430certain color types and bit depths.
2431
2432Transformations you request are ignored if they don't have any meaning for a
2433particular input data format. However some transformations can have an effect
2434as a result of a previous transformation. If you specify a contradictory set of
2435transformations, for example both adding and removing the alpha channel, you
2436cannot predict the final result.
2437
2438The color used for the transparency values should be supplied in the same
2439format/depth as the current image data. It is stored in the same format/depth
2440as the image data in a tRNS chunk, so this is what libpng expects for this data.
2441
2442The color used for the background value depends on the need_expand argument as
2443described below.
2444
2445Data will be decoded into the supplied row buffers packed into bytes
2446unless the library has been told to transform it into another format.
2447For example, 4 bit/pixel paletted or grayscale data will be returned
24482 pixels/byte with the leftmost pixel in the high-order bits of the
2449byte, unless png_set_packing() is called. 8-bit RGB data will be stored
2450in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
2451is called to insert filler bytes, either before or after each RGB triplet.
245216-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
2453byte of the color value first, unless png_set_scale_16() is called to
2454transform it to regular RGB RGB triplets, or png_set_filler() or
2455png_set_add alpha() is called to insert filler bytes, either before or
2456after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
2457be modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),
2458or png_set_scale_16().
2459
2460The following code transforms grayscale images of less than 8 to 8 bits,
2461changes paletted images to RGB, and adds a full alpha channel if there is
2462transparency information in a tRNS chunk. This is most useful on
2463grayscale images with bit depths of 2 or 4 or if there is a multiple-image
2464viewing application that wishes to treat all images in the same way.
2465
2466 if (color_type == PNG_COLOR_TYPE_PALETTE)
2467 png_set_palette_to_rgb(png_ptr);
2468
2469 if (png_get_valid(png_ptr, info_ptr,
2470 PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
2471
2472 if (color_type == PNG_COLOR_TYPE_GRAY &&
2473 bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
2474
2475The first two functions are actually aliases for png_set_expand(), added
2476in libpng version 1.0.4, with the function names expanded to improve code
2477readability. In some future version they may actually do different
2478things.
2479
2480As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
2481added. It expands the sample depth without changing tRNS to alpha.
2482
2483As of libpng version 1.5.2, png_set_expand_16() was added. It behaves as
2484png_set_expand(); however, the resultant channels have 16 bits rather than 8.
2485Use this when the output color or gray channels are made linear to avoid fairly
2486severe accuracy loss.
2487
2488 if (bit_depth < 16)
2489 png_set_expand_16(png_ptr);
2490
2491PNG can have files with 16 bits per channel. If you only can handle
24928 bits per channel, this will strip the pixels down to 8-bit.
2493
2494 if (bit_depth == 16)
2495#if PNG_LIBPNG_VER >= 10504
2496 png_set_scale_16(png_ptr);
2497#else
2498 png_set_strip_16(png_ptr);
2499#endif
2500
2501(The more accurate "png_set_scale_16()" API became available in libpng version
25021.5.4).
2503
2504If you need to process the alpha channel on the image separately from the image
2505data (for example if you convert it to a bitmap mask) it is possible to have
2506libpng strip the channel leaving just RGB or gray data:
2507
2508 if (color_type & PNG_COLOR_MASK_ALPHA)
2509 png_set_strip_alpha(png_ptr);
2510
2511If you strip the alpha channel you need to find some other way of dealing with
2512the information. If, instead, you want to convert the image to an opaque
2513version with no alpha channel use png_set_background; see below.
2514
2515As of libpng version 1.5.2, almost all useful expansions are supported, the
2516major ommissions are conversion of grayscale to indexed images (which can be
2517done trivially in the application) and conversion of indexed to grayscale (which
2518can be done by a trivial manipulation of the palette.)
2519
2520In the following table, the 01 means grayscale with depth<8, 31 means
2521indexed with depth<8, other numerals represent the color type, "T" means
2522the tRNS chunk is present, A means an alpha channel is present, and O
2523means tRNS or alpha is present but all pixels in the image are opaque.
2524
2525 FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
2526 TO
2527 01 - [G] - - - - - - - - - - - - -
2528 31 [Q] Q [Q] [Q] [Q] Q Q Q Q Q Q [Q] [Q] Q Q
2529 0 1 G + . . G G G G G G B B GB GB
2530 0T lt Gt t + . Gt G G Gt G G Bt Bt GBt GBt
2531 0O lt Gt t . + Gt Gt G Gt Gt G Bt Bt GBt GBt
2532 2 C P C C C + . . C - - CB CB B B
2533 2T Ct - Ct C C t + t - - - CBt CBt Bt Bt
2534 2O Ct - Ct C C t t + - - - CBt CBt Bt Bt
2535 3 [Q] p [Q] [Q] [Q] Q Q Q + . . [Q] [Q] Q Q
2536 3T [Qt] p [Qt][Q] [Q] Qt Qt Qt t + t [Qt][Qt] Qt Qt
2537 3O [Qt] p [Qt][Q] [Q] Qt Qt Qt t t + [Qt][Qt] Qt Qt
2538 4A lA G A T T GA GT GT GA GT GT + BA G GBA
2539 4O lA GBA A T T GA GT GT GA GT GT BA + GBA G
2540 6A CA PA CA C C A T tT PA P P C CBA + BA
2541 6O CA PBA CA C C A tT T PA P P CBA C BA +
2542
2543Within the matrix,
2544 "+" identifies entries where 'from' and 'to' are the same.
2545 "-" means the transformation is not supported.
2546 "." means nothing is necessary (a tRNS chunk can just be ignored).
2547 "t" means the transformation is obtained by png_set_tRNS.
2548 "A" means the transformation is obtained by png_set_add_alpha().
2549 "X" means the transformation is obtained by png_set_expand().
2550 "1" means the transformation is obtained by
2551 png_set_expand_gray_1_2_4_to_8() (and by png_set_expand() if there
2552 is no transparency in the original or the final format).
2553 "C" means the transformation is obtained by png_set_gray_to_rgb().
2554 "G" means the transformation is obtained by png_set_rgb_to_gray().
2555 "P" means the transformation is obtained by
2556 png_set_expand_palette_to_rgb().
2557 "p" means the transformation is obtained by png_set_packing().
2558 "Q" means the transformation is obtained by png_set_quantize().
2559 "T" means the transformation is obtained by png_set_tRNS_to_alpha().
2560 "B" means the transformation is obtained by png_set_background(), or
2561 png_strip_alpha().
2562
2563When an entry has multiple transforms listed all are required to cause the
2564right overall transformation. When two transforms are separated by a comma
2565either will do the job. When transforms are enclosed in [] the transform should
2566do the job but this is currently unimplemented - a different format will result
2567if the suggested transformations are used.
2568
2569In PNG files, the alpha channel in an image
2570is the level of opacity. If you need the alpha channel in an image to
2571be the level of transparency instead of opacity, you can invert the
2572alpha channel (or the tRNS chunk data) after it's read, so that 0 is
2573fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
2574images) is fully transparent, with
2575
2576 png_set_invert_alpha(png_ptr);
2577
2578PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
2579they can, resulting in, for example, 8 pixels per byte for 1 bit
2580files. This code expands to 1 pixel per byte without changing the
2581values of the pixels:
2582
2583 if (bit_depth < 8)
2584 png_set_packing(png_ptr);
2585
2586PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
2587stored in a PNG image have been "scaled" or "shifted" up to the next
2588higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
2589to 8 bits/sample in the range [0, 255]). However, it is also possible
2590to convert the PNG pixel data back to the original bit depth of the
2591image. This call reduces the pixels back down to the original bit depth:
2592
2593 png_color_8p sig_bit;
2594
2595 if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
2596 png_set_shift(png_ptr, sig_bit);
2597
2598PNG files store 3-color pixels in red, green, blue order. This code
2599changes the storage of the pixels to blue, green, red:
2600
2601 if (color_type == PNG_COLOR_TYPE_RGB ||
2602 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2603 png_set_bgr(png_ptr);
2604
2605PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
2606into 4 or 8 bytes for windowing systems that need them in this format:
2607
2608 if (color_type == PNG_COLOR_TYPE_RGB)
2609 png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
2610
2611where "filler" is the 8 or 16-bit number to fill with, and the location is
2612either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
2613you want the filler before the RGB or after. This transformation
2614does not affect images that already have full alpha channels. To add an
2615opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
2616will generate RGBA pixels.
2617
2618Note that png_set_filler() does not change the color type. If you want
2619to do that, you can add a true alpha channel with
2620
2621 if (color_type == PNG_COLOR_TYPE_RGB ||
2622 color_type == PNG_COLOR_TYPE_GRAY)
2623 png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
2624
2625where "filler" contains the alpha value to assign to each pixel.
2626This function was added in libpng-1.2.7.
2627
2628If you are reading an image with an alpha channel, and you need the
2629data as ARGB instead of the normal PNG format RGBA:
2630
2631 if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2632 png_set_swap_alpha(png_ptr);
2633
2634For some uses, you may want a grayscale image to be represented as
2635RGB. This code will do that conversion:
2636
2637 if (color_type == PNG_COLOR_TYPE_GRAY ||
2638 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2639 png_set_gray_to_rgb(png_ptr);
2640
2641Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
2642with alpha.
2643
2644 if (color_type == PNG_COLOR_TYPE_RGB ||
2645 color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2646 png_set_rgb_to_gray(png_ptr, error_action, double red_weight,
2647 double green_weight);
2648
2649 error_action = 1: silently do the conversion
2650
2651 error_action = 2: issue a warning if the original
2652 image has any pixel where
2653 red != green or red != blue
2654
2655 error_action = 3: issue an error and abort the
2656 conversion if the original
2657 image has any pixel where
2658 red != green or red != blue
2659
2660 red_weight: weight of red component
2661
2662 green_weight: weight of green component
2663 If either weight is negative, default
2664 weights are used.
2665
2666In the corresponding fixed point API the red_weight and green_weight values are
2667simply scaled by 100,000:
2668
2669 png_set_rgb_to_gray(png_ptr, error_action, png_fixed_point red_weight,
2670 png_fixed_point green_weight);
2671
2672If you have set error_action = 1 or 2, you can
2673later check whether the image really was gray, after processing
2674the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
2675It will return a png_byte that is zero if the image was gray or
26761 if there were any non-gray pixels. Background and sBIT data
2677will be silently converted to grayscale, using the green channel
2678data for sBIT, regardless of the error_action setting.
2679
2680The default values come from the PNG file cHRM chunk if present; otherwise, the
2681defaults correspond to the ITU-R recommendation 709, and also the sRGB color
2682space, as recommended in the Charles Poynton's Colour FAQ,
2683<http://www.poynton.com/>, in section 9:
2684
2685 <http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>
2686
2687 Y = 0.2126 * R + 0.7152 * G + 0.0722 * B
2688
2689Previous versions of this document, 1998 through 2002, recommended a slightly
2690different formula:
2691
2692 Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2693
2694Libpng uses an integer approximation:
2695
2696 Y = (6968 * R + 23434 * G + 2366 * B)/32768
2697
2698The calculation is done in a linear colorspace, if the image gamma
2699can be determined.
2700
2701The png_set_background() function has been described already; it tells libpng to
2702composite images with alpha or simple transparency against the supplied
2703background color. For compatibility with versions of libpng earlier than
2704libpng-1.5.4 it is recommended that you call the function after reading the file
2705header, even if you don't want to use the color in a bKGD chunk, if one exists.
2706
2707If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
2708you may use this color, or supply another color more suitable for
2709the current display (e.g., the background color from a web page). You
2710need to tell libpng how the color is represented, both the format of the
2711component values in the color (the number of bits) and the gamma encoding of the
2712color. The function takes two arguments, background_gamma_mode and need_expand
2713to convey this information, however only two combinations are likely to be
2714useful:
2715
2716 png_color_16 my_background;
2717 png_color_16p image_background;
2718
2719 if (png_get_bKGD(png_ptr, info_ptr, &image_background))
2720 png_set_background(png_ptr, image_background,
2721 PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);
2722 else
2723 png_set_background(png_ptr, &my_background,
2724 PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);
2725
2726The second call was described above - my_background is in the format of the
2727final, display, output produced by libpng. Because you now know the format of
2728the PNG it is possible to avoid the need to choose either 8-bit or 16-bit
2729output and to retain palette images (the palette colors will be modified
2730appropriately and the tRNS chunk removed.) However, if you are doing this,
2731take great care not to ask for transformations without checking first that
2732they apply!
2733
2734In the first call the background color has the original bit depth and color type
2735of the PNG file. So, for palette images the color is supplied as a palette
2736index and for low bit greyscale images the color is a reduced bit value in
2737image_background->gray.
2738
2739If you didn't call png_set_gamma() before reading the file header, for example
2740if you need your code to remain compatible with older versions of libpng prior
2741to libpng-1.5.4, this is the place to call it.
2742
2743Do not call it if you called png_set_alpha_mode(); doing so will damage the
2744settings put in place by png_set_alpha_mode(). (If png_set_alpha_mode() is
2745supported then you can certainly do png_set_gamma() before reading the PNG
2746header.)
2747
2748This API unconditionally sets the screen and file gamma values, so it will
2749override the value in the PNG file unless it is called before the PNG file
2750reading starts. For this reason you must always call it with the PNG file
2751value when you call it in this position:
2752
2753 if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))
2754 png_set_gamma(png_ptr, screen_gamma, file_gamma);
2755
2756 else
2757 png_set_gamma(png_ptr, screen_gamma, 0.45455);
2758
2759If you need to reduce an RGB file to a paletted file, or if a paletted
2760file has more entries then will fit on your screen, png_set_quantize()
2761will do that. Note that this is a simple match quantization that merely
2762finds the closest color available. This should work fairly well with
2763optimized palettes, but fairly badly with linear color cubes. If you
2764pass a palette that is larger than maximum_colors, the file will
2765reduce the number of colors in the palette so it will fit into
2766maximum_colors. If there is a histogram, libpng will use it to make
2767more intelligent choices when reducing the palette. If there is no
2768histogram, it may not do as good a job.
2769
2770 if (color_type & PNG_COLOR_MASK_COLOR)
2771 {
2772 if (png_get_valid(png_ptr, info_ptr,
2773 PNG_INFO_PLTE))
2774 {
2775 png_uint_16p histogram = NULL;
2776
2777 png_get_hIST(png_ptr, info_ptr,
2778 &histogram);
2779 png_set_quantize(png_ptr, palette, num_palette,
2780 max_screen_colors, histogram, 1);
2781 }
2782
2783 else
2784 {
2785 png_color std_color_cube[MAX_SCREEN_COLORS] =
2786 { ... colors ... };
2787
2788 png_set_quantize(png_ptr, std_color_cube,
2789 MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
2790 NULL,0);
2791 }
2792 }
2793
2794PNG files describe monochrome as black being zero and white being one.
2795The following code will reverse this (make black be one and white be
2796zero):
2797
2798 if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
2799 png_set_invert_mono(png_ptr);
2800
2801This function can also be used to invert grayscale and gray-alpha images:
2802
2803 if (color_type == PNG_COLOR_TYPE_GRAY ||
2804 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2805 png_set_invert_mono(png_ptr);
2806
2807PNG files store 16-bit pixels in network byte order (big-endian,
2808ie. most significant bits first). This code changes the storage to the
2809other way (little-endian, i.e. least significant bits first, the
2810way PCs store them):
2811
2812 if (bit_depth == 16)
2813 png_set_swap(png_ptr);
2814
2815If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
2816need to change the order the pixels are packed into bytes, you can use:
2817
2818 if (bit_depth < 8)
2819 png_set_packswap(png_ptr);
2820
2821Finally, you can write your own transformation function if none of
2822the existing ones meets your needs. This is done by setting a callback
2823with
2824
2825 png_set_read_user_transform_fn(png_ptr,
2826 read_transform_fn);
2827
2828You must supply the function
2829
2830 void read_transform_fn(png_structp png_ptr, png_row_infop
2831 row_info, png_bytep data)
2832
2833See pngtest.c for a working example. Your function will be called
2834after all of the other transformations have been processed. Take care with
2835interlaced images if you do the interlace yourself - the width of the row is the
2836width in 'row_info', not the overall image width.
2837
2838If supported, libpng provides two information routines that you can use to find
2839where you are in processing the image:
2840
2841 png_get_current_pass_number(png_structp png_ptr);
2842 png_get_current_row_number(png_structp png_ptr);
2843
2844Don't try using these outside a transform callback - firstly they are only
2845supported if user transforms are supported, secondly they may well return
2846unexpected results unless the row is actually being processed at the moment they
2847are called.
2848
2849With interlaced
2850images the value returned is the row in the input sub-image image. Use
2851PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
2852find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
2853
2854The discussion of interlace handling above contains more information on how to
2855use these values.
2856
2857You can also set up a pointer to a user structure for use by your
2858callback function, and you can inform libpng that your transform
2859function will change the number of channels or bit depth with the
2860function
2861
2862 png_set_user_transform_info(png_ptr, user_ptr,
2863 user_depth, user_channels);
2864
2865The user's application, not libpng, is responsible for allocating and
2866freeing any memory required for the user structure.
2867
2868You can retrieve the pointer via the function
2869png_get_user_transform_ptr(). For example:
2870
2871 voidp read_user_transform_ptr =
2872 png_get_user_transform_ptr(png_ptr);
2873
2874The last thing to handle is interlacing; this is covered in detail below,
2875but you must call the function here if you want libpng to handle expansion
2876of the interlaced image.
2877
2878 number_of_passes = png_set_interlace_handling(png_ptr);
2879
2880After setting the transformations, libpng can update your png_info
2881structure to reflect any transformations you've requested with this
2882call.
2883
2884 png_read_update_info(png_ptr, info_ptr);
2885
2886This is most useful to update the info structure's rowbytes
2887field so you can use it to allocate your image memory. This function
2888will also update your palette with the correct screen_gamma and
2889background if these have been given with the calls above. You may
2890only call png_read_update_info() once with a particular info_ptr.
2891
2892After you call png_read_update_info(), you can allocate any
2893memory you need to hold the image. The row data is simply
2894raw byte data for all forms of images. As the actual allocation
2895varies among applications, no example will be given. If you
2896are allocating one large chunk, you will need to build an
2897array of pointers to each row, as it will be needed for some
2898of the functions below.
2899
2900Remember: Before you call png_read_update_info(), the png_get_*()
2901functions return the values corresponding to the original PNG image.
2902After you call png_read_update_info the values refer to the image
2903that libpng will output. Consequently you must call all the png_set_
2904functions before you call png_read_update_info(). This is particularly
2905important for png_set_interlace_handling() - if you are going to call
2906png_read_update_info() you must call png_set_interlace_handling() before
2907it unless you want to receive interlaced output.
2908
2909.SS Reading image data
2910
2911After you've allocated memory, you can read the image data.
2912The simplest way to do this is in one function call. If you are
2913allocating enough memory to hold the whole image, you can just
2914call png_read_image() and libpng will read in all the image data
2915and put it in the memory area supplied. You will need to pass in
2916an array of pointers to each row.
2917
2918This function automatically handles interlacing, so you don't
2919need to call png_set_interlace_handling() (unless you call
2920png_read_update_info()) or call this function multiple times, or any
2921of that other stuff necessary with png_read_rows().
2922
2923 png_read_image(png_ptr, row_pointers);
2924
2925where row_pointers is:
2926
2927 png_bytep row_pointers[height];
2928
2929You can point to void or char or whatever you use for pixels.
2930
2931If you don't want to read in the whole image at once, you can
2932use png_read_rows() instead. If there is no interlacing (check
2933interlace_type == PNG_INTERLACE_NONE), this is simple:
2934
2935 png_read_rows(png_ptr, row_pointers, NULL,
2936 number_of_rows);
2937
2938where row_pointers is the same as in the png_read_image() call.
2939
2940If you are doing this just one row at a time, you can do this with
2941a single row_pointer instead of an array of row_pointers:
2942
2943 png_bytep row_pointer = row;
2944 png_read_row(png_ptr, row_pointer, NULL);
2945
2946If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
2947get somewhat harder. The only current (PNG Specification version 1.2)
2948interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);
2949a somewhat complicated 2D interlace scheme, known as Adam7, that
2950breaks down an image into seven smaller images of varying size, based
2951on an 8x8 grid. This number is defined (from libpng 1.5) as
2952PNG_INTERLACE_ADAM7_PASSES in png.h
2953
2954libpng can fill out those images or it can give them to you "as is".
2955It is almost always better to have libpng handle the interlacing for you.
2956If you want the images filled out, there are two ways to do that. The one
2957mentioned in the PNG specification is to expand each pixel to cover
2958those pixels that have not been read yet (the "rectangle" method).
2959This results in a blocky image for the first pass, which gradually
2960smooths out as more pixels are read. The other method is the "sparkle"
2961method, where pixels are drawn only in their final locations, with the
2962rest of the image remaining whatever colors they were initialized to
2963before the start of the read. The first method usually looks better,
2964but tends to be slower, as there are more pixels to put in the rows.
2965
2966If, as is likely, you want libpng to expand the images, call this before
2967calling png_start_read_image() or png_read_update_info():
2968
2969 if (interlace_type == PNG_INTERLACE_ADAM7)
2970 number_of_passes
2971 = png_set_interlace_handling(png_ptr);
2972
2973This will return the number of passes needed. Currently, this is seven,
2974but may change if another interlace type is added. This function can be
2975called even if the file is not interlaced, where it will return one pass.
2976You then need to read the whole image 'number_of_passes' times. Each time
2977will distribute the pixels from the current pass to the correct place in
2978the output image, so you need to supply the same rows to png_read_rows in
2979each pass.
2980
2981If you are not going to display the image after each pass, but are
2982going to wait until the entire image is read in, use the sparkle
2983effect. This effect is faster and the end result of either method
2984is exactly the same. If you are planning on displaying the image
2985after each pass, the "rectangle" effect is generally considered the
2986better looking one.
2987
2988If you only want the "sparkle" effect, just call png_read_rows() as
2989normal, with the third parameter NULL. Make sure you make pass over
2990the image number_of_passes times, and you don't change the data in the
2991rows between calls. You can change the locations of the data, just
2992not the data. Each pass only writes the pixels appropriate for that
2993pass, and assumes the data from previous passes is still valid.
2994
2995 png_read_rows(png_ptr, row_pointers, NULL,
2996 number_of_rows);
2997
2998If you only want the first effect (the rectangles), do the same as
2999before except pass the row buffer in the third parameter, and leave
3000the second parameter NULL.
3001
3002 png_read_rows(png_ptr, NULL, row_pointers,
3003 number_of_rows);
3004
3005If you don't want libpng to handle the interlacing details, just call
3006png_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.
3007Each of the images is a valid image by itself, however you will almost
3008certainly need to distribute the pixels from each sub-image to the
3009correct place. This is where everything gets very tricky.
3010
3011If you want to retrieve the separate images you must pass the correct
3012number of rows to each successive call of png_read_rows(). The calculation
3013gets pretty complicated for small images, where some sub-images may
3014not even exist because either their width or height ends up zero.
3015libpng provides two macros to help you in 1.5 and later versions:
3016
3017 png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);
3018 png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);
3019
3020Respectively these tell you the width and height of the sub-image
3021corresponding to the numbered pass. 'pass' is in in the range 0 to 6 -
3022this can be confusing because the specification refers to the same passes
3023as 1 to 7! Be careful, you must check both the width and height before
3024calling png_read_rows() and not call it for that pass if either is zero.
3025
3026You can, of course, read each sub-image row by row. If you want to
3027produce optimal code to make a pixel-by-pixel transformation of an
3028interlaced image this is the best approach; read each row of each pass,
3029transform it, and write it out to a new interlaced image.
3030
3031If you want to de-interlace the image yourself libpng provides further
3032macros to help that tell you where to place the pixels in the output image.
3033Because the interlacing scheme is rectangular - sub-image pixels are always
3034arranged on a rectangular grid - all you need to know for each pass is the
3035starting column and row in the output image of the first pixel plus the
3036spacing between each pixel. As of libpng 1.5 there are four macros to
3037retrieve this information:
3038
3039 png_uint_32 x = PNG_PASS_START_COL(pass);
3040 png_uint_32 y = PNG_PASS_START_ROW(pass);
3041 png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);
3042 png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);
3043
3044These allow you to write the obvious loop:
3045
3046 png_uint_32 input_y = 0;
3047 png_uint_32 output_y = PNG_PASS_START_ROW(pass);
3048
3049 while (output_y < output_image_height)
3050 {
3051 png_uint_32 input_x = 0;
3052 png_uint_32 output_x = PNG_PASS_START_COL(pass);
3053
3054 while (output_x < output_image_width)
3055 {
3056 image[output_y][output_x] =
3057 subimage[pass][input_y][input_x++];
3058
3059 output_x += xStep;
3060 }
3061
3062 ++input_y;
3063 output_y += yStep;
3064 }
3065
3066Notice that the steps between successive output rows and columns are
3067returned as shifts. This is possible because the pixels in the subimages
3068are always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original
3069image. In practice you may need to directly calculate the output coordinate
3070given an input coordinate. libpng provides two further macros for this
3071purpose:
3072
3073 png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);
3074 png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);
3075
3076Finally a pair of macros are provided to tell you if a particular image
3077row or column appears in a given pass:
3078
3079 int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);
3080 int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);
3081
3082Bear in mind that you will probably also need to check the width and height
3083of the pass in addition to the above to be sure the pass even exists!
3084
3085With any luck you are convinced by now that you don't want to do your own
3086interlace handling. In reality normally the only good reason for doing this
3087is if you are processing PNG files on a pixel-by-pixel basis and don't want
3088to load the whole file into memory when it is interlaced.
3089
3090libpng includes a test program, pngvalid, that illustrates reading and
3091writing of interlaced images. If you can't get interlacing to work in your
3092code and don't want to leave it to libpng (the recommended approach), see
3093how pngvalid.c does it.
3094
3095.SS Finishing a sequential read
3096
3097After you are finished reading the image through the
3098low-level interface, you can finish reading the file. If you are
3099interested in comments or time, which may be stored either before or
3100after the image data, you should pass the separate png_info struct if
3101you want to keep the comments from before and after the image
3102separate.
3103
3104 png_infop end_info = png_create_info_struct(png_ptr);
3105
3106 if (!end_info)
3107 {
3108 png_destroy_read_struct(&png_ptr, &info_ptr,
3109 (png_infopp)NULL);
3110 return (ERROR);
3111 }
3112
3113 png_read_end(png_ptr, end_info);
3114
3115If you are not interested, you should still call png_read_end()
3116but you can pass NULL, avoiding the need to create an end_info structure.
3117
3118 png_read_end(png_ptr, (png_infop)NULL);
3119
3120If you don't call png_read_end(), then your file pointer will be
3121left pointing to the first chunk after the last IDAT, which is probably
3122not what you want if you expect to read something beyond the end of
3123the PNG datastream.
3124
3125When you are done, you can free all memory allocated by libpng like this:
3126
3127 png_destroy_read_struct(&png_ptr, &info_ptr,
3128 &end_info);
3129
3130or, if you didn't create an end_info structure,
3131
3132 png_destroy_read_struct(&png_ptr, &info_ptr,
3133 (png_infopp)NULL);
3134
3135It is also possible to individually free the info_ptr members that
3136point to libpng-allocated storage with the following function:
3137
3138 png_free_data(png_ptr, info_ptr, mask, seq)
3139
3140 mask - identifies data to be freed, a mask
3141 containing the bitwise OR of one or
3142 more of
3143 PNG_FREE_PLTE, PNG_FREE_TRNS,
3144 PNG_FREE_HIST, PNG_FREE_ICCP,
3145 PNG_FREE_PCAL, PNG_FREE_ROWS,
3146 PNG_FREE_SCAL, PNG_FREE_SPLT,
3147 PNG_FREE_TEXT, PNG_FREE_UNKN,
3148 or simply PNG_FREE_ALL
3149
3150 seq - sequence number of item to be freed
3151 (-1 for all items)
3152
3153This function may be safely called when the relevant storage has
3154already been freed, or has not yet been allocated, or was allocated
3155by the user and not by libpng, and will in those cases do nothing.
3156The "seq" parameter is ignored if only one item of the selected data
3157type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
3158are allowed for the data type identified in the mask, such as text or
3159sPLT, only the n'th item in the structure is freed, where n is "seq".
3160
3161The default behavior is only to free data that was allocated internally
3162by libpng. This can be changed, so that libpng will not free the data,
3163or so that it will free data that was allocated by the user with png_malloc()
3164or png_zalloc() and passed in via a png_set_*() function, with
3165
3166 png_data_freer(png_ptr, info_ptr, freer, mask)
3167
3168 freer - one of
3169 PNG_DESTROY_WILL_FREE_DATA
3170 PNG_SET_WILL_FREE_DATA
3171 PNG_USER_WILL_FREE_DATA
3172
3173 mask - which data elements are affected
3174 same choices as in png_free_data()
3175
3176This function only affects data that has already been allocated.
3177You can call this function after reading the PNG data but before calling
3178any png_set_*() functions, to control whether the user or the png_set_*()
3179function is responsible for freeing any existing data that might be present,
3180and again after the png_set_*() functions to control whether the user
3181or png_destroy_*() is supposed to free the data. When the user assumes
3182responsibility for libpng-allocated data, the application must use
3183png_free() to free it, and when the user transfers responsibility to libpng
3184for data that the user has allocated, the user must have used png_malloc()
3185or png_zalloc() to allocate it.
3186
3187If you allocated your row_pointers in a single block, as suggested above in
3188the description of the high level read interface, you must not transfer
3189responsibility for freeing it to the png_set_rows or png_read_destroy function,
3190because they would also try to free the individual row_pointers[i].
3191
3192If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
3193separately, do not transfer responsibility for freeing text_ptr to libpng,
3194because when libpng fills a png_text structure it combines these members with
3195the key member, and png_free_data() will free only text_ptr.key. Similarly,
3196if you transfer responsibility for free'ing text_ptr from libpng to your
3197application, your application must not separately free those members.
3198
3199The png_free_data() function will turn off the "valid" flag for anything
3200it frees. If you need to turn the flag off for a chunk that was freed by
3201your application instead of by libpng, you can use
3202
3203 png_set_invalid(png_ptr, info_ptr, mask);
3204
3205 mask - identifies the chunks to be made invalid,
3206 containing the bitwise OR of one or
3207 more of
3208 PNG_INFO_gAMA, PNG_INFO_sBIT,
3209 PNG_INFO_cHRM, PNG_INFO_PLTE,
3210 PNG_INFO_tRNS, PNG_INFO_bKGD,
3211 PNG_INFO_hIST, PNG_INFO_pHYs,
3212 PNG_INFO_oFFs, PNG_INFO_tIME,
3213 PNG_INFO_pCAL, PNG_INFO_sRGB,
3214 PNG_INFO_iCCP, PNG_INFO_sPLT,
3215 PNG_INFO_sCAL, PNG_INFO_IDAT
3216
3217For a more compact example of reading a PNG image, see the file example.c.
3218
3219.SS Reading PNG files progressively
3220
3221The progressive reader is slightly different then the non-progressive
3222reader. Instead of calling png_read_info(), png_read_rows(), and
3223png_read_end(), you make one call to png_process_data(), which calls
3224callbacks when it has the info, a row, or the end of the image. You
3225set up these callbacks with png_set_progressive_read_fn(). You don't
3226have to worry about the input/output functions of libpng, as you are
3227giving the library the data directly in png_process_data(). I will
3228assume that you have read the section on reading PNG files above,
3229so I will only highlight the differences (although I will show
3230all of the code).
3231
3232png_structp png_ptr;
3233png_infop info_ptr;
3234
3235 /* An example code fragment of how you would
3236 initialize the progressive reader in your
3237 application. */
3238 int
3239 initialize_png_reader()
3240 {
3241 png_ptr = png_create_read_struct
3242 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3243 user_error_fn, user_warning_fn);
3244
3245 if (!png_ptr)
3246 return (ERROR);
3247
3248 info_ptr = png_create_info_struct(png_ptr);
3249
3250 if (!info_ptr)
3251 {
3252 png_destroy_read_struct(&png_ptr,
3253 (png_infopp)NULL, (png_infopp)NULL);
3254 return (ERROR);
3255 }
3256
3257 if (setjmp(png_jmpbuf(png_ptr)))
3258 {
3259 png_destroy_read_struct(&png_ptr, &info_ptr,
3260 (png_infopp)NULL);
3261 return (ERROR);
3262 }
3263
3264 /* This one's new. You can provide functions
3265 to be called when the header info is valid,
3266 when each row is completed, and when the image
3267 is finished. If you aren't using all functions,
3268 you can specify NULL parameters. Even when all
3269 three functions are NULL, you need to call
3270 png_set_progressive_read_fn(). You can use
3271 any struct as the user_ptr (cast to a void pointer
3272 for the function call), and retrieve the pointer
3273 from inside the callbacks using the function
3274
3275 png_get_progressive_ptr(png_ptr);
3276
3277 which will return a void pointer, which you have
3278 to cast appropriately.
3279 */
3280 png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
3281 info_callback, row_callback, end_callback);
3282
3283 return 0;
3284 }
3285
3286 /* A code fragment that you call as you receive blocks
3287 of data */
3288 int
3289 process_data(png_bytep buffer, png_uint_32 length)
3290 {
3291 if (setjmp(png_jmpbuf(png_ptr)))
3292 {
3293 png_destroy_read_struct(&png_ptr, &info_ptr,
3294 (png_infopp)NULL);
3295 return (ERROR);
3296 }
3297
3298 /* This one's new also. Simply give it a chunk
3299 of data from the file stream (in order, of
3300 course). On machines with segmented memory
3301 models machines, don't give it any more than
3302 64K. The library seems to run fine with sizes
3303 of 4K. Although you can give it much less if
3304 necessary (I assume you can give it chunks of
3305 1 byte, I haven't tried less then 256 bytes
3306 yet). When this function returns, you may
3307 want to display any rows that were generated
3308 in the row callback if you don't already do
3309 so there.
3310 */
3311 png_process_data(png_ptr, info_ptr, buffer, length);
3312
3313 /* At this point you can call png_process_data_skip if
3314 you want to handle data the library will skip yourself;
3315 it simply returns the number of bytes to skip (and stops
3316 libpng skipping that number of bytes on the next
3317 png_process_data call).
3318 return 0;
3319 }
3320
3321 /* This function is called (as set by
3322 png_set_progressive_read_fn() above) when enough data
3323 has been supplied so all of the header has been
3324 read.
3325 */
3326 void
3327 info_callback(png_structp png_ptr, png_infop info)
3328 {
3329 /* Do any setup here, including setting any of
3330 the transformations mentioned in the Reading
3331 PNG files section. For now, you _must_ call
3332 either png_start_read_image() or
3333 png_read_update_info() after all the
3334 transformations are set (even if you don't set
3335 any). You may start getting rows before
3336 png_process_data() returns, so this is your
3337 last chance to prepare for that.
3338
3339 This is where you turn on interlace handling,
3340 assuming you don't want to do it yourself.
3341
3342 If you need to you can stop the processing of
3343 your original input data at this point by calling
3344 png_process_data_pause. This returns the number
3345 of unprocessed bytes from the last png_process_data
3346 call - it is up to you to ensure that the next call
3347 sees these bytes again. If you don't want to bother
3348 with this you can get libpng to cache the unread
3349 bytes by setting the 'save' parameter (see png.h) but
3350 then libpng will have to copy the data internally.
3351 */
3352 }
3353
3354 /* This function is called when each row of image
3355 data is complete */
3356 void
3357 row_callback(png_structp png_ptr, png_bytep new_row,
3358 png_uint_32 row_num, int pass)
3359 {
3360 /* If the image is interlaced, and you turned
3361 on the interlace handler, this function will
3362 be called for every row in every pass. Some
3363 of these rows will not be changed from the
3364 previous pass. When the row is not changed,
3365 the new_row variable will be NULL. The rows
3366 and passes are called in order, so you don't
3367 really need the row_num and pass, but I'm
3368 supplying them because it may make your life
3369 easier.
3370
3371 If you did not turn on interlace handling then
3372 the callback is called for each row of each
3373 sub-image when the image is interlaced. In this
3374 case 'row_num' is the row in the sub-image, not
3375 the row in the output image as it is in all other
3376 cases.
3377
3378 For the non-NULL rows of interlaced images when
3379 you have switched on libpng interlace handling,
3380 you must call png_progressive_combine_row()
3381 passing in the row and the old row. You can
3382 call this function for NULL rows (it will just
3383 return) and for non-interlaced images (it just
3384 does the memcpy for you) if it will make the
3385 code easier. Thus, you can just do this for
3386 all cases if you switch on interlace handling;
3387 */
3388
3389 png_progressive_combine_row(png_ptr, old_row,
3390 new_row);
3391
3392 /* where old_row is what was displayed for
3393 previously for the row. Note that the first
3394 pass (pass == 0, really) will completely cover
3395 the old row, so the rows do not have to be
3396 initialized. After the first pass (and only
3397 for interlaced images), you will have to pass
3398 the current row, and the function will combine
3399 the old row and the new row.
3400
3401 You can also call png_process_data_pause in this
3402 callback - see above.
3403 */
3404 }
3405
3406 void
3407 end_callback(png_structp png_ptr, png_infop info)
3408 {
3409 /* This function is called after the whole image
3410 has been read, including any chunks after the
3411 image (up to and including the IEND). You
3412 will usually have the same info chunk as you
3413 had in the header, although some data may have
3414 been added to the comments and time fields.
3415
3416 Most people won't do much here, perhaps setting
3417 a flag that marks the image as finished.
3418 */
3419 }
3420
3421
3422
3423.SH IV. Writing
3424
3425Much of this is very similar to reading. However, everything of
3426importance is repeated here, so you won't have to constantly look
3427back up in the reading section to understand writing.
3428
3429.SS Setup
3430
3431You will want to do the I/O initialization before you get into libpng,
3432so if it doesn't work, you don't have anything to undo. If you are not
3433using the standard I/O functions, you will need to replace them with
3434custom writing functions. See the discussion under Customizing libpng.
3435
3436 FILE *fp = fopen(file_name, "wb");
3437
3438 if (!fp)
3439 return (ERROR);
3440
3441Next, png_struct and png_info need to be allocated and initialized.
3442As these can be both relatively large, you may not want to store these
3443on the stack, unless you have stack space to spare. Of course, you
3444will want to check if they return NULL. If you are also reading,
3445you won't want to name your read structure and your write structure
3446both "png_ptr"; you can call them anything you like, such as
3447"read_ptr" and "write_ptr". Look at pngtest.c, for example.
3448
3449 png_structp png_ptr = png_create_write_struct
3450 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3451 user_error_fn, user_warning_fn);
3452
3453 if (!png_ptr)
3454 return (ERROR);
3455
3456 png_infop info_ptr = png_create_info_struct(png_ptr);
3457 if (!info_ptr)
3458 {
3459 png_destroy_write_struct(&png_ptr,
3460 (png_infopp)NULL);
3461 return (ERROR);
3462 }
3463
3464If you want to use your own memory allocation routines,
3465define PNG_USER_MEM_SUPPORTED and use
3466png_create_write_struct_2() instead of png_create_write_struct():
3467
3468 png_structp png_ptr = png_create_write_struct_2
3469 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
3470 user_error_fn, user_warning_fn, (png_voidp)
3471 user_mem_ptr, user_malloc_fn, user_free_fn);
3472
3473After you have these structures, you will need to set up the
3474error handling. When libpng encounters an error, it expects to
3475longjmp() back to your routine. Therefore, you will need to call
3476setjmp() and pass the png_jmpbuf(png_ptr). If you
3477write the file from different routines, you will need to update
3478the png_jmpbuf(png_ptr) every time you enter a new routine that will
3479call a png_*() function. See your documentation of setjmp/longjmp
3480for your compiler for more information on setjmp/longjmp. See
3481the discussion on libpng error handling in the Customizing Libpng
3482section below for more information on the libpng error handling.
3483
3484 if (setjmp(png_jmpbuf(png_ptr)))
3485 {
3486 png_destroy_write_struct(&png_ptr, &info_ptr);
3487 fclose(fp);
3488 return (ERROR);
3489 }
3490 ...
3491 return;
3492
3493If you would rather avoid the complexity of setjmp/longjmp issues,
3494you can compile libpng with PNG_NO_SETJMP, in which case
3495errors will result in a call to PNG_ABORT() which defaults to abort().
3496
3497You can #define PNG_ABORT() to a function that does something
3498more useful than abort(), as long as your function does not
3499return.
3500
3501Now you need to set up the output code. The default for libpng is to
3502use the C function fwrite(). If you use this, you will need to pass a
3503valid FILE * in the function png_init_io(). Be sure that the file is
3504opened in binary mode. Again, if you wish to handle writing data in
3505another way, see the discussion on libpng I/O handling in the Customizing
3506Libpng section below.
3507
3508 png_init_io(png_ptr, fp);
3509
3510If you are embedding your PNG into a datastream such as MNG, and don't
3511want libpng to write the 8-byte signature, or if you have already
3512written the signature in your application, use
3513
3514 png_set_sig_bytes(png_ptr, 8);
3515
3516to inform libpng that it should not write a signature.
3517
3518.SS Write callbacks
3519
3520At this point, you can set up a callback function that will be
3521called after each row has been written, which you can use to control
3522a progress meter or the like. It's demonstrated in pngtest.c.
3523You must supply a function
3524
3525 void write_row_callback(png_structp png_ptr, png_uint_32 row,
3526 int pass);
3527 {
3528 /* put your code here */
3529 }
3530
3531(You can give it another name that you like instead of "write_row_callback")
3532
3533To inform libpng about your function, use
3534
3535 png_set_write_status_fn(png_ptr, write_row_callback);
3536
3537When this function is called the row has already been completely processed and
3538it has also been written out. The 'row' and 'pass' refer to the next row to be
3539handled. For the
3540non-interlaced case the row that was just handled is simply one less than the
3541passed in row number, and pass will always be 0. For the interlaced case the
3542same applies unless the row value is 0, in which case the row just handled was
3543the last one from one of the preceding passes. Because interlacing may skip a
3544pass you cannot be sure that the preceding pass is just 'pass-1', if you really
3545need to know what the last pass is record (row,pass) from the callback and use
3546the last recorded value each time.
3547
3548As with the user transform you can find the output row using the
3549PNG_ROW_FROM_PASS_ROW macro.
3550
3551You now have the option of modifying how the compression library will
3552run. The following functions are mainly for testing, but may be useful
3553in some cases, like if you need to write PNG files extremely fast and
3554are willing to give up some compression, or if you want to get the
3555maximum possible compression at the expense of slower writing. If you
3556have no special needs in this area, let the library do what it wants by
3557not calling this function at all, as it has been tuned to deliver a good
3558speed/compression ratio. The second parameter to png_set_filter() is
3559the filter method, for which the only valid values are 0 (as of the
3560July 1999 PNG specification, version 1.2) or 64 (if you are writing
3561a PNG datastream that is to be embedded in a MNG datastream). The third
3562parameter is a flag that indicates which filter type(s) are to be tested
3563for each scanline. See the PNG specification for details on the specific
3564filter types.
3565
3566
3567 /* turn on or off filtering, and/or choose
3568 specific filters. You can use either a single
3569 PNG_FILTER_VALUE_NAME or the bitwise OR of one
3570 or more PNG_FILTER_NAME masks.
3571 */
3572 png_set_filter(png_ptr, 0,
3573 PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
3574 PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
3575 PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
3576 PNG_FILTER_AVG | PNG_FILTER_VALUE_AVG |
3577 PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
3578 PNG_ALL_FILTERS);
3579
3580If an application wants to start and stop using particular filters during
3581compression, it should start out with all of the filters (to ensure that
3582the previous row of pixels will be stored in case it's needed later),
3583and then add and remove them after the start of compression.
3584
3585If you are writing a PNG datastream that is to be embedded in a MNG
3586datastream, the second parameter can be either 0 or 64.
3587
3588The png_set_compression_*() functions interface to the zlib compression
3589library, and should mostly be ignored unless you really know what you are
3590doing. The only generally useful call is png_set_compression_level()
3591which changes how much time zlib spends on trying to compress the image
3592data. See the Compression Library (zlib.h and algorithm.txt, distributed
3593with zlib) for details on the compression levels.
3594
3595 #include zlib.h
3596
3597 /* Set the zlib compression level */
3598 png_set_compression_level(png_ptr,
3599 Z_BEST_COMPRESSION);
3600
3601 /* Set other zlib parameters for compressing IDAT */
3602 png_set_compression_mem_level(png_ptr, 8);
3603 png_set_compression_strategy(png_ptr,
3604 Z_DEFAULT_STRATEGY);
3605 png_set_compression_window_bits(png_ptr, 15);
3606 png_set_compression_method(png_ptr, 8);
3607 png_set_compression_buffer_size(png_ptr, 8192)
3608
3609 /* Set zlib parameters for text compression
3610 * If you don't call these, the parameters
3611 * fall back on those defined for IDAT chunks
3612 */
3613 png_set_text_compression_mem_level(png_ptr, 8);
3614 png_set_text_compression_strategy(png_ptr,
3615 Z_DEFAULT_STRATEGY);
3616 png_set_text_compression_window_bits(png_ptr, 15);
3617 png_set_text_compression_method(png_ptr, 8);
3618
3619.SS Setting the contents of info for output
3620
3621You now need to fill in the png_info structure with all the data you
3622wish to write before the actual image. Note that the only thing you
3623are allowed to write after the image is the text chunks and the time
3624chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
3625the latest PNG specification for more information on that. If you
3626wish to write them before the image, fill them in now, and flag that
3627data as being valid. If you want to wait until after the data, don't
3628fill them until png_write_end(). For all the fields in png_info and
3629their data types, see png.h. For explanations of what the fields
3630contain, see the PNG specification.
3631
3632Some of the more important parts of the png_info are:
3633
3634 png_set_IHDR(png_ptr, info_ptr, width, height,
3635 bit_depth, color_type, interlace_type,
3636 compression_type, filter_method)
3637
3638 width - holds the width of the image
3639 in pixels (up to 2^31).
3640
3641 height - holds the height of the image
3642 in pixels (up to 2^31).
3643
3644 bit_depth - holds the bit depth of one of the
3645 image channels.
3646 (valid values are 1, 2, 4, 8, 16
3647 and depend also on the
3648 color_type. See also significant
3649 bits (sBIT) below).
3650
3651 color_type - describes which color/alpha
3652 channels are present.
3653 PNG_COLOR_TYPE_GRAY
3654 (bit depths 1, 2, 4, 8, 16)
3655 PNG_COLOR_TYPE_GRAY_ALPHA
3656 (bit depths 8, 16)
3657 PNG_COLOR_TYPE_PALETTE
3658 (bit depths 1, 2, 4, 8)
3659 PNG_COLOR_TYPE_RGB
3660 (bit_depths 8, 16)
3661 PNG_COLOR_TYPE_RGB_ALPHA
3662 (bit_depths 8, 16)
3663
3664 PNG_COLOR_MASK_PALETTE
3665 PNG_COLOR_MASK_COLOR
3666 PNG_COLOR_MASK_ALPHA
3667
3668 interlace_type - PNG_INTERLACE_NONE or
3669 PNG_INTERLACE_ADAM7
3670
3671 compression_type - (must be
3672 PNG_COMPRESSION_TYPE_DEFAULT)
3673
3674 filter_method - (must be PNG_FILTER_TYPE_DEFAULT
3675 or, if you are writing a PNG to
3676 be embedded in a MNG datastream,
3677 can also be
3678 PNG_INTRAPIXEL_DIFFERENCING)
3679
3680If you call png_set_IHDR(), the call must appear before any of the
3681other png_set_*() functions, because they might require access to some of
3682the IHDR settings. The remaining png_set_*() functions can be called
3683in any order.
3684
3685If you wish, you can reset the compression_type, interlace_type, or
3686filter_method later by calling png_set_IHDR() again; if you do this, the
3687width, height, bit_depth, and color_type must be the same in each call.
3688
3689 png_set_PLTE(png_ptr, info_ptr, palette,
3690 num_palette);
3691
3692 palette - the palette for the file
3693 (array of png_color)
3694 num_palette - number of entries in the palette
3695
3696 png_set_gAMA(png_ptr, info_ptr, file_gamma);
3697 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
3698
3699 file_gamma - the gamma at which the image was
3700 created (PNG_INFO_gAMA)
3701
3702 int_file_gamma - 100,000 times the gamma at which
3703 the image was created
3704
3705 png_set_cHRM(png_ptr, info_ptr, white_x, white_y, red_x, red_y,
3706 green_x, green_y, blue_x, blue_y)
3707 png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,
3708 green_Y, green_Z, blue_X, blue_Y, blue_Z)
3709 png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,
3710 int_red_x, int_red_y, int_green_x, int_green_y,
3711 int_blue_x, int_blue_y)
3712 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,
3713 int_red_Z, int_green_X, int_green_Y, int_green_Z,
3714 int_blue_X, int_blue_Y, int_blue_Z)
3715
3716 {white,red,green,blue}_{x,y}
3717 A color space encoding specified using the chromaticities
3718 of the end points and the white point.
3719
3720 {red,green,blue}_{X,Y,Z}
3721 A color space encoding specified using the encoding end
3722 points - the CIE tristimulus specification of the intended
3723 color of the red, green and blue channels in the PNG RGB
3724 data. The white point is simply the sum of the three end
3725 points.
3726
3727 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
3728
3729 srgb_intent - the rendering intent
3730 (PNG_INFO_sRGB) The presence of
3731 the sRGB chunk means that the pixel
3732 data is in the sRGB color space.
3733 This chunk also implies specific
3734 values of gAMA and cHRM. Rendering
3735 intent is the CSS-1 property that
3736 has been defined by the International
3737 Color Consortium
3738 (http://www.color.org).
3739 It can be one of
3740 PNG_sRGB_INTENT_SATURATION,
3741 PNG_sRGB_INTENT_PERCEPTUAL,
3742 PNG_sRGB_INTENT_ABSOLUTE, or
3743 PNG_sRGB_INTENT_RELATIVE.
3744
3745
3746 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
3747 srgb_intent);
3748
3749 srgb_intent - the rendering intent
3750 (PNG_INFO_sRGB) The presence of the
3751 sRGB chunk means that the pixel
3752 data is in the sRGB color space.
3753 This function also causes gAMA and
3754 cHRM chunks with the specific values
3755 that are consistent with sRGB to be
3756 written.
3757
3758 png_set_iCCP(png_ptr, info_ptr, name, compression_type,
3759 profile, proflen);
3760
3761 name - The profile name.
3762
3763 compression_type - The compression type; always
3764 PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
3765 You may give NULL to this argument to
3766 ignore it.
3767
3768 profile - International Color Consortium color
3769 profile data. May contain NULs.
3770
3771 proflen - length of profile data in bytes.
3772
3773 png_set_sBIT(png_ptr, info_ptr, sig_bit);
3774
3775 sig_bit - the number of significant bits for
3776 (PNG_INFO_sBIT) each of the gray, red,
3777 green, and blue channels, whichever are
3778 appropriate for the given color type
3779 (png_color_16)
3780
3781 png_set_tRNS(png_ptr, info_ptr, trans_alpha,
3782 num_trans, trans_color);
3783
3784 trans_alpha - array of alpha (transparency)
3785 entries for palette (PNG_INFO_tRNS)
3786
3787 num_trans - number of transparent entries
3788 (PNG_INFO_tRNS)
3789
3790 trans_color - graylevel or color sample values
3791 (in order red, green, blue) of the
3792 single transparent color for
3793 non-paletted images (PNG_INFO_tRNS)
3794
3795 png_set_hIST(png_ptr, info_ptr, hist);
3796
3797 hist - histogram of palette (array of
3798 png_uint_16) (PNG_INFO_hIST)
3799
3800 png_set_tIME(png_ptr, info_ptr, mod_time);
3801
3802 mod_time - time image was last modified
3803 (PNG_VALID_tIME)
3804
3805 png_set_bKGD(png_ptr, info_ptr, background);
3806
3807 background - background color (of type
3808 png_color_16p) (PNG_VALID_bKGD)
3809
3810 png_set_text(png_ptr, info_ptr, text_ptr, num_text);
3811
3812 text_ptr - array of png_text holding image
3813 comments
3814
3815 text_ptr[i].compression - type of compression used
3816 on "text" PNG_TEXT_COMPRESSION_NONE
3817 PNG_TEXT_COMPRESSION_zTXt
3818 PNG_ITXT_COMPRESSION_NONE
3819 PNG_ITXT_COMPRESSION_zTXt
3820 text_ptr[i].key - keyword for comment. Must contain
3821 1-79 characters.
3822 text_ptr[i].text - text comments for current
3823 keyword. Can be NULL or empty.
3824 text_ptr[i].text_length - length of text string,
3825 after decompression, 0 for iTXt
3826 text_ptr[i].itxt_length - length of itxt string,
3827 after decompression, 0 for tEXt/zTXt
3828 text_ptr[i].lang - language of comment (NULL or
3829 empty for unknown).
3830 text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
3831 or empty for unknown).
3832
3833 Note that the itxt_length, lang, and lang_key
3834 members of the text_ptr structure only exist when the
3835 library is built with iTXt chunk support. Prior to
3836 libpng-1.4.0 the library was built by default without
3837 iTXt support. Also note that when iTXt is supported,
3838 they contain NULL pointers when the "compression"
3839 field contains PNG_TEXT_COMPRESSION_NONE or
3840 PNG_TEXT_COMPRESSION_zTXt.
3841
3842 num_text - number of comments
3843
3844 png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
3845 num_spalettes);
3846
3847 palette_ptr - array of png_sPLT_struct structures
3848 to be added to the list of palettes
3849 in the info structure.
3850 num_spalettes - number of palette structures to be
3851 added.
3852
3853 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
3854 unit_type);
3855
3856 offset_x - positive offset from the left
3857 edge of the screen
3858
3859 offset_y - positive offset from the top
3860 edge of the screen
3861
3862 unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
3863
3864 png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
3865 unit_type);
3866
3867 res_x - pixels/unit physical resolution
3868 in x direction
3869
3870 res_y - pixels/unit physical resolution
3871 in y direction
3872
3873 unit_type - PNG_RESOLUTION_UNKNOWN,
3874 PNG_RESOLUTION_METER
3875
3876 png_set_sCAL(png_ptr, info_ptr, unit, width, height)
3877
3878 unit - physical scale units (an integer)
3879
3880 width - width of a pixel in physical scale units
3881
3882 height - height of a pixel in physical scale units
3883 (width and height are doubles)
3884
3885 png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
3886
3887 unit - physical scale units (an integer)
3888
3889 width - width of a pixel in physical scale units
3890 expressed as a string
3891
3892 height - height of a pixel in physical scale units
3893 (width and height are strings like "2.54")
3894
3895 png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
3896 num_unknowns)
3897
3898 unknowns - array of png_unknown_chunk
3899 structures holding unknown chunks
3900 unknowns[i].name - name of unknown chunk
3901 unknowns[i].data - data of unknown chunk
3902 unknowns[i].size - size of unknown chunk's data
3903 unknowns[i].location - position to write chunk in file
3904 0: do not write chunk
3905 PNG_HAVE_IHDR: before PLTE
3906 PNG_HAVE_PLTE: before IDAT
3907 PNG_AFTER_IDAT: after IDAT
3908
3909The "location" member is set automatically according to
3910what part of the output file has already been written.
3911You can change its value after calling png_set_unknown_chunks()
3912as demonstrated in pngtest.c. Within each of the "locations",
3913the chunks are sequenced according to their position in the
3914structure (that is, the value of "i", which is the order in which
3915the chunk was either read from the input file or defined with
3916png_set_unknown_chunks).
3917
3918A quick word about text and num_text. text is an array of png_text
3919structures. num_text is the number of valid structures in the array.
3920Each png_text structure holds a language code, a keyword, a text value,
3921and a compression type.
3922
3923The compression types have the same valid numbers as the compression
3924types of the image data. Currently, the only valid number is zero.
3925However, you can store text either compressed or uncompressed, unlike
3926images, which always have to be compressed. So if you don't want the
3927text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
3928Because tEXt and zTXt chunks don't have a language field, if you
3929specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
3930any language code or translated keyword will not be written out.
3931
3932Until text gets around a few hundred bytes, it is not worth compressing it.
3933After the text has been written out to the file, the compression type
3934is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
3935so that it isn't written out again at the end (in case you are calling
3936png_write_end() with the same struct).
3937
3938The keywords that are given in the PNG Specification are:
3939
3940 Title Short (one line) title or
3941 caption for image
3942
3943 Author Name of image's creator
3944
3945 Description Description of image (possibly long)
3946
3947 Copyright Copyright notice
3948
3949 Creation Time Time of original image creation
3950 (usually RFC 1123 format, see below)
3951
3952 Software Software used to create the image
3953
3954 Disclaimer Legal disclaimer
3955
3956 Warning Warning of nature of content
3957
3958 Source Device used to create the image
3959
3960 Comment Miscellaneous comment; conversion
3961 from other image format
3962
3963The keyword-text pairs work like this. Keywords should be short
3964simple descriptions of what the comment is about. Some typical
3965keywords are found in the PNG specification, as is some recommendations
3966on keywords. You can repeat keywords in a file. You can even write
3967some text before the image and some after. For example, you may want
3968to put a description of the image before the image, but leave the
3969disclaimer until after, so viewers working over modem connections
3970don't have to wait for the disclaimer to go over the modem before
3971they start seeing the image. Finally, keywords should be full
3972words, not abbreviations. Keywords and text are in the ISO 8859-1
3973(Latin-1) character set (a superset of regular ASCII) and can not
3974contain NUL characters, and should not contain control or other
3975unprintable characters. To make the comments widely readable, stick
3976with basic ASCII, and avoid machine specific character set extensions
3977like the IBM-PC character set. The keyword must be present, but
3978you can leave off the text string on non-compressed pairs.
3979Compressed pairs must have a text string, as only the text string
3980is compressed anyway, so the compression would be meaningless.
3981
3982PNG supports modification time via the png_time structure. Two
3983conversion routines are provided, png_convert_from_time_t() for
3984time_t and png_convert_from_struct_tm() for struct tm. The
3985time_t routine uses gmtime(). You don't have to use either of
3986these, but if you wish to fill in the png_time structure directly,
3987you should provide the time in universal time (GMT) if possible
3988instead of your local time. Note that the year number is the full
3989year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
3990that months start with 1.
3991
3992If you want to store the time of the original image creation, you should
3993use a plain tEXt chunk with the "Creation Time" keyword. This is
3994necessary because the "creation time" of a PNG image is somewhat vague,
3995depending on whether you mean the PNG file, the time the image was
3996created in a non-PNG format, a still photo from which the image was
3997scanned, or possibly the subject matter itself. In order to facilitate
3998machine-readable dates, it is recommended that the "Creation Time"
3999tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
4000although this isn't a requirement. Unlike the tIME chunk, the
4001"Creation Time" tEXt chunk is not expected to be automatically changed
4002by the software. To facilitate the use of RFC 1123 dates, a function
4003png_convert_to_rfc1123(png_timep) is provided to convert from PNG
4004time to an RFC 1123 format string.
4005
4006.SS Writing unknown chunks
4007
4008You can use the png_set_unknown_chunks function to queue up chunks
4009for writing. You give it a chunk name, raw data, and a size; that's
4010all there is to it. The chunks will be written by the next following
4011png_write_info_before_PLTE, png_write_info, or png_write_end function.
4012Any chunks previously read into the info structure's unknown-chunk
4013list will also be written out in a sequence that satisfies the PNG
4014specification's ordering rules.
4015
4016.SS The high-level write interface
4017
4018At this point there are two ways to proceed; through the high-level
4019write interface, or through a sequence of low-level write operations.
4020You can use the high-level interface if your image data is present
4021in the info structure. All defined output
4022transformations are permitted, enabled by the following masks.
4023
4024 PNG_TRANSFORM_IDENTITY No transformation
4025 PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
4026 PNG_TRANSFORM_PACKSWAP Change order of packed
4027 pixels to LSB first
4028 PNG_TRANSFORM_INVERT_MONO Invert monochrome images
4029 PNG_TRANSFORM_SHIFT Normalize pixels to the
4030 sBIT depth
4031 PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
4032 to BGRA
4033 PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
4034 to AG
4035 PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
4036 to transparency
4037 PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
4038 PNG_TRANSFORM_STRIP_FILLER Strip out filler
4039 bytes (deprecated).
4040 PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading
4041 filler bytes
4042 PNG_TRANSFORM_STRIP_FILLER_AFTER Strip out trailing
4043 filler bytes
4044
4045If you have valid image data in the info structure (you can use
4046png_set_rows() to put image data in the info structure), simply do this:
4047
4048 png_write_png(png_ptr, info_ptr, png_transforms, NULL)
4049
4050where png_transforms is an integer containing the bitwise OR of some set of
4051transformation flags. This call is equivalent to png_write_info(),
4052followed the set of transformations indicated by the transform mask,
4053then png_write_image(), and finally png_write_end().
4054
4055(The final parameter of this call is not yet used. Someday it might point
4056to transformation parameters required by some future output transform.)
4057
4058You must use png_transforms and not call any png_set_transform() functions
4059when you use png_write_png().
4060
4061.SS The low-level write interface
4062
4063If you are going the low-level route instead, you are now ready to
4064write all the file information up to the actual image data. You do
4065this with a call to png_write_info().
4066
4067 png_write_info(png_ptr, info_ptr);
4068
4069Note that there is one transformation you may need to do before
4070png_write_info(). In PNG files, the alpha channel in an image is the
4071level of opacity. If your data is supplied as a level of transparency,
4072you can invert the alpha channel before you write it, so that 0 is
4073fully transparent and 255 (in 8-bit or paletted images) or 65535
4074(in 16-bit images) is fully opaque, with
4075
4076 png_set_invert_alpha(png_ptr);
4077
4078This must appear before png_write_info() instead of later with the
4079other transformations because in the case of paletted images the tRNS
4080chunk data has to be inverted before the tRNS chunk is written. If
4081your image is not a paletted image, the tRNS data (which in such cases
4082represents a single color to be rendered as transparent) won't need to
4083be changed, and you can safely do this transformation after your
4084png_write_info() call.
4085
4086If you need to write a private chunk that you want to appear before
4087the PLTE chunk when PLTE is present, you can write the PNG info in
4088two steps, and insert code to write your own chunk between them:
4089
4090 png_write_info_before_PLTE(png_ptr, info_ptr);
4091 png_set_unknown_chunks(png_ptr, info_ptr, ...);
4092 png_write_info(png_ptr, info_ptr);
4093
4094After you've written the file information, you can set up the library
4095to handle any special transformations of the image data. The various
4096ways to transform the data will be described in the order that they
4097should occur. This is important, as some of these change the color
4098type and/or bit depth of the data, and some others only work on
4099certain color types and bit depths. Even though each transformation
4100checks to see if it has data that it can do something with, you should
4101make sure to only enable a transformation if it will be valid for the
4102data. For example, don't swap red and blue on grayscale data.
4103
4104PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
4105the library to strip input data that has 4 or 8 bytes per pixel down
4106to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
4107bytes per pixel).
4108
4109 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
4110
4111where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
4112PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
4113is stored XRGB or RGBX.
4114
4115PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
4116they can, resulting in, for example, 8 pixels per byte for 1 bit files.
4117If the data is supplied at 1 pixel per byte, use this code, which will
4118correctly pack the pixels into a single byte:
4119
4120 png_set_packing(png_ptr);
4121
4122PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
4123data is of another bit depth, you can write an sBIT chunk into the
4124file so that decoders can recover the original data if desired.
4125
4126 /* Set the true bit depth of the image data */
4127 if (color_type & PNG_COLOR_MASK_COLOR)
4128 {
4129 sig_bit.red = true_bit_depth;
4130 sig_bit.green = true_bit_depth;
4131 sig_bit.blue = true_bit_depth;
4132 }
4133
4134 else
4135 {
4136 sig_bit.gray = true_bit_depth;
4137 }
4138
4139 if (color_type & PNG_COLOR_MASK_ALPHA)
4140 {
4141 sig_bit.alpha = true_bit_depth;
4142 }
4143
4144 png_set_sBIT(png_ptr, info_ptr, &sig_bit);
4145
4146If the data is stored in the row buffer in a bit depth other than
4147one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
4148this will scale the values to appear to be the correct bit depth as
4149is required by PNG.
4150
4151 png_set_shift(png_ptr, &sig_bit);
4152
4153PNG files store 16-bit pixels in network byte order (big-endian,
4154ie. most significant bits first). This code would be used if they are
4155supplied the other way (little-endian, i.e. least significant bits
4156first, the way PCs store them):
4157
4158 if (bit_depth > 8)
4159 png_set_swap(png_ptr);
4160
4161If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
4162need to change the order the pixels are packed into bytes, you can use:
4163
4164 if (bit_depth < 8)
4165 png_set_packswap(png_ptr);
4166
4167PNG files store 3 color pixels in red, green, blue order. This code
4168would be used if they are supplied as blue, green, red:
4169
4170 png_set_bgr(png_ptr);
4171
4172PNG files describe monochrome as black being zero and white being
4173one. This code would be used if the pixels are supplied with this reversed
4174(black being one and white being zero):
4175
4176 png_set_invert_mono(png_ptr);
4177
4178Finally, you can write your own transformation function if none of
4179the existing ones meets your needs. This is done by setting a callback
4180with
4181
4182 png_set_write_user_transform_fn(png_ptr,
4183 write_transform_fn);
4184
4185You must supply the function
4186
4187 void write_transform_fn(png_structp png_ptr, png_row_infop
4188 row_info, png_bytep data)
4189
4190See pngtest.c for a working example. Your function will be called
4191before any of the other transformations are processed. If supported
4192libpng also supplies an information routine that may be called from
4193your callback:
4194
4195 png_get_current_row_number(png_ptr);
4196 png_get_current_pass_number(png_ptr);
4197
4198This returns the current row passed to the transform. With interlaced
4199images the value returned is the row in the input sub-image image. Use
4200PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
4201find the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).
4202
4203The discussion of interlace handling above contains more information on how to
4204use these values.
4205
4206You can also set up a pointer to a user structure for use by your
4207callback function.
4208
4209 png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
4210
4211The user_channels and user_depth parameters of this function are ignored
4212when writing; you can set them to zero as shown.
4213
4214You can retrieve the pointer via the function png_get_user_transform_ptr().
4215For example:
4216
4217 voidp write_user_transform_ptr =
4218 png_get_user_transform_ptr(png_ptr);
4219
4220It is possible to have libpng flush any pending output, either manually,
4221or automatically after a certain number of lines have been written. To
4222flush the output stream a single time call:
4223
4224 png_write_flush(png_ptr);
4225
4226and to have libpng flush the output stream periodically after a certain
4227number of scanlines have been written, call:
4228
4229 png_set_flush(png_ptr, nrows);
4230
4231Note that the distance between rows is from the last time png_write_flush()
4232was called, or the first row of the image if it has never been called.
4233So if you write 50 lines, and then png_set_flush 25, it will flush the
4234output on the next scanline, and every 25 lines thereafter, unless
4235png_write_flush() is called before 25 more lines have been written.
4236If nrows is too small (less than about 10 lines for a 640 pixel wide
4237RGB image) the image compression may decrease noticeably (although this
4238may be acceptable for real-time applications). Infrequent flushing will
4239only degrade the compression performance by a few percent over images
4240that do not use flushing.
4241
4242.SS Writing the image data
4243
4244That's it for the transformations. Now you can write the image data.
4245The simplest way to do this is in one function call. If you have the
4246whole image in memory, you can just call png_write_image() and libpng
4247will write the image. You will need to pass in an array of pointers to
4248each row. This function automatically handles interlacing, so you don't
4249need to call png_set_interlace_handling() or call this function multiple
4250times, or any of that other stuff necessary with png_write_rows().
4251
4252 png_write_image(png_ptr, row_pointers);
4253
4254where row_pointers is:
4255
4256 png_byte *row_pointers[height];
4257
4258You can point to void or char or whatever you use for pixels.
4259
4260If you don't want to write the whole image at once, you can
4261use png_write_rows() instead. If the file is not interlaced,
4262this is simple:
4263
4264 png_write_rows(png_ptr, row_pointers,
4265 number_of_rows);
4266
4267row_pointers is the same as in the png_write_image() call.
4268
4269If you are just writing one row at a time, you can do this with
4270a single row_pointer instead of an array of row_pointers:
4271
4272 png_bytep row_pointer = row;
4273
4274 png_write_row(png_ptr, row_pointer);
4275
4276When the file is interlaced, things can get a good deal more complicated.
4277The only currently (as of the PNG Specification version 1.2, dated July
42781999) defined interlacing scheme for PNG files is the "Adam7" interlace
4279scheme, that breaks down an image into seven smaller images of varying
4280size. libpng will build these images for you, or you can do them
4281yourself. If you want to build them yourself, see the PNG specification
4282for details of which pixels to write when.
4283
4284If you don't want libpng to handle the interlacing details, just
4285use png_set_interlace_handling() and call png_write_rows() the
4286correct number of times to write all the sub-images
4287(png_set_interlace_handling() returns the number of sub-images.)
4288
4289If you want libpng to build the sub-images, call this before you start
4290writing any rows:
4291
4292 number_of_passes = png_set_interlace_handling(png_ptr);
4293
4294This will return the number of passes needed. Currently, this is seven,
4295but may change if another interlace type is added.
4296
4297Then write the complete image number_of_passes times.
4298
4299 png_write_rows(png_ptr, row_pointers, number_of_rows);
4300
4301Think carefully before you write an interlaced image. Typically code that
4302reads such images reads all the image data into memory, uncompressed, before
4303doing any processing. Only code that can display an image on the fly can
4304take advantage of the interlacing and even then the image has to be exactly
4305the correct size for the output device, because scaling an image requires
4306adjacent pixels and these are not available until all the passes have been
4307read.
4308
4309If you do write an interlaced image you will hardly ever need to handle
4310the interlacing yourself. Call png_set_interlace_handling() and use the
4311approach described above.
4312
4313The only time it is conceivable that you will really need to write an
4314interlaced image pass-by-pass is when you have read one pass by pass and
4315made some pixel-by-pixel transformation to it, as described in the read
4316code above. In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros
4317to determine the size of each sub-image in turn and simply write the rows
4318you obtained from the read code.
4319
4320.SS Finishing a sequential write
4321
4322After you are finished writing the image, you should finish writing
4323the file. If you are interested in writing comments or time, you should
4324pass an appropriately filled png_info pointer. If you are not interested,
4325you can pass NULL.
4326
4327 png_write_end(png_ptr, info_ptr);
4328
4329When you are done, you can free all memory used by libpng like this:
4330
4331 png_destroy_write_struct(&png_ptr, &info_ptr);
4332
4333It is also possible to individually free the info_ptr members that
4334point to libpng-allocated storage with the following function:
4335
4336 png_free_data(png_ptr, info_ptr, mask, seq)
4337
4338 mask - identifies data to be freed, a mask
4339 containing the bitwise OR of one or
4340 more of
4341 PNG_FREE_PLTE, PNG_FREE_TRNS,
4342 PNG_FREE_HIST, PNG_FREE_ICCP,
4343 PNG_FREE_PCAL, PNG_FREE_ROWS,
4344 PNG_FREE_SCAL, PNG_FREE_SPLT,
4345 PNG_FREE_TEXT, PNG_FREE_UNKN,
4346 or simply PNG_FREE_ALL
4347
4348 seq - sequence number of item to be freed
4349 (-1 for all items)
4350
4351This function may be safely called when the relevant storage has
4352already been freed, or has not yet been allocated, or was allocated
4353by the user and not by libpng, and will in those cases do nothing.
4354The "seq" parameter is ignored if only one item of the selected data
4355type, such as PLTE, is allowed. If "seq" is not -1, and multiple items
4356are allowed for the data type identified in the mask, such as text or
4357sPLT, only the n'th item in the structure is freed, where n is "seq".
4358
4359If you allocated data such as a palette that you passed in to libpng
4360with png_set_*, you must not free it until just before the call to
4361png_destroy_write_struct().
4362
4363The default behavior is only to free data that was allocated internally
4364by libpng. This can be changed, so that libpng will not free the data,
4365or so that it will free data that was allocated by the user with png_malloc()
4366or png_zalloc() and passed in via a png_set_*() function, with
4367
4368 png_data_freer(png_ptr, info_ptr, freer, mask)
4369
4370 freer - one of
4371 PNG_DESTROY_WILL_FREE_DATA
4372 PNG_SET_WILL_FREE_DATA
4373 PNG_USER_WILL_FREE_DATA
4374
4375 mask - which data elements are affected
4376 same choices as in png_free_data()
4377
4378For example, to transfer responsibility for some data from a read structure
4379to a write structure, you could use
4380
4381 png_data_freer(read_ptr, read_info_ptr,
4382 PNG_USER_WILL_FREE_DATA,
4383 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4384
4385 png_data_freer(write_ptr, write_info_ptr,
4386 PNG_DESTROY_WILL_FREE_DATA,
4387 PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
4388
4389thereby briefly reassigning responsibility for freeing to the user but
4390immediately afterwards reassigning it once more to the write_destroy
4391function. Having done this, it would then be safe to destroy the read
4392structure and continue to use the PLTE, tRNS, and hIST data in the write
4393structure.
4394
4395This function only affects data that has already been allocated.
4396You can call this function before calling after the png_set_*() functions
4397to control whether the user or png_destroy_*() is supposed to free the data.
4398When the user assumes responsibility for libpng-allocated data, the
4399application must use
4400png_free() to free it, and when the user transfers responsibility to libpng
4401for data that the user has allocated, the user must have used png_malloc()
4402or png_zalloc() to allocate it.
4403
4404If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
4405separately, do not transfer responsibility for freeing text_ptr to libpng,
4406because when libpng fills a png_text structure it combines these members with
4407the key member, and png_free_data() will free only text_ptr.key. Similarly,
4408if you transfer responsibility for free'ing text_ptr from libpng to your
4409application, your application must not separately free those members.
4410For a more compact example of writing a PNG image, see the file example.c.
4411
4412.SH V. Modifying/Customizing libpng:
4413
4414There are two issues here. The first is changing how libpng does
4415standard things like memory allocation, input/output, and error handling.
4416The second deals with more complicated things like adding new chunks,
4417adding new transformations, and generally changing how libpng works.
4418Both of those are compile-time issues; that is, they are generally
4419determined at the time the code is written, and there is rarely a need
4420to provide the user with a means of changing them.
4421
4422Memory allocation, input/output, and error handling
4423
4424All of the memory allocation, input/output, and error handling in libpng
4425goes through callbacks that are user-settable. The default routines are
4426in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
4427these functions, call the appropriate png_set_*_fn() function.
4428
4429Memory allocation is done through the functions png_malloc(), png_calloc(),
4430and png_free(). These currently just call the standard C functions.
4431png_calloc() calls png_malloc() and then clears the newly
4432allocated memory to zero. There is limited support for certain systems
4433with segmented memory architectures and the types of pointers declared by
4434png.h match this; you will have to use appropriate pointers in your
4435application. Since it is
4436unlikely that the method of handling memory allocation on a platform
4437will change between applications, these functions must be modified in
4438the library at compile time. If you prefer to use a different method
4439of allocating and freeing data, you can use png_create_read_struct_2() or
4440png_create_write_struct_2() to register your own functions as described
4441above. These functions also provide a void pointer that can be retrieved
4442via
4443
4444 mem_ptr=png_get_mem_ptr(png_ptr);
4445
4446Your replacement memory functions must have prototypes as follows:
4447
4448 png_voidp malloc_fn(png_structp png_ptr,
4449 png_alloc_size_t size);
4450
4451 void free_fn(png_structp png_ptr, png_voidp ptr);
4452
4453Your malloc_fn() must return NULL in case of failure. The png_malloc()
4454function will normally call png_error() if it receives a NULL from the
4455system memory allocator or from your replacement malloc_fn().
4456
4457Your free_fn() will never be called with a NULL ptr, since libpng's
4458png_free() checks for NULL before calling free_fn().
4459
4460Input/Output in libpng is done through png_read() and png_write(),
4461which currently just call fread() and fwrite(). The FILE * is stored in
4462png_struct and is initialized via png_init_io(). If you wish to change
4463the method of I/O, the library supplies callbacks that you can set
4464through the function png_set_read_fn() and png_set_write_fn() at run
4465time, instead of calling the png_init_io() function. These functions
4466also provide a void pointer that can be retrieved via the function
4467png_get_io_ptr(). For example:
4468
4469 png_set_read_fn(png_structp read_ptr,
4470 voidp read_io_ptr, png_rw_ptr read_data_fn)
4471
4472 png_set_write_fn(png_structp write_ptr,
4473 voidp write_io_ptr, png_rw_ptr write_data_fn,
4474 png_flush_ptr output_flush_fn);
4475
4476 voidp read_io_ptr = png_get_io_ptr(read_ptr);
4477 voidp write_io_ptr = png_get_io_ptr(write_ptr);
4478
4479The replacement I/O functions must have prototypes as follows:
4480
4481 void user_read_data(png_structp png_ptr,
4482 png_bytep data, png_size_t length);
4483
4484 void user_write_data(png_structp png_ptr,
4485 png_bytep data, png_size_t length);
4486
4487 void user_flush_data(png_structp png_ptr);
4488
4489The user_read_data() function is responsible for detecting and
4490handling end-of-data errors.
4491
4492Supplying NULL for the read, write, or flush functions sets them back
4493to using the default C stream functions, which expect the io_ptr to
4494point to a standard *FILE structure. It is probably a mistake
4495to use NULL for one of write_data_fn and output_flush_fn but not both
4496of them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.
4497It is an error to read from a write stream, and vice versa.
4498
4499Error handling in libpng is done through png_error() and png_warning().
4500Errors handled through png_error() are fatal, meaning that png_error()
4501should never return to its caller. Currently, this is handled via
4502setjmp() and longjmp() (unless you have compiled libpng with
4503PNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),
4504but you could change this to do things like exit() if you should wish,
4505as long as your function does not return.
4506
4507On non-fatal errors, png_warning() is called
4508to print a warning message, and then control returns to the calling code.
4509By default png_error() and png_warning() print a message on stderr via
4510fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
4511(because you don't want the messages) or PNG_NO_STDIO defined (because
4512fprintf() isn't available). If you wish to change the behavior of the error
4513functions, you will need to set up your own message callbacks. These
4514functions are normally supplied at the time that the png_struct is created.
4515It is also possible to redirect errors and warnings to your own replacement
4516functions after png_create_*_struct() has been called by calling:
4517
4518 png_set_error_fn(png_structp png_ptr,
4519 png_voidp error_ptr, png_error_ptr error_fn,
4520 png_error_ptr warning_fn);
4521
4522 png_voidp error_ptr = png_get_error_ptr(png_ptr);
4523
4524If NULL is supplied for either error_fn or warning_fn, then the libpng
4525default function will be used, calling fprintf() and/or longjmp() if a
4526problem is encountered. The replacement error functions should have
4527parameters as follows:
4528
4529 void user_error_fn(png_structp png_ptr,
4530 png_const_charp error_msg);
4531
4532 void user_warning_fn(png_structp png_ptr,
4533 png_const_charp warning_msg);
4534
4535The motivation behind using setjmp() and longjmp() is the C++ throw and
4536catch exception handling methods. This makes the code much easier to write,
4537as there is no need to check every return code of every function call.
4538However, there are some uncertainties about the status of local variables
4539after a longjmp, so the user may want to be careful about doing anything
4540after setjmp returns non-zero besides returning itself. Consult your
4541compiler documentation for more details. For an alternative approach, you
4542may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net),
4543which is illustrated in pngvalid.c and in contrib/visupng.
4544
4545.SS Custom chunks
4546
4547If you need to read or write custom chunks, you may need to get deeper
4548into the libpng code. The library now has mechanisms for storing
4549and writing chunks of unknown type; you can even declare callbacks
4550for custom chunks. However, this may not be good enough if the
4551library code itself needs to know about interactions between your
4552chunk and existing `intrinsic' chunks.
4553
4554If you need to write a new intrinsic chunk, first read the PNG
4555specification. Acquire a first level of understanding of how it works.
4556Pay particular attention to the sections that describe chunk names,
4557and look at how other chunks were designed, so you can do things
4558similarly. Second, check out the sections of libpng that read and
4559write chunks. Try to find a chunk that is similar to yours and use
4560it as a template. More details can be found in the comments inside
4561the code. It is best to handle private or unknown chunks in a generic method,
4562via callback functions, instead of by modifying libpng functions. This
4563is illustrated in pngtest.c, which uses a callback function to handle a
4564private "vpAg" chunk and the new "sTER" chunk, which are both unknown to
4565libpng.
4566
4567If you wish to write your own transformation for the data, look through
4568the part of the code that does the transformations, and check out some of
4569the simpler ones to get an idea of how they work. Try to find a similar
4570transformation to the one you want to add and copy off of it. More details
4571can be found in the comments inside the code itself.
4572
4573.SS Configuring for 16-bit platforms
4574
4575You will want to look into zconf.h to tell zlib (and thus libpng) that
4576it cannot allocate more then 64K at a time. Even if you can, the memory
4577won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
4578
4579.SS Configuring for DOS
4580
4581For DOS users who only have access to the lower 640K, you will
4582have to limit zlib's memory usage via a png_set_compression_mem_level()
4583call. See zlib.h or zconf.h in the zlib library for more information.
4584
4585.SS Configuring for Medium Model
4586
4587Libpng's support for medium model has been tested on most of the popular
4588compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
4589defined, and FAR gets defined to far in pngconf.h, and you should be
4590all set. Everything in the library (except for zlib's structure) is
4591expecting far data. You must use the typedefs with the p or pp on
4592the end for pointers (or at least look at them and be careful). Make
4593note that the rows of data are defined as png_bytepp, which is
4594an "unsigned char far * far *".
4595
4596.SS Configuring for gui/windowing platforms:
4597
4598You will need to write new error and warning functions that use the GUI
4599interface, as described previously, and set them to be the error and
4600warning functions at the time that png_create_*_struct() is called,
4601in order to have them available during the structure initialization.
4602They can be changed later via png_set_error_fn(). On some compilers,
4603you may also have to change the memory allocators (png_malloc, etc.).
4604
4605.SS Configuring for compiler xxx:
4606
4607All includes for libpng are in pngconf.h. If you need to add, change
4608or delete an include, this is the place to do it.
4609The includes that are not needed outside libpng are placed in pngpriv.h,
4610which is only used by the routines inside libpng itself.
4611The files in libpng proper only include pngpriv.h and png.h, which
4612%14%in turn includes pngconf.h.
4613in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
4614As of libpng-1.5.0, pngpriv.h also includes three other private header
4615files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
4616that previously appeared in the public headers.
4617
4618.SS Configuring zlib:
4619
4620There are special functions to configure the compression. Perhaps the
4621most useful one changes the compression level, which currently uses
4622input compression values in the range 0 - 9. The library normally
4623uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
4624have shown that for a large majority of images, compression values in
4625the range 3-6 compress nearly as well as higher levels, and do so much
4626faster. For online applications it may be desirable to have maximum speed
4627(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
4628specify no compression (Z_NO_COMPRESSION = 0), but this would create
4629files larger than just storing the raw bitmap. You can specify the
4630compression level by calling:
4631
4632 #include zlib.h
4633 png_set_compression_level(png_ptr, level);
4634
4635Another useful one is to reduce the memory level used by the library.
4636The memory level defaults to 8, but it can be lowered if you are
4637short on memory (running DOS, for example, where you only have 640K).
4638Note that the memory level does have an effect on compression; among
4639other things, lower levels will result in sections of incompressible
4640data being emitted in smaller stored blocks, with a correspondingly
4641larger relative overhead of up to 15% in the worst case.
4642
4643 #include zlib.h
4644 png_set_compression_mem_level(png_ptr, level);
4645
4646The other functions are for configuring zlib. They are not recommended
4647for normal use and may result in writing an invalid PNG file. See
4648zlib.h for more information on what these mean.
4649
4650 #include zlib.h
4651 png_set_compression_strategy(png_ptr,
4652 strategy);
4653
4654 png_set_compression_window_bits(png_ptr,
4655 window_bits);
4656
4657 png_set_compression_method(png_ptr, method);
4658
4659 png_set_compression_buffer_size(png_ptr, size);
4660
4661As of libpng version 1.5.4, additional APIs became
4662available to set these separately for non-IDAT
4663compressed chunks such as zTXt, iTXt, and iCCP:
4664
4665 #include zlib.h
4666 #if PNG_LIBPNG_VER <= 10504
4667 png_set_text_compression_level(png_ptr, level);
4668
4669 png_set_text_compression_mem_level(png_ptr, level);
4670
4671 png_set_text_compression_strategy(png_ptr,
4672 strategy);
4673
4674 png_set_text_compression_window_bits(png_ptr,
4675 window_bits);
4676
4677 png_set_text_compression_method(png_ptr, method);
4678 #endif
4679
4680.SS Controlling row filtering
4681
4682If you want to control whether libpng uses filtering or not, which
4683filters are used, and how it goes about picking row filters, you
4684can call one of these functions. The selection and configuration
4685of row filters can have a significant impact on the size and
4686encoding speed and a somewhat lesser impact on the decoding speed
4687of an image. Filtering is enabled by default for RGB and grayscale
4688images (with and without alpha), but not for paletted images nor
4689for any images with bit depths less than 8 bits/pixel.
4690
4691The 'method' parameter sets the main filtering method, which is
4692currently only '0' in the PNG 1.2 specification. The 'filters'
4693parameter sets which filter(s), if any, should be used for each
4694scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
4695to turn filtering on and off, respectively.
4696
4697Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
4698PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
4699ORed together with '|' to specify one or more filters to use.
4700These filters are described in more detail in the PNG specification.
4701If you intend to change the filter type during the course of writing
4702the image, you should start with flags set for all of the filters
4703you intend to use so that libpng can initialize its internal
4704structures appropriately for all of the filter types. (Note that this
4705means the first row must always be adaptively filtered, because libpng
4706currently does not allocate the filter buffers until png_write_row()
4707is called for the first time.)
4708
4709 filters = PNG_FILTER_NONE | PNG_FILTER_SUB
4710 PNG_FILTER_UP | PNG_FILTER_AVG |
4711 PNG_FILTER_PAETH | PNG_ALL_FILTERS;
4712
4713 png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
4714 filters);
4715 The second parameter can also be
4716 PNG_INTRAPIXEL_DIFFERENCING if you are
4717 writing a PNG to be embedded in a MNG
4718 datastream. This parameter must be the
4719 same as the value of filter_method used
4720 in png_set_IHDR().
4721
4722It is also possible to influence how libpng chooses from among the
4723available filters. This is done in one or both of two ways - by
4724telling it how important it is to keep the same filter for successive
4725rows, and by telling it the relative computational costs of the filters.
4726
4727 double weights[3] = {1.5, 1.3, 1.1},
4728 costs[PNG_FILTER_VALUE_LAST] =
4729 {1.0, 1.3, 1.3, 1.5, 1.7};
4730
4731 png_set_filter_heuristics(png_ptr,
4732 PNG_FILTER_HEURISTIC_WEIGHTED, 3,
4733 weights, costs);
4734
4735The weights are multiplying factors that indicate to libpng that the
4736row filter should be the same for successive rows unless another row filter
4737is that many times better than the previous filter. In the above example,
4738if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
4739"sum of absolute differences" 1.5 x 1.3 times higher than other filters
4740and still be chosen, while the NONE filter could have a sum 1.1 times
4741higher than other filters and still be chosen. Unspecified weights are
4742taken to be 1.0, and the specified weights should probably be declining
4743like those above in order to emphasize recent filters over older filters.
4744
4745The filter costs specify for each filter type a relative decoding cost
4746to be considered when selecting row filters. This means that filters
4747with higher costs are less likely to be chosen over filters with lower
4748costs, unless their "sum of absolute differences" is that much smaller.
4749The costs do not necessarily reflect the exact computational speeds of
4750the various filters, since this would unduly influence the final image
4751size.
4752
4753Note that the numbers above were invented purely for this example and
4754are given only to help explain the function usage. Little testing has
4755been done to find optimum values for either the costs or the weights.
4756
4757.SS Removing unwanted object code
4758
4759There are a bunch of #define's in pngconf.h that control what parts of
4760libpng are compiled. All the defines end in _SUPPORTED. If you are
4761never going to use a capability, you can change the #define to #undef
4762before recompiling libpng and save yourself code and data space, or
4763you can turn off individual capabilities with defines that begin with
4764PNG_NO_.
4765
4766In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
4767
4768You can also turn all of the transforms and ancillary chunk capabilities
4769off en masse with compiler directives that define
4770PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
4771or all four,
4772along with directives to turn on any of the capabilities that you do
4773want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
4774transformations but still leave the library fully capable of reading
4775and writing PNG files with all known public chunks. Use of the
4776PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
4777that is incapable of reading or writing ancillary chunks. If you are
4778not using the progressive reading capability, you can turn that off
4779with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
4780capability, which you'll still have).
4781
4782All the reading and writing specific code are in separate files, so the
4783linker should only grab the files it needs. However, if you want to
4784make sure, or if you are building a stand alone library, all the
4785reading files start with "pngr" and all the writing files start with "pngw".
4786The files that don't match either (like png.c, pngtrans.c, etc.)
4787are used for both reading and writing, and always need to be included.
4788The progressive reader is in pngpread.c
4789
4790If you are creating or distributing a dynamically linked library (a .so
4791or DLL file), you should not remove or disable any parts of the library,
4792as this will cause applications linked with different versions of the
4793library to fail if they call functions not available in your library.
4794The size of the library itself should not be an issue, because only
4795those sections that are actually used will be loaded into memory.
4796
4797.SS Requesting debug printout
4798
4799The macro definition PNG_DEBUG can be used to request debugging
4800printout. Set it to an integer value in the range 0 to 3. Higher
4801numbers result in increasing amounts of debugging information. The
4802information is printed to the "stderr" file, unless another file
4803name is specified in the PNG_DEBUG_FILE macro definition.
4804
4805When PNG_DEBUG > 0, the following functions (macros) become available:
4806
4807 png_debug(level, message)
4808 png_debug1(level, message, p1)
4809 png_debug2(level, message, p1, p2)
4810
4811in which "level" is compared to PNG_DEBUG to decide whether to print
4812the message, "message" is the formatted string to be printed,
4813and p1 and p2 are parameters that are to be embedded in the string
4814according to printf-style formatting directives. For example,
4815
4816 png_debug1(2, "foo=%d\n", foo);
4817
4818is expanded to
4819
4820 if (PNG_DEBUG > 2)
4821 fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
4822
4823When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
4824can still use PNG_DEBUG to control your own debugging:
4825
4826 #ifdef PNG_DEBUG
4827 fprintf(stderr, ...
4828 #endif
4829
4830When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
4831having level = 0 will be printed. There aren't any such statements in
4832this version of libpng, but if you insert some they will be printed.
4833
4834.SH VI. MNG support
4835
4836The MNG specification (available at http://www.libpng.org/pub/mng) allows
4837certain extensions to PNG for PNG images that are embedded in MNG datastreams.
4838Libpng can support some of these extensions. To enable them, use the
4839png_permit_mng_features() function:
4840
4841 feature_set = png_permit_mng_features(png_ptr, mask)
4842
4843 mask is a png_uint_32 containing the bitwise OR of the
4844 features you want to enable. These include
4845 PNG_FLAG_MNG_EMPTY_PLTE
4846 PNG_FLAG_MNG_FILTER_64
4847 PNG_ALL_MNG_FEATURES
4848
4849 feature_set is a png_uint_32 that is the bitwise AND of
4850 your mask with the set of MNG features that is
4851 supported by the version of libpng that you are using.
4852
4853It is an error to use this function when reading or writing a standalone
4854PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
4855in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
4856and the MHDR and MEND chunks. Libpng does not provide support for these
4857or any other MNG chunks; your application must provide its own support for
4858them. You may wish to consider using libmng (available at
4859http://www.libmng.com) instead.
4860
4861.SH VII. Changes to Libpng from version 0.88
4862
4863It should be noted that versions of libpng later than 0.96 are not
4864distributed by the original libpng author, Guy Schalnat, nor by
4865Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
4866distributed versions 0.89 through 0.96, but rather by another member
4867of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
4868still alive and well, but they have moved on to other things.
4869
4870The old libpng functions png_read_init(), png_write_init(),
4871png_info_init(), png_read_destroy(), and png_write_destroy() have been
4872moved to PNG_INTERNAL in version 0.95 to discourage their use. These
4873functions will be removed from libpng version 1.4.0.
4874
4875The preferred method of creating and initializing the libpng structures is
4876via the png_create_read_struct(), png_create_write_struct(), and
4877png_create_info_struct() because they isolate the size of the structures
4878from the application, allow version error checking, and also allow the
4879use of custom error handling routines during the initialization, which
4880the old functions do not. The functions png_read_destroy() and
4881png_write_destroy() do not actually free the memory that libpng
4882allocated for these structs, but just reset the data structures, so they
4883can be used instead of png_destroy_read_struct() and
4884png_destroy_write_struct() if you feel there is too much system overhead
4885allocating and freeing the png_struct for each image read.
4886
4887Setting the error callbacks via png_set_message_fn() before
4888png_read_init() as was suggested in libpng-0.88 is no longer supported
4889because this caused applications that do not use custom error functions
4890to fail if the png_ptr was not initialized to zero. It is still possible
4891to set the error callbacks AFTER png_read_init(), or to change them with
4892png_set_error_fn(), which is essentially the same function, but with a new
4893name to force compilation errors with applications that try to use the old
4894method.
4895
4896Starting with version 1.0.7, you can find out which version of the library
4897you are using at run-time:
4898
4899 png_uint_32 libpng_vn = png_access_version_number();
4900
4901The number libpng_vn is constructed from the major version, minor
4902version with leading zero, and release number with leading zero,
4903(e.g., libpng_vn for version 1.0.7 is 10007).
4904
4905Note that this function does not take a png_ptr, so you can call it
4906before you've created one.
4907
4908You can also check which version of png.h you used when compiling your
4909application:
4910
4911 png_uint_32 application_vn = PNG_LIBPNG_VER;
4912
4913.SH VIII. Changes to Libpng from version 1.0.x to 1.2.x
4914
4915Support for user memory management was enabled by default. To
4916accomplish this, the functions png_create_read_struct_2(),
4917png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
4918png_malloc_default(), and png_free_default() were added.
4919
4920Support for the iTXt chunk has been enabled by default as of
4921version 1.2.41.
4922
4923Support for certain MNG features was enabled.
4924
4925Support for numbered error messages was added. However, we never got
4926around to actually numbering the error messages. The function
4927png_set_strip_error_numbers() was added (Note: the prototype for this
4928function was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE
4929builds of libpng-1.2.15. It was restored in libpng-1.2.36).
4930
4931The png_malloc_warn() function was added at libpng-1.2.3. This issues
4932a png_warning and returns NULL instead of aborting when it fails to
4933acquire the requested memory allocation.
4934
4935Support for setting user limits on image width and height was enabled
4936by default. The functions png_set_user_limits(), png_get_user_width_max(),
4937and png_get_user_height_max() were added at libpng-1.2.6.
4938
4939The png_set_add_alpha() function was added at libpng-1.2.7.
4940
4941The function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.
4942Unlike png_set_gray_1_2_4_to_8(), the new function does not expand the
4943tRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is
4944deprecated.
4945
4946A number of macro definitions in support of runtime selection of
4947assembler code features (especially Intel MMX code support) were
4948added at libpng-1.2.0:
4949
4950 PNG_ASM_FLAG_MMX_SUPPORT_COMPILED
4951 PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
4952 PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
4953 PNG_ASM_FLAG_MMX_READ_INTERLACE
4954 PNG_ASM_FLAG_MMX_READ_FILTER_SUB
4955 PNG_ASM_FLAG_MMX_READ_FILTER_UP
4956 PNG_ASM_FLAG_MMX_READ_FILTER_AVG
4957 PNG_ASM_FLAG_MMX_READ_FILTER_PAETH
4958 PNG_ASM_FLAGS_INITIALIZED
4959 PNG_MMX_READ_FLAGS
4960 PNG_MMX_FLAGS
4961 PNG_MMX_WRITE_FLAGS
4962 PNG_MMX_FLAGS
4963
4964We added the following functions in support of runtime
4965selection of assembler code features:
4966
4967 png_get_mmx_flagmask()
4968 png_set_mmx_thresholds()
4969 png_get_asm_flags()
4970 png_get_mmx_bitdepth_threshold()
4971 png_get_mmx_rowbytes_threshold()
4972 png_set_asm_flags()
4973
4974We replaced all of these functions with simple stubs in libpng-1.2.20,
4975when the Intel assembler code was removed due to a licensing issue.
4976
4977These macros are deprecated:
4978
4979 PNG_READ_TRANSFORMS_NOT_SUPPORTED
4980 PNG_PROGRESSIVE_READ_NOT_SUPPORTED
4981 PNG_NO_SEQUENTIAL_READ_SUPPORTED
4982 PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
4983 PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
4984 PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
4985
4986They have been replaced, respectively, by:
4987
4988 PNG_NO_READ_TRANSFORMS
4989 PNG_NO_PROGRESSIVE_READ
4990 PNG_NO_SEQUENTIAL_READ
4991 PNG_NO_WRITE_TRANSFORMS
4992 PNG_NO_READ_ANCILLARY_CHUNKS
4993 PNG_NO_WRITE_ANCILLARY_CHUNKS
4994
4995PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
4996deprecated since libpng-1.0.16 and libpng-1.2.6.
4997
4998The function
4999 png_check_sig(sig, num)
5000was replaced with
5001 !png_sig_cmp(sig, 0, num)
5002It has been deprecated since libpng-0.90.
5003
5004The function
5005 png_set_gray_1_2_4_to_8()
5006which also expands tRNS to alpha was replaced with
5007 png_set_expand_gray_1_2_4_to_8()
5008which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
5009
5010.SH IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
5011
5012Private libpng prototypes and macro definitions were moved from
5013png.h and pngconf.h into a new pngpriv.h header file.
5014
5015Functions png_set_benign_errors(), png_benign_error(), and
5016png_chunk_benign_error() were added.
5017
5018Support for setting the maximum amount of memory that the application
5019will allocate for reading chunks was added, as a security measure.
5020The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
5021were added to the library.
5022
5023We implemented support for I/O states by adding png_ptr member io_state
5024and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
5025
5026We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
5027input transforms.
5028
5029Checking for and reporting of errors in the IHDR chunk is more thorough.
5030
5031Support for global arrays was removed, to improve thread safety.
5032
5033Some obsolete/deprecated macros and functions have been removed.
5034
5035Typecasted NULL definitions such as
5036 #define png_voidp_NULL (png_voidp)NULL
5037were eliminated. If you used these in your application, just use
5038NULL instead.
5039
5040The png_struct and info_struct members "trans" and "trans_values" were
5041changed to "trans_alpha" and "trans_color", respectively.
5042
5043The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
5044were removed.
5045
5046The PNG_1_0_X and PNG_1_2_X macros were eliminated.
5047
5048The PNG_LEGACY_SUPPORTED macro was eliminated.
5049
5050Many WIN32_WCE #ifdefs were removed.
5051
5052The functions png_read_init(info_ptr), png_write_init(info_ptr),
5053png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
5054have been removed. They have been deprecated since libpng-0.95.
5055
5056The png_permit_empty_plte() was removed. It has been deprecated
5057since libpng-1.0.9. Use png_permit_mng_features() instead.
5058
5059We removed the obsolete stub functions png_get_mmx_flagmask(),
5060png_set_mmx_thresholds(), png_get_asm_flags(),
5061png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
5062png_set_asm_flags(), and png_mmx_supported()
5063
5064We removed the obsolete png_check_sig(), png_memcpy_check(), and
5065png_memset_check() functions. Instead use !png_sig_cmp(), memcpy(),
5066and memset(), respectively.
5067
5068The function png_set_gray_1_2_4_to_8() was removed. It has been
5069deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
5070png_set_expand_gray_1_2_4_to_8() because the former function also
5071expanded any tRNS chunk to an alpha channel.
5072
5073Macros for png_get_uint_16, png_get_uint_32, and png_get_int_32
5074were added and are used by default instead of the corresponding
5075functions. Unfortunately,
5076from libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5077function) incorrectly returned a value of type png_uint_32.
5078
5079We changed the prototype for png_malloc() from
5080 png_malloc(png_structp png_ptr, png_uint_32 size)
5081to
5082 png_malloc(png_structp png_ptr, png_alloc_size_t size)
5083
5084This also applies to the prototype for the user replacement malloc_fn().
5085
5086The png_calloc() function was added and is used in place of
5087of "png_malloc(); memset();" except in the case in png_read_png()
5088where the array consists of pointers; in this case a "for" loop is used
5089after the png_malloc() to set the pointers to NULL, to give robust.
5090behavior in case the application runs out of memory part-way through
5091the process.
5092
5093We changed the prototypes of png_get_compression_buffer_size() and
5094png_set_compression_buffer_size() to work with png_size_t instead of
5095png_uint_32.
5096
5097Support for numbered error messages was removed by default, since we
5098never got around to actually numbering the error messages. The function
5099png_set_strip_error_numbers() was removed from the library by default.
5100
5101The png_zalloc() and png_zfree() functions are no longer exported.
5102The png_zalloc() function no longer zeroes out the memory that it
5103allocates.
5104
5105Support for dithering was disabled by default in libpng-1.4.0, because
5106it has not been well tested and doesn't actually "dither".
5107The code was not
5108removed, however, and could be enabled by building libpng with
5109PNG_READ_DITHER_SUPPORTED defined. In libpng-1.4.2, this support
5110was reenabled, but the function was renamed png_set_quantize() to
5111reflect more accurately what it actually does. At the same time,
5112the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to
5113PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED
5114was renamed to PNG_READ_QUANTIZE_SUPPORTED.
5115
5116We removed the trailing '.' from the warning and error messages.
5117
5118.SH X. Changes to Libpng from version 1.4.x to 1.5.x
5119
5120From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5121function) incorrectly returned a value of type png_uint_32.
5122
5123A. Changes that affect users of libpng
5124
5125There are no substantial API changes between the non-deprecated parts of
5126the 1.4.5 API and the 1.5.0 API, however the ability to directly access
5127the main libpng control structures, png_struct and png_info, deprecated
5128in earlier versions of libpng, has been completely removed from
5129libpng 1.5.
5130
5131We no longer include zlib.h in png.h. Applications that need access
5132to information in zlib.h will need to add the '#include "zlib.h"'
5133directive. It does not matter whether it is placed prior to or after
5134the '"#include png.h"' directive.
5135
5136We moved the png_strcpy(), png_strncpy(), png_strlen(), png_memcpy(),
5137png_memcmp(), png_sprintf, and png_memcpy() macros into a private
5138header file (pngpriv.h) that is not accessible to applications.
5139
5140In png_get_iCCP, the type of "profile" was changed from png_charpp
5141to png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.
5142
5143There are changes of form in png.h, including new and changed macros to
5144declare parts of the API. Some API functions with arguments that are
5145pointers to data not modified within the function have been corrected to
5146declare these arguments with PNG_CONST.
5147
5148Much of the internal use of C macros to control the library build has also
5149changed and some of this is visible in the exported header files, in
5150particular the use of macros to control data and API elements visible
5151during application compilation may require significant revision to
5152application code. (It is extremely rare for an application to do this.)
5153
5154Any program that compiled against libpng 1.4 and did not use deprecated
5155features or access internal library structures should compile and work
5156against libpng 1.5, except for the change in the prototype for
5157png_get_iCCP() and png_set_iCCP() API functions mentioned above.
5158
5159libpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of
5160interlaced images. The macros return the number of rows and columns in
5161each pass and information that can be used to de-interlace and (if
5162absolutely necessary) interlace an image.
5163
5164libpng 1.5.0 adds an API png_longjmp(png_ptr, value). This API calls
5165the application-provided png_longjmp_ptr on the internal, but application
5166initialized, longjmp buffer. It is provided as a convenience to avoid
5167the need to use the png_jmpbuf macro, which had the unnecessary side
5168effect of resetting the internal png_longjmp_ptr value.
5169
5170libpng 1.5.0 includes a complete fixed point API. By default this is
5171present along with the corresponding floating point API. In general the
5172fixed point API is faster and smaller than the floating point one because
5173the PNG file format used fixed point, not floating point. This applies
5174even if the library uses floating point in internal calculations. A new
5175macro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library
5176uses floating point arithmetic (the default) or fixed point arithmetic
5177internally for performance critical calculations such as gamma correction.
5178In some cases, the gamma calculations may produce slightly different
5179results. This has changed the results in png_rgb_to_gray and in alpha
5180composition (png_set_background for example). This applies even if the
5181original image was already linear (gamma == 1.0) and, therefore, it is
5182not necessary to linearize the image. This is because libpng has *not*
5183been changed to optimize that case correctly, yet.
5184
5185Fixed point support for the sCAL chunk comes with an important caveat;
5186the sCAL specification uses a decimal encoding of floating point values
5187and the accuracy of PNG fixed point values is insufficient for
5188representation of these values. Consequently a "string" API
5189(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading
5190arbitrary sCAL chunks in the absence of either the floating point API or
5191internal floating point calculations.
5192
5193Applications no longer need to include the optional distribution header
5194file pngusr.h or define the corresponding macros during application
5195build in order to see the correct variant of the libpng API. From 1.5.0
5196application code can check for the corresponding _SUPPORTED macro:
5197
5198#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
5199 /* code that uses the inch conversion APIs. */
5200#endif
5201
5202This macro will only be defined if the inch conversion functions have been
5203compiled into libpng. The full set of macros, and whether or not support
5204has been compiled in, are available in the header file pnglibconf.h.
5205This header file is specific to the libpng build. Notice that prior to
52061.5.0 the _SUPPORTED macros would always have the default definition unless
5207reset by pngusr.h or by explicit settings on the compiler command line.
5208These settings may produce compiler warnings or errors in 1.5.0 because
5209of macro redefinition.
5210
5211From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
5212function) incorrectly returned a value of type png_uint_32. libpng 1.5.0
5213is consistent with the implementation in 1.4.5 and 1.2.x (where the macro
5214did not exist.)
5215
5216Applications can now choose whether to use these macros or to call the
5217corresponding function by defining PNG_USE_READ_MACROS or
5218PNG_NO_USE_READ_MACROS before including png.h. Notice that this is
5219only supported from 1.5.0 -defining PNG_NO_USE_READ_MACROS prior to 1.5.0
5220will lead to a link failure.
5221
5222Prior to libpng-1.5.4, the zlib compressor used the same set of parameters
5223when compressing the IDAT data and textual data such as zTXt and iCCP.
5224In libpng-1.5.4 we reinitialized the zlib stream for each type of data.
5225We added five png_set_text_*() functions for setting the parameters to
5226use with textual data.
5227
5228Prior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
5229option was off by default, and slightly inaccurate scaling occurred.
5230This option can no longer be turned off, and the choice of accurate
5231or inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()
5232API for accurate scaling or the old png_set_strip_16_to_8() API for simple
5233chopping.
5234
5235Prior to libpng-1.5.4, the png_set_user_limits() function could only be
5236used to reduce the width and height limits from the value of
5237PNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said
5238that it could be used to override them. Now this function will reduce or
5239increase the limits.
5240
5241B. Changes to the build and configuration of libpng
5242
5243Details of internal changes to the library code can be found in the CHANGES
5244file and in the GIT repository logs. These will be of no concern to the vast
5245majority of library users or builders, however the few who configure libpng
5246to a non-default feature set may need to change how this is done.
5247
5248There should be no need for library builders to alter build scripts if
5249these use the distributed build support - configure or the makefiles -
5250however users of the makefiles may care to update their build scripts
5251to build pnglibconf.h where the corresponding makefile does not do so.
5252
5253Building libpng with a non-default configuration has changed completely.
5254The old method using pngusr.h should still work correctly even though the
5255way pngusr.h is used in the build has been changed; however, library
5256builders will probably want to examine the changes to take advantage of
5257new capabilities and to simplify their build system.
5258
5259B.1 Specific changes to library configuration capabilities
5260
5261The library now supports a complete fixed point implementation and can
5262thus be used on systems that have no floating point support or very
5263limited or slow support. Previously gamma correction, an essential part
5264of complete PNG support, required reasonably fast floating point.
5265
5266As part of this the choice of internal implementation has been made
5267independent of the choice of fixed versus floating point APIs and all the
5268missing fixed point APIs have been implemented.
5269
5270The exact mechanism used to control attributes of API functions has
5271changed. A single set of operating system independent macro definitions
5272is used and operating system specific directives are defined in
5273pnglibconf.h
5274
5275As part of this the mechanism used to choose procedure call standards on
5276those systems that allow a choice has been changed. At present this only
5277affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
5278running on Intel processors. As before, PNGAPI is defined where required
5279to control the exported API functions; however, two new macros, PNGCBAPI
5280and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
5281(PNGCAPI) for functions that must match a C library prototype (currently
5282only png_longjmp_ptr, which must match the C longjmp function.) The new
5283approach is documented in pngconf.h
5284
5285Despite these changes, libpng 1.5.0 only supports the native C function
5286calling standard on those platforms tested so far (__cdecl on Microsoft
5287Windows). This is because the support requirements for alternative
5288calling conventions seem to no longer exist. Developers who find it
5289necessary to set PNG_API_RULE to 1 should advise the mailing list
5290(png-mng-implement) of this and library builders who use Openwatcom and
5291therefore set PNG_API_RULE to 2 should also contact the mailing list.
5292
5293A new test program, pngvalid, is provided in addition to pngtest.
5294pngvalid validates the arithmetic accuracy of the gamma correction
5295calculations and includes a number of validations of the file format.
5296A subset of the full range of tests is run when "make check" is done
5297(in the 'configure' build.) pngvalid also allows total allocated memory
5298usage to be evaluated and performs additional memory overwrite validation.
5299
5300Many changes to individual feature macros have been made. The following
5301are the changes most likely to be noticed by library builders who
5302configure libpng:
5303
53041) All feature macros now have consistent naming:
5305
5306#define PNG_NO_feature turns the feature off
5307#define PNG_feature_SUPPORTED turns the feature on
5308
5309pnglibconf.h contains one line for each feature macro which is either:
5310
5311#define PNG_feature_SUPPORTED
5312
5313if the feature is supported or:
5314
5315/*#undef PNG_feature_SUPPORTED*/
5316
5317if it is not. Library code consistently checks for the 'SUPPORTED' macro.
5318It does not, and libpng applications should not, check for the 'NO' macro
5319which will not normally be defined even if the feature is not supported.
5320The 'NO' macros are only used internally for setting or not setting the
5321corresponding 'SUPPORTED' macros.
5322
5323Compatibility with the old names is provided as follows:
5324
5325PNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED
5326
5327And the following definitions disable the corresponding feature:
5328
5329PNG_SETJMP_NOT_SUPPORTED disables SETJMP
5330PNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS
5331PNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV
5332PNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS
5333PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS
5334PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS
5335
5336Library builders should remove use of the above, inconsistent, names.
5337
53382) Warning and error message formatting was previously conditional on
5339the STDIO feature. The library has been changed to use the
5340CONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled
5341the library no longer uses the printf(3) functions, even though the
5342default read/write implementations use (FILE) style stdio.h functions.
5343
53443) Three feature macros now control the fixed/floating point decisions:
5345
5346PNG_FLOATING_POINT_SUPPORTED enables the floating point APIs
5347
5348PNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in
5349practice these are normally required internally anyway (because the PNG
5350file format is fixed point), therefore in most cases PNG_NO_FIXED_POINT
5351merely stops the function from being exported.
5352
5353PNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating
5354point implementation or the fixed point one. Typically the fixed point
5355implementation is larger and slower than the floating point implementation
5356on a system that supports floating point, however it may be faster on a
5357system which lacks floating point hardware and therefore uses a software
5358emulation.
5359
53604) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED. This allows the
5361functions to read and write ints to be disabled independently of
5362PNG_USE_READ_MACROS, which allows libpng to be built with the functions
5363even though the default is to use the macros - this allows applications
5364to choose at app buildtime whether or not to use macros (previously
5365impossible because the functions weren't in the default build.)
5366
5367B.2 Changes to the configuration mechanism
5368
5369Prior to libpng-1.5.0 library builders who needed to configure libpng
5370had either to modify the exported pngconf.h header file to add system
5371specific configuration or had to write feature selection macros into
5372pngusr.h and cause this to be included into pngconf.h by defining
5373PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
5374application built without PNG_USER_CONFIG defined would see the
5375unmodified, default, libpng API and thus would probably fail to link.
5376
5377These mechanisms still work in the configure build and in any makefile
5378build that builds pnglibconf.h, although the feature selection macros
5379have changed somewhat as described above. In 1.5.0, however, pngusr.h is
5380processed only once, when the exported header file pnglibconf.h is built.
5381pngconf.h no longer includes pngusr.h, therefore pngusr.h is ignored after the
5382build of pnglibconf.h and it is never included in an application build.
5383
5384The rarely used alternative of adding a list of feature macros to the
5385CFLAGS setting in the build also still works, however the macros will be
5386copied to pnglibconf.h and this may produce macro redefinition warnings
5387when the individual C files are compiled.
5388
5389All configuration now only works if pnglibconf.h is built from
5390scripts/pnglibconf.dfa. This requires the program awk. Brian Kernighan
5391(the original author of awk) maintains C source code of that awk and this
5392and all known later implementations (often called by subtly different
5393names - nawk and gawk for example) are adequate to build pnglibconf.h.
5394The Sun Microsystems (now Oracle) program 'awk' is an earlier version
5395and does not work; this may also apply to other systems that have a
5396functioning awk called 'nawk'.
5397
5398Configuration options are now documented in scripts/pnglibconf.dfa. This
5399file also includes dependency information that ensures a configuration is
5400consistent; that is, if a feature is switched off dependent features are
5401also removed. As a recommended alternative to using feature macros in
5402pngusr.h a system builder may also define equivalent options in pngusr.dfa
5403(or, indeed, any file) and add that to the configuration by setting
5404DFA_XTRA to the file name. The makefiles in contrib/pngminim illustrate
5405how to do this, and a case where pngusr.h is still required.
5406
5407.SH XI. Detecting libpng
5408
5409The png_get_io_ptr() function has been present since libpng-0.88, has never
5410changed, and is unaffected by conditional compilation macros. It is the
5411best choice for use in configure scripts for detecting the presence of any
5412libpng version since 0.88. In an autoconf "configure.in" you could use
5413
5414 AC_CHECK_LIB(png, png_get_io_ptr, ...
5415
5416.SH XII. Source code repository
5417
5418Since about February 2009, version 1.2.34, libpng has been under "git" source
5419control. The git repository was built from old libpng-x.y.z.tar.gz files
5420going back to version 0.70. You can access the git repository (read only)
5421at
5422
5423 git://libpng.git.sourceforge.net/gitroot/libpng
5424
5425or you can browse it via "gitweb" at
5426
5427 http://libpng.git.sourceforge.net/git/gitweb.cgi?p=libpng
5428
5429Patches can be sent to glennrp at users.sourceforge.net or to
5430png-mng-implement at lists.sourceforge.net or you can upload them to
5431the libpng bug tracker at
5432
5433 http://libpng.sourceforge.net
5434
5435We also accept patches built from the tar or zip distributions, and
5436simple verbal discriptions of bug fixes, reported either to the
5437SourceForge bug tracker, to the png-mng-implement at lists.sf.net
5438mailing list, or directly to glennrp.
5439
5440.SH XIII. Coding style
5441
5442Our coding style is similar to the "Allman" style, with curly
5443braces on separate lines:
5444
5445 if (condition)
5446 {
5447 action;
5448 }
5449
5450 else if (another condition)
5451 {
5452 another action;
5453 }
5454
5455The braces can be omitted from simple one-line actions:
5456
5457 if (condition)
5458 return (0);
5459
5460We use 3-space indentation, except for continued statements which
5461are usually indented the same as the first line of the statement
5462plus four more spaces.
5463
5464For macro definitions we use 2-space indentation, always leaving the "#"
5465in the first column.
5466
5467 #ifndef PNG_NO_FEATURE
5468 # ifndef PNG_FEATURE_SUPPORTED
5469 # define PNG_FEATURE_SUPPORTED
5470 # endif
5471 #endif
5472
5473Comments appear with the leading "/*" at the same indentation as
5474the statement that follows the comment:
5475
5476 /* Single-line comment */
5477 statement;
5478
5479 /* This is a multiple-line
5480 * comment.
5481 */
5482 statement;
5483
5484Very short comments can be placed after the end of the statement
5485to which they pertain:
5486
5487 statement; /* comment */
5488
5489We don't use C++ style ("//") comments. We have, however,
5490used them in the past in some now-abandoned MMX assembler
5491code.
5492
5493Functions and their curly braces are not indented, and
5494exported functions are marked with PNGAPI:
5495
5496 /* This is a public function that is visible to
5497 * application programmers. It does thus-and-so.
5498 */
5499 void PNGAPI
5500 png_exported_function(png_ptr, png_info, foo)
5501 {
5502 body;
5503 }
5504
5505The prototypes for all exported functions appear in png.h,
5506above the comment that says
5507
5508 /* Maintainer: Put new public prototypes here ... */
5509
5510We mark all non-exported functions with "/* PRIVATE */"":
5511
5512 void /* PRIVATE */
5513 png_non_exported_function(png_ptr, png_info, foo)
5514 {
5515 body;
5516 }
5517
5518The prototypes for non-exported functions (except for those in
5519pngtest) appear in
5520pngpriv.h
5521above the comment that says
5522
5523 /* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
5524
5525To avoid polluting the global namespace, the names of all exported
5526functions and variables begin with "png_", and all publicly visible C
5527preprocessor macros begin with "PNG_". We request that applications that
5528use libpng *not* begin any of their own symbols with either of these strings.
5529
5530We put a space after each comma and after each semicolon
5531in "for" statements, and we put spaces before and after each
5532C binary operator and after "for" or "while", and before
5533"?". We don't put a space between a typecast and the expression
5534being cast, nor do we put one between a function name and the
5535left parenthesis that follows it:
5536
5537 for (i = 2; i > 0; --i)
5538 y[i] = a(x) + (int)b;
5539
5540We prefer #ifdef and #ifndef to #if defined() and if !defined()
5541when there is only one macro being tested.
5542
5543We prefer to express integers that are used as bit masks in hex format,
5544with an even number of lower-case hex digits (e.g., 0x00, 0xff, 0x0100).
5545
5546We do not use the TAB character for indentation in the C sources.
5547
5548Lines do not exceed 80 characters.
5549
5550Other rules can be inferred by inspecting the libpng source.
5551
5552.SH XIV. Y2K Compliance in libpng
5553
5554February 18, 2012
5555
5556Since the PNG Development group is an ad-hoc body, we can't make
5557an official declaration.
5558
5559This is your unofficial assurance that libpng from version 0.71 and
5560upward through 1.5.9 are Y2K compliant. It is my belief that earlier
5561versions were also Y2K compliant.
5562
5563Libpng only has three year fields. One is a 2-byte unsigned integer that
5564will hold years up to 65535. The other two hold the date in text
5565format, and will hold years up to 9999.
5566
5567The integer is
5568 "png_uint_16 year" in png_time_struct.
5569
5570The strings are
5571 "png_charp time_buffer" in png_struct and
5572 "near_time_buffer", which is a local character string in png.c.
5573
5574There are seven time-related functions:
5575
5576 png_convert_to_rfc_1123() in png.c
5577 (formerly png_convert_to_rfc_1152() in error)
5578 png_convert_from_struct_tm() in pngwrite.c, called
5579 in pngwrite.c
5580 png_convert_from_time_t() in pngwrite.c
5581 png_get_tIME() in pngget.c
5582 png_handle_tIME() in pngrutil.c, called in pngread.c
5583 png_set_tIME() in pngset.c
5584 png_write_tIME() in pngwutil.c, called in pngwrite.c
5585
5586All appear to handle dates properly in a Y2K environment. The
5587png_convert_from_time_t() function calls gmtime() to convert from system
5588clock time, which returns (year - 1900), which we properly convert to
5589the full 4-digit year. There is a possibility that applications using
5590libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
5591function, or that they are incorrectly passing only a 2-digit year
5592instead of "year - 1900" into the png_convert_from_struct_tm() function,
5593but this is not under our control. The libpng documentation has always
5594stated that it works with 4-digit years, and the APIs have been
5595documented as such.
5596
5597The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
5598integer to hold the year, and can hold years as large as 65535.
5599
5600zlib, upon which libpng depends, is also Y2K compliant. It contains
5601no date-related code.
5602
5603
5604 Glenn Randers-Pehrson
5605 libpng maintainer
5606 PNG Development Group
5607
5608.SH NOTE
5609
5610Note about libpng version numbers:
5611
5612Due to various miscommunications, unforeseen code incompatibilities
5613and occasional factors outside the authors' control, version numbering
5614on the library has not always been consistent and straightforward.
5615The following table summarizes matters since version 0.89c, which was
5616the first widely used release:
5617
5618 source png.h png.h shared-lib
5619 version string int version
5620 ------- ------ ----- ----------
5621 0.89c ("beta 3") 0.89 89 1.0.89
5622 0.90 ("beta 4") 0.90 90 0.90
5623 0.95 ("beta 5") 0.95 95 0.95
5624 0.96 ("beta 6") 0.96 96 0.96
5625 0.97b ("beta 7") 1.00.97 97 1.0.1
5626 0.97c 0.97 97 2.0.97
5627 0.98 0.98 98 2.0.98
5628 0.99 0.99 98 2.0.99
5629 0.99a-m 0.99 99 2.0.99
5630 1.00 1.00 100 2.1.0
5631 1.0.0 1.0.0 100 2.1.0
5632 1.0.0 (from here on, the 100 2.1.0
5633 1.0.1 png.h string is 10001 2.1.0
5634 1.0.1a-e identical to the 10002 from here on, the
5635 1.0.2 source version) 10002 shared library is 2.V
5636 1.0.2a-b 10003 where V is the source
5637 1.0.1 10001 code version except as
5638 1.0.1a-e 10002 2.1.0.1a-e noted.
5639 1.0.2 10002 2.1.0.2
5640 1.0.2a-b 10003 2.1.0.2a-b
5641 1.0.3 10003 2.1.0.3
5642 1.0.3a-d 10004 2.1.0.3a-d
5643 1.0.4 10004 2.1.0.4
5644 1.0.4a-f 10005 2.1.0.4a-f
5645 1.0.5 (+ 2 patches) 10005 2.1.0.5
5646 1.0.5a-d 10006 2.1.0.5a-d
5647 1.0.5e-r 10100 2.1.0.5e-r
5648 1.0.5s-v 10006 2.1.0.5s-v
5649 1.0.6 (+ 3 patches) 10006 2.1.0.6
5650 1.0.6d-g 10007 2.1.0.6d-g
5651 1.0.6h 10007 10.6h
5652 1.0.6i 10007 10.6i
5653 1.0.6j 10007 2.1.0.6j
5654 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14
5655 1.0.7beta15-18 1 10007 2.1.0.7beta15-18
5656 1.0.7rc1-2 1 10007 2.1.0.7rc1-2
5657 1.0.7 1 10007 2.1.0.7
5658 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
5659 1.0.8rc1 1 10008 2.1.0.8rc1
5660 1.0.8 1 10008 2.1.0.8
5661 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
5662 1.0.9rc1 1 10009 2.1.0.9rc1
5663 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
5664 1.0.9rc2 1 10009 2.1.0.9rc2
5665 1.0.9 1 10009 2.1.0.9
5666 1.0.10beta1 1 10010 2.1.0.10beta1
5667 1.0.10rc1 1 10010 2.1.0.10rc1
5668 1.0.10 1 10010 2.1.0.10
5669 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
5670 1.0.11rc1 1 10011 2.1.0.11rc1
5671 1.0.11 1 10011 2.1.0.11
5672 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
5673 1.0.12rc1 2 10012 2.1.0.12rc1
5674 1.0.12 2 10012 2.1.0.12
5675 1.1.0a-f - 10100 2.1.1.0a-f abandoned
5676 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
5677 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
5678 1.2.0rc1 3 10200 3.1.2.0rc1
5679 1.2.0 3 10200 3.1.2.0
5680 1.2.1beta-4 3 10201 3.1.2.1beta1-4
5681 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
5682 1.2.1 3 10201 3.1.2.1
5683 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
5684 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
5685 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
5686 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
5687 1.0.13 10 10013 10.so.0.1.0.13
5688 1.2.2 12 10202 12.so.0.1.2.2
5689 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
5690 1.2.3 12 10203 12.so.0.1.2.3
5691 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
5692 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
5693 1.0.14 10 10014 10.so.0.1.0.14
5694 1.2.4 13 10204 12.so.0.1.2.4
5695 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
5696 1.0.15rc1 10 10015 10.so.0.1.0.15rc1
5697 1.0.15 10 10015 10.so.0.1.0.15
5698 1.2.5 13 10205 12.so.0.1.2.5
5699 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
5700 1.2.6rc1-5 13 10206 12.so.0.1.2.6rc1-5
5701 1.0.16 10 10016 10.so.0.1.0.16
5702 1.2.6 13 10206 12.so.0.1.2.6
5703 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
5704 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
5705 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
5706 1.0.17 10 10017 12.so.0.1.0.17
5707 1.2.7 13 10207 12.so.0.1.2.7
5708 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
5709 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
5710 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
5711 1.0.18 10 10018 12.so.0.1.0.18
5712 1.2.8 13 10208 12.so.0.1.2.8
5713 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
5714 1.2.9beta4-11 13 10209 12.so.0.9[.0]
5715 1.2.9rc1 13 10209 12.so.0.9[.0]
5716 1.2.9 13 10209 12.so.0.9[.0]
5717 1.2.10beta1-7 13 10210 12.so.0.10[.0]
5718 1.2.10rc1-2 13 10210 12.so.0.10[.0]
5719 1.2.10 13 10210 12.so.0.10[.0]
5720 1.4.0beta1-6 14 10400 14.so.0.0[.0]
5721 1.2.11beta1-4 13 10210 12.so.0.11[.0]
5722 1.4.0beta7-8 14 10400 14.so.0.0[.0]
5723 1.2.11 13 10211 12.so.0.11[.0]
5724 1.2.12 13 10212 12.so.0.12[.0]
5725 1.4.0beta9-14 14 10400 14.so.0.0[.0]
5726 1.2.13 13 10213 12.so.0.13[.0]
5727 1.4.0beta15-36 14 10400 14.so.0.0[.0]
5728 1.4.0beta37-87 14 10400 14.so.14.0[.0]
5729 1.4.0rc01 14 10400 14.so.14.0[.0]
5730 1.4.0beta88-109 14 10400 14.so.14.0[.0]
5731 1.4.0rc02-08 14 10400 14.so.14.0[.0]
5732 1.4.0 14 10400 14.so.14.0[.0]
5733 1.4.1beta01-03 14 10401 14.so.14.1[.0]
5734 1.4.1rc01 14 10401 14.so.14.1[.0]
5735 1.4.1beta04-12 14 10401 14.so.14.1[.0]
5736 1.4.1 14 10401 14.so.14.1[.0]
5737 1.4.2 14 10402 14.so.14.2[.0]
5738 1.4.3 14 10403 14.so.14.3[.0]
5739 1.4.4 14 10404 14.so.14.4[.0]
5740 1.5.0beta01-58 15 10500 15.so.15.0[.0]
5741 1.5.0rc01-07 15 10500 15.so.15.0[.0]
5742 1.5.0 15 10500 15.so.15.0[.0]
5743 1.5.1beta01-11 15 10501 15.so.15.1[.0]
5744 1.5.1rc01-02 15 10501 15.so.15.1[.0]
5745 1.5.1 15 10501 15.so.15.1[.0]
5746 1.5.2beta01-03 15 10502 15.so.15.2[.0]
5747 1.5.2rc01-03 15 10502 15.so.15.2[.0]
5748 1.5.2 15 10502 15.so.15.2[.0]
5749 1.5.3beta01-10 15 10503 15.so.15.3[.0]
5750 1.5.3rc01-02 15 10503 15.so.15.3[.0]
5751 1.5.3beta11 15 10503 15.so.15.3[.0]
5752 1.5.3 [omitted]
5753 1.5.4beta01-08 15 10504 15.so.15.4[.0]
5754 1.5.4rc01 15 10504 15.so.15.4[.0]
5755 1.5.4 15 10504 15.so.15.4[.0]
5756 1.5.5beta01-08 15 10505 15.so.15.5[.0]
5757 1.5.5rc01 15 10505 15.so.15.5[.0]
5758 1.5.5 15 10505 15.so.15.5[.0]
5759 1.5.6beta01-07 15 10506 15.so.15.6[.0]
5760 1.5.6rc01-03 15 10506 15.so.15.6[.0]
5761 1.5.6 15 10506 15.so.15.6[.0]
5762 1.5.7beta01-05 15 10507 15.so.15.7[.0]
5763 1.5.7rc01-03 15 10507 15.so.15.7[.0]
5764 1.5.7 15 10507 15.so.15.7[.0]
5765 1.5.8beta01 15 10508 15.so.15.8[.0]
5766 1.5.8rc01 15 10508 15.so.15.8[.0]
5767 1.5.8 15 10508 15.so.15.8[.0]
5768 1.5.9beta01-02 15 10509 15.so.15.9[.0]
5769 1.5.9rc01 15 10509 15.so.15.9[.0]
5770 1.5.9 15 10509 15.so.15.9[.0]
5771
5772Henceforth the source version will match the shared-library minor
5773and patch numbers; the shared-library major version number will be
5774used for changes in backward compatibility, as it is intended. The
5775PNG_PNGLIB_VER macro, which is not used within libpng but is available
5776for applications, is an unsigned integer of the form xyyzz corresponding
5777to the source version x.y.z (leading zeros in y and z). Beta versions
5778were given the previous public release number plus a letter, until
5779version 1.0.6j; from then on they were given the upcoming public
5780release number plus "betaNN" or "rcN".
5781
5782.SH "SEE ALSO"
5783.BR "png"(5), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
5784
5785.LP
5786.IR libpng :
5787.IP
5788http://libpng.sourceforge.net (follow the [DOWNLOAD] link)
5789http://www.libpng.org/pub/png
5790
5791.LP
5792.IR zlib :
5793.IP
5794(generally) at the same location as
5795.I libpng
5796or at
5797.br
5798ftp://ftp.info-zip.org/pub/infozip/zlib
5799
5800.LP
5801.IR PNG specification: RFC 2083
5802.IP
5803(generally) at the same location as
5804.I libpng
5805or at
5806.br
5807ftp://ds.internic.net/rfc/rfc2083.txt
5808.br
5809or (as a W3C Recommendation) at
5810.br
5811http://www.w3.org/TR/REC-png.html
5812
5813.LP
5814In the case of any inconsistency between the PNG specification
5815and this library, the specification takes precedence.
5816
5817.SH AUTHORS
5818This man page: Glenn Randers-Pehrson
5819<glennrp at users.sourceforge.net>
5820
5821The contributing authors would like to thank all those who helped
5822with testing, bug fixes, and patience. This wouldn't have been
5823possible without all of you.
5824
5825Thanks to Frank J. T. Wojcik for helping with the documentation.
5826
5827Libpng version 1.5.9 - February 18, 2012:
5828Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
5829Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
5830
5831Supported by the PNG development group
5832.br
5833png-mng-implement at lists.sf.net
5834(subscription required; visit
5835png-mng-implement at lists.sourceforge.net (subscription required; visit
5836https://lists.sourceforge.net/lists/listinfo/png-mng-implement
5837to subscribe).
5838
5839.SH COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
5840
5841(This copy of the libpng notices is provided for your convenience. In case of
5842any discrepancy between this copy and the notices in the file png.h that is
5843included in the libpng distribution, the latter shall prevail.)
5844
5845If you modify libpng you may insert additional notices immediately following
5846this sentence.
5847
5848This code is released under the libpng license.
5849
5850libpng versions 1.2.6, August 15, 2004, through 1.5.9, February 18, 2012, are
5851Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
5852distributed according to the same disclaimer and license as libpng-1.2.5
5853with the following individual added to the list of Contributing Authors
5854
5855 Cosmin Truta
5856
5857libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
5858Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
5859distributed according to the same disclaimer and license as libpng-1.0.6
5860with the following individuals added to the list of Contributing Authors
5861
5862 Simon-Pierre Cadieux
5863 Eric S. Raymond
5864 Gilles Vollant
5865
5866and with the following additions to the disclaimer:
5867
5868 There is no warranty against interference with your
5869 enjoyment of the library or against infringement.
5870 There is no warranty that our efforts or the library
5871 will fulfill any of your particular purposes or needs.
5872 This library is provided with all faults, and the entire
5873 risk of satisfactory quality, performance, accuracy, and
5874 effort is with the user.
5875
5876libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
5877Copyright (c) 1998, 1999 Glenn Randers-Pehrson
5878Distributed according to the same disclaimer and license as libpng-0.96,
5879with the following individuals added to the list of Contributing Authors:
5880
5881 Tom Lane
5882 Glenn Randers-Pehrson
5883 Willem van Schaik
5884
5885libpng versions 0.89, June 1996, through 0.96, May 1997, are
5886Copyright (c) 1996, 1997 Andreas Dilger
5887Distributed according to the same disclaimer and license as libpng-0.88,
5888with the following individuals added to the list of Contributing Authors:
5889
5890 John Bowler
5891 Kevin Bracey
5892 Sam Bushell
5893 Magnus Holmgren
5894 Greg Roelofs
5895 Tom Tanner
5896
5897libpng versions 0.5, May 1995, through 0.88, January 1996, are
5898Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
5899
5900For the purposes of this copyright and license, "Contributing Authors"
5901is defined as the following set of individuals:
5902
5903 Andreas Dilger
5904 Dave Martindale
5905 Guy Eric Schalnat
5906 Paul Schmidt
5907 Tim Wegner
5908
5909The PNG Reference Library is supplied "AS IS". The Contributing Authors
5910and Group 42, Inc. disclaim all warranties, expressed or implied,
5911including, without limitation, the warranties of merchantability and of
5912fitness for any purpose. The Contributing Authors and Group 42, Inc.
5913assume no liability for direct, indirect, incidental, special, exemplary,
5914or consequential damages, which may result from the use of the PNG
5915Reference Library, even if advised of the possibility of such damage.
5916
5917Permission is hereby granted to use, copy, modify, and distribute this
5918source code, or portions hereof, for any purpose, without fee, subject
5919to the following restrictions:
5920
59211. The origin of this source code must not be misrepresented.
5922
59232. Altered versions must be plainly marked as such and
5924 must not be misrepresented as being the original source.
5925
59263. This Copyright notice may not be removed or altered from
5927 any source or altered source distribution.
5928
5929The Contributing Authors and Group 42, Inc. specifically permit, without
5930fee, and encourage the use of this source code as a component to
5931supporting the PNG file format in commercial products. If you use this
5932source code in a product, acknowledgment is not required but would be
5933appreciated.
5934
5935
5936A "png_get_copyright" function is available, for convenient use in "about"
5937boxes and the like:
5938
5939 printf("%s",png_get_copyright(NULL));
5940
5941Also, the PNG logo (in PNG format, of course) is supplied in the
5942files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
5943
5944Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
5945certification mark of the Open Source Initiative.
5946
5947Glenn Randers-Pehrson
5948glennrp at users.sourceforge.net
5949February 18, 2012
5950
5951.\" end of man page
5952
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.pc.in b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.pc.in
new file mode 100644
index 0000000..05ad81e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpng.pc.in
@@ -0,0 +1,11 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
5
6Name: libpng
7Description: Loads and saves PNG files
8Version: @PNGLIB_VERSION@
9Libs: -L${libdir} -lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@
10Libs.private: @LIBS@
11Cflags: -I${includedir}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpngpf.3 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpngpf.3
new file mode 100644
index 0000000..ef54f7b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/libpngpf.3
@@ -0,0 +1,28 @@
1.TH LIBPNGPF 3 "February 18, 2012"
2.SH NAME
3libpng \- Portable Network Graphics (PNG) Reference Library 1.5.9
4(private functions)
5.SH SYNOPSIS
6\fB#include \fI"pngpriv.h"
7
8\fI\fB
9
10\fBAs of libpng version \fP\fI1.5.1\fP\fB, this section is no longer \fP\fImaintained\fP\fB, now \fIthat
11
12\fBthe private function prototypes are hidden in pngpriv.h and not \fIaccessible
13
14\fBto applications. Look in pngpriv.h for the prototypes and a short \fIdescription
15
16\fBof each \fIfunction.
17
18\fI\fB
19
20.SH DESCRIPTION
21The functions previously listed here are used privately by libpng
22and are not recommended for use by applications. They are
23not "exported" to applications using shared libraries.
24
25.SH SEE ALSO
26.BR "png"(5), " libpng"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
27.SH AUTHOR
28Glenn Randers-Pehrson
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.5 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.5
new file mode 100644
index 0000000..6df917d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.5
@@ -0,0 +1,74 @@
1.TH PNG 5 "February 18, 2012"
2.SH NAME
3png \- Portable Network Graphics (PNG) format
4.SH DESCRIPTION
5PNG (Portable Network Graphics) is an extensible file format for the
6lossless, portable, well-compressed storage of raster images. PNG provides
7a patent-free replacement for GIF and can also replace many
8common uses of TIFF. Indexed-color, grayscale, and truecolor images are
9supported, plus an optional alpha channel. Sample depths range from
101 to 16 bits.
11.br
12
13PNG is designed to work well in online viewing applications, such as the
14World Wide Web, so it is fully streamable with a progressive display
15option. PNG is robust, providing both full file integrity checking and
16fast, simple detection of common transmission errors. Also, PNG can store
17gamma and chromaticity data for improved color matching on heterogeneous
18platforms.
19
20.SH "SEE ALSO"
21.BR "libpng"(3), " libpngpf"(3), " zlib"(3), " deflate"(5), " " and " zlib"(5)
22.LP
23PNG specification (second edition), November 2003:
24.IP
25.br
26 <http://www.w3.org/TR/2003/REC-PNG-20031110/
27PNG 1.2 specification, July 1999:
28.IP
29.br
30http://www.libpng.org/pub/png
31.LP
32PNG 1.0 specification, October 1996:
33.IP
34.br
35RFC 2083
36.IP
37.br
38ftp://ds.internic.net/rfc/rfc2083.txt
39.br
40or (as a W3C Recommendation) at
41.br
42http://www.w3.org/TR/REC-png.html
43.SH AUTHORS
44This man page: Glenn Randers-Pehrson
45.LP
46Portable Network Graphics (PNG) Specification (Second Edition)
47Information technology - Computer graphics and image processing -
48Portable Network Graphics (PNG): Functional specification.
49ISO/IEC 15948:2003 (E) (November 10, 2003): David Duce and others.
50.LP
51Portable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):
52Glenn Randers-Pehrson and others (png-list).
53.LP
54Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
55Thomas Boutell and others (png-list).
56.LP
57
58
59.SH COPYRIGHT NOTICE
60.LP
61This man page is Copyright (c) 1998-2006 Glenn Randers-Pehrson. See png.h
62for conditions of use and distribution.
63.LP
64The PNG Specification (Second Edition) is
65Copyright (c) 2003 W3C. (MIT, ERCIM, Keio), All Rights Reserved.
66.LP
67The PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.
68See the specification for conditions of use and distribution.
69.LP
70The PNG-1.0 specification is copyright (c) 1996 Massachusetts Institute of
71Technology. See the specification for conditions of use and distribution.
72.LP
73.\" end of man page
74
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.c
new file mode 100644
index 0000000..5a490b2
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.c
@@ -0,0 +1,2870 @@
1
2/* png.c - location for general purpose libpng functions
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16/* Generate a compiler error if there is an old png.h in the search path. */
17typedef png_libpng_version_1_5_9 Your_png_h_is_not_version_1_5_9;
18
19/* Tells libpng that we have already handled the first "num_bytes" bytes
20 * of the PNG file signature. If the PNG data is embedded into another
21 * stream we can set num_bytes = 8 so that libpng will not attempt to read
22 * or write any of the magic bytes before it starts on the IHDR.
23 */
24
25#ifdef PNG_READ_SUPPORTED
26void PNGAPI
27png_set_sig_bytes(png_structp png_ptr, int num_bytes)
28{
29 png_debug(1, "in png_set_sig_bytes");
30
31 if (png_ptr == NULL)
32 return;
33
34 if (num_bytes > 8)
35 png_error(png_ptr, "Too many bytes for PNG signature");
36
37 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
38}
39
40/* Checks whether the supplied bytes match the PNG signature. We allow
41 * checking less than the full 8-byte signature so that those apps that
42 * already read the first few bytes of a file to determine the file type
43 * can simply check the remaining bytes for extra assurance. Returns
44 * an integer less than, equal to, or greater than zero if sig is found,
45 * respectively, to be less than, to match, or be greater than the correct
46 * PNG signature (this is the same behavior as strcmp, memcmp, etc).
47 */
48int PNGAPI
49png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)
50{
51 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
52
53 if (num_to_check > 8)
54 num_to_check = 8;
55
56 else if (num_to_check < 1)
57 return (-1);
58
59 if (start > 7)
60 return (-1);
61
62 if (start + num_to_check > 8)
63 num_to_check = 8 - start;
64
65 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
66}
67
68#endif /* PNG_READ_SUPPORTED */
69
70#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
71/* Function to allocate memory for zlib */
72PNG_FUNCTION(voidpf /* PRIVATE */,
73png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
74{
75 png_voidp ptr;
76 png_structp p=(png_structp)png_ptr;
77 png_uint_32 save_flags=p->flags;
78 png_alloc_size_t num_bytes;
79
80 if (png_ptr == NULL)
81 return (NULL);
82
83 if (items > PNG_UINT_32_MAX/size)
84 {
85 png_warning (p, "Potential overflow in png_zalloc()");
86 return (NULL);
87 }
88 num_bytes = (png_alloc_size_t)items * size;
89
90 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
91 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
92 p->flags=save_flags;
93
94 return ((voidpf)ptr);
95}
96
97/* Function to free memory for zlib */
98void /* PRIVATE */
99png_zfree(voidpf png_ptr, voidpf ptr)
100{
101 png_free((png_structp)png_ptr, (png_voidp)ptr);
102}
103
104/* Reset the CRC variable to 32 bits of 1's. Care must be taken
105 * in case CRC is > 32 bits to leave the top bits 0.
106 */
107void /* PRIVATE */
108png_reset_crc(png_structp png_ptr)
109{
110 /* The cast is safe because the crc is a 32 bit value. */
111 png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);
112}
113
114/* Calculate the CRC over a section of data. We can only pass as
115 * much data to this routine as the largest single buffer size. We
116 * also check that this data will actually be used before going to the
117 * trouble of calculating it.
118 */
119void /* PRIVATE */
120png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length)
121{
122 int need_crc = 1;
123
124 if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name))
125 {
126 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
127 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
128 need_crc = 0;
129 }
130
131 else /* critical */
132 {
133 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
134 need_crc = 0;
135 }
136
137 /* 'uLong' is defined as unsigned long, this means that on some systems it is
138 * a 64 bit value. crc32, however, returns 32 bits so the following cast is
139 * safe. 'uInt' may be no more than 16 bits, so it is necessary to perform a
140 * loop here.
141 */
142 if (need_crc && length > 0)
143 {
144 uLong crc = png_ptr->crc; /* Should never issue a warning */
145
146 do
147 {
148 uInt safeLength = (uInt)length;
149 if (safeLength == 0)
150 safeLength = (uInt)-1; /* evil, but safe */
151
152 crc = crc32(crc, ptr, safeLength);
153
154 /* The following should never issue compiler warnings, if they do the
155 * target system has characteristics that will probably violate other
156 * assumptions within the libpng code.
157 */
158 ptr += safeLength;
159 length -= safeLength;
160 }
161 while (length > 0);
162
163 /* And the following is always safe because the crc is only 32 bits. */
164 png_ptr->crc = (png_uint_32)crc;
165 }
166}
167
168/* Check a user supplied version number, called from both read and write
169 * functions that create a png_struct
170 */
171int
172png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver)
173{
174 if (user_png_ver)
175 {
176 int i = 0;
177
178 do
179 {
180 if (user_png_ver[i] != png_libpng_ver[i])
181 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
182 } while (png_libpng_ver[i++]);
183 }
184
185 else
186 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
187
188 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
189 {
190 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
191 * we must recompile any applications that use any older library version.
192 * For versions after libpng 1.0, we will be compatible, so we need
193 * only check the first digit.
194 */
195 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
196 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
197 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
198 {
199#ifdef PNG_WARNINGS_SUPPORTED
200 size_t pos = 0;
201 char m[128];
202
203 pos = png_safecat(m, sizeof m, pos, "Application built with libpng-");
204 pos = png_safecat(m, sizeof m, pos, user_png_ver);
205 pos = png_safecat(m, sizeof m, pos, " but running with ");
206 pos = png_safecat(m, sizeof m, pos, png_libpng_ver);
207
208 png_warning(png_ptr, m);
209#endif
210
211#ifdef PNG_ERROR_NUMBERS_SUPPORTED
212 png_ptr->flags = 0;
213#endif
214
215 return 0;
216 }
217 }
218
219 /* Success return. */
220 return 1;
221}
222
223/* Allocate the memory for an info_struct for the application. We don't
224 * really need the png_ptr, but it could potentially be useful in the
225 * future. This should be used in favour of malloc(png_sizeof(png_info))
226 * and png_info_init() so that applications that want to use a shared
227 * libpng don't have to be recompiled if png_info changes size.
228 */
229PNG_FUNCTION(png_infop,PNGAPI
230png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED)
231{
232 png_infop info_ptr;
233
234 png_debug(1, "in png_create_info_struct");
235
236 if (png_ptr == NULL)
237 return (NULL);
238
239#ifdef PNG_USER_MEM_SUPPORTED
240 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
241 png_ptr->malloc_fn, png_ptr->mem_ptr);
242#else
243 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
244#endif
245 if (info_ptr != NULL)
246 png_info_init_3(&info_ptr, png_sizeof(png_info));
247
248 return (info_ptr);
249}
250
251/* This function frees the memory associated with a single info struct.
252 * Normally, one would use either png_destroy_read_struct() or
253 * png_destroy_write_struct() to free an info struct, but this may be
254 * useful for some applications.
255 */
256void PNGAPI
257png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
258{
259 png_infop info_ptr = NULL;
260
261 png_debug(1, "in png_destroy_info_struct");
262
263 if (png_ptr == NULL)
264 return;
265
266 if (info_ptr_ptr != NULL)
267 info_ptr = *info_ptr_ptr;
268
269 if (info_ptr != NULL)
270 {
271 png_info_destroy(png_ptr, info_ptr);
272
273#ifdef PNG_USER_MEM_SUPPORTED
274 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
275 png_ptr->mem_ptr);
276#else
277 png_destroy_struct((png_voidp)info_ptr);
278#endif
279 *info_ptr_ptr = NULL;
280 }
281}
282
283/* Initialize the info structure. This is now an internal function (0.89)
284 * and applications using it are urged to use png_create_info_struct()
285 * instead.
286 */
287
288void PNGAPI
289png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
290{
291 png_infop info_ptr = *ptr_ptr;
292
293 png_debug(1, "in png_info_init_3");
294
295 if (info_ptr == NULL)
296 return;
297
298 if (png_sizeof(png_info) > png_info_struct_size)
299 {
300 png_destroy_struct(info_ptr);
301 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
302 *ptr_ptr = info_ptr;
303 }
304
305 /* Set everything to 0 */
306 png_memset(info_ptr, 0, png_sizeof(png_info));
307}
308
309void PNGAPI
310png_data_freer(png_structp png_ptr, png_infop info_ptr,
311 int freer, png_uint_32 mask)
312{
313 png_debug(1, "in png_data_freer");
314
315 if (png_ptr == NULL || info_ptr == NULL)
316 return;
317
318 if (freer == PNG_DESTROY_WILL_FREE_DATA)
319 info_ptr->free_me |= mask;
320
321 else if (freer == PNG_USER_WILL_FREE_DATA)
322 info_ptr->free_me &= ~mask;
323
324 else
325 png_warning(png_ptr,
326 "Unknown freer parameter in png_data_freer");
327}
328
329void PNGAPI
330png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
331 int num)
332{
333 png_debug(1, "in png_free_data");
334
335 if (png_ptr == NULL || info_ptr == NULL)
336 return;
337
338#ifdef PNG_TEXT_SUPPORTED
339 /* Free text item num or (if num == -1) all text items */
340 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
341 {
342 if (num != -1)
343 {
344 if (info_ptr->text && info_ptr->text[num].key)
345 {
346 png_free(png_ptr, info_ptr->text[num].key);
347 info_ptr->text[num].key = NULL;
348 }
349 }
350
351 else
352 {
353 int i;
354 for (i = 0; i < info_ptr->num_text; i++)
355 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
356 png_free(png_ptr, info_ptr->text);
357 info_ptr->text = NULL;
358 info_ptr->num_text=0;
359 }
360 }
361#endif
362
363#ifdef PNG_tRNS_SUPPORTED
364 /* Free any tRNS entry */
365 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
366 {
367 png_free(png_ptr, info_ptr->trans_alpha);
368 info_ptr->trans_alpha = NULL;
369 info_ptr->valid &= ~PNG_INFO_tRNS;
370 }
371#endif
372
373#ifdef PNG_sCAL_SUPPORTED
374 /* Free any sCAL entry */
375 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
376 {
377 png_free(png_ptr, info_ptr->scal_s_width);
378 png_free(png_ptr, info_ptr->scal_s_height);
379 info_ptr->scal_s_width = NULL;
380 info_ptr->scal_s_height = NULL;
381 info_ptr->valid &= ~PNG_INFO_sCAL;
382 }
383#endif
384
385#ifdef PNG_pCAL_SUPPORTED
386 /* Free any pCAL entry */
387 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
388 {
389 png_free(png_ptr, info_ptr->pcal_purpose);
390 png_free(png_ptr, info_ptr->pcal_units);
391 info_ptr->pcal_purpose = NULL;
392 info_ptr->pcal_units = NULL;
393 if (info_ptr->pcal_params != NULL)
394 {
395 int i;
396 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
397 {
398 png_free(png_ptr, info_ptr->pcal_params[i]);
399 info_ptr->pcal_params[i] = NULL;
400 }
401 png_free(png_ptr, info_ptr->pcal_params);
402 info_ptr->pcal_params = NULL;
403 }
404 info_ptr->valid &= ~PNG_INFO_pCAL;
405 }
406#endif
407
408#ifdef PNG_iCCP_SUPPORTED
409 /* Free any iCCP entry */
410 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
411 {
412 png_free(png_ptr, info_ptr->iccp_name);
413 png_free(png_ptr, info_ptr->iccp_profile);
414 info_ptr->iccp_name = NULL;
415 info_ptr->iccp_profile = NULL;
416 info_ptr->valid &= ~PNG_INFO_iCCP;
417 }
418#endif
419
420#ifdef PNG_sPLT_SUPPORTED
421 /* Free a given sPLT entry, or (if num == -1) all sPLT entries */
422 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
423 {
424 if (num != -1)
425 {
426 if (info_ptr->splt_palettes)
427 {
428 png_free(png_ptr, info_ptr->splt_palettes[num].name);
429 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
430 info_ptr->splt_palettes[num].name = NULL;
431 info_ptr->splt_palettes[num].entries = NULL;
432 }
433 }
434
435 else
436 {
437 if (info_ptr->splt_palettes_num)
438 {
439 int i;
440 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
441 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
442
443 png_free(png_ptr, info_ptr->splt_palettes);
444 info_ptr->splt_palettes = NULL;
445 info_ptr->splt_palettes_num = 0;
446 }
447 info_ptr->valid &= ~PNG_INFO_sPLT;
448 }
449 }
450#endif
451
452#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
453 if (png_ptr->unknown_chunk.data)
454 {
455 png_free(png_ptr, png_ptr->unknown_chunk.data);
456 png_ptr->unknown_chunk.data = NULL;
457 }
458
459 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
460 {
461 if (num != -1)
462 {
463 if (info_ptr->unknown_chunks)
464 {
465 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
466 info_ptr->unknown_chunks[num].data = NULL;
467 }
468 }
469
470 else
471 {
472 int i;
473
474 if (info_ptr->unknown_chunks_num)
475 {
476 for (i = 0; i < info_ptr->unknown_chunks_num; i++)
477 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
478
479 png_free(png_ptr, info_ptr->unknown_chunks);
480 info_ptr->unknown_chunks = NULL;
481 info_ptr->unknown_chunks_num = 0;
482 }
483 }
484 }
485#endif
486
487#ifdef PNG_hIST_SUPPORTED
488 /* Free any hIST entry */
489 if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
490 {
491 png_free(png_ptr, info_ptr->hist);
492 info_ptr->hist = NULL;
493 info_ptr->valid &= ~PNG_INFO_hIST;
494 }
495#endif
496
497 /* Free any PLTE entry that was internally allocated */
498 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
499 {
500 png_zfree(png_ptr, info_ptr->palette);
501 info_ptr->palette = NULL;
502 info_ptr->valid &= ~PNG_INFO_PLTE;
503 info_ptr->num_palette = 0;
504 }
505
506#ifdef PNG_INFO_IMAGE_SUPPORTED
507 /* Free any image bits attached to the info structure */
508 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
509 {
510 if (info_ptr->row_pointers)
511 {
512 int row;
513 for (row = 0; row < (int)info_ptr->height; row++)
514 {
515 png_free(png_ptr, info_ptr->row_pointers[row]);
516 info_ptr->row_pointers[row] = NULL;
517 }
518 png_free(png_ptr, info_ptr->row_pointers);
519 info_ptr->row_pointers = NULL;
520 }
521 info_ptr->valid &= ~PNG_INFO_IDAT;
522 }
523#endif
524
525 if (num != -1)
526 mask &= ~PNG_FREE_MUL;
527
528 info_ptr->free_me &= ~mask;
529}
530
531/* This is an internal routine to free any memory that the info struct is
532 * pointing to before re-using it or freeing the struct itself. Recall
533 * that png_free() checks for NULL pointers for us.
534 */
535void /* PRIVATE */
536png_info_destroy(png_structp png_ptr, png_infop info_ptr)
537{
538 png_debug(1, "in png_info_destroy");
539
540 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
541
542#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
543 if (png_ptr->num_chunk_list)
544 {
545 png_free(png_ptr, png_ptr->chunk_list);
546 png_ptr->chunk_list = NULL;
547 png_ptr->num_chunk_list = 0;
548 }
549#endif
550
551 png_info_init_3(&info_ptr, png_sizeof(png_info));
552}
553#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
554
555/* This function returns a pointer to the io_ptr associated with the user
556 * functions. The application should free any memory associated with this
557 * pointer before png_write_destroy() or png_read_destroy() are called.
558 */
559png_voidp PNGAPI
560png_get_io_ptr(png_structp png_ptr)
561{
562 if (png_ptr == NULL)
563 return (NULL);
564
565 return (png_ptr->io_ptr);
566}
567
568#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
569# ifdef PNG_STDIO_SUPPORTED
570/* Initialize the default input/output functions for the PNG file. If you
571 * use your own read or write routines, you can call either png_set_read_fn()
572 * or png_set_write_fn() instead of png_init_io(). If you have defined
573 * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a
574 * function of your own because "FILE *" isn't necessarily available.
575 */
576void PNGAPI
577png_init_io(png_structp png_ptr, png_FILE_p fp)
578{
579 png_debug(1, "in png_init_io");
580
581 if (png_ptr == NULL)
582 return;
583
584 png_ptr->io_ptr = (png_voidp)fp;
585}
586# endif
587
588# ifdef PNG_TIME_RFC1123_SUPPORTED
589/* Convert the supplied time into an RFC 1123 string suitable for use in
590 * a "Creation Time" or other text-based time string.
591 */
592png_const_charp PNGAPI
593png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
594{
595 static PNG_CONST char short_months[12][4] =
596 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
597 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
598
599 if (png_ptr == NULL)
600 return (NULL);
601
602 if (ptime->year > 9999 /* RFC1123 limitation */ ||
603 ptime->month == 0 || ptime->month > 12 ||
604 ptime->day == 0 || ptime->day > 31 ||
605 ptime->hour > 23 || ptime->minute > 59 ||
606 ptime->second > 60)
607 {
608 png_warning(png_ptr, "Ignoring invalid time value");
609 return (NULL);
610 }
611
612 {
613 size_t pos = 0;
614 char number_buf[5]; /* enough for a four-digit year */
615
616# define APPEND_STRING(string)\
617 pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\
618 pos, (string))
619# define APPEND_NUMBER(format, value)\
620 APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))
621# define APPEND(ch)\
622 if (pos < (sizeof png_ptr->time_buffer)-1)\
623 png_ptr->time_buffer[pos++] = (ch)
624
625 APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day);
626 APPEND(' ');
627 APPEND_STRING(short_months[(ptime->month - 1)]);
628 APPEND(' ');
629 APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year);
630 APPEND(' ');
631 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour);
632 APPEND(':');
633 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute);
634 APPEND(':');
635 APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second);
636 APPEND_STRING(" +0000"); /* This reliably terminates the buffer */
637
638# undef APPEND
639# undef APPEND_NUMBER
640# undef APPEND_STRING
641 }
642
643 return png_ptr->time_buffer;
644}
645# endif /* PNG_TIME_RFC1123_SUPPORTED */
646
647#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
648
649png_const_charp PNGAPI
650png_get_copyright(png_const_structp png_ptr)
651{
652 PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */
653#ifdef PNG_STRING_COPYRIGHT
654 return PNG_STRING_COPYRIGHT
655#else
656# ifdef __STDC__
657 return PNG_STRING_NEWLINE \
658 "libpng version 1.5.9 - February 18, 2012" PNG_STRING_NEWLINE \
659 "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
660 "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
661 "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
662 PNG_STRING_NEWLINE;
663# else
664 return "libpng version 1.5.9 - February 18, 2012\
665 Copyright (c) 1998-2011 Glenn Randers-Pehrson\
666 Copyright (c) 1996-1997 Andreas Dilger\
667 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
668# endif
669#endif
670}
671
672/* The following return the library version as a short string in the
673 * format 1.0.0 through 99.99.99zz. To get the version of *.h files
674 * used with your application, print out PNG_LIBPNG_VER_STRING, which
675 * is defined in png.h.
676 * Note: now there is no difference between png_get_libpng_ver() and
677 * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard,
678 * it is guaranteed that png.c uses the correct version of png.h.
679 */
680png_const_charp PNGAPI
681png_get_libpng_ver(png_const_structp png_ptr)
682{
683 /* Version of *.c files used when building libpng */
684 return png_get_header_ver(png_ptr);
685}
686
687png_const_charp PNGAPI
688png_get_header_ver(png_const_structp png_ptr)
689{
690 /* Version of *.h files used when building libpng */
691 PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */
692 return PNG_LIBPNG_VER_STRING;
693}
694
695png_const_charp PNGAPI
696png_get_header_version(png_const_structp png_ptr)
697{
698 /* Returns longer string containing both version and date */
699 PNG_UNUSED(png_ptr) /* Silence compiler warning about unused png_ptr */
700#ifdef __STDC__
701 return PNG_HEADER_VERSION_STRING
702# ifndef PNG_READ_SUPPORTED
703 " (NO READ SUPPORT)"
704# endif
705 PNG_STRING_NEWLINE;
706#else
707 return PNG_HEADER_VERSION_STRING;
708#endif
709}
710
711#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
712int PNGAPI
713png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name)
714{
715 /* Check chunk_name and return "keep" value if it's on the list, else 0 */
716 png_const_bytep p, p_end;
717
718 if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list <= 0)
719 return PNG_HANDLE_CHUNK_AS_DEFAULT;
720
721 p_end = png_ptr->chunk_list;
722 p = p_end + png_ptr->num_chunk_list*5; /* beyond end */
723
724 /* The code is the fifth byte after each four byte string. Historically this
725 * code was always searched from the end of the list, so it should continue
726 * to do so in case there are duplicated entries.
727 */
728 do /* num_chunk_list > 0, so at least one */
729 {
730 p -= 5;
731 if (!png_memcmp(chunk_name, p, 4))
732 return p[4];
733 }
734 while (p > p_end);
735
736 return PNG_HANDLE_CHUNK_AS_DEFAULT;
737}
738
739int /* PRIVATE */
740png_chunk_unknown_handling(png_structp png_ptr, png_uint_32 chunk_name)
741{
742 png_byte chunk_string[5];
743
744 PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name);
745 return png_handle_as_unknown(png_ptr, chunk_string);
746}
747#endif
748
749#ifdef PNG_READ_SUPPORTED
750/* This function, added to libpng-1.0.6g, is untested. */
751int PNGAPI
752png_reset_zstream(png_structp png_ptr)
753{
754 if (png_ptr == NULL)
755 return Z_STREAM_ERROR;
756
757 return (inflateReset(&png_ptr->zstream));
758}
759#endif /* PNG_READ_SUPPORTED */
760
761/* This function was added to libpng-1.0.7 */
762png_uint_32 PNGAPI
763png_access_version_number(void)
764{
765 /* Version of *.c files used when building libpng */
766 return((png_uint_32)PNG_LIBPNG_VER);
767}
768
769
770
771#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
772/* png_convert_size: a PNGAPI but no longer in png.h, so deleted
773 * at libpng 1.5.5!
774 */
775
776/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
777# ifdef PNG_CHECK_cHRM_SUPPORTED
778
779int /* PRIVATE */
780png_check_cHRM_fixed(png_structp png_ptr,
781 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
782 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
783 png_fixed_point blue_x, png_fixed_point blue_y)
784{
785 int ret = 1;
786 unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
787
788 png_debug(1, "in function png_check_cHRM_fixed");
789
790 if (png_ptr == NULL)
791 return 0;
792
793 /* (x,y,z) values are first limited to 0..100000 (PNG_FP_1), the white
794 * y must also be greater than 0. To test for the upper limit calculate
795 * (PNG_FP_1-y) - x must be <= to this for z to be >= 0 (and the expression
796 * cannot overflow.) At this point we know x and y are >= 0 and (x+y) is
797 * <= PNG_FP_1. The previous test on PNG_MAX_UINT_31 is removed because it
798 * pointless (and it produces compiler warnings!)
799 */
800 if (white_x < 0 || white_y <= 0 ||
801 red_x < 0 || red_y < 0 ||
802 green_x < 0 || green_y < 0 ||
803 blue_x < 0 || blue_y < 0)
804 {
805 png_warning(png_ptr,
806 "Ignoring attempt to set negative chromaticity value");
807 ret = 0;
808 }
809 /* And (x+y) must be <= PNG_FP_1 (so z is >= 0) */
810 if (white_x > PNG_FP_1 - white_y)
811 {
812 png_warning(png_ptr, "Invalid cHRM white point");
813 ret = 0;
814 }
815
816 if (red_x > PNG_FP_1 - red_y)
817 {
818 png_warning(png_ptr, "Invalid cHRM red point");
819 ret = 0;
820 }
821
822 if (green_x > PNG_FP_1 - green_y)
823 {
824 png_warning(png_ptr, "Invalid cHRM green point");
825 ret = 0;
826 }
827
828 if (blue_x > PNG_FP_1 - blue_y)
829 {
830 png_warning(png_ptr, "Invalid cHRM blue point");
831 ret = 0;
832 }
833
834 png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo);
835 png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo);
836
837 if (xy_hi == yx_hi && xy_lo == yx_lo)
838 {
839 png_warning(png_ptr,
840 "Ignoring attempt to set cHRM RGB triangle with zero area");
841 ret = 0;
842 }
843
844 return ret;
845}
846# endif /* PNG_CHECK_cHRM_SUPPORTED */
847
848#ifdef PNG_cHRM_SUPPORTED
849/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for
850 * cHRM, as opposed to using chromaticities. These internal APIs return
851 * non-zero on a parameter error. The X, Y and Z values are required to be
852 * positive and less than 1.0.
853 */
854int png_xy_from_XYZ(png_xy *xy, png_XYZ XYZ)
855{
856 png_int_32 d, dwhite, whiteX, whiteY;
857
858 d = XYZ.redX + XYZ.redY + XYZ.redZ;
859 if (!png_muldiv(&xy->redx, XYZ.redX, PNG_FP_1, d)) return 1;
860 if (!png_muldiv(&xy->redy, XYZ.redY, PNG_FP_1, d)) return 1;
861 dwhite = d;
862 whiteX = XYZ.redX;
863 whiteY = XYZ.redY;
864
865 d = XYZ.greenX + XYZ.greenY + XYZ.greenZ;
866 if (!png_muldiv(&xy->greenx, XYZ.greenX, PNG_FP_1, d)) return 1;
867 if (!png_muldiv(&xy->greeny, XYZ.greenY, PNG_FP_1, d)) return 1;
868 dwhite += d;
869 whiteX += XYZ.greenX;
870 whiteY += XYZ.greenY;
871
872 d = XYZ.blueX + XYZ.blueY + XYZ.blueZ;
873 if (!png_muldiv(&xy->bluex, XYZ.blueX, PNG_FP_1, d)) return 1;
874 if (!png_muldiv(&xy->bluey, XYZ.blueY, PNG_FP_1, d)) return 1;
875 dwhite += d;
876 whiteX += XYZ.blueX;
877 whiteY += XYZ.blueY;
878
879 /* The reference white is simply the same of the end-point (X,Y,Z) vectors,
880 * thus:
881 */
882 if (!png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite)) return 1;
883 if (!png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite)) return 1;
884
885 return 0;
886}
887
888int png_XYZ_from_xy(png_XYZ *XYZ, png_xy xy)
889{
890 png_fixed_point red_inverse, green_inverse, blue_scale;
891 png_fixed_point left, right, denominator;
892
893 /* Check xy and, implicitly, z. Note that wide gamut color spaces typically
894 * have end points with 0 tristimulus values (these are impossible end
895 * points, but they are used to cover the possible colors.)
896 */
897 if (xy.redx < 0 || xy.redx > PNG_FP_1) return 1;
898 if (xy.redy < 0 || xy.redy > PNG_FP_1-xy.redx) return 1;
899 if (xy.greenx < 0 || xy.greenx > PNG_FP_1) return 1;
900 if (xy.greeny < 0 || xy.greeny > PNG_FP_1-xy.greenx) return 1;
901 if (xy.bluex < 0 || xy.bluex > PNG_FP_1) return 1;
902 if (xy.bluey < 0 || xy.bluey > PNG_FP_1-xy.bluex) return 1;
903 if (xy.whitex < 0 || xy.whitex > PNG_FP_1) return 1;
904 if (xy.whitey < 0 || xy.whitey > PNG_FP_1-xy.whitex) return 1;
905
906 /* The reverse calculation is more difficult because the original tristimulus
907 * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8
908 * derived values were recorded in the cHRM chunk;
909 * (red,green,blue,white)x(x,y). This loses one degree of freedom and
910 * therefore an arbitrary ninth value has to be introduced to undo the
911 * original transformations.
912 *
913 * Think of the original end-points as points in (X,Y,Z) space. The
914 * chromaticity values (c) have the property:
915 *
916 * C
917 * c = ---------
918 * X + Y + Z
919 *
920 * For each c (x,y,z) from the corresponding original C (X,Y,Z). Thus the
921 * three chromaticity values (x,y,z) for each end-point obey the
922 * relationship:
923 *
924 * x + y + z = 1
925 *
926 * This describes the plane in (X,Y,Z) space that intersects each axis at the
927 * value 1.0; call this the chromaticity plane. Thus the chromaticity
928 * calculation has scaled each end-point so that it is on the x+y+z=1 plane
929 * and chromaticity is the intersection of the vector from the origin to the
930 * (X,Y,Z) value with the chromaticity plane.
931 *
932 * To fully invert the chromaticity calculation we would need the three
933 * end-point scale factors, (red-scale, green-scale, blue-scale), but these
934 * were not recorded. Instead we calculated the reference white (X,Y,Z) and
935 * recorded the chromaticity of this. The reference white (X,Y,Z) would have
936 * given all three of the scale factors since:
937 *
938 * color-C = color-c * color-scale
939 * white-C = red-C + green-C + blue-C
940 * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale
941 *
942 * But cHRM records only white-x and white-y, so we have lost the white scale
943 * factor:
944 *
945 * white-C = white-c*white-scale
946 *
947 * To handle this the inverse transformation makes an arbitrary assumption
948 * about white-scale:
949 *
950 * Assume: white-Y = 1.0
951 * Hence: white-scale = 1/white-y
952 * Or: red-Y + green-Y + blue-Y = 1.0
953 *
954 * Notice the last statement of the assumption gives an equation in three of
955 * the nine values we want to calculate. 8 more equations come from the
956 * above routine as summarised at the top above (the chromaticity
957 * calculation):
958 *
959 * Given: color-x = color-X / (color-X + color-Y + color-Z)
960 * Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0
961 *
962 * This is 9 simultaneous equations in the 9 variables "color-C" and can be
963 * solved by Cramer's rule. Cramer's rule requires calculating 10 9x9 matrix
964 * determinants, however this is not as bad as it seems because only 28 of
965 * the total of 90 terms in the various matrices are non-zero. Nevertheless
966 * Cramer's rule is notoriously numerically unstable because the determinant
967 * calculation involves the difference of large, but similar, numbers. It is
968 * difficult to be sure that the calculation is stable for real world values
969 * and it is certain that it becomes unstable where the end points are close
970 * together.
971 *
972 * So this code uses the perhaps slighly less optimal but more understandable
973 * and totally obvious approach of calculating color-scale.
974 *
975 * This algorithm depends on the precision in white-scale and that is
976 * (1/white-y), so we can immediately see that as white-y approaches 0 the
977 * accuracy inherent in the cHRM chunk drops off substantially.
978 *
979 * libpng arithmetic: a simple invertion of the above equations
980 * ------------------------------------------------------------
981 *
982 * white_scale = 1/white-y
983 * white-X = white-x * white-scale
984 * white-Y = 1.0
985 * white-Z = (1 - white-x - white-y) * white_scale
986 *
987 * white-C = red-C + green-C + blue-C
988 * = red-c*red-scale + green-c*green-scale + blue-c*blue-scale
989 *
990 * This gives us three equations in (red-scale,green-scale,blue-scale) where
991 * all the coefficients are now known:
992 *
993 * red-x*red-scale + green-x*green-scale + blue-x*blue-scale
994 * = white-x/white-y
995 * red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1
996 * red-z*red-scale + green-z*green-scale + blue-z*blue-scale
997 * = (1 - white-x - white-y)/white-y
998 *
999 * In the last equation color-z is (1 - color-x - color-y) so we can add all
1000 * three equations together to get an alternative third:
1001 *
1002 * red-scale + green-scale + blue-scale = 1/white-y = white-scale
1003 *
1004 * So now we have a Cramer's rule solution where the determinants are just
1005 * 3x3 - far more tractible. Unfortunately 3x3 determinants still involve
1006 * multiplication of three coefficients so we can't guarantee to avoid
1007 * overflow in the libpng fixed point representation. Using Cramer's rule in
1008 * floating point is probably a good choice here, but it's not an option for
1009 * fixed point. Instead proceed to simplify the first two equations by
1010 * eliminating what is likely to be the largest value, blue-scale:
1011 *
1012 * blue-scale = white-scale - red-scale - green-scale
1013 *
1014 * Hence:
1015 *
1016 * (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale =
1017 * (white-x - blue-x)*white-scale
1018 *
1019 * (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale =
1020 * 1 - blue-y*white-scale
1021 *
1022 * And now we can trivially solve for (red-scale,green-scale):
1023 *
1024 * green-scale =
1025 * (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale
1026 * -----------------------------------------------------------
1027 * green-x - blue-x
1028 *
1029 * red-scale =
1030 * 1 - blue-y*white-scale - (green-y - blue-y) * green-scale
1031 * ---------------------------------------------------------
1032 * red-y - blue-y
1033 *
1034 * Hence:
1035 *
1036 * red-scale =
1037 * ( (green-x - blue-x) * (white-y - blue-y) -
1038 * (green-y - blue-y) * (white-x - blue-x) ) / white-y
1039 * -------------------------------------------------------------------------
1040 * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x)
1041 *
1042 * green-scale =
1043 * ( (red-y - blue-y) * (white-x - blue-x) -
1044 * (red-x - blue-x) * (white-y - blue-y) ) / white-y
1045 * -------------------------------------------------------------------------
1046 * (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x)
1047 *
1048 * Accuracy:
1049 * The input values have 5 decimal digits of accuracy. The values are all in
1050 * the range 0 < value < 1, so simple products are in the same range but may
1051 * need up to 10 decimal digits to preserve the original precision and avoid
1052 * underflow. Because we are using a 32-bit signed representation we cannot
1053 * match this; the best is a little over 9 decimal digits, less than 10.
1054 *
1055 * The approach used here is to preserve the maximum precision within the
1056 * signed representation. Because the red-scale calculation above uses the
1057 * difference between two products of values that must be in the range -1..+1
1058 * it is sufficient to divide the product by 7; ceil(100,000/32767*2). The
1059 * factor is irrelevant in the calculation because it is applied to both
1060 * numerator and denominator.
1061 *
1062 * Note that the values of the differences of the products of the
1063 * chromaticities in the above equations tend to be small, for example for
1064 * the sRGB chromaticities they are:
1065 *
1066 * red numerator: -0.04751
1067 * green numerator: -0.08788
1068 * denominator: -0.2241 (without white-y multiplication)
1069 *
1070 * The resultant Y coefficients from the chromaticities of some widely used
1071 * color space definitions are (to 15 decimal places):
1072 *
1073 * sRGB
1074 * 0.212639005871510 0.715168678767756 0.072192315360734
1075 * Kodak ProPhoto
1076 * 0.288071128229293 0.711843217810102 0.000085653960605
1077 * Adobe RGB
1078 * 0.297344975250536 0.627363566255466 0.075291458493998
1079 * Adobe Wide Gamut RGB
1080 * 0.258728243040113 0.724682314948566 0.016589442011321
1081 */
1082 /* By the argument, above overflow should be impossible here. The return
1083 * value of 2 indicates an internal error to the caller.
1084 */
1085 if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.redy - xy.bluey, 7)) return 2;
1086 if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.redx - xy.bluex, 7)) return 2;
1087 denominator = left - right;
1088
1089 /* Now find the red numerator. */
1090 if (!png_muldiv(&left, xy.greenx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2;
1091 if (!png_muldiv(&right, xy.greeny-xy.bluey, xy.whitex-xy.bluex, 7)) return 2;
1092
1093 /* Overflow is possible here and it indicates an extreme set of PNG cHRM
1094 * chunk values. This calculation actually returns the reciprocal of the
1095 * scale value because this allows us to delay the multiplication of white-y
1096 * into the denominator, which tends to produce a small number.
1097 */
1098 if (!png_muldiv(&red_inverse, xy.whitey, denominator, left-right) ||
1099 red_inverse <= xy.whitey /* r+g+b scales = white scale */)
1100 return 1;
1101
1102 /* Similarly for green_inverse: */
1103 if (!png_muldiv(&left, xy.redy-xy.bluey, xy.whitex-xy.bluex, 7)) return 2;
1104 if (!png_muldiv(&right, xy.redx-xy.bluex, xy.whitey-xy.bluey, 7)) return 2;
1105 if (!png_muldiv(&green_inverse, xy.whitey, denominator, left-right) ||
1106 green_inverse <= xy.whitey)
1107 return 1;
1108
1109 /* And the blue scale, the checks above guarantee this can't overflow but it
1110 * can still produce 0 for extreme cHRM values.
1111 */
1112 blue_scale = png_reciprocal(xy.whitey) - png_reciprocal(red_inverse) -
1113 png_reciprocal(green_inverse);
1114 if (blue_scale <= 0) return 1;
1115
1116
1117 /* And fill in the png_XYZ: */
1118 if (!png_muldiv(&XYZ->redX, xy.redx, PNG_FP_1, red_inverse)) return 1;
1119 if (!png_muldiv(&XYZ->redY, xy.redy, PNG_FP_1, red_inverse)) return 1;
1120 if (!png_muldiv(&XYZ->redZ, PNG_FP_1 - xy.redx - xy.redy, PNG_FP_1,
1121 red_inverse))
1122 return 1;
1123
1124 if (!png_muldiv(&XYZ->greenX, xy.greenx, PNG_FP_1, green_inverse)) return 1;
1125 if (!png_muldiv(&XYZ->greenY, xy.greeny, PNG_FP_1, green_inverse)) return 1;
1126 if (!png_muldiv(&XYZ->greenZ, PNG_FP_1 - xy.greenx - xy.greeny, PNG_FP_1,
1127 green_inverse))
1128 return 1;
1129
1130 if (!png_muldiv(&XYZ->blueX, xy.bluex, blue_scale, PNG_FP_1)) return 1;
1131 if (!png_muldiv(&XYZ->blueY, xy.bluey, blue_scale, PNG_FP_1)) return 1;
1132 if (!png_muldiv(&XYZ->blueZ, PNG_FP_1 - xy.bluex - xy.bluey, blue_scale,
1133 PNG_FP_1))
1134 return 1;
1135
1136 return 0; /*success*/
1137}
1138
1139int png_XYZ_from_xy_checked(png_structp png_ptr, png_XYZ *XYZ, png_xy xy)
1140{
1141 switch (png_XYZ_from_xy(XYZ, xy))
1142 {
1143 case 0: /* success */
1144 return 1;
1145
1146 case 1:
1147 /* The chunk may be technically valid, but we got png_fixed_point
1148 * overflow while trying to get XYZ values out of it. This is
1149 * entirely benign - the cHRM chunk is pretty extreme.
1150 */
1151 png_warning(png_ptr,
1152 "extreme cHRM chunk cannot be converted to tristimulus values");
1153 break;
1154
1155 default:
1156 /* libpng is broken; this should be a warning but if it happens we
1157 * want error reports so for the moment it is an error.
1158 */
1159 png_error(png_ptr, "internal error in png_XYZ_from_xy");
1160 break;
1161 }
1162
1163 /* ERROR RETURN */
1164 return 0;
1165}
1166#endif
1167
1168void /* PRIVATE */
1169png_check_IHDR(png_structp png_ptr,
1170 png_uint_32 width, png_uint_32 height, int bit_depth,
1171 int color_type, int interlace_type, int compression_type,
1172 int filter_type)
1173{
1174 int error = 0;
1175
1176 /* Check for width and height valid values */
1177 if (width == 0)
1178 {
1179 png_warning(png_ptr, "Image width is zero in IHDR");
1180 error = 1;
1181 }
1182
1183 if (height == 0)
1184 {
1185 png_warning(png_ptr, "Image height is zero in IHDR");
1186 error = 1;
1187 }
1188
1189# ifdef PNG_SET_USER_LIMITS_SUPPORTED
1190 if (width > png_ptr->user_width_max)
1191
1192# else
1193 if (width > PNG_USER_WIDTH_MAX)
1194# endif
1195 {
1196 png_warning(png_ptr, "Image width exceeds user limit in IHDR");
1197 error = 1;
1198 }
1199
1200# ifdef PNG_SET_USER_LIMITS_SUPPORTED
1201 if (height > png_ptr->user_height_max)
1202# else
1203 if (height > PNG_USER_HEIGHT_MAX)
1204# endif
1205 {
1206 png_warning(png_ptr, "Image height exceeds user limit in IHDR");
1207 error = 1;
1208 }
1209
1210 if (width > PNG_UINT_31_MAX)
1211 {
1212 png_warning(png_ptr, "Invalid image width in IHDR");
1213 error = 1;
1214 }
1215
1216 if (height > PNG_UINT_31_MAX)
1217 {
1218 png_warning(png_ptr, "Invalid image height in IHDR");
1219 error = 1;
1220 }
1221
1222 if (width > (PNG_UINT_32_MAX
1223 >> 3) /* 8-byte RGBA pixels */
1224 - 48 /* bigrowbuf hack */
1225 - 1 /* filter byte */
1226 - 7*8 /* rounding of width to multiple of 8 pixels */
1227 - 8) /* extra max_pixel_depth pad */
1228 png_warning(png_ptr, "Width is too large for libpng to process pixels");
1229
1230 /* Check other values */
1231 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
1232 bit_depth != 8 && bit_depth != 16)
1233 {
1234 png_warning(png_ptr, "Invalid bit depth in IHDR");
1235 error = 1;
1236 }
1237
1238 if (color_type < 0 || color_type == 1 ||
1239 color_type == 5 || color_type > 6)
1240 {
1241 png_warning(png_ptr, "Invalid color type in IHDR");
1242 error = 1;
1243 }
1244
1245 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
1246 ((color_type == PNG_COLOR_TYPE_RGB ||
1247 color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
1248 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
1249 {
1250 png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
1251 error = 1;
1252 }
1253
1254 if (interlace_type >= PNG_INTERLACE_LAST)
1255 {
1256 png_warning(png_ptr, "Unknown interlace method in IHDR");
1257 error = 1;
1258 }
1259
1260 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
1261 {
1262 png_warning(png_ptr, "Unknown compression method in IHDR");
1263 error = 1;
1264 }
1265
1266# ifdef PNG_MNG_FEATURES_SUPPORTED
1267 /* Accept filter_method 64 (intrapixel differencing) only if
1268 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
1269 * 2. Libpng did not read a PNG signature (this filter_method is only
1270 * used in PNG datastreams that are embedded in MNG datastreams) and
1271 * 3. The application called png_permit_mng_features with a mask that
1272 * included PNG_FLAG_MNG_FILTER_64 and
1273 * 4. The filter_method is 64 and
1274 * 5. The color_type is RGB or RGBA
1275 */
1276 if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
1277 png_ptr->mng_features_permitted)
1278 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
1279
1280 if (filter_type != PNG_FILTER_TYPE_BASE)
1281 {
1282 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
1283 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
1284 ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
1285 (color_type == PNG_COLOR_TYPE_RGB ||
1286 color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
1287 {
1288 png_warning(png_ptr, "Unknown filter method in IHDR");
1289 error = 1;
1290 }
1291
1292 if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
1293 {
1294 png_warning(png_ptr, "Invalid filter method in IHDR");
1295 error = 1;
1296 }
1297 }
1298
1299# else
1300 if (filter_type != PNG_FILTER_TYPE_BASE)
1301 {
1302 png_warning(png_ptr, "Unknown filter method in IHDR");
1303 error = 1;
1304 }
1305# endif
1306
1307 if (error == 1)
1308 png_error(png_ptr, "Invalid IHDR data");
1309}
1310
1311#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
1312/* ASCII to fp functions */
1313/* Check an ASCII formated floating point value, see the more detailed
1314 * comments in pngpriv.h
1315 */
1316/* The following is used internally to preserve the sticky flags */
1317#define png_fp_add(state, flags) ((state) |= (flags))
1318#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))
1319
1320int /* PRIVATE */
1321png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
1322 png_size_tp whereami)
1323{
1324 int state = *statep;
1325 png_size_t i = *whereami;
1326
1327 while (i < size)
1328 {
1329 int type;
1330 /* First find the type of the next character */
1331 switch (string[i])
1332 {
1333 case 43: type = PNG_FP_SAW_SIGN; break;
1334 case 45: type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break;
1335 case 46: type = PNG_FP_SAW_DOT; break;
1336 case 48: type = PNG_FP_SAW_DIGIT; break;
1337 case 49: case 50: case 51: case 52:
1338 case 53: case 54: case 55: case 56:
1339 case 57: type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break;
1340 case 69:
1341 case 101: type = PNG_FP_SAW_E; break;
1342 default: goto PNG_FP_End;
1343 }
1344
1345 /* Now deal with this type according to the current
1346 * state, the type is arranged to not overlap the
1347 * bits of the PNG_FP_STATE.
1348 */
1349 switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY))
1350 {
1351 case PNG_FP_INTEGER + PNG_FP_SAW_SIGN:
1352 if (state & PNG_FP_SAW_ANY)
1353 goto PNG_FP_End; /* not a part of the number */
1354
1355 png_fp_add(state, type);
1356 break;
1357
1358 case PNG_FP_INTEGER + PNG_FP_SAW_DOT:
1359 /* Ok as trailer, ok as lead of fraction. */
1360 if (state & PNG_FP_SAW_DOT) /* two dots */
1361 goto PNG_FP_End;
1362
1363 else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */
1364 png_fp_add(state, type);
1365
1366 else
1367 png_fp_set(state, PNG_FP_FRACTION | type);
1368
1369 break;
1370
1371 case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT:
1372 if (state & PNG_FP_SAW_DOT) /* delayed fraction */
1373 png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT);
1374
1375 png_fp_add(state, type | PNG_FP_WAS_VALID);
1376
1377 break;
1378
1379 case PNG_FP_INTEGER + PNG_FP_SAW_E:
1380 if ((state & PNG_FP_SAW_DIGIT) == 0)
1381 goto PNG_FP_End;
1382
1383 png_fp_set(state, PNG_FP_EXPONENT);
1384
1385 break;
1386
1387 /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN:
1388 goto PNG_FP_End; ** no sign in fraction */
1389
1390 /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT:
1391 goto PNG_FP_End; ** Because SAW_DOT is always set */
1392
1393 case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT:
1394 png_fp_add(state, type | PNG_FP_WAS_VALID);
1395 break;
1396
1397 case PNG_FP_FRACTION + PNG_FP_SAW_E:
1398 /* This is correct because the trailing '.' on an
1399 * integer is handled above - so we can only get here
1400 * with the sequence ".E" (with no preceding digits).
1401 */
1402 if ((state & PNG_FP_SAW_DIGIT) == 0)
1403 goto PNG_FP_End;
1404
1405 png_fp_set(state, PNG_FP_EXPONENT);
1406
1407 break;
1408
1409 case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN:
1410 if (state & PNG_FP_SAW_ANY)
1411 goto PNG_FP_End; /* not a part of the number */
1412
1413 png_fp_add(state, PNG_FP_SAW_SIGN);
1414
1415 break;
1416
1417 /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT:
1418 goto PNG_FP_End; */
1419
1420 case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT:
1421 png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID);
1422
1423 break;
1424
1425 /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E:
1426 goto PNG_FP_End; */
1427
1428 default: goto PNG_FP_End; /* I.e. break 2 */
1429 }
1430
1431 /* The character seems ok, continue. */
1432 ++i;
1433 }
1434
1435PNG_FP_End:
1436 /* Here at the end, update the state and return the correct
1437 * return code.
1438 */
1439 *statep = state;
1440 *whereami = i;
1441
1442 return (state & PNG_FP_SAW_DIGIT) != 0;
1443}
1444
1445
1446/* The same but for a complete string. */
1447int
1448png_check_fp_string(png_const_charp string, png_size_t size)
1449{
1450 int state=0;
1451 png_size_t char_index=0;
1452
1453 if (png_check_fp_number(string, size, &state, &char_index) &&
1454 (char_index == size || string[char_index] == 0))
1455 return state /* must be non-zero - see above */;
1456
1457 return 0; /* i.e. fail */
1458}
1459#endif /* pCAL or sCAL */
1460
1461#ifdef PNG_READ_sCAL_SUPPORTED
1462# ifdef PNG_FLOATING_POINT_SUPPORTED
1463/* Utility used below - a simple accurate power of ten from an integral
1464 * exponent.
1465 */
1466static double
1467png_pow10(int power)
1468{
1469 int recip = 0;
1470 double d = 1;
1471
1472 /* Handle negative exponent with a reciprocal at the end because
1473 * 10 is exact whereas .1 is inexact in base 2
1474 */
1475 if (power < 0)
1476 {
1477 if (power < DBL_MIN_10_EXP) return 0;
1478 recip = 1, power = -power;
1479 }
1480
1481 if (power > 0)
1482 {
1483 /* Decompose power bitwise. */
1484 double mult = 10;
1485 do
1486 {
1487 if (power & 1) d *= mult;
1488 mult *= mult;
1489 power >>= 1;
1490 }
1491 while (power > 0);
1492
1493 if (recip) d = 1/d;
1494 }
1495 /* else power is 0 and d is 1 */
1496
1497 return d;
1498}
1499
1500/* Function to format a floating point value in ASCII with a given
1501 * precision.
1502 */
1503void /* PRIVATE */
1504png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size,
1505 double fp, unsigned int precision)
1506{
1507 /* We use standard functions from math.h, but not printf because
1508 * that would require stdio. The caller must supply a buffer of
1509 * sufficient size or we will png_error. The tests on size and
1510 * the space in ascii[] consumed are indicated below.
1511 */
1512 if (precision < 1)
1513 precision = DBL_DIG;
1514
1515 /* Enforce the limit of the implementation precision too. */
1516 if (precision > DBL_DIG+1)
1517 precision = DBL_DIG+1;
1518
1519 /* Basic sanity checks */
1520 if (size >= precision+5) /* See the requirements below. */
1521 {
1522 if (fp < 0)
1523 {
1524 fp = -fp;
1525 *ascii++ = 45; /* '-' PLUS 1 TOTAL 1 */
1526 --size;
1527 }
1528
1529 if (fp >= DBL_MIN && fp <= DBL_MAX)
1530 {
1531 int exp_b10; /* A base 10 exponent */
1532 double base; /* 10^exp_b10 */
1533
1534 /* First extract a base 10 exponent of the number,
1535 * the calculation below rounds down when converting
1536 * from base 2 to base 10 (multiply by log10(2) -
1537 * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to
1538 * be increased. Note that the arithmetic shift
1539 * performs a floor() unlike C arithmetic - using a
1540 * C multiply would break the following for negative
1541 * exponents.
1542 */
1543 (void)frexp(fp, &exp_b10); /* exponent to base 2 */
1544
1545 exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */
1546
1547 /* Avoid underflow here. */
1548 base = png_pow10(exp_b10); /* May underflow */
1549
1550 while (base < DBL_MIN || base < fp)
1551 {
1552 /* And this may overflow. */
1553 double test = png_pow10(exp_b10+1);
1554
1555 if (test <= DBL_MAX)
1556 ++exp_b10, base = test;
1557
1558 else
1559 break;
1560 }
1561
1562 /* Normalize fp and correct exp_b10, after this fp is in the
1563 * range [.1,1) and exp_b10 is both the exponent and the digit
1564 * *before* which the decimal point should be inserted
1565 * (starting with 0 for the first digit). Note that this
1566 * works even if 10^exp_b10 is out of range because of the
1567 * test on DBL_MAX above.
1568 */
1569 fp /= base;
1570 while (fp >= 1) fp /= 10, ++exp_b10;
1571
1572 /* Because of the code above fp may, at this point, be
1573 * less than .1, this is ok because the code below can
1574 * handle the leading zeros this generates, so no attempt
1575 * is made to correct that here.
1576 */
1577
1578 {
1579 int czero, clead, cdigits;
1580 char exponent[10];
1581
1582 /* Allow up to two leading zeros - this will not lengthen
1583 * the number compared to using E-n.
1584 */
1585 if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */
1586 {
1587 czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */
1588 exp_b10 = 0; /* Dot added below before first output. */
1589 }
1590 else
1591 czero = 0; /* No zeros to add */
1592
1593 /* Generate the digit list, stripping trailing zeros and
1594 * inserting a '.' before a digit if the exponent is 0.
1595 */
1596 clead = czero; /* Count of leading zeros */
1597 cdigits = 0; /* Count of digits in list. */
1598
1599 do
1600 {
1601 double d;
1602
1603 fp *= 10;
1604 /* Use modf here, not floor and subtract, so that
1605 * the separation is done in one step. At the end
1606 * of the loop don't break the number into parts so
1607 * that the final digit is rounded.
1608 */
1609 if (cdigits+czero-clead+1 < (int)precision)
1610 fp = modf(fp, &d);
1611
1612 else
1613 {
1614 d = floor(fp + .5);
1615
1616 if (d > 9)
1617 {
1618 /* Rounding up to 10, handle that here. */
1619 if (czero > 0)
1620 {
1621 --czero, d = 1;
1622 if (cdigits == 0) --clead;
1623 }
1624 else
1625 {
1626 while (cdigits > 0 && d > 9)
1627 {
1628 int ch = *--ascii;
1629
1630 if (exp_b10 != (-1))
1631 ++exp_b10;
1632
1633 else if (ch == 46)
1634 {
1635 ch = *--ascii, ++size;
1636 /* Advance exp_b10 to '1', so that the
1637 * decimal point happens after the
1638 * previous digit.
1639 */
1640 exp_b10 = 1;
1641 }
1642
1643 --cdigits;
1644 d = ch - 47; /* I.e. 1+(ch-48) */
1645 }
1646
1647 /* Did we reach the beginning? If so adjust the
1648 * exponent but take into account the leading
1649 * decimal point.
1650 */
1651 if (d > 9) /* cdigits == 0 */
1652 {
1653 if (exp_b10 == (-1))
1654 {
1655 /* Leading decimal point (plus zeros?), if
1656 * we lose the decimal point here it must
1657 * be reentered below.
1658 */
1659 int ch = *--ascii;
1660
1661 if (ch == 46)
1662 ++size, exp_b10 = 1;
1663
1664 /* Else lost a leading zero, so 'exp_b10' is
1665 * still ok at (-1)
1666 */
1667 }
1668 else
1669 ++exp_b10;
1670
1671 /* In all cases we output a '1' */
1672 d = 1;
1673 }
1674 }
1675 }
1676 fp = 0; /* Guarantees termination below. */
1677 }
1678
1679 if (d == 0)
1680 {
1681 ++czero;
1682 if (cdigits == 0) ++clead;
1683 }
1684 else
1685 {
1686 /* Included embedded zeros in the digit count. */
1687 cdigits += czero - clead;
1688 clead = 0;
1689
1690 while (czero > 0)
1691 {
1692 /* exp_b10 == (-1) means we just output the decimal
1693 * place - after the DP don't adjust 'exp_b10' any
1694 * more!
1695 */
1696 if (exp_b10 != (-1))
1697 {
1698 if (exp_b10 == 0) *ascii++ = 46, --size;
1699 /* PLUS 1: TOTAL 4 */
1700 --exp_b10;
1701 }
1702 *ascii++ = 48, --czero;
1703 }
1704
1705 if (exp_b10 != (-1))
1706 {
1707 if (exp_b10 == 0) *ascii++ = 46, --size; /* counted
1708 above */
1709 --exp_b10;
1710 }
1711 *ascii++ = (char)(48 + (int)d), ++cdigits;
1712 }
1713 }
1714 while (cdigits+czero-clead < (int)precision && fp > DBL_MIN);
1715
1716 /* The total output count (max) is now 4+precision */
1717
1718 /* Check for an exponent, if we don't need one we are
1719 * done and just need to terminate the string. At
1720 * this point exp_b10==(-1) is effectively if flag - it got
1721 * to '-1' because of the decrement after outputing
1722 * the decimal point above (the exponent required is
1723 * *not* -1!)
1724 */
1725 if (exp_b10 >= (-1) && exp_b10 <= 2)
1726 {
1727 /* The following only happens if we didn't output the
1728 * leading zeros above for negative exponent, so this
1729 * doest add to the digit requirement. Note that the
1730 * two zeros here can only be output if the two leading
1731 * zeros were *not* output, so this doesn't increase
1732 * the output count.
1733 */
1734 while (--exp_b10 >= 0) *ascii++ = 48;
1735
1736 *ascii = 0;
1737
1738 /* Total buffer requirement (including the '\0') is
1739 * 5+precision - see check at the start.
1740 */
1741 return;
1742 }
1743
1744 /* Here if an exponent is required, adjust size for
1745 * the digits we output but did not count. The total
1746 * digit output here so far is at most 1+precision - no
1747 * decimal point and no leading or trailing zeros have
1748 * been output.
1749 */
1750 size -= cdigits;
1751
1752 *ascii++ = 69, --size; /* 'E': PLUS 1 TOTAL 2+precision */
1753
1754 /* The following use of an unsigned temporary avoids ambiguities in
1755 * the signed arithmetic on exp_b10 and permits GCC at least to do
1756 * better optimization.
1757 */
1758 {
1759 unsigned int uexp_b10;
1760
1761 if (exp_b10 < 0)
1762 {
1763 *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */
1764 uexp_b10 = -exp_b10;
1765 }
1766
1767 else
1768 uexp_b10 = exp_b10;
1769
1770 cdigits = 0;
1771
1772 while (uexp_b10 > 0)
1773 {
1774 exponent[cdigits++] = (char)(48 + uexp_b10 % 10);
1775 uexp_b10 /= 10;
1776 }
1777 }
1778
1779 /* Need another size check here for the exponent digits, so
1780 * this need not be considered above.
1781 */
1782 if ((int)size > cdigits)
1783 {
1784 while (cdigits > 0) *ascii++ = exponent[--cdigits];
1785
1786 *ascii = 0;
1787
1788 return;
1789 }
1790 }
1791 }
1792 else if (!(fp >= DBL_MIN))
1793 {
1794 *ascii++ = 48; /* '0' */
1795 *ascii = 0;
1796 return;
1797 }
1798 else
1799 {
1800 *ascii++ = 105; /* 'i' */
1801 *ascii++ = 110; /* 'n' */
1802 *ascii++ = 102; /* 'f' */
1803 *ascii = 0;
1804 return;
1805 }
1806 }
1807
1808 /* Here on buffer too small. */
1809 png_error(png_ptr, "ASCII conversion buffer too small");
1810}
1811
1812# endif /* FLOATING_POINT */
1813
1814# ifdef PNG_FIXED_POINT_SUPPORTED
1815/* Function to format a fixed point value in ASCII.
1816 */
1817void /* PRIVATE */
1818png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size,
1819 png_fixed_point fp)
1820{
1821 /* Require space for 10 decimal digits, a decimal point, a minus sign and a
1822 * trailing \0, 13 characters:
1823 */
1824 if (size > 12)
1825 {
1826 png_uint_32 num;
1827
1828 /* Avoid overflow here on the minimum integer. */
1829 if (fp < 0)
1830 *ascii++ = 45, --size, num = -fp;
1831 else
1832 num = fp;
1833
1834 if (num <= 0x80000000) /* else overflowed */
1835 {
1836 unsigned int ndigits = 0, first = 16 /* flag value */;
1837 char digits[10];
1838
1839 while (num)
1840 {
1841 /* Split the low digit off num: */
1842 unsigned int tmp = num/10;
1843 num -= tmp*10;
1844 digits[ndigits++] = (char)(48 + num);
1845 /* Record the first non-zero digit, note that this is a number
1846 * starting at 1, it's not actually the array index.
1847 */
1848 if (first == 16 && num > 0)
1849 first = ndigits;
1850 num = tmp;
1851 }
1852
1853 if (ndigits > 0)
1854 {
1855 while (ndigits > 5) *ascii++ = digits[--ndigits];
1856 /* The remaining digits are fractional digits, ndigits is '5' or
1857 * smaller at this point. It is certainly not zero. Check for a
1858 * non-zero fractional digit:
1859 */
1860 if (first <= 5)
1861 {
1862 unsigned int i;
1863 *ascii++ = 46; /* decimal point */
1864 /* ndigits may be <5 for small numbers, output leading zeros
1865 * then ndigits digits to first:
1866 */
1867 i = 5;
1868 while (ndigits < i) *ascii++ = 48, --i;
1869 while (ndigits >= first) *ascii++ = digits[--ndigits];
1870 /* Don't output the trailing zeros! */
1871 }
1872 }
1873 else
1874 *ascii++ = 48;
1875
1876 /* And null terminate the string: */
1877 *ascii = 0;
1878 return;
1879 }
1880 }
1881
1882 /* Here on buffer too small. */
1883 png_error(png_ptr, "ASCII conversion buffer too small");
1884}
1885# endif /* FIXED_POINT */
1886#endif /* READ_SCAL */
1887
1888#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
1889 !defined(PNG_FIXED_POINT_MACRO_SUPPORTED)
1890png_fixed_point
1891png_fixed(png_structp png_ptr, double fp, png_const_charp text)
1892{
1893 double r = floor(100000 * fp + .5);
1894
1895 if (r > 2147483647. || r < -2147483648.)
1896 png_fixed_error(png_ptr, text);
1897
1898 return (png_fixed_point)r;
1899}
1900#endif
1901
1902#if defined(PNG_READ_GAMMA_SUPPORTED) || \
1903 defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED)
1904/* muldiv functions */
1905/* This API takes signed arguments and rounds the result to the nearest
1906 * integer (or, for a fixed point number - the standard argument - to
1907 * the nearest .00001). Overflow and divide by zero are signalled in
1908 * the result, a boolean - true on success, false on overflow.
1909 */
1910int
1911png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
1912 png_int_32 divisor)
1913{
1914 /* Return a * times / divisor, rounded. */
1915 if (divisor != 0)
1916 {
1917 if (a == 0 || times == 0)
1918 {
1919 *res = 0;
1920 return 1;
1921 }
1922 else
1923 {
1924#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
1925 double r = a;
1926 r *= times;
1927 r /= divisor;
1928 r = floor(r+.5);
1929
1930 /* A png_fixed_point is a 32-bit integer. */
1931 if (r <= 2147483647. && r >= -2147483648.)
1932 {
1933 *res = (png_fixed_point)r;
1934 return 1;
1935 }
1936#else
1937 int negative = 0;
1938 png_uint_32 A, T, D;
1939 png_uint_32 s16, s32, s00;
1940
1941 if (a < 0)
1942 negative = 1, A = -a;
1943 else
1944 A = a;
1945
1946 if (times < 0)
1947 negative = !negative, T = -times;
1948 else
1949 T = times;
1950
1951 if (divisor < 0)
1952 negative = !negative, D = -divisor;
1953 else
1954 D = divisor;
1955
1956 /* Following can't overflow because the arguments only
1957 * have 31 bits each, however the result may be 32 bits.
1958 */
1959 s16 = (A >> 16) * (T & 0xffff) +
1960 (A & 0xffff) * (T >> 16);
1961 /* Can't overflow because the a*times bit is only 30
1962 * bits at most.
1963 */
1964 s32 = (A >> 16) * (T >> 16) + (s16 >> 16);
1965 s00 = (A & 0xffff) * (T & 0xffff);
1966
1967 s16 = (s16 & 0xffff) << 16;
1968 s00 += s16;
1969
1970 if (s00 < s16)
1971 ++s32; /* carry */
1972
1973 if (s32 < D) /* else overflow */
1974 {
1975 /* s32.s00 is now the 64-bit product, do a standard
1976 * division, we know that s32 < D, so the maximum
1977 * required shift is 31.
1978 */
1979 int bitshift = 32;
1980 png_fixed_point result = 0; /* NOTE: signed */
1981
1982 while (--bitshift >= 0)
1983 {
1984 png_uint_32 d32, d00;
1985
1986 if (bitshift > 0)
1987 d32 = D >> (32-bitshift), d00 = D << bitshift;
1988
1989 else
1990 d32 = 0, d00 = D;
1991
1992 if (s32 > d32)
1993 {
1994 if (s00 < d00) --s32; /* carry */
1995 s32 -= d32, s00 -= d00, result += 1<<bitshift;
1996 }
1997
1998 else
1999 if (s32 == d32 && s00 >= d00)
2000 s32 = 0, s00 -= d00, result += 1<<bitshift;
2001 }
2002
2003 /* Handle the rounding. */
2004 if (s00 >= (D >> 1))
2005 ++result;
2006
2007 if (negative)
2008 result = -result;
2009
2010 /* Check for overflow. */
2011 if ((negative && result <= 0) || (!negative && result >= 0))
2012 {
2013 *res = result;
2014 return 1;
2015 }
2016 }
2017#endif
2018 }
2019 }
2020
2021 return 0;
2022}
2023#endif /* READ_GAMMA || INCH_CONVERSIONS */
2024
2025#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
2026/* The following is for when the caller doesn't much care about the
2027 * result.
2028 */
2029png_fixed_point
2030png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times,
2031 png_int_32 divisor)
2032{
2033 png_fixed_point result;
2034
2035 if (png_muldiv(&result, a, times, divisor))
2036 return result;
2037
2038 png_warning(png_ptr, "fixed point overflow ignored");
2039 return 0;
2040}
2041#endif
2042
2043#ifdef PNG_READ_GAMMA_SUPPORTED /* more fixed point functions for gammma */
2044/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */
2045png_fixed_point
2046png_reciprocal(png_fixed_point a)
2047{
2048#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2049 double r = floor(1E10/a+.5);
2050
2051 if (r <= 2147483647. && r >= -2147483648.)
2052 return (png_fixed_point)r;
2053#else
2054 png_fixed_point res;
2055
2056 if (png_muldiv(&res, 100000, 100000, a))
2057 return res;
2058#endif
2059
2060 return 0; /* error/overflow */
2061}
2062
2063/* A local convenience routine. */
2064static png_fixed_point
2065png_product2(png_fixed_point a, png_fixed_point b)
2066{
2067 /* The required result is 1/a * 1/b; the following preserves accuracy. */
2068#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2069 double r = a * 1E-5;
2070 r *= b;
2071 r = floor(r+.5);
2072
2073 if (r <= 2147483647. && r >= -2147483648.)
2074 return (png_fixed_point)r;
2075#else
2076 png_fixed_point res;
2077
2078 if (png_muldiv(&res, a, b, 100000))
2079 return res;
2080#endif
2081
2082 return 0; /* overflow */
2083}
2084
2085/* The inverse of the above. */
2086png_fixed_point
2087png_reciprocal2(png_fixed_point a, png_fixed_point b)
2088{
2089 /* The required result is 1/a * 1/b; the following preserves accuracy. */
2090#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2091 double r = 1E15/a;
2092 r /= b;
2093 r = floor(r+.5);
2094
2095 if (r <= 2147483647. && r >= -2147483648.)
2096 return (png_fixed_point)r;
2097#else
2098 /* This may overflow because the range of png_fixed_point isn't symmetric,
2099 * but this API is only used for the product of file and screen gamma so it
2100 * doesn't matter that the smallest number it can produce is 1/21474, not
2101 * 1/100000
2102 */
2103 png_fixed_point res = png_product2(a, b);
2104
2105 if (res != 0)
2106 return png_reciprocal(res);
2107#endif
2108
2109 return 0; /* overflow */
2110}
2111#endif /* READ_GAMMA */
2112
2113#ifdef PNG_CHECK_cHRM_SUPPORTED
2114/* Added at libpng version 1.2.34 (Dec 8, 2008) and 1.4.0 (Jan 2,
2115 * 2010: moved from pngset.c) */
2116/*
2117 * Multiply two 32-bit numbers, V1 and V2, using 32-bit
2118 * arithmetic, to produce a 64-bit result in the HI/LO words.
2119 *
2120 * A B
2121 * x C D
2122 * ------
2123 * AD || BD
2124 * AC || CB || 0
2125 *
2126 * where A and B are the high and low 16-bit words of V1,
2127 * C and D are the 16-bit words of V2, AD is the product of
2128 * A and D, and X || Y is (X << 16) + Y.
2129*/
2130
2131void /* PRIVATE */
2132png_64bit_product (long v1, long v2, unsigned long *hi_product,
2133 unsigned long *lo_product)
2134{
2135 int a, b, c, d;
2136 long lo, hi, x, y;
2137
2138 a = (v1 >> 16) & 0xffff;
2139 b = v1 & 0xffff;
2140 c = (v2 >> 16) & 0xffff;
2141 d = v2 & 0xffff;
2142
2143 lo = b * d; /* BD */
2144 x = a * d + c * b; /* AD + CB */
2145 y = ((lo >> 16) & 0xffff) + x;
2146
2147 lo = (lo & 0xffff) | ((y & 0xffff) << 16);
2148 hi = (y >> 16) & 0xffff;
2149
2150 hi += a * c; /* AC */
2151
2152 *hi_product = (unsigned long)hi;
2153 *lo_product = (unsigned long)lo;
2154}
2155#endif /* CHECK_cHRM */
2156
2157#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */
2158#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
2159/* Fixed point gamma.
2160 *
2161 * To calculate gamma this code implements fast log() and exp() calls using only
2162 * fixed point arithmetic. This code has sufficient precision for either 8-bit
2163 * or 16-bit sample values.
2164 *
2165 * The tables used here were calculated using simple 'bc' programs, but C double
2166 * precision floating point arithmetic would work fine. The programs are given
2167 * at the head of each table.
2168 *
2169 * 8-bit log table
2170 * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to
2171 * 255, so it's the base 2 logarithm of a normalized 8-bit floating point
2172 * mantissa. The numbers are 32-bit fractions.
2173 */
2174static png_uint_32
2175png_8bit_l2[128] =
2176{
2177# ifdef PNG_DO_BC
2178 for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; }
2179# else
2180 4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,
2181 3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,
2182 3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,
2183 3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U,
2184 3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U,
2185 2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U,
2186 2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U,
2187 2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U,
2188 2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U,
2189 2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U,
2190 1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U,
2191 1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U,
2192 1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U,
2193 1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U,
2194 1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U,
2195 971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U,
2196 803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U,
2197 639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U,
2198 479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U,
2199 324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,
2200 172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,
2201 24347096U, 0U
2202# endif
2203
2204#if 0
2205 /* The following are the values for 16-bit tables - these work fine for the
2206 * 8-bit conversions but produce very slightly larger errors in the 16-bit
2207 * log (about 1.2 as opposed to 0.7 absolute error in the final value). To
2208 * use these all the shifts below must be adjusted appropriately.
2209 */
2210 65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054,
2211 57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803,
2212 50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068,
2213 43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782,
2214 37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887,
2215 31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339,
2216 25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098,
2217 20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132,
2218 15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415,
2219 10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523,
2220 6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495,
2221 1119, 744, 372
2222#endif
2223};
2224
2225PNG_STATIC png_int_32
2226png_log8bit(unsigned int x)
2227{
2228 unsigned int lg2 = 0;
2229 /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log,
2230 * because the log is actually negate that means adding 1. The final
2231 * returned value thus has the range 0 (for 255 input) to 7.994 (for 1
2232 * input), return 7.99998 for the overflow (log 0) case - so the result is
2233 * always at most 19 bits.
2234 */
2235 if ((x &= 0xff) == 0)
2236 return 0xffffffff;
2237
2238 if ((x & 0xf0) == 0)
2239 lg2 = 4, x <<= 4;
2240
2241 if ((x & 0xc0) == 0)
2242 lg2 += 2, x <<= 2;
2243
2244 if ((x & 0x80) == 0)
2245 lg2 += 1, x <<= 1;
2246
2247 /* result is at most 19 bits, so this cast is safe: */
2248 return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));
2249}
2250
2251/* The above gives exact (to 16 binary places) log2 values for 8-bit images,
2252 * for 16-bit images we use the most significant 8 bits of the 16-bit value to
2253 * get an approximation then multiply the approximation by a correction factor
2254 * determined by the remaining up to 8 bits. This requires an additional step
2255 * in the 16-bit case.
2256 *
2257 * We want log2(value/65535), we have log2(v'/255), where:
2258 *
2259 * value = v' * 256 + v''
2260 * = v' * f
2261 *
2262 * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128
2263 * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less
2264 * than 258. The final factor also needs to correct for the fact that our 8-bit
2265 * value is scaled by 255, whereas the 16-bit values must be scaled by 65535.
2266 *
2267 * This gives a final formula using a calculated value 'x' which is value/v' and
2268 * scaling by 65536 to match the above table:
2269 *
2270 * log2(x/257) * 65536
2271 *
2272 * Since these numbers are so close to '1' we can use simple linear
2273 * interpolation between the two end values 256/257 (result -368.61) and 258/257
2274 * (result 367.179). The values used below are scaled by a further 64 to give
2275 * 16-bit precision in the interpolation:
2276 *
2277 * Start (256): -23591
2278 * Zero (257): 0
2279 * End (258): 23499
2280 */
2281PNG_STATIC png_int_32
2282png_log16bit(png_uint_32 x)
2283{
2284 unsigned int lg2 = 0;
2285
2286 /* As above, but now the input has 16 bits. */
2287 if ((x &= 0xffff) == 0)
2288 return 0xffffffff;
2289
2290 if ((x & 0xff00) == 0)
2291 lg2 = 8, x <<= 8;
2292
2293 if ((x & 0xf000) == 0)
2294 lg2 += 4, x <<= 4;
2295
2296 if ((x & 0xc000) == 0)
2297 lg2 += 2, x <<= 2;
2298
2299 if ((x & 0x8000) == 0)
2300 lg2 += 1, x <<= 1;
2301
2302 /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional
2303 * value.
2304 */
2305 lg2 <<= 28;
2306 lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;
2307
2308 /* Now we need to interpolate the factor, this requires a division by the top
2309 * 8 bits. Do this with maximum precision.
2310 */
2311 x = ((x << 16) + (x >> 9)) / (x >> 8);
2312
2313 /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24,
2314 * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly
2315 * 16 bits to interpolate to get the low bits of the result. Round the
2316 * answer. Note that the end point values are scaled by 64 to retain overall
2317 * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust
2318 * the overall scaling by 6-12. Round at every step.
2319 */
2320 x -= 1U << 24;
2321
2322 if (x <= 65536U) /* <= '257' */
2323 lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);
2324
2325 else
2326 lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
2327
2328 /* Safe, because the result can't have more than 20 bits: */
2329 return (png_int_32)((lg2 + 2048) >> 12);
2330}
2331
2332/* The 'exp()' case must invert the above, taking a 20-bit fixed point
2333 * logarithmic value and returning a 16 or 8-bit number as appropriate. In
2334 * each case only the low 16 bits are relevant - the fraction - since the
2335 * integer bits (the top 4) simply determine a shift.
2336 *
2337 * The worst case is the 16-bit distinction between 65535 and 65534, this
2338 * requires perhaps spurious accuracy in the decoding of the logarithm to
2339 * distinguish log2(65535/65534.5) - 10^-5 or 17 bits. There is little chance
2340 * of getting this accuracy in practice.
2341 *
2342 * To deal with this the following exp() function works out the exponent of the
2343 * frational part of the logarithm by using an accurate 32-bit value from the
2344 * top four fractional bits then multiplying in the remaining bits.
2345 */
2346static png_uint_32
2347png_32bit_exp[16] =
2348{
2349# ifdef PNG_DO_BC
2350 for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; }
2351# else
2352 /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */
2353 4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,
2354 3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,
2355 2553802834U, 2445529972U, 2341847524U, 2242560872U
2356# endif
2357};
2358
2359/* Adjustment table; provided to explain the numbers in the code below. */
2360#ifdef PNG_DO_BC
2361for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"}
2362 11 44937.64284865548751208448
2363 10 45180.98734845585101160448
2364 9 45303.31936980687359311872
2365 8 45364.65110595323018870784
2366 7 45395.35850361789624614912
2367 6 45410.72259715102037508096
2368 5 45418.40724413220722311168
2369 4 45422.25021786898173001728
2370 3 45424.17186732298419044352
2371 2 45425.13273269940811464704
2372 1 45425.61317555035558641664
2373 0 45425.85339951654943850496
2374#endif
2375
2376PNG_STATIC png_uint_32
2377png_exp(png_fixed_point x)
2378{
2379 if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */
2380 {
2381 /* Obtain a 4-bit approximation */
2382 png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf];
2383
2384 /* Incorporate the low 12 bits - these decrease the returned value by
2385 * multiplying by a number less than 1 if the bit is set. The multiplier
2386 * is determined by the above table and the shift. Notice that the values
2387 * converge on 45426 and this is used to allow linear interpolation of the
2388 * low bits.
2389 */
2390 if (x & 0x800)
2391 e -= (((e >> 16) * 44938U) + 16U) >> 5;
2392
2393 if (x & 0x400)
2394 e -= (((e >> 16) * 45181U) + 32U) >> 6;
2395
2396 if (x & 0x200)
2397 e -= (((e >> 16) * 45303U) + 64U) >> 7;
2398
2399 if (x & 0x100)
2400 e -= (((e >> 16) * 45365U) + 128U) >> 8;
2401
2402 if (x & 0x080)
2403 e -= (((e >> 16) * 45395U) + 256U) >> 9;
2404
2405 if (x & 0x040)
2406 e -= (((e >> 16) * 45410U) + 512U) >> 10;
2407
2408 /* And handle the low 6 bits in a single block. */
2409 e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9;
2410
2411 /* Handle the upper bits of x. */
2412 e >>= x >> 16;
2413 return e;
2414 }
2415
2416 /* Check for overflow */
2417 if (x <= 0)
2418 return png_32bit_exp[0];
2419
2420 /* Else underflow */
2421 return 0;
2422}
2423
2424PNG_STATIC png_byte
2425png_exp8bit(png_fixed_point lg2)
2426{
2427 /* Get a 32-bit value: */
2428 png_uint_32 x = png_exp(lg2);
2429
2430 /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the
2431 * second, rounding, step can't overflow because of the first, subtraction,
2432 * step.
2433 */
2434 x -= x >> 8;
2435 return (png_byte)((x + 0x7fffffU) >> 24);
2436}
2437
2438PNG_STATIC png_uint_16
2439png_exp16bit(png_fixed_point lg2)
2440{
2441 /* Get a 32-bit value: */
2442 png_uint_32 x = png_exp(lg2);
2443
2444 /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */
2445 x -= x >> 16;
2446 return (png_uint_16)((x + 32767U) >> 16);
2447}
2448#endif /* FLOATING_ARITHMETIC */
2449
2450png_byte
2451png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)
2452{
2453 if (value > 0 && value < 255)
2454 {
2455# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2456 double r = floor(255*pow(value/255.,gamma_val*.00001)+.5);
2457 return (png_byte)r;
2458# else
2459 png_int_32 lg2 = png_log8bit(value);
2460 png_fixed_point res;
2461
2462 if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
2463 return png_exp8bit(res);
2464
2465 /* Overflow. */
2466 value = 0;
2467# endif
2468 }
2469
2470 return (png_byte)value;
2471}
2472
2473png_uint_16
2474png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
2475{
2476 if (value > 0 && value < 65535)
2477 {
2478# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2479 double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5);
2480 return (png_uint_16)r;
2481# else
2482 png_int_32 lg2 = png_log16bit(value);
2483 png_fixed_point res;
2484
2485 if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
2486 return png_exp16bit(res);
2487
2488 /* Overflow. */
2489 value = 0;
2490# endif
2491 }
2492
2493 return (png_uint_16)value;
2494}
2495
2496/* This does the right thing based on the bit_depth field of the
2497 * png_struct, interpreting values as 8-bit or 16-bit. While the result
2498 * is nominally a 16-bit value if bit depth is 8 then the result is
2499 * 8-bit (as are the arguments.)
2500 */
2501png_uint_16 /* PRIVATE */
2502png_gamma_correct(png_structp png_ptr, unsigned int value,
2503 png_fixed_point gamma_val)
2504{
2505 if (png_ptr->bit_depth == 8)
2506 return png_gamma_8bit_correct(value, gamma_val);
2507
2508 else
2509 return png_gamma_16bit_correct(value, gamma_val);
2510}
2511
2512/* This is the shared test on whether a gamma value is 'significant' - whether
2513 * it is worth doing gamma correction.
2514 */
2515int /* PRIVATE */
2516png_gamma_significant(png_fixed_point gamma_val)
2517{
2518 return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED ||
2519 gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED;
2520}
2521
2522/* Internal function to build a single 16-bit table - the table consists of
2523 * 'num' 256-entry subtables, where 'num' is determined by 'shift' - the amount
2524 * to shift the input values right (or 16-number_of_signifiant_bits).
2525 *
2526 * The caller is responsible for ensuring that the table gets cleaned up on
2527 * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument
2528 * should be somewhere that will be cleaned.
2529 */
2530static void
2531png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable,
2532 PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
2533{
2534 /* Various values derived from 'shift': */
2535 PNG_CONST unsigned int num = 1U << (8U - shift);
2536 PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
2537 PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
2538 unsigned int i;
2539
2540 png_uint_16pp table = *ptable =
2541 (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p));
2542
2543 for (i = 0; i < num; i++)
2544 {
2545 png_uint_16p sub_table = table[i] =
2546 (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16));
2547
2548 /* The 'threshold' test is repeated here because it can arise for one of
2549 * the 16-bit tables even if the others don't hit it.
2550 */
2551 if (png_gamma_significant(gamma_val))
2552 {
2553 /* The old code would overflow at the end and this would cause the
2554 * 'pow' function to return a result >1, resulting in an
2555 * arithmetic error. This code follows the spec exactly; ig is
2556 * the recovered input sample, it always has 8-16 bits.
2557 *
2558 * We want input * 65535/max, rounded, the arithmetic fits in 32
2559 * bits (unsigned) so long as max <= 32767.
2560 */
2561 unsigned int j;
2562 for (j = 0; j < 256; j++)
2563 {
2564 png_uint_32 ig = (j << (8-shift)) + i;
2565# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2566 /* Inline the 'max' scaling operation: */
2567 double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5);
2568 sub_table[j] = (png_uint_16)d;
2569# else
2570 if (shift)
2571 ig = (ig * 65535U + max_by_2)/max;
2572
2573 sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);
2574# endif
2575 }
2576 }
2577 else
2578 {
2579 /* We must still build a table, but do it the fast way. */
2580 unsigned int j;
2581
2582 for (j = 0; j < 256; j++)
2583 {
2584 png_uint_32 ig = (j << (8-shift)) + i;
2585
2586 if (shift)
2587 ig = (ig * 65535U + max_by_2)/max;
2588
2589 sub_table[j] = (png_uint_16)ig;
2590 }
2591 }
2592 }
2593}
2594
2595/* NOTE: this function expects the *inverse* of the overall gamma transformation
2596 * required.
2597 */
2598static void
2599png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable,
2600 PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
2601{
2602 PNG_CONST unsigned int num = 1U << (8U - shift);
2603 PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
2604 unsigned int i;
2605 png_uint_32 last;
2606
2607 png_uint_16pp table = *ptable =
2608 (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p));
2609
2610 /* 'num' is the number of tables and also the number of low bits of the
2611 * input 16-bit value used to select a table. Each table is itself indexed
2612 * by the high 8 bits of the value.
2613 */
2614 for (i = 0; i < num; i++)
2615 table[i] = (png_uint_16p)png_malloc(png_ptr,
2616 256 * png_sizeof(png_uint_16));
2617
2618 /* 'gamma_val' is set to the reciprocal of the value calculated above, so
2619 * pow(out,g) is an *input* value. 'last' is the last input value set.
2620 *
2621 * In the loop 'i' is used to find output values. Since the output is
2622 * 8-bit there are only 256 possible values. The tables are set up to
2623 * select the closest possible output value for each input by finding
2624 * the input value at the boundary between each pair of output values
2625 * and filling the table up to that boundary with the lower output
2626 * value.
2627 *
2628 * The boundary values are 0.5,1.5..253.5,254.5. Since these are 9-bit
2629 * values the code below uses a 16-bit value in i; the values start at
2630 * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last
2631 * entries are filled with 255). Start i at 128 and fill all 'last'
2632 * table entries <= 'max'
2633 */
2634 last = 0;
2635 for (i = 0; i < 255; ++i) /* 8-bit output value */
2636 {
2637 /* Find the corresponding maximum input value */
2638 png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */
2639
2640 /* Find the boundary value in 16 bits: */
2641 png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val);
2642
2643 /* Adjust (round) to (16-shift) bits: */
2644 bound = (bound * max + 32768U)/65535U + 1U;
2645
2646 while (last < bound)
2647 {
2648 table[last & (0xffU >> shift)][last >> (8U - shift)] = out;
2649 last++;
2650 }
2651 }
2652
2653 /* And fill in the final entries. */
2654 while (last < (num << 8))
2655 {
2656 table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;
2657 last++;
2658 }
2659}
2660
2661/* Build a single 8-bit table: same as the 16-bit case but much simpler (and
2662 * typically much faster). Note that libpng currently does no sBIT processing
2663 * (apparently contrary to the spec) so a 256-entry table is always generated.
2664 */
2665static void
2666png_build_8bit_table(png_structp png_ptr, png_bytepp ptable,
2667 PNG_CONST png_fixed_point gamma_val)
2668{
2669 unsigned int i;
2670 png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
2671
2672 if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++)
2673 table[i] = png_gamma_8bit_correct(i, gamma_val);
2674
2675 else for (i=0; i<256; ++i)
2676 table[i] = (png_byte)i;
2677}
2678
2679/* Used from png_read_destroy and below to release the memory used by the gamma
2680 * tables.
2681 */
2682void /* PRIVATE */
2683png_destroy_gamma_table(png_structp png_ptr)
2684{
2685 png_free(png_ptr, png_ptr->gamma_table);
2686 png_ptr->gamma_table = NULL;
2687
2688 if (png_ptr->gamma_16_table != NULL)
2689 {
2690 int i;
2691 int istop = (1 << (8 - png_ptr->gamma_shift));
2692 for (i = 0; i < istop; i++)
2693 {
2694 png_free(png_ptr, png_ptr->gamma_16_table[i]);
2695 }
2696 png_free(png_ptr, png_ptr->gamma_16_table);
2697 png_ptr->gamma_16_table = NULL;
2698 }
2699
2700#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2701 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2702 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2703 png_free(png_ptr, png_ptr->gamma_from_1);
2704 png_ptr->gamma_from_1 = NULL;
2705 png_free(png_ptr, png_ptr->gamma_to_1);
2706 png_ptr->gamma_to_1 = NULL;
2707
2708 if (png_ptr->gamma_16_from_1 != NULL)
2709 {
2710 int i;
2711 int istop = (1 << (8 - png_ptr->gamma_shift));
2712 for (i = 0; i < istop; i++)
2713 {
2714 png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
2715 }
2716 png_free(png_ptr, png_ptr->gamma_16_from_1);
2717 png_ptr->gamma_16_from_1 = NULL;
2718 }
2719 if (png_ptr->gamma_16_to_1 != NULL)
2720 {
2721 int i;
2722 int istop = (1 << (8 - png_ptr->gamma_shift));
2723 for (i = 0; i < istop; i++)
2724 {
2725 png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
2726 }
2727 png_free(png_ptr, png_ptr->gamma_16_to_1);
2728 png_ptr->gamma_16_to_1 = NULL;
2729 }
2730#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
2731}
2732
2733/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit
2734 * tables, we don't make a full table if we are reducing to 8-bit in
2735 * the future. Note also how the gamma_16 tables are segmented so that
2736 * we don't need to allocate > 64K chunks for a full 16-bit table.
2737 */
2738void /* PRIVATE */
2739png_build_gamma_table(png_structp png_ptr, int bit_depth)
2740{
2741 png_debug(1, "in png_build_gamma_table");
2742
2743 /* Remove any existing table; this copes with multiple calls to
2744 * png_read_update_info. The warning is because building the gamma tables
2745 * multiple times is a performance hit - it's harmless but the ability to call
2746 * png_read_update_info() multiple times is new in 1.5.6 so it seems sensible
2747 * to warn if the app introduces such a hit.
2748 */
2749 if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)
2750 {
2751 png_warning(png_ptr, "gamma table being rebuilt");
2752 png_destroy_gamma_table(png_ptr);
2753 }
2754
2755 if (bit_depth <= 8)
2756 {
2757 png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
2758 png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma,
2759 png_ptr->screen_gamma) : PNG_FP_1);
2760
2761#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2762 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2763 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2764 if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
2765 {
2766 png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
2767 png_reciprocal(png_ptr->gamma));
2768
2769 png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
2770 png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
2771 png_ptr->gamma/* Probably doing rgb_to_gray */);
2772 }
2773#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
2774 }
2775 else
2776 {
2777 png_byte shift, sig_bit;
2778
2779 if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
2780 {
2781 sig_bit = png_ptr->sig_bit.red;
2782
2783 if (png_ptr->sig_bit.green > sig_bit)
2784 sig_bit = png_ptr->sig_bit.green;
2785
2786 if (png_ptr->sig_bit.blue > sig_bit)
2787 sig_bit = png_ptr->sig_bit.blue;
2788 }
2789 else
2790 sig_bit = png_ptr->sig_bit.gray;
2791
2792 /* 16-bit gamma code uses this equation:
2793 *
2794 * ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
2795 *
2796 * Where 'iv' is the input color value and 'ov' is the output value -
2797 * pow(iv, gamma).
2798 *
2799 * Thus the gamma table consists of up to 256 256-entry tables. The table
2800 * is selected by the (8-gamma_shift) most significant of the low 8 bits of
2801 * the color value then indexed by the upper 8 bits:
2802 *
2803 * table[low bits][high 8 bits]
2804 *
2805 * So the table 'n' corresponds to all those 'iv' of:
2806 *
2807 * <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
2808 *
2809 */
2810 if (sig_bit > 0 && sig_bit < 16U)
2811 shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */
2812
2813 else
2814 shift = 0; /* keep all 16 bits */
2815
2816 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
2817 {
2818 /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
2819 * the significant bits in the *input* when the output will
2820 * eventually be 8 bits. By default it is 11.
2821 */
2822 if (shift < (16U - PNG_MAX_GAMMA_8))
2823 shift = (16U - PNG_MAX_GAMMA_8);
2824 }
2825
2826 if (shift > 8U)
2827 shift = 8U; /* Guarantees at least one table! */
2828
2829 png_ptr->gamma_shift = shift;
2830
2831#ifdef PNG_16BIT_SUPPORTED
2832 /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
2833 * PNG_COMPOSE). This effectively smashed the background calculation for
2834 * 16-bit output because the 8-bit table assumes the result will be reduced
2835 * to 8 bits.
2836 */
2837 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
2838#endif
2839 png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
2840 png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma,
2841 png_ptr->screen_gamma) : PNG_FP_1);
2842
2843#ifdef PNG_16BIT_SUPPORTED
2844 else
2845 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
2846 png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma,
2847 png_ptr->screen_gamma) : PNG_FP_1);
2848#endif
2849
2850#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
2851 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
2852 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2853 if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
2854 {
2855 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
2856 png_reciprocal(png_ptr->gamma));
2857
2858 /* Notice that the '16 from 1' table should be full precision, however
2859 * the lookup on this table still uses gamma_shift, so it can't be.
2860 * TODO: fix this.
2861 */
2862 png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
2863 png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
2864 png_ptr->gamma/* Probably doing rgb_to_gray */);
2865 }
2866#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
2867 }
2868}
2869#endif /* READ_GAMMA */
2870#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.h
new file mode 100644
index 0000000..8126767
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/png.h
@@ -0,0 +1,2658 @@
1
2/* png.h - header file for PNG reference library
3 *
4 * libpng version 1.5.9 - February 18, 2012
5 * Copyright (c) 1998-2012 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license (See LICENSE, below)
10 *
11 * Authors and maintainers:
12 * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
13 * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
14 * libpng versions 0.97, January 1998, through 1.5.9 - February 18, 2012: Glenn
15 * See also "Contributing Authors", below.
16 *
17 * Note about libpng version numbers:
18 *
19 * Due to various miscommunications, unforeseen code incompatibilities
20 * and occasional factors outside the authors' control, version numbering
21 * on the library has not always been consistent and straightforward.
22 * The following table summarizes matters since version 0.89c, which was
23 * the first widely used release:
24 *
25 * source png.h png.h shared-lib
26 * version string int version
27 * ------- ------ ----- ----------
28 * 0.89c "1.0 beta 3" 0.89 89 1.0.89
29 * 0.90 "1.0 beta 4" 0.90 90 0.90 [should have been 2.0.90]
30 * 0.95 "1.0 beta 5" 0.95 95 0.95 [should have been 2.0.95]
31 * 0.96 "1.0 beta 6" 0.96 96 0.96 [should have been 2.0.96]
32 * 0.97b "1.00.97 beta 7" 1.00.97 97 1.0.1 [should have been 2.0.97]
33 * 0.97c 0.97 97 2.0.97
34 * 0.98 0.98 98 2.0.98
35 * 0.99 0.99 98 2.0.99
36 * 0.99a-m 0.99 99 2.0.99
37 * 1.00 1.00 100 2.1.0 [100 should be 10000]
38 * 1.0.0 (from here on, the 100 2.1.0 [100 should be 10000]
39 * 1.0.1 png.h string is 10001 2.1.0
40 * 1.0.1a-e identical to the 10002 from here on, the shared library
41 * 1.0.2 source version) 10002 is 2.V where V is the source code
42 * 1.0.2a-b 10003 version, except as noted.
43 * 1.0.3 10003
44 * 1.0.3a-d 10004
45 * 1.0.4 10004
46 * 1.0.4a-f 10005
47 * 1.0.5 (+ 2 patches) 10005
48 * 1.0.5a-d 10006
49 * 1.0.5e-r 10100 (not source compatible)
50 * 1.0.5s-v 10006 (not binary compatible)
51 * 1.0.6 (+ 3 patches) 10006 (still binary incompatible)
52 * 1.0.6d-f 10007 (still binary incompatible)
53 * 1.0.6g 10007
54 * 1.0.6h 10007 10.6h (testing xy.z so-numbering)
55 * 1.0.6i 10007 10.6i
56 * 1.0.6j 10007 2.1.0.6j (incompatible with 1.0.0)
57 * 1.0.7beta11-14 DLLNUM 10007 2.1.0.7beta11-14 (binary compatible)
58 * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible)
59 * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible)
60 * 1.0.7 1 10007 (still compatible)
61 * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4
62 * 1.0.8rc1 1 10008 2.1.0.8rc1
63 * 1.0.8 1 10008 2.1.0.8
64 * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6
65 * 1.0.9rc1 1 10009 2.1.0.9rc1
66 * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
67 * 1.0.9rc2 1 10009 2.1.0.9rc2
68 * 1.0.9 1 10009 2.1.0.9
69 * 1.0.10beta1 1 10010 2.1.0.10beta1
70 * 1.0.10rc1 1 10010 2.1.0.10rc1
71 * 1.0.10 1 10010 2.1.0.10
72 * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
73 * 1.0.11rc1 1 10011 2.1.0.11rc1
74 * 1.0.11 1 10011 2.1.0.11
75 * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
76 * 1.0.12rc1 2 10012 2.1.0.12rc1
77 * 1.0.12 2 10012 2.1.0.12
78 * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned)
79 * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
80 * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
81 * 1.2.0rc1 3 10200 3.1.2.0rc1
82 * 1.2.0 3 10200 3.1.2.0
83 * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4
84 * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
85 * 1.2.1 3 10201 3.1.2.1
86 * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
87 * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
88 * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
89 * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
90 * 1.0.13 10 10013 10.so.0.1.0.13
91 * 1.2.2 12 10202 12.so.0.1.2.2
92 * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
93 * 1.2.3 12 10203 12.so.0.1.2.3
94 * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
95 * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1
96 * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
97 * 1.0.14 10 10014 10.so.0.1.0.14
98 * 1.2.4 13 10204 12.so.0.1.2.4
99 * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
100 * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3
101 * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3
102 * 1.0.15 10 10015 10.so.0.1.0.15
103 * 1.2.5 13 10205 12.so.0.1.2.5
104 * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4
105 * 1.0.16 10 10016 10.so.0.1.0.16
106 * 1.2.6 13 10206 12.so.0.1.2.6
107 * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2
108 * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1
109 * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1
110 * 1.0.17 10 10017 12.so.0.1.0.17
111 * 1.2.7 13 10207 12.so.0.1.2.7
112 * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5
113 * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5
114 * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
115 * 1.0.18 10 10018 12.so.0.1.0.18
116 * 1.2.8 13 10208 12.so.0.1.2.8
117 * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
118 * 1.2.9beta4-11 13 10209 12.so.0.9[.0]
119 * 1.2.9rc1 13 10209 12.so.0.9[.0]
120 * 1.2.9 13 10209 12.so.0.9[.0]
121 * 1.2.10beta1-7 13 10210 12.so.0.10[.0]
122 * 1.2.10rc1-2 13 10210 12.so.0.10[.0]
123 * 1.2.10 13 10210 12.so.0.10[.0]
124 * 1.4.0beta1-5 14 10400 14.so.0.0[.0]
125 * 1.2.11beta1-4 13 10211 12.so.0.11[.0]
126 * 1.4.0beta7-8 14 10400 14.so.0.0[.0]
127 * 1.2.11 13 10211 12.so.0.11[.0]
128 * 1.2.12 13 10212 12.so.0.12[.0]
129 * 1.4.0beta9-14 14 10400 14.so.0.0[.0]
130 * 1.2.13 13 10213 12.so.0.13[.0]
131 * 1.4.0beta15-36 14 10400 14.so.0.0[.0]
132 * 1.4.0beta37-87 14 10400 14.so.14.0[.0]
133 * 1.4.0rc01 14 10400 14.so.14.0[.0]
134 * 1.4.0beta88-109 14 10400 14.so.14.0[.0]
135 * 1.4.0rc02-08 14 10400 14.so.14.0[.0]
136 * 1.4.0 14 10400 14.so.14.0[.0]
137 * 1.4.1beta01-03 14 10401 14.so.14.1[.0]
138 * 1.4.1rc01 14 10401 14.so.14.1[.0]
139 * 1.4.1beta04-12 14 10401 14.so.14.1[.0]
140 * 1.4.1 14 10401 14.so.14.1[.0]
141 * 1.4.2 14 10402 14.so.14.2[.0]
142 * 1.4.3 14 10403 14.so.14.3[.0]
143 * 1.4.4 14 10404 14.so.14.4[.0]
144 * 1.5.0beta01-58 15 10500 15.so.15.0[.0]
145 * 1.5.0rc01-07 15 10500 15.so.15.0[.0]
146 * 1.5.0 15 10500 15.so.15.0[.0]
147 * 1.5.1beta01-11 15 10501 15.so.15.1[.0]
148 * 1.5.1rc01-02 15 10501 15.so.15.1[.0]
149 * 1.5.1 15 10501 15.so.15.1[.0]
150 * 1.5.2beta01-03 15 10502 15.so.15.2[.0]
151 * 1.5.2rc01-03 15 10502 15.so.15.2[.0]
152 * 1.5.2 15 10502 15.so.15.2[.0]
153 * 1.5.3beta01-10 15 10503 15.so.15.3[.0]
154 * 1.5.3rc01-02 15 10503 15.so.15.3[.0]
155 * 1.5.3beta11 15 10503 15.so.15.3[.0]
156 * 1.5.3 [omitted]
157 * 1.5.4beta01-08 15 10504 15.so.15.4[.0]
158 * 1.5.4rc01 15 10504 15.so.15.4[.0]
159 * 1.5.4 15 10504 15.so.15.4[.0]
160 * 1.5.5beta01-08 15 10505 15.so.15.5[.0]
161 * 1.5.5rc01 15 10505 15.so.15.5[.0]
162 * 1.5.5 15 10505 15.so.15.5[.0]
163 * 1.5.6beta01-07 15 10506 15.so.15.6[.0]
164 * 1.5.6rc01-03 15 10506 15.so.15.6[.0]
165 * 1.5.6 15 10506 15.so.15.6[.0]
166 * 1.5.7beta01-05 15 10507 15.so.15.7[.0]
167 * 1.5.7rc01-03 15 10507 15.so.15.7[.0]
168 * 1.5.7 15 10507 15.so.15.7[.0]
169 * 1.5.8beta01 15 10508 15.so.15.8[.0]
170 * 1.5.8rc01 15 10508 15.so.15.8[.0]
171 * 1.5.8 15 10508 15.so.15.8[.0]
172 * 1.5.9beta01-02 15 10509 15.so.15.9[.0]
173 * 1.5.9rc01 15 10509 15.so.15.9[.0]
174 * 1.5.9 15 10509 15.so.15.9[.0]
175 *
176 * Henceforth the source version will match the shared-library major
177 * and minor numbers; the shared-library major version number will be
178 * used for changes in backward compatibility, as it is intended. The
179 * PNG_LIBPNG_VER macro, which is not used within libpng but is available
180 * for applications, is an unsigned integer of the form xyyzz corresponding
181 * to the source version x.y.z (leading zeros in y and z). Beta versions
182 * were given the previous public release number plus a letter, until
183 * version 1.0.6j; from then on they were given the upcoming public
184 * release number plus "betaNN" or "rcN".
185 *
186 * Binary incompatibility exists only when applications make direct access
187 * to the info_ptr or png_ptr members through png.h, and the compiled
188 * application is loaded with a different version of the library.
189 *
190 * DLLNUM will change each time there are forward or backward changes
191 * in binary compatibility (e.g., when a new feature is added).
192 *
193 * See libpng-manual.txt or libpng.3 for more information. The PNG
194 * specification is available as a W3C Recommendation and as an ISO
195 * Specification, <http://www.w3.org/TR/2003/REC-PNG-20031110/
196 */
197
198/*
199 * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
200 *
201 * If you modify libpng you may insert additional notices immediately following
202 * this sentence.
203 *
204 * This code is released under the libpng license.
205 *
206 * libpng versions 1.2.6, August 15, 2004, through 1.5.9, February 18, 2012, are
207 * Copyright (c) 2004, 2006-2012 Glenn Randers-Pehrson, and are
208 * distributed according to the same disclaimer and license as libpng-1.2.5
209 * with the following individual added to the list of Contributing Authors:
210 *
211 * Cosmin Truta
212 *
213 * libpng versions 1.0.7, July 1, 2000, through 1.2.5, October 3, 2002, are
214 * Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
215 * distributed according to the same disclaimer and license as libpng-1.0.6
216 * with the following individuals added to the list of Contributing Authors:
217 *
218 * Simon-Pierre Cadieux
219 * Eric S. Raymond
220 * Gilles Vollant
221 *
222 * and with the following additions to the disclaimer:
223 *
224 * There is no warranty against interference with your enjoyment of the
225 * library or against infringement. There is no warranty that our
226 * efforts or the library will fulfill any of your particular purposes
227 * or needs. This library is provided with all faults, and the entire
228 * risk of satisfactory quality, performance, accuracy, and effort is with
229 * the user.
230 *
231 * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
232 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson, and are
233 * distributed according to the same disclaimer and license as libpng-0.96,
234 * with the following individuals added to the list of Contributing Authors:
235 *
236 * Tom Lane
237 * Glenn Randers-Pehrson
238 * Willem van Schaik
239 *
240 * libpng versions 0.89, June 1996, through 0.96, May 1997, are
241 * Copyright (c) 1996, 1997 Andreas Dilger
242 * Distributed according to the same disclaimer and license as libpng-0.88,
243 * with the following individuals added to the list of Contributing Authors:
244 *
245 * John Bowler
246 * Kevin Bracey
247 * Sam Bushell
248 * Magnus Holmgren
249 * Greg Roelofs
250 * Tom Tanner
251 *
252 * libpng versions 0.5, May 1995, through 0.88, January 1996, are
253 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
254 *
255 * For the purposes of this copyright and license, "Contributing Authors"
256 * is defined as the following set of individuals:
257 *
258 * Andreas Dilger
259 * Dave Martindale
260 * Guy Eric Schalnat
261 * Paul Schmidt
262 * Tim Wegner
263 *
264 * The PNG Reference Library is supplied "AS IS". The Contributing Authors
265 * and Group 42, Inc. disclaim all warranties, expressed or implied,
266 * including, without limitation, the warranties of merchantability and of
267 * fitness for any purpose. The Contributing Authors and Group 42, Inc.
268 * assume no liability for direct, indirect, incidental, special, exemplary,
269 * or consequential damages, which may result from the use of the PNG
270 * Reference Library, even if advised of the possibility of such damage.
271 *
272 * Permission is hereby granted to use, copy, modify, and distribute this
273 * source code, or portions hereof, for any purpose, without fee, subject
274 * to the following restrictions:
275 *
276 * 1. The origin of this source code must not be misrepresented.
277 *
278 * 2. Altered versions must be plainly marked as such and must not
279 * be misrepresented as being the original source.
280 *
281 * 3. This Copyright notice may not be removed or altered from
282 * any source or altered source distribution.
283 *
284 * The Contributing Authors and Group 42, Inc. specifically permit, without
285 * fee, and encourage the use of this source code as a component to
286 * supporting the PNG file format in commercial products. If you use this
287 * source code in a product, acknowledgment is not required but would be
288 * appreciated.
289 */
290
291/*
292 * A "png_get_copyright" function is available, for convenient use in "about"
293 * boxes and the like:
294 *
295 * printf("%s", png_get_copyright(NULL));
296 *
297 * Also, the PNG logo (in PNG format, of course) is supplied in the
298 * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
299 */
300
301/*
302 * Libpng is OSI Certified Open Source Software. OSI Certified is a
303 * certification mark of the Open Source Initiative.
304 */
305
306/*
307 * The contributing authors would like to thank all those who helped
308 * with testing, bug fixes, and patience. This wouldn't have been
309 * possible without all of you.
310 *
311 * Thanks to Frank J. T. Wojcik for helping with the documentation.
312 */
313
314/*
315 * Y2K compliance in libpng:
316 * =========================
317 *
318 * February 18, 2012
319 *
320 * Since the PNG Development group is an ad-hoc body, we can't make
321 * an official declaration.
322 *
323 * This is your unofficial assurance that libpng from version 0.71 and
324 * upward through 1.5.9 are Y2K compliant. It is my belief that
325 * earlier versions were also Y2K compliant.
326 *
327 * Libpng only has two year fields. One is a 2-byte unsigned integer
328 * that will hold years up to 65535. The other holds the date in text
329 * format, and will hold years up to 9999.
330 *
331 * The integer is
332 * "png_uint_16 year" in png_time_struct.
333 *
334 * The string is
335 * "png_char time_buffer" in png_struct
336 *
337 * There are seven time-related functions:
338 * png.c: png_convert_to_rfc_1123() in png.c
339 * (formerly png_convert_to_rfc_1152() in error)
340 * png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
341 * png_convert_from_time_t() in pngwrite.c
342 * png_get_tIME() in pngget.c
343 * png_handle_tIME() in pngrutil.c, called in pngread.c
344 * png_set_tIME() in pngset.c
345 * png_write_tIME() in pngwutil.c, called in pngwrite.c
346 *
347 * All handle dates properly in a Y2K environment. The
348 * png_convert_from_time_t() function calls gmtime() to convert from system
349 * clock time, which returns (year - 1900), which we properly convert to
350 * the full 4-digit year. There is a possibility that applications using
351 * libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
352 * function, or that they are incorrectly passing only a 2-digit year
353 * instead of "year - 1900" into the png_convert_from_struct_tm() function,
354 * but this is not under our control. The libpng documentation has always
355 * stated that it works with 4-digit years, and the APIs have been
356 * documented as such.
357 *
358 * The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
359 * integer to hold the year, and can hold years as large as 65535.
360 *
361 * zlib, upon which libpng depends, is also Y2K compliant. It contains
362 * no date-related code.
363 *
364 * Glenn Randers-Pehrson
365 * libpng maintainer
366 * PNG Development Group
367 */
368
369#ifndef PNG_H
370#define PNG_H
371
372/* This is not the place to learn how to use libpng. The file libpng-manual.txt
373 * describes how to use libpng, and the file example.c summarizes it
374 * with some code on which to build. This file is useful for looking
375 * at the actual function definitions and structure components.
376 *
377 * If you just need to read a PNG file and don't want to read the documentation
378 * skip to the end of this file and read the section entitled 'simplified API'.
379 */
380
381/* Version information for png.h - this should match the version in png.c */
382#define PNG_LIBPNG_VER_STRING "1.5.9"
383#define PNG_HEADER_VERSION_STRING \
384 " libpng version 1.5.9 - February 18, 2012\n"
385
386#define PNG_LIBPNG_VER_SONUM 15
387#define PNG_LIBPNG_VER_DLLNUM 15
388
389/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
390#define PNG_LIBPNG_VER_MAJOR 1
391#define PNG_LIBPNG_VER_MINOR 5
392#define PNG_LIBPNG_VER_RELEASE 9
393
394/* This should match the numeric part of the final component of
395 * PNG_LIBPNG_VER_STRING, omitting any leading zero:
396 */
397
398#define PNG_LIBPNG_VER_BUILD 0
399
400/* Release Status */
401#define PNG_LIBPNG_BUILD_ALPHA 1
402#define PNG_LIBPNG_BUILD_BETA 2
403#define PNG_LIBPNG_BUILD_RC 3
404#define PNG_LIBPNG_BUILD_STABLE 4
405#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
406
407/* Release-Specific Flags */
408#define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
409 PNG_LIBPNG_BUILD_STABLE only */
410#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
411 PNG_LIBPNG_BUILD_SPECIAL */
412#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
413 PNG_LIBPNG_BUILD_PRIVATE */
414
415#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
416
417/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
418 * We must not include leading zeros.
419 * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
420 * version 1.0.0 was mis-numbered 100 instead of 10000). From
421 * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
422 */
423#define PNG_LIBPNG_VER 10509 /* 1.5.9 */
424
425/* Library configuration: these options cannot be changed after
426 * the library has been built.
427 */
428#ifndef PNGLCONF_H
429 /* If pnglibconf.h is missing, you can
430 * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
431 */
432# include "pnglibconf.h"
433#endif
434
435#ifndef PNG_VERSION_INFO_ONLY
436# ifndef PNG_BUILDING_SYMBOL_TABLE
437 /*
438 * Standard header files (not needed for the version info or while
439 * building symbol table -- see scripts/pnglibconf.dfa)
440 */
441# ifdef PNG_SETJMP_SUPPORTED
442# include <setjmp.h>
443# endif
444
445 /* Need the time information for converting tIME chunks, it
446 * defines struct tm:
447 */
448# ifdef PNG_CONVERT_tIME_SUPPORTED
449 /* "time.h" functions are not supported on all operating systems */
450# include <time.h>
451# endif
452# endif
453
454/* Machine specific configuration. */
455# include "pngconf.h"
456#endif
457
458/*
459 * Added at libpng-1.2.8
460 *
461 * Ref MSDN: Private as priority over Special
462 * VS_FF_PRIVATEBUILD File *was not* built using standard release
463 * procedures. If this value is given, the StringFileInfo block must
464 * contain a PrivateBuild string.
465 *
466 * VS_FF_SPECIALBUILD File *was* built by the original company using
467 * standard release procedures but is a variation of the standard
468 * file of the same version number. If this value is given, the
469 * StringFileInfo block must contain a SpecialBuild string.
470 */
471
472#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */
473# define PNG_LIBPNG_BUILD_TYPE \
474 (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
475#else
476# ifdef PNG_LIBPNG_SPECIALBUILD
477# define PNG_LIBPNG_BUILD_TYPE \
478 (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
479# else
480# define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
481# endif
482#endif
483
484#ifndef PNG_VERSION_INFO_ONLY
485
486/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
487#ifdef __cplusplus
488extern "C" {
489#endif /* __cplusplus */
490
491/* Version information for C files, stored in png.c. This had better match
492 * the version above.
493 */
494#define png_libpng_ver png_get_header_ver(NULL)
495
496/* This file is arranged in several sections:
497 *
498 * 1. Any configuration options that can be specified by for the application
499 * code when it is built. (Build time configuration is in pnglibconf.h)
500 * 2. Type definitions (base types are defined in pngconf.h), structure
501 * definitions.
502 * 3. Exported library functions.
503 *
504 * The library source code has additional files (principally pngpriv.h) that
505 * allow configuration of the library.
506 */
507/* Section 1: run time configuration
508 * See pnglibconf.h for build time configuration
509 *
510 * Run time configuration allows the application to choose between
511 * implementations of certain arithmetic APIs. The default is set
512 * at build time and recorded in pnglibconf.h, but it is safe to
513 * override these (and only these) settings. Note that this won't
514 * change what the library does, only application code, and the
515 * settings can (and probably should) be made on a per-file basis
516 * by setting the #defines before including png.h
517 *
518 * Use macros to read integers from PNG data or use the exported
519 * functions?
520 * PNG_USE_READ_MACROS: use the macros (see below) Note that
521 * the macros evaluate their argument multiple times.
522 * PNG_NO_USE_READ_MACROS: call the relevant library function.
523 *
524 * Use the alternative algorithm for compositing alpha samples that
525 * does not use division?
526 * PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'
527 * algorithm.
528 * PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.
529 *
530 * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is
531 * false?
532 * PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error
533 * APIs to png_warning.
534 * Otherwise the calls are mapped to png_error.
535 */
536
537/* Section 2: type definitions, including structures and compile time
538 * constants.
539 * See pngconf.h for base types that vary by machine/system
540 */
541
542/* This triggers a compiler error in png.c, if png.c and png.h
543 * do not agree upon the version number.
544 */
545typedef char* png_libpng_version_1_5_9;
546
547/* Three color definitions. The order of the red, green, and blue, (and the
548 * exact size) is not important, although the size of the fields need to
549 * be png_byte or png_uint_16 (as defined below).
550 */
551typedef struct png_color_struct
552{
553 png_byte red;
554 png_byte green;
555 png_byte blue;
556} png_color;
557typedef png_color FAR * png_colorp;
558typedef PNG_CONST png_color FAR * png_const_colorp;
559typedef png_color FAR * FAR * png_colorpp;
560
561typedef struct png_color_16_struct
562{
563 png_byte index; /* used for palette files */
564 png_uint_16 red; /* for use in red green blue files */
565 png_uint_16 green;
566 png_uint_16 blue;
567 png_uint_16 gray; /* for use in grayscale files */
568} png_color_16;
569typedef png_color_16 FAR * png_color_16p;
570typedef PNG_CONST png_color_16 FAR * png_const_color_16p;
571typedef png_color_16 FAR * FAR * png_color_16pp;
572
573typedef struct png_color_8_struct
574{
575 png_byte red; /* for use in red green blue files */
576 png_byte green;
577 png_byte blue;
578 png_byte gray; /* for use in grayscale files */
579 png_byte alpha; /* for alpha channel files */
580} png_color_8;
581typedef png_color_8 FAR * png_color_8p;
582typedef PNG_CONST png_color_8 FAR * png_const_color_8p;
583typedef png_color_8 FAR * FAR * png_color_8pp;
584
585/*
586 * The following two structures are used for the in-core representation
587 * of sPLT chunks.
588 */
589typedef struct png_sPLT_entry_struct
590{
591 png_uint_16 red;
592 png_uint_16 green;
593 png_uint_16 blue;
594 png_uint_16 alpha;
595 png_uint_16 frequency;
596} png_sPLT_entry;
597typedef png_sPLT_entry FAR * png_sPLT_entryp;
598typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp;
599typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
600
601/* When the depth of the sPLT palette is 8 bits, the color and alpha samples
602 * occupy the LSB of their respective members, and the MSB of each member
603 * is zero-filled. The frequency member always occupies the full 16 bits.
604 */
605
606typedef struct png_sPLT_struct
607{
608 png_charp name; /* palette name */
609 png_byte depth; /* depth of palette samples */
610 png_sPLT_entryp entries; /* palette entries */
611 png_int_32 nentries; /* number of palette entries */
612} png_sPLT_t;
613typedef png_sPLT_t FAR * png_sPLT_tp;
614typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp;
615typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
616
617#ifdef PNG_TEXT_SUPPORTED
618/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
619 * and whether that contents is compressed or not. The "key" field
620 * points to a regular zero-terminated C string. The "text" fields can be a
621 * regular C string, an empty string, or a NULL pointer.
622 * However, the structure returned by png_get_text() will always contain
623 * the "text" field as a regular zero-terminated C string (possibly
624 * empty), never a NULL pointer, so it can be safely used in printf() and
625 * other string-handling functions. Note that the "itxt_length", "lang", and
626 * "lang_key" members of the structure only exist when the library is built
627 * with iTXt chunk support. Prior to libpng-1.4.0 the library was built by
628 * default without iTXt support. Also note that when iTXt *is* supported,
629 * the "lang" and "lang_key" fields contain NULL pointers when the
630 * "compression" field contains * PNG_TEXT_COMPRESSION_NONE or
631 * PNG_TEXT_COMPRESSION_zTXt. Note that the "compression value" is not the
632 * same as what appears in the PNG tEXt/zTXt/iTXt chunk's "compression flag"
633 * which is always 0 or 1, or its "compression method" which is always 0.
634 */
635typedef struct png_text_struct
636{
637 int compression; /* compression value:
638 -1: tEXt, none
639 0: zTXt, deflate
640 1: iTXt, none
641 2: iTXt, deflate */
642 png_charp key; /* keyword, 1-79 character description of "text" */
643 png_charp text; /* comment, may be an empty string (ie "")
644 or a NULL pointer */
645 png_size_t text_length; /* length of the text string */
646 png_size_t itxt_length; /* length of the itxt string */
647 png_charp lang; /* language code, 0-79 characters
648 or a NULL pointer */
649 png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
650 chars or a NULL pointer */
651} png_text;
652typedef png_text FAR * png_textp;
653typedef PNG_CONST png_text FAR * png_const_textp;
654typedef png_text FAR * FAR * png_textpp;
655#endif
656
657/* Supported compression types for text in PNG files (tEXt, and zTXt).
658 * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */
659#define PNG_TEXT_COMPRESSION_NONE_WR -3
660#define PNG_TEXT_COMPRESSION_zTXt_WR -2
661#define PNG_TEXT_COMPRESSION_NONE -1
662#define PNG_TEXT_COMPRESSION_zTXt 0
663#define PNG_ITXT_COMPRESSION_NONE 1
664#define PNG_ITXT_COMPRESSION_zTXt 2
665#define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
666
667/* png_time is a way to hold the time in an machine independent way.
668 * Two conversions are provided, both from time_t and struct tm. There
669 * is no portable way to convert to either of these structures, as far
670 * as I know. If you know of a portable way, send it to me. As a side
671 * note - PNG has always been Year 2000 compliant!
672 */
673typedef struct png_time_struct
674{
675 png_uint_16 year; /* full year, as in, 1995 */
676 png_byte month; /* month of year, 1 - 12 */
677 png_byte day; /* day of month, 1 - 31 */
678 png_byte hour; /* hour of day, 0 - 23 */
679 png_byte minute; /* minute of hour, 0 - 59 */
680 png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
681} png_time;
682typedef png_time FAR * png_timep;
683typedef PNG_CONST png_time FAR * png_const_timep;
684typedef png_time FAR * FAR * png_timepp;
685
686#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
687 defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
688/* png_unknown_chunk is a structure to hold queued chunks for which there is
689 * no specific support. The idea is that we can use this to queue
690 * up private chunks for output even though the library doesn't actually
691 * know about their semantics.
692 */
693typedef struct png_unknown_chunk_t
694{
695 png_byte name[5];
696 png_byte *data;
697 png_size_t size;
698
699 /* libpng-using applications should NOT directly modify this byte. */
700 png_byte location; /* mode of operation at read time */
701}
702
703
704png_unknown_chunk;
705typedef png_unknown_chunk FAR * png_unknown_chunkp;
706typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp;
707typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
708#endif
709
710/* Values for the unknown chunk location byte */
711
712#define PNG_HAVE_IHDR 0x01
713#define PNG_HAVE_PLTE 0x02
714#define PNG_AFTER_IDAT 0x08
715
716/* The complete definition of png_info has, as of libpng-1.5.0,
717 * been moved into a separate header file that is not accessible to
718 * applications. Read libpng-manual.txt or libpng.3 for more info.
719 */
720typedef struct png_info_def png_info;
721typedef png_info FAR * png_infop;
722typedef PNG_CONST png_info FAR * png_const_infop;
723typedef png_info FAR * FAR * png_infopp;
724
725/* Maximum positive integer used in PNG is (2^31)-1 */
726#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
727#define PNG_UINT_32_MAX ((png_uint_32)(-1))
728#define PNG_SIZE_MAX ((png_size_t)(-1))
729
730/* These are constants for fixed point values encoded in the
731 * PNG specification manner (x100000)
732 */
733#define PNG_FP_1 100000
734#define PNG_FP_HALF 50000
735#define PNG_FP_MAX ((png_fixed_point)0x7fffffffL)
736#define PNG_FP_MIN (-PNG_FP_MAX)
737
738/* These describe the color_type field in png_info. */
739/* color type masks */
740#define PNG_COLOR_MASK_PALETTE 1
741#define PNG_COLOR_MASK_COLOR 2
742#define PNG_COLOR_MASK_ALPHA 4
743
744/* color types. Note that not all combinations are legal */
745#define PNG_COLOR_TYPE_GRAY 0
746#define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
747#define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
748#define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
749#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
750/* aliases */
751#define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
752#define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
753
754/* This is for compression type. PNG 1.0-1.2 only define the single type. */
755#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
756#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
757
758/* This is for filter type. PNG 1.0-1.2 only define the single type. */
759#define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
760#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
761#define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
762
763/* These are for the interlacing type. These values should NOT be changed. */
764#define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
765#define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
766#define PNG_INTERLACE_LAST 2 /* Not a valid value */
767
768/* These are for the oFFs chunk. These values should NOT be changed. */
769#define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
770#define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
771#define PNG_OFFSET_LAST 2 /* Not a valid value */
772
773/* These are for the pCAL chunk. These values should NOT be changed. */
774#define PNG_EQUATION_LINEAR 0 /* Linear transformation */
775#define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
776#define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
777#define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
778#define PNG_EQUATION_LAST 4 /* Not a valid value */
779
780/* These are for the sCAL chunk. These values should NOT be changed. */
781#define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
782#define PNG_SCALE_METER 1 /* meters per pixel */
783#define PNG_SCALE_RADIAN 2 /* radians per pixel */
784#define PNG_SCALE_LAST 3 /* Not a valid value */
785
786/* These are for the pHYs chunk. These values should NOT be changed. */
787#define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
788#define PNG_RESOLUTION_METER 1 /* pixels/meter */
789#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
790
791/* These are for the sRGB chunk. These values should NOT be changed. */
792#define PNG_sRGB_INTENT_PERCEPTUAL 0
793#define PNG_sRGB_INTENT_RELATIVE 1
794#define PNG_sRGB_INTENT_SATURATION 2
795#define PNG_sRGB_INTENT_ABSOLUTE 3
796#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
797
798/* This is for text chunks */
799#define PNG_KEYWORD_MAX_LENGTH 79
800
801/* Maximum number of entries in PLTE/sPLT/tRNS arrays */
802#define PNG_MAX_PALETTE_LENGTH 256
803
804/* These determine if an ancillary chunk's data has been successfully read
805 * from the PNG header, or if the application has filled in the corresponding
806 * data in the info_struct to be written into the output file. The values
807 * of the PNG_INFO_<chunk> defines should NOT be changed.
808 */
809#define PNG_INFO_gAMA 0x0001
810#define PNG_INFO_sBIT 0x0002
811#define PNG_INFO_cHRM 0x0004
812#define PNG_INFO_PLTE 0x0008
813#define PNG_INFO_tRNS 0x0010
814#define PNG_INFO_bKGD 0x0020
815#define PNG_INFO_hIST 0x0040
816#define PNG_INFO_pHYs 0x0080
817#define PNG_INFO_oFFs 0x0100
818#define PNG_INFO_tIME 0x0200
819#define PNG_INFO_pCAL 0x0400
820#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
821#define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
822#define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
823#define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
824#define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */
825
826/* This is used for the transformation routines, as some of them
827 * change these values for the row. It also should enable using
828 * the routines for other purposes.
829 */
830typedef struct png_row_info_struct
831{
832 png_uint_32 width; /* width of row */
833 png_size_t rowbytes; /* number of bytes in row */
834 png_byte color_type; /* color type of row */
835 png_byte bit_depth; /* bit depth of row */
836 png_byte channels; /* number of channels (1, 2, 3, or 4) */
837 png_byte pixel_depth; /* bits per pixel (depth * channels) */
838} png_row_info;
839
840typedef png_row_info FAR * png_row_infop;
841typedef png_row_info FAR * FAR * png_row_infopp;
842
843/* The complete definition of png_struct has, as of libpng-1.5.0,
844 * been moved into a separate header file that is not accessible to
845 * applications. Read libpng-manual.txt or libpng.3 for more info.
846 */
847typedef struct png_struct_def png_struct;
848typedef PNG_CONST png_struct FAR * png_const_structp;
849typedef png_struct FAR * png_structp;
850
851/* These are the function types for the I/O functions and for the functions
852 * that allow the user to override the default I/O functions with his or her
853 * own. The png_error_ptr type should match that of user-supplied warning
854 * and error functions, while the png_rw_ptr type should match that of the
855 * user read/write data functions. Note that the 'write' function must not
856 * modify the buffer it is passed. The 'read' function, on the other hand, is
857 * expected to return the read data in the buffer.
858 */
859typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
860typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t));
861typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
862typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,
863 int));
864typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32,
865 int));
866
867#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
868typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
869typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
870
871/* The following callback receives png_uint_32 row_number, int pass for the
872 * png_bytep data of the row. When transforming an interlaced image the
873 * row number is the row number within the sub-image of the interlace pass, so
874 * the value will increase to the height of the sub-image (not the full image)
875 * then reset to 0 for the next pass.
876 *
877 * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
878 * find the output pixel (x,y) given an interlaced sub-image pixel
879 * (row,col,pass). (See below for these macros.)
880 */
881typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep,
882 png_uint_32, int));
883#endif
884
885#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
886 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
887typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,
888 png_bytep));
889#endif
890
891#ifdef PNG_USER_CHUNKS_SUPPORTED
892typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,
893 png_unknown_chunkp));
894#endif
895#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
896typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp));
897#endif
898
899#ifdef PNG_SETJMP_SUPPORTED
900/* This must match the function definition in <setjmp.h>, and the application
901 * must include this before png.h to obtain the definition of jmp_buf. The
902 * function is required to be PNG_NORETURN, but this is not checked. If the
903 * function does return the application will crash via an abort() or similar
904 * system level call.
905 *
906 * If you get a warning here while building the library you may need to make
907 * changes to ensure that pnglibconf.h records the calling convention used by
908 * your compiler. This may be very difficult - try using a different compiler
909 * to build the library!
910 */
911PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);
912#endif
913
914/* Transform masks for the high-level interface */
915#define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
916#define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
917#define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
918#define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
919#define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
920#define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
921#define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
922#define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
923#define PNG_TRANSFORM_BGR 0x0080 /* read and write */
924#define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
925#define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
926#define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
927#define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* write only */
928/* Added to libpng-1.2.34 */
929#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER
930#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */
931/* Added to libpng-1.4.0 */
932#define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */
933/* Added to libpng-1.5.4 */
934#define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */
935#define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */
936
937/* Flags for MNG supported features */
938#define PNG_FLAG_MNG_EMPTY_PLTE 0x01
939#define PNG_FLAG_MNG_FILTER_64 0x04
940#define PNG_ALL_MNG_FEATURES 0x05
941
942/* NOTE: prior to 1.5 these functions had no 'API' style declaration,
943 * this allowed the zlib default functions to be used on Windows
944 * platforms. In 1.5 the zlib default malloc (which just calls malloc and
945 * ignores the first argument) should be completely compatible with the
946 * following.
947 */
948typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,
949 png_alloc_size_t));
950typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
951
952typedef png_struct FAR * FAR * png_structpp;
953
954/* Section 3: exported functions
955 * Here are the function definitions most commonly used. This is not
956 * the place to find out how to use libpng. See libpng-manual.txt for the
957 * full explanation, see example.c for the summary. This just provides
958 * a simple one line description of the use of each function.
959 *
960 * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in
961 * pngconf.h and in the *.dfn files in the scripts directory.
962 *
963 * PNG_EXPORT(ordinal, type, name, (args));
964 *
965 * ordinal: ordinal that is used while building
966 * *.def files. The ordinal value is only
967 * relevant when preprocessing png.h with
968 * the *.dfn files for building symbol table
969 * entries, and are removed by pngconf.h.
970 * type: return type of the function
971 * name: function name
972 * args: function arguments, with types
973 *
974 * When we wish to append attributes to a function prototype we use
975 * the PNG_EXPORTA() macro instead.
976 *
977 * PNG_EXPORTA(ordinal, type, name, (args), attributes);
978 *
979 * ordinal, type, name, and args: same as in PNG_EXPORT().
980 * attributes: function attributes
981 */
982
983/* Returns the version number of the library */
984PNG_EXPORT(1, png_uint_32, png_access_version_number, (void));
985
986/* Tell lib we have already handled the first <num_bytes> magic bytes.
987 * Handling more than 8 bytes from the beginning of the file is an error.
988 */
989PNG_EXPORT(2, void, png_set_sig_bytes, (png_structp png_ptr, int num_bytes));
990
991/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
992 * PNG file. Returns zero if the supplied bytes match the 8-byte PNG
993 * signature, and non-zero otherwise. Having num_to_check == 0 or
994 * start > 7 will always fail (ie return non-zero).
995 */
996PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start,
997 png_size_t num_to_check));
998
999/* Simple signature checking function. This is the same as calling
1000 * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
1001 */
1002#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
1003
1004/* Allocate and initialize png_ptr struct for reading, and any other memory. */
1005PNG_EXPORTA(4, png_structp, png_create_read_struct,
1006 (png_const_charp user_png_ver, png_voidp error_ptr,
1007 png_error_ptr error_fn, png_error_ptr warn_fn),
1008 PNG_ALLOCATED);
1009
1010/* Allocate and initialize png_ptr struct for writing, and any other memory */
1011PNG_EXPORTA(5, png_structp, png_create_write_struct,
1012 (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1013 png_error_ptr warn_fn),
1014 PNG_ALLOCATED);
1015
1016PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size,
1017 (png_const_structp png_ptr));
1018
1019PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr,
1020 png_size_t size));
1021
1022/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp
1023 * match up.
1024 */
1025#ifdef PNG_SETJMP_SUPPORTED
1026/* This function returns the jmp_buf built in to *png_ptr. It must be
1027 * supplied with an appropriate 'longjmp' function to use on that jmp_buf
1028 * unless the default error function is overridden in which case NULL is
1029 * acceptable. The size of the jmp_buf is checked against the actual size
1030 * allocated by the library - the call will return NULL on a mismatch
1031 * indicating an ABI mismatch.
1032 */
1033PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr,
1034 png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));
1035# define png_jmpbuf(png_ptr) \
1036 (*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf)))
1037#else
1038# define png_jmpbuf(png_ptr) \
1039 (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
1040#endif
1041/* This function should be used by libpng applications in place of
1042 * longjmp(png_ptr->jmpbuf, val). If longjmp_fn() has been set, it
1043 * will use it; otherwise it will call PNG_ABORT(). This function was
1044 * added in libpng-1.5.0.
1045 */
1046PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val),
1047 PNG_NORETURN);
1048
1049#ifdef PNG_READ_SUPPORTED
1050/* Reset the compression stream */
1051PNG_EXPORT(10, int, png_reset_zstream, (png_structp png_ptr));
1052#endif
1053
1054/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
1055#ifdef PNG_USER_MEM_SUPPORTED
1056PNG_EXPORTA(11, png_structp, png_create_read_struct_2,
1057 (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1058 png_error_ptr warn_fn,
1059 png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
1060 PNG_ALLOCATED);
1061PNG_EXPORTA(12, png_structp, png_create_write_struct_2,
1062 (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
1063 png_error_ptr warn_fn,
1064 png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
1065 PNG_ALLOCATED);
1066#endif
1067
1068/* Write the PNG file signature. */
1069PNG_EXPORT(13, void, png_write_sig, (png_structp png_ptr));
1070
1071/* Write a PNG chunk - size, type, (optional) data, CRC. */
1072PNG_EXPORT(14, void, png_write_chunk, (png_structp png_ptr, png_const_bytep
1073 chunk_name, png_const_bytep data, png_size_t length));
1074
1075/* Write the start of a PNG chunk - length and chunk name. */
1076PNG_EXPORT(15, void, png_write_chunk_start, (png_structp png_ptr,
1077 png_const_bytep chunk_name, png_uint_32 length));
1078
1079/* Write the data of a PNG chunk started with png_write_chunk_start(). */
1080PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr,
1081 png_const_bytep data, png_size_t length));
1082
1083/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
1084PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr));
1085
1086/* Allocate and initialize the info structure */
1087PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr),
1088 PNG_ALLOCATED);
1089
1090PNG_EXPORT(19, void, png_info_init_3, (png_infopp info_ptr,
1091 png_size_t png_info_struct_size));
1092
1093/* Writes all the PNG information before the image. */
1094PNG_EXPORT(20, void, png_write_info_before_PLTE,
1095 (png_structp png_ptr, png_infop info_ptr));
1096PNG_EXPORT(21, void, png_write_info,
1097 (png_structp png_ptr, png_infop info_ptr));
1098
1099#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1100/* Read the information before the actual image data. */
1101PNG_EXPORT(22, void, png_read_info,
1102 (png_structp png_ptr, png_infop info_ptr));
1103#endif
1104
1105#ifdef PNG_TIME_RFC1123_SUPPORTED
1106PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123,
1107 (png_structp png_ptr,
1108 png_const_timep ptime));
1109#endif
1110
1111#ifdef PNG_CONVERT_tIME_SUPPORTED
1112/* Convert from a struct tm to png_time */
1113PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime,
1114 PNG_CONST struct tm FAR * ttime));
1115
1116/* Convert from time_t to png_time. Uses gmtime() */
1117PNG_EXPORT(25, void, png_convert_from_time_t,
1118 (png_timep ptime, time_t ttime));
1119#endif /* PNG_CONVERT_tIME_SUPPORTED */
1120
1121#ifdef PNG_READ_EXPAND_SUPPORTED
1122/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
1123PNG_EXPORT(26, void, png_set_expand, (png_structp png_ptr));
1124PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structp png_ptr));
1125PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr));
1126PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr));
1127#endif
1128
1129#ifdef PNG_READ_EXPAND_16_SUPPORTED
1130/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion
1131 * of a tRNS chunk if present.
1132 */
1133PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr));
1134#endif
1135
1136#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
1137/* Use blue, green, red order for pixels. */
1138PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr));
1139#endif
1140
1141#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1142/* Expand the grayscale to 24-bit RGB if necessary. */
1143PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr));
1144#endif
1145
1146#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1147/* Reduce RGB to grayscale. */
1148#define PNG_ERROR_ACTION_NONE 1
1149#define PNG_ERROR_ACTION_WARN 2
1150#define PNG_ERROR_ACTION_ERROR 3
1151#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/
1152
1153PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr,
1154 int error_action, double red, double green));
1155PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr,
1156 int error_action, png_fixed_point red, png_fixed_point green));
1157
1158PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp
1159 png_ptr));
1160#endif
1161
1162#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
1163PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,
1164 png_colorp palette));
1165#endif
1166
1167#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1168/* How the alpha channel is interpreted - this affects how the color channels of
1169 * a PNG file are returned when an alpha channel, or tRNS chunk in a palette
1170 * file, is present.
1171 *
1172 * This has no effect on the way pixels are written into a PNG output
1173 * datastream. The color samples in a PNG datastream are never premultiplied
1174 * with the alpha samples.
1175 *
1176 * The default is to return data according to the PNG specification: the alpha
1177 * channel is a linear measure of the contribution of the pixel to the
1178 * corresponding composited pixel. The gamma encoded color channels must be
1179 * scaled according to the contribution and to do this it is necessary to undo
1180 * the encoding, scale the color values, perform the composition and reencode
1181 * the values. This is the 'PNG' mode.
1182 *
1183 * The alternative is to 'associate' the alpha with the color information by
1184 * storing color channel values that have been scaled by the alpha. The
1185 * advantage is that the color channels can be resampled (the image can be
1186 * scaled) in this form. The disadvantage is that normal practice is to store
1187 * linear, not (gamma) encoded, values and this requires 16-bit channels for
1188 * still images rather than the 8-bit channels that are just about sufficient if
1189 * gamma encoding is used. In addition all non-transparent pixel values,
1190 * including completely opaque ones, must be gamma encoded to produce the final
1191 * image. This is the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' mode (the
1192 * latter being the two common names for associated alpha color channels.)
1193 *
1194 * Since it is not necessary to perform arithmetic on opaque color values so
1195 * long as they are not to be resampled and are in the final color space it is
1196 * possible to optimize the handling of alpha by storing the opaque pixels in
1197 * the PNG format (adjusted for the output color space) while storing partially
1198 * opaque pixels in the standard, linear, format. The accuracy required for
1199 * standard alpha composition is relatively low, because the pixels are
1200 * isolated, therefore typically the accuracy loss in storing 8-bit linear
1201 * values is acceptable. (This is not true if the alpha channel is used to
1202 * simulate transparency over large areas - use 16 bits or the PNG mode in
1203 * this case!) This is the 'OPTIMIZED' mode. For this mode a pixel is
1204 * treated as opaque only if the alpha value is equal to the maximum value.
1205 *
1206 * The final choice is to gamma encode the alpha channel as well. This is
1207 * broken because, in practice, no implementation that uses this choice
1208 * correctly undoes the encoding before handling alpha composition. Use this
1209 * choice only if other serious errors in the software or hardware you use
1210 * mandate it; the typical serious error is for dark halos to appear around
1211 * opaque areas of the composited PNG image because of arithmetic overflow.
1212 *
1213 * The API function png_set_alpha_mode specifies which of these choices to use
1214 * with an enumerated 'mode' value and the gamma of the required output:
1215 */
1216#define PNG_ALPHA_PNG 0 /* according to the PNG standard */
1217#define PNG_ALPHA_STANDARD 1 /* according to Porter/Duff */
1218#define PNG_ALPHA_ASSOCIATED 1 /* as above; this is the normal practice */
1219#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */
1220#define PNG_ALPHA_OPTIMIZED 2 /* 'PNG' for opaque pixels, else 'STANDARD' */
1221#define PNG_ALPHA_BROKEN 3 /* the alpha channel is gamma encoded */
1222
1223PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structp png_ptr, int mode,
1224 double output_gamma));
1225PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr,
1226 int mode, png_fixed_point output_gamma));
1227#endif
1228
1229#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)
1230/* The output_gamma value is a screen gamma in libpng terminology: it expresses
1231 * how to decode the output values, not how they are encoded. The values used
1232 * correspond to the normal numbers used to describe the overall gamma of a
1233 * computer display system; for example 2.2 for an sRGB conformant system. The
1234 * values are scaled by 100000 in the _fixed version of the API (so 220000 for
1235 * sRGB.)
1236 *
1237 * The inverse of the value is always used to provide a default for the PNG file
1238 * encoding if it has no gAMA chunk and if png_set_gamma() has not been called
1239 * to override the PNG gamma information.
1240 *
1241 * When the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode
1242 * opaque pixels however pixels with lower alpha values are not encoded,
1243 * regardless of the output gamma setting.
1244 *
1245 * When the standard Porter Duff handling is requested with mode 1 the output
1246 * encoding is set to be linear and the output_gamma value is only relevant
1247 * as a default for input data that has no gamma information. The linear output
1248 * encoding will be overridden if png_set_gamma() is called - the results may be
1249 * highly unexpected!
1250 *
1251 * The following numbers are derived from the sRGB standard and the research
1252 * behind it. sRGB is defined to be approximated by a PNG gAMA chunk value of
1253 * 0.45455 (1/2.2) for PNG. The value implicitly includes any viewing
1254 * correction required to take account of any differences in the color
1255 * environment of the original scene and the intended display environment; the
1256 * value expresses how to *decode* the image for display, not how the original
1257 * data was *encoded*.
1258 *
1259 * sRGB provides a peg for the PNG standard by defining a viewing environment.
1260 * sRGB itself, and earlier TV standards, actually use a more complex transform
1261 * (a linear portion then a gamma 2.4 power law) than PNG can express. (PNG is
1262 * limited to simple power laws.) By saying that an image for direct display on
1263 * an sRGB conformant system should be stored with a gAMA chunk value of 45455
1264 * (11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification
1265 * makes it possible to derive values for other display systems and
1266 * environments.
1267 *
1268 * The Mac value is deduced from the sRGB based on an assumption that the actual
1269 * extra viewing correction used in early Mac display systems was implemented as
1270 * a power 1.45 lookup table.
1271 *
1272 * Any system where a programmable lookup table is used or where the behavior of
1273 * the final display device characteristics can be changed requires system
1274 * specific code to obtain the current characteristic. However this can be
1275 * difficult and most PNG gamma correction only requires an approximate value.
1276 *
1277 * By default, if png_set_alpha_mode() is not called, libpng assumes that all
1278 * values are unencoded, linear, values and that the output device also has a
1279 * linear characteristic. This is only very rarely correct - it is invariably
1280 * better to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the
1281 * default if you don't know what the right answer is!
1282 *
1283 * The special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS
1284 * 10.6) which used a correction table to implement a somewhat lower gamma on an
1285 * otherwise sRGB system.
1286 *
1287 * Both these values are reserved (not simple gamma values) in order to allow
1288 * more precise correction internally in the future.
1289 *
1290 * NOTE: the following values can be passed to either the fixed or floating
1291 * point APIs, but the floating point API will also accept floating point
1292 * values.
1293 */
1294#define PNG_DEFAULT_sRGB -1 /* sRGB gamma and color space */
1295#define PNG_GAMMA_MAC_18 -2 /* Old Mac '1.8' gamma and color space */
1296#define PNG_GAMMA_sRGB 220000 /* Television standards--matches sRGB gamma */
1297#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */
1298#endif
1299
1300/* The following are examples of calls to png_set_alpha_mode to achieve the
1301 * required overall gamma correction and, where necessary, alpha
1302 * premultiplication.
1303 *
1304 * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
1305 * This is the default libpng handling of the alpha channel - it is not
1306 * pre-multiplied into the color components. In addition the call states
1307 * that the output is for a sRGB system and causes all PNG files without gAMA
1308 * chunks to be assumed to be encoded using sRGB.
1309 *
1310 * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
1311 * In this case the output is assumed to be something like an sRGB conformant
1312 * display preceeded by a power-law lookup table of power 1.45. This is how
1313 * early Mac systems behaved.
1314 *
1315 * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);
1316 * This is the classic Jim Blinn approach and will work in academic
1317 * environments where everything is done by the book. It has the shortcoming
1318 * of assuming that input PNG data with no gamma information is linear - this
1319 * is unlikely to be correct unless the PNG files where generated locally.
1320 * Most of the time the output precision will be so low as to show
1321 * significant banding in dark areas of the image.
1322 *
1323 * png_set_expand_16(pp);
1324 * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);
1325 * This is a somewhat more realistic Jim Blinn inspired approach. PNG files
1326 * are assumed to have the sRGB encoding if not marked with a gamma value and
1327 * the output is always 16 bits per component. This permits accurate scaling
1328 * and processing of the data. If you know that your input PNG files were
1329 * generated locally you might need to replace PNG_DEFAULT_sRGB with the
1330 * correct value for your system.
1331 *
1332 * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);
1333 * If you just need to composite the PNG image onto an existing background
1334 * and if you control the code that does this you can use the optimization
1335 * setting. In this case you just copy completely opaque pixels to the
1336 * output. For pixels that are not completely transparent (you just skip
1337 * those) you do the composition math using png_composite or png_composite_16
1338 * below then encode the resultant 8-bit or 16-bit values to match the output
1339 * encoding.
1340 *
1341 * Other cases
1342 * If neither the PNG nor the standard linear encoding work for you because
1343 * of the software or hardware you use then you have a big problem. The PNG
1344 * case will probably result in halos around the image. The linear encoding
1345 * will probably result in a washed out, too bright, image (it's actually too
1346 * contrasty.) Try the ALPHA_OPTIMIZED mode above - this will probably
1347 * substantially reduce the halos. Alternatively try:
1348 *
1349 * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);
1350 * This option will also reduce the halos, but there will be slight dark
1351 * halos round the opaque parts of the image where the background is light.
1352 * In the OPTIMIZED mode the halos will be light halos where the background
1353 * is dark. Take your pick - the halos are unavoidable unless you can get
1354 * your hardware/software fixed! (The OPTIMIZED approach is slightly
1355 * faster.)
1356 *
1357 * When the default gamma of PNG files doesn't match the output gamma.
1358 * If you have PNG files with no gamma information png_set_alpha_mode allows
1359 * you to provide a default gamma, but it also sets the ouput gamma to the
1360 * matching value. If you know your PNG files have a gamma that doesn't
1361 * match the output you can take advantage of the fact that
1362 * png_set_alpha_mode always sets the output gamma but only sets the PNG
1363 * default if it is not already set:
1364 *
1365 * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
1366 * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
1367 * The first call sets both the default and the output gamma values, the
1368 * second call overrides the output gamma without changing the default. This
1369 * is easier than achieving the same effect with png_set_gamma. You must use
1370 * PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will
1371 * fire if more than one call to png_set_alpha_mode and png_set_background is
1372 * made in the same read operation, however multiple calls with PNG_ALPHA_PNG
1373 * are ignored.
1374 */
1375
1376#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1377PNG_EXPORT(36, void, png_set_strip_alpha, (png_structp png_ptr));
1378#endif
1379
1380#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
1381 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
1382PNG_EXPORT(37, void, png_set_swap_alpha, (png_structp png_ptr));
1383#endif
1384
1385#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
1386 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1387PNG_EXPORT(38, void, png_set_invert_alpha, (png_structp png_ptr));
1388#endif
1389
1390#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
1391/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */
1392PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler,
1393 int flags));
1394/* The values of the PNG_FILLER_ defines should NOT be changed */
1395# define PNG_FILLER_BEFORE 0
1396# define PNG_FILLER_AFTER 1
1397/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
1398PNG_EXPORT(40, void, png_set_add_alpha,
1399 (png_structp png_ptr, png_uint_32 filler,
1400 int flags));
1401#endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
1402
1403#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
1404/* Swap bytes in 16-bit depth files. */
1405PNG_EXPORT(41, void, png_set_swap, (png_structp png_ptr));
1406#endif
1407
1408#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
1409/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
1410PNG_EXPORT(42, void, png_set_packing, (png_structp png_ptr));
1411#endif
1412
1413#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
1414 defined(PNG_WRITE_PACKSWAP_SUPPORTED)
1415/* Swap packing order of pixels in bytes. */
1416PNG_EXPORT(43, void, png_set_packswap, (png_structp png_ptr));
1417#endif
1418
1419#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
1420/* Converts files to legal bit depths. */
1421PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p
1422 true_bits));
1423#endif
1424
1425#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
1426 defined(PNG_WRITE_INTERLACING_SUPPORTED)
1427/* Have the code handle the interlacing. Returns the number of passes.
1428 * MUST be called before png_read_update_info or png_start_read_image,
1429 * otherwise it will not have the desired effect. Note that it is still
1430 * necessary to call png_read_row or png_read_rows png_get_image_height
1431 * times for each pass.
1432*/
1433PNG_EXPORT(45, int, png_set_interlace_handling, (png_structp png_ptr));
1434#endif
1435
1436#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
1437/* Invert monochrome files */
1438PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr));
1439#endif
1440
1441#ifdef PNG_READ_BACKGROUND_SUPPORTED
1442/* Handle alpha and tRNS by replacing with a background color. Prior to
1443 * libpng-1.5.4 this API must not be called before the PNG file header has been
1444 * read. Doing so will result in unexpected behavior and possible warnings or
1445 * errors if the PNG file contains a bKGD chunk.
1446 */
1447PNG_FP_EXPORT(47, void, png_set_background, (png_structp png_ptr,
1448 png_const_color_16p background_color, int background_gamma_code,
1449 int need_expand, double background_gamma));
1450PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr,
1451 png_const_color_16p background_color, int background_gamma_code,
1452 int need_expand, png_fixed_point background_gamma));
1453#endif
1454#ifdef PNG_READ_BACKGROUND_SUPPORTED
1455# define PNG_BACKGROUND_GAMMA_UNKNOWN 0
1456# define PNG_BACKGROUND_GAMMA_SCREEN 1
1457# define PNG_BACKGROUND_GAMMA_FILE 2
1458# define PNG_BACKGROUND_GAMMA_UNIQUE 3
1459#endif
1460
1461#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1462/* Scale a 16-bit depth file down to 8-bit, accurately. */
1463PNG_EXPORT(229, void, png_set_scale_16, (png_structp png_ptr));
1464#endif
1465
1466#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1467#define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */
1468/* Strip the second byte of information from a 16-bit depth file. */
1469PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr));
1470#endif
1471
1472#ifdef PNG_READ_QUANTIZE_SUPPORTED
1473/* Turn on quantizing, and reduce the palette to the number of colors
1474 * available.
1475 */
1476PNG_EXPORT(49, void, png_set_quantize,
1477 (png_structp png_ptr, png_colorp palette,
1478 int num_palette, int maximum_colors, png_const_uint_16p histogram,
1479 int full_quantize));
1480#endif
1481
1482#ifdef PNG_READ_GAMMA_SUPPORTED
1483/* The threshold on gamma processing is configurable but hard-wired into the
1484 * library. The following is the floating point variant.
1485 */
1486#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001)
1487
1488/* Handle gamma correction. Screen_gamma=(display_exponent).
1489 * NOTE: this API simply sets the screen and file gamma values. It will
1490 * therefore override the value for gamma in a PNG file if it is called after
1491 * the file header has been read - use with care - call before reading the PNG
1492 * file for best results!
1493 *
1494 * These routines accept the same gamma values as png_set_alpha_mode (described
1495 * above). The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either
1496 * API (floating point or fixed.) Notice, however, that the 'file_gamma' value
1497 * is the inverse of a 'screen gamma' value.
1498 */
1499PNG_FP_EXPORT(50, void, png_set_gamma,
1500 (png_structp png_ptr, double screen_gamma,
1501 double override_file_gamma));
1502PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr,
1503 png_fixed_point screen_gamma, png_fixed_point override_file_gamma));
1504#endif
1505
1506#ifdef PNG_WRITE_FLUSH_SUPPORTED
1507/* Set how many lines between output flushes - 0 for no flushing */
1508PNG_EXPORT(51, void, png_set_flush, (png_structp png_ptr, int nrows));
1509/* Flush the current PNG output buffer */
1510PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr));
1511#endif
1512
1513/* Optional update palette with requested transformations */
1514PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr));
1515
1516/* Optional call to update the users info structure */
1517PNG_EXPORT(54, void, png_read_update_info,
1518 (png_structp png_ptr, png_infop info_ptr));
1519
1520#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1521/* Read one or more rows of image data. */
1522PNG_EXPORT(55, void, png_read_rows, (png_structp png_ptr, png_bytepp row,
1523 png_bytepp display_row, png_uint_32 num_rows));
1524#endif
1525
1526#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1527/* Read a row of data. */
1528PNG_EXPORT(56, void, png_read_row, (png_structp png_ptr, png_bytep row,
1529 png_bytep display_row));
1530#endif
1531
1532#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1533/* Read the whole image into memory at once. */
1534PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image));
1535#endif
1536
1537/* Write a row of image data */
1538PNG_EXPORT(58, void, png_write_row,
1539 (png_structp png_ptr, png_const_bytep row));
1540
1541/* Write a few rows of image data: (*row) is not written; however, the type
1542 * is declared as writeable to maintain compatibility with previous versions
1543 * of libpng and to allow the 'display_row' array from read_rows to be passed
1544 * unchanged to write_rows.
1545 */
1546PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row,
1547 png_uint_32 num_rows));
1548
1549/* Write the image data */
1550PNG_EXPORT(60, void, png_write_image,
1551 (png_structp png_ptr, png_bytepp image));
1552
1553/* Write the end of the PNG file. */
1554PNG_EXPORT(61, void, png_write_end,
1555 (png_structp png_ptr, png_infop info_ptr));
1556
1557#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1558/* Read the end of the PNG file. */
1559PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr));
1560#endif
1561
1562/* Free any memory associated with the png_info_struct */
1563PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr,
1564 png_infopp info_ptr_ptr));
1565
1566/* Free any memory associated with the png_struct and the png_info_structs */
1567PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr,
1568 png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
1569
1570/* Free any memory associated with the png_struct and the png_info_structs */
1571PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr,
1572 png_infopp info_ptr_ptr));
1573
1574/* Set the libpng method of handling chunk CRC errors */
1575PNG_EXPORT(66, void, png_set_crc_action,
1576 (png_structp png_ptr, int crit_action, int ancil_action));
1577
1578/* Values for png_set_crc_action() say how to handle CRC errors in
1579 * ancillary and critical chunks, and whether to use the data contained
1580 * therein. Note that it is impossible to "discard" data in a critical
1581 * chunk. For versions prior to 0.90, the action was always error/quit,
1582 * whereas in version 0.90 and later, the action for CRC errors in ancillary
1583 * chunks is warn/discard. These values should NOT be changed.
1584 *
1585 * value action:critical action:ancillary
1586 */
1587#define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
1588#define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
1589#define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
1590#define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
1591#define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
1592#define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
1593
1594/* These functions give the user control over the scan-line filtering in
1595 * libpng and the compression methods used by zlib. These functions are
1596 * mainly useful for testing, as the defaults should work with most users.
1597 * Those users who are tight on memory or want faster performance at the
1598 * expense of compression can modify them. See the compression library
1599 * header file (zlib.h) for an explination of the compression functions.
1600 */
1601
1602/* Set the filtering method(s) used by libpng. Currently, the only valid
1603 * value for "method" is 0.
1604 */
1605PNG_EXPORT(67, void, png_set_filter,
1606 (png_structp png_ptr, int method, int filters));
1607
1608/* Flags for png_set_filter() to say which filters to use. The flags
1609 * are chosen so that they don't conflict with real filter types
1610 * below, in case they are supplied instead of the #defined constants.
1611 * These values should NOT be changed.
1612 */
1613#define PNG_NO_FILTERS 0x00
1614#define PNG_FILTER_NONE 0x08
1615#define PNG_FILTER_SUB 0x10
1616#define PNG_FILTER_UP 0x20
1617#define PNG_FILTER_AVG 0x40
1618#define PNG_FILTER_PAETH 0x80
1619#define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
1620 PNG_FILTER_AVG | PNG_FILTER_PAETH)
1621
1622/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.
1623 * These defines should NOT be changed.
1624 */
1625#define PNG_FILTER_VALUE_NONE 0
1626#define PNG_FILTER_VALUE_SUB 1
1627#define PNG_FILTER_VALUE_UP 2
1628#define PNG_FILTER_VALUE_AVG 3
1629#define PNG_FILTER_VALUE_PAETH 4
1630#define PNG_FILTER_VALUE_LAST 5
1631
1632#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */
1633/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
1634 * defines, either the default (minimum-sum-of-absolute-differences), or
1635 * the experimental method (weighted-minimum-sum-of-absolute-differences).
1636 *
1637 * Weights are factors >= 1.0, indicating how important it is to keep the
1638 * filter type consistent between rows. Larger numbers mean the current
1639 * filter is that many times as likely to be the same as the "num_weights"
1640 * previous filters. This is cumulative for each previous row with a weight.
1641 * There needs to be "num_weights" values in "filter_weights", or it can be
1642 * NULL if the weights aren't being specified. Weights have no influence on
1643 * the selection of the first row filter. Well chosen weights can (in theory)
1644 * improve the compression for a given image.
1645 *
1646 * Costs are factors >= 1.0 indicating the relative decoding costs of a
1647 * filter type. Higher costs indicate more decoding expense, and are
1648 * therefore less likely to be selected over a filter with lower computational
1649 * costs. There needs to be a value in "filter_costs" for each valid filter
1650 * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't
1651 * setting the costs. Costs try to improve the speed of decompression without
1652 * unduly increasing the compressed image size.
1653 *
1654 * A negative weight or cost indicates the default value is to be used, and
1655 * values in the range [0.0, 1.0) indicate the value is to remain unchanged.
1656 * The default values for both weights and costs are currently 1.0, but may
1657 * change if good general weighting/cost heuristics can be found. If both
1658 * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
1659 * to the UNWEIGHTED method, but with added encoding time/computation.
1660 */
1661PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr,
1662 int heuristic_method, int num_weights, png_const_doublep filter_weights,
1663 png_const_doublep filter_costs));
1664PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed,
1665 (png_structp png_ptr,
1666 int heuristic_method, int num_weights, png_const_fixed_point_p
1667 filter_weights, png_const_fixed_point_p filter_costs));
1668#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
1669
1670/* Heuristic used for row filter selection. These defines should NOT be
1671 * changed.
1672 */
1673#define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
1674#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
1675#define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
1676#define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
1677
1678#ifdef PNG_WRITE_SUPPORTED
1679/* Set the library compression level. Currently, valid values range from
1680 * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
1681 * (0 - no compression, 9 - "maximal" compression). Note that tests have
1682 * shown that zlib compression levels 3-6 usually perform as well as level 9
1683 * for PNG images, and do considerably fewer caclulations. In the future,
1684 * these values may not correspond directly to the zlib compression levels.
1685 */
1686PNG_EXPORT(69, void, png_set_compression_level,
1687 (png_structp png_ptr, int level));
1688
1689PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr,
1690 int mem_level));
1691
1692PNG_EXPORT(71, void, png_set_compression_strategy, (png_structp png_ptr,
1693 int strategy));
1694
1695/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
1696 * smaller value of window_bits if it can do so safely.
1697 */
1698PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structp png_ptr,
1699 int window_bits));
1700
1701PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr,
1702 int method));
1703#endif
1704
1705#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
1706/* Also set zlib parameters for compressing non-IDAT chunks */
1707PNG_EXPORT(222, void, png_set_text_compression_level,
1708 (png_structp png_ptr, int level));
1709
1710PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr,
1711 int mem_level));
1712
1713PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr,
1714 int strategy));
1715
1716/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
1717 * smaller value of window_bits if it can do so safely.
1718 */
1719PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp
1720 png_ptr, int window_bits));
1721
1722PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr,
1723 int method));
1724#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
1725
1726/* These next functions are called for input/output, memory, and error
1727 * handling. They are in the file pngrio.c, pngwio.c, and pngerror.c,
1728 * and call standard C I/O routines such as fread(), fwrite(), and
1729 * fprintf(). These functions can be made to use other I/O routines
1730 * at run time for those applications that need to handle I/O in a
1731 * different manner by calling png_set_???_fn(). See libpng-manual.txt for
1732 * more information.
1733 */
1734
1735#ifdef PNG_STDIO_SUPPORTED
1736/* Initialize the input/output for the PNG file to the default functions. */
1737PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp));
1738#endif
1739
1740/* Replace the (error and abort), and warning functions with user
1741 * supplied functions. If no messages are to be printed you must still
1742 * write and use replacement functions. The replacement error_fn should
1743 * still do a longjmp to the last setjmp location if you are using this
1744 * method of error handling. If error_fn or warning_fn is NULL, the
1745 * default function will be used.
1746 */
1747
1748PNG_EXPORT(75, void, png_set_error_fn,
1749 (png_structp png_ptr, png_voidp error_ptr,
1750 png_error_ptr error_fn, png_error_ptr warning_fn));
1751
1752/* Return the user pointer associated with the error functions */
1753PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr));
1754
1755/* Replace the default data output functions with a user supplied one(s).
1756 * If buffered output is not used, then output_flush_fn can be set to NULL.
1757 * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
1758 * output_flush_fn will be ignored (and thus can be NULL).
1759 * It is probably a mistake to use NULL for output_flush_fn if
1760 * write_data_fn is not also NULL unless you have built libpng with
1761 * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's
1762 * default flush function, which uses the standard *FILE structure, will
1763 * be used.
1764 */
1765PNG_EXPORT(77, void, png_set_write_fn, (png_structp png_ptr, png_voidp io_ptr,
1766 png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
1767
1768/* Replace the default data input function with a user supplied one. */
1769PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr,
1770 png_rw_ptr read_data_fn));
1771
1772/* Return the user pointer associated with the I/O functions */
1773PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr));
1774
1775PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr,
1776 png_read_status_ptr read_row_fn));
1777
1778PNG_EXPORT(81, void, png_set_write_status_fn, (png_structp png_ptr,
1779 png_write_status_ptr write_row_fn));
1780
1781#ifdef PNG_USER_MEM_SUPPORTED
1782/* Replace the default memory allocation functions with user supplied one(s). */
1783PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr,
1784 png_malloc_ptr malloc_fn, png_free_ptr free_fn));
1785/* Return the user pointer associated with the memory functions */
1786PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr));
1787#endif
1788
1789#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1790PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr,
1791 png_user_transform_ptr read_user_transform_fn));
1792#endif
1793
1794#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1795PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr,
1796 png_user_transform_ptr write_user_transform_fn));
1797#endif
1798
1799#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
1800PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr,
1801 png_voidp user_transform_ptr, int user_transform_depth,
1802 int user_transform_channels));
1803/* Return the user pointer associated with the user transform functions */
1804PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr,
1805 (png_const_structp png_ptr));
1806#endif
1807
1808#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
1809/* Return information about the row currently being processed. Note that these
1810 * APIs do not fail but will return unexpected results if called outside a user
1811 * transform callback. Also note that when transforming an interlaced image the
1812 * row number is the row number within the sub-image of the interlace pass, so
1813 * the value will increase to the height of the sub-image (not the full image)
1814 * then reset to 0 for the next pass.
1815 *
1816 * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
1817 * find the output pixel (x,y) given an interlaced sub-image pixel
1818 * (row,col,pass). (See below for these macros.)
1819 */
1820PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp));
1821PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp));
1822#endif
1823
1824#ifdef PNG_USER_CHUNKS_SUPPORTED
1825PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr,
1826 png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
1827PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr));
1828#endif
1829
1830#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1831/* Sets the function callbacks for the push reader, and a pointer to a
1832 * user-defined structure available to the callback functions.
1833 */
1834PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr,
1835 png_voidp progressive_ptr, png_progressive_info_ptr info_fn,
1836 png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));
1837
1838/* Returns the user pointer associated with the push read functions */
1839PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr));
1840
1841/* Function to be called when data becomes available */
1842PNG_EXPORT(92, void, png_process_data,
1843 (png_structp png_ptr, png_infop info_ptr,
1844 png_bytep buffer, png_size_t buffer_size));
1845
1846/* A function which may be called *only* within png_process_data to stop the
1847 * processing of any more data. The function returns the number of bytes
1848 * remaining, excluding any that libpng has cached internally. A subsequent
1849 * call to png_process_data must supply these bytes again. If the argument
1850 * 'save' is set to true the routine will first save all the pending data and
1851 * will always return 0.
1852 */
1853PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save));
1854
1855/* A function which may be called *only* outside (after) a call to
1856 * png_process_data. It returns the number of bytes of data to skip in the
1857 * input. Normally it will return 0, but if it returns a non-zero value the
1858 * application must skip than number of bytes of input data and pass the
1859 * following data to the next call to png_process_data.
1860 */
1861PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp));
1862
1863#ifdef PNG_READ_INTERLACING_SUPPORTED
1864/* Function that combines rows. 'new_row' is a flag that should come from
1865 * the callback and be non-NULL if anything needs to be done; the library
1866 * stores its own version of the new data internally and ignores the passed
1867 * in value.
1868 */
1869PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr,
1870 png_bytep old_row, png_const_bytep new_row));
1871#endif /* PNG_READ_INTERLACING_SUPPORTED */
1872#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1873
1874PNG_EXPORTA(94, png_voidp, png_malloc,
1875 (png_structp png_ptr, png_alloc_size_t size),
1876 PNG_ALLOCATED);
1877/* Added at libpng version 1.4.0 */
1878PNG_EXPORTA(95, png_voidp, png_calloc,
1879 (png_structp png_ptr, png_alloc_size_t size),
1880 PNG_ALLOCATED);
1881
1882/* Added at libpng version 1.2.4 */
1883PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr,
1884 png_alloc_size_t size), PNG_ALLOCATED);
1885
1886/* Frees a pointer allocated by png_malloc() */
1887PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr));
1888
1889/* Free data that was allocated internally */
1890PNG_EXPORT(98, void, png_free_data,
1891 (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num));
1892
1893/* Reassign responsibility for freeing existing data, whether allocated
1894 * by libpng or by the application */
1895PNG_EXPORT(99, void, png_data_freer,
1896 (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask));
1897
1898/* Assignments for png_data_freer */
1899#define PNG_DESTROY_WILL_FREE_DATA 1
1900#define PNG_SET_WILL_FREE_DATA 1
1901#define PNG_USER_WILL_FREE_DATA 2
1902/* Flags for png_ptr->free_me and info_ptr->free_me */
1903#define PNG_FREE_HIST 0x0008
1904#define PNG_FREE_ICCP 0x0010
1905#define PNG_FREE_SPLT 0x0020
1906#define PNG_FREE_ROWS 0x0040
1907#define PNG_FREE_PCAL 0x0080
1908#define PNG_FREE_SCAL 0x0100
1909#define PNG_FREE_UNKN 0x0200
1910#define PNG_FREE_LIST 0x0400
1911#define PNG_FREE_PLTE 0x1000
1912#define PNG_FREE_TRNS 0x2000
1913#define PNG_FREE_TEXT 0x4000
1914#define PNG_FREE_ALL 0x7fff
1915#define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
1916
1917#ifdef PNG_USER_MEM_SUPPORTED
1918PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr,
1919 png_alloc_size_t size), PNG_ALLOCATED);
1920PNG_EXPORT(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr));
1921#endif
1922
1923#ifdef PNG_ERROR_TEXT_SUPPORTED
1924/* Fatal error in PNG image of libpng - can't continue */
1925PNG_EXPORTA(102, void, png_error,
1926 (png_structp png_ptr, png_const_charp error_message),
1927 PNG_NORETURN);
1928
1929/* The same, but the chunk name is prepended to the error string. */
1930PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr,
1931 png_const_charp error_message), PNG_NORETURN);
1932
1933#else
1934/* Fatal error in PNG image of libpng - can't continue */
1935PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN);
1936#endif
1937
1938#ifdef PNG_WARNINGS_SUPPORTED
1939/* Non-fatal error in libpng. Can continue, but may have a problem. */
1940PNG_EXPORT(105, void, png_warning, (png_structp png_ptr,
1941 png_const_charp warning_message));
1942
1943/* Non-fatal error in libpng, chunk name is prepended to message. */
1944PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr,
1945 png_const_charp warning_message));
1946#endif
1947
1948#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1949/* Benign error in libpng. Can continue, but may have a problem.
1950 * User can choose whether to handle as a fatal error or as a warning. */
1951# undef png_benign_error
1952PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr,
1953 png_const_charp warning_message));
1954
1955/* Same, chunk name is prepended to message. */
1956# undef png_chunk_benign_error
1957PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr,
1958 png_const_charp warning_message));
1959
1960PNG_EXPORT(109, void, png_set_benign_errors,
1961 (png_structp png_ptr, int allowed));
1962#else
1963# ifdef PNG_ALLOW_BENIGN_ERRORS
1964# define png_benign_error png_warning
1965# define png_chunk_benign_error png_chunk_warning
1966# else
1967# define png_benign_error png_error
1968# define png_chunk_benign_error png_chunk_error
1969# endif
1970#endif
1971
1972/* The png_set_<chunk> functions are for storing values in the png_info_struct.
1973 * Similarly, the png_get_<chunk> calls are used to read values from the
1974 * png_info_struct, either storing the parameters in the passed variables, or
1975 * setting pointers into the png_info_struct where the data is stored. The
1976 * png_get_<chunk> functions return a non-zero value if the data was available
1977 * in info_ptr, or return zero and do not change any of the parameters if the
1978 * data was not available.
1979 *
1980 * These functions should be used instead of directly accessing png_info
1981 * to avoid problems with future changes in the size and internal layout of
1982 * png_info_struct.
1983 */
1984/* Returns "flag" if chunk data is valid in info_ptr. */
1985PNG_EXPORT(110, png_uint_32, png_get_valid,
1986 (png_const_structp png_ptr, png_const_infop info_ptr,
1987 png_uint_32 flag));
1988
1989/* Returns number of bytes needed to hold a transformed row. */
1990PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr,
1991 png_const_infop info_ptr));
1992
1993#ifdef PNG_INFO_IMAGE_SUPPORTED
1994/* Returns row_pointers, which is an array of pointers to scanlines that was
1995 * returned from png_read_png().
1996 */
1997PNG_EXPORT(112, png_bytepp, png_get_rows,
1998 (png_const_structp png_ptr, png_const_infop info_ptr));
1999/* Set row_pointers, which is an array of pointers to scanlines for use
2000 * by png_write_png().
2001 */
2002PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr,
2003 png_infop info_ptr, png_bytepp row_pointers));
2004#endif
2005
2006/* Returns number of color channels in image. */
2007PNG_EXPORT(114, png_byte, png_get_channels,
2008 (png_const_structp png_ptr, png_const_infop info_ptr));
2009
2010#ifdef PNG_EASY_ACCESS_SUPPORTED
2011/* Returns image width in pixels. */
2012PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr,
2013 png_const_infop info_ptr));
2014
2015/* Returns image height in pixels. */
2016PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr,
2017 png_const_infop info_ptr));
2018
2019/* Returns image bit_depth. */
2020PNG_EXPORT(117, png_byte, png_get_bit_depth,
2021 (png_const_structp png_ptr, png_const_infop info_ptr));
2022
2023/* Returns image color_type. */
2024PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr,
2025 png_const_infop info_ptr));
2026
2027/* Returns image filter_type. */
2028PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr,
2029 png_const_infop info_ptr));
2030
2031/* Returns image interlace_type. */
2032PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr,
2033 png_const_infop info_ptr));
2034
2035/* Returns image compression_type. */
2036PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr,
2037 png_const_infop info_ptr));
2038
2039/* Returns image resolution in pixels per meter, from pHYs chunk data. */
2040PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter,
2041 (png_const_structp png_ptr, png_const_infop info_ptr));
2042PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter,
2043 (png_const_structp png_ptr, png_const_infop info_ptr));
2044PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter,
2045 (png_const_structp png_ptr, png_const_infop info_ptr));
2046
2047/* Returns pixel aspect ratio, computed from pHYs chunk data. */
2048PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio,
2049 (png_const_structp png_ptr, png_const_infop info_ptr));
2050PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed,
2051 (png_const_structp png_ptr, png_const_infop info_ptr));
2052
2053/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
2054PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels,
2055 (png_const_structp png_ptr, png_const_infop info_ptr));
2056PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels,
2057 (png_const_structp png_ptr, png_const_infop info_ptr));
2058PNG_EXPORT(128, png_int_32, png_get_x_offset_microns,
2059 (png_const_structp png_ptr, png_const_infop info_ptr));
2060PNG_EXPORT(129, png_int_32, png_get_y_offset_microns,
2061 (png_const_structp png_ptr, png_const_infop info_ptr));
2062
2063#endif /* PNG_EASY_ACCESS_SUPPORTED */
2064
2065/* Returns pointer to signature string read from PNG header */
2066PNG_EXPORT(130, png_const_bytep, png_get_signature,
2067 (png_const_structp png_ptr, png_infop info_ptr));
2068
2069#ifdef PNG_bKGD_SUPPORTED
2070PNG_EXPORT(131, png_uint_32, png_get_bKGD,
2071 (png_const_structp png_ptr, png_infop info_ptr,
2072 png_color_16p *background));
2073#endif
2074
2075#ifdef PNG_bKGD_SUPPORTED
2076PNG_EXPORT(132, void, png_set_bKGD, (png_structp png_ptr, png_infop info_ptr,
2077 png_const_color_16p background));
2078#endif
2079
2080#ifdef PNG_cHRM_SUPPORTED
2081PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr,
2082 png_const_infop info_ptr, double *white_x, double *white_y, double *red_x,
2083 double *red_y, double *green_x, double *green_y, double *blue_x,
2084 double *blue_y));
2085PNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_structp png_ptr,
2086 png_const_infop info_ptr, double *red_X, double *red_Y, double *red_Z,
2087 double *green_X, double *green_Y, double *green_Z, double *blue_X,
2088 double *blue_Y, double *blue_Z));
2089#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */
2090PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,
2091 (png_const_structp png_ptr,
2092 png_const_infop info_ptr, png_fixed_point *int_white_x,
2093 png_fixed_point *int_white_y, png_fixed_point *int_red_x,
2094 png_fixed_point *int_red_y, png_fixed_point *int_green_x,
2095 png_fixed_point *int_green_y, png_fixed_point *int_blue_x,
2096 png_fixed_point *int_blue_y));
2097#endif
2098PNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed,
2099 (png_structp png_ptr, png_const_infop info_ptr,
2100 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
2101 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
2102 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
2103 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
2104 png_fixed_point *int_blue_Z));
2105#endif
2106
2107#ifdef PNG_cHRM_SUPPORTED
2108PNG_FP_EXPORT(135, void, png_set_cHRM,
2109 (png_structp png_ptr, png_infop info_ptr,
2110 double white_x, double white_y, double red_x, double red_y, double green_x,
2111 double green_y, double blue_x, double blue_y));
2112PNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_structp png_ptr,
2113 png_infop info_ptr, double red_X, double red_Y, double red_Z,
2114 double green_X, double green_Y, double green_Z, double blue_X,
2115 double blue_Y, double blue_Z));
2116PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_structp png_ptr,
2117 png_infop info_ptr, png_fixed_point int_white_x,
2118 png_fixed_point int_white_y, png_fixed_point int_red_x,
2119 png_fixed_point int_red_y, png_fixed_point int_green_x,
2120 png_fixed_point int_green_y, png_fixed_point int_blue_x,
2121 png_fixed_point int_blue_y));
2122PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_structp png_ptr,
2123 png_infop info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y,
2124 png_fixed_point int_red_Z, png_fixed_point int_green_X,
2125 png_fixed_point int_green_Y, png_fixed_point int_green_Z,
2126 png_fixed_point int_blue_X, png_fixed_point int_blue_Y,
2127 png_fixed_point int_blue_Z));
2128#endif
2129
2130#ifdef PNG_gAMA_SUPPORTED
2131PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA,
2132 (png_const_structp png_ptr, png_const_infop info_ptr,
2133 double *file_gamma));
2134PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed,
2135 (png_const_structp png_ptr, png_const_infop info_ptr,
2136 png_fixed_point *int_file_gamma));
2137#endif
2138
2139#ifdef PNG_gAMA_SUPPORTED
2140PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr,
2141 png_infop info_ptr, double file_gamma));
2142PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr,
2143 png_infop info_ptr, png_fixed_point int_file_gamma));
2144#endif
2145
2146#ifdef PNG_hIST_SUPPORTED
2147PNG_EXPORT(141, png_uint_32, png_get_hIST,
2148 (png_const_structp png_ptr, png_const_infop info_ptr,
2149 png_uint_16p *hist));
2150#endif
2151
2152#ifdef PNG_hIST_SUPPORTED
2153PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr,
2154 png_infop info_ptr, png_const_uint_16p hist));
2155#endif
2156
2157PNG_EXPORT(143, png_uint_32, png_get_IHDR,
2158 (png_structp png_ptr, png_infop info_ptr,
2159 png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type,
2160 int *interlace_method, int *compression_method, int *filter_method));
2161
2162PNG_EXPORT(144, void, png_set_IHDR,
2163 (png_structp png_ptr, png_infop info_ptr,
2164 png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,
2165 int interlace_method, int compression_method, int filter_method));
2166
2167#ifdef PNG_oFFs_SUPPORTED
2168PNG_EXPORT(145, png_uint_32, png_get_oFFs,
2169 (png_const_structp png_ptr, png_const_infop info_ptr,
2170 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type));
2171#endif
2172
2173#ifdef PNG_oFFs_SUPPORTED
2174PNG_EXPORT(146, void, png_set_oFFs,
2175 (png_structp png_ptr, png_infop info_ptr,
2176 png_int_32 offset_x, png_int_32 offset_y, int unit_type));
2177#endif
2178
2179#ifdef PNG_pCAL_SUPPORTED
2180PNG_EXPORT(147, png_uint_32, png_get_pCAL,
2181 (png_const_structp png_ptr, png_const_infop info_ptr,
2182 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type,
2183 int *nparams,
2184 png_charp *units, png_charpp *params));
2185#endif
2186
2187#ifdef PNG_pCAL_SUPPORTED
2188PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr,
2189 png_infop info_ptr,
2190 png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
2191 int nparams, png_const_charp units, png_charpp params));
2192#endif
2193
2194#ifdef PNG_pHYs_SUPPORTED
2195PNG_EXPORT(149, png_uint_32, png_get_pHYs,
2196 (png_const_structp png_ptr, png_const_infop info_ptr,
2197 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
2198#endif
2199
2200#ifdef PNG_pHYs_SUPPORTED
2201PNG_EXPORT(150, void, png_set_pHYs,
2202 (png_structp png_ptr, png_infop info_ptr,
2203 png_uint_32 res_x, png_uint_32 res_y, int unit_type));
2204#endif
2205
2206PNG_EXPORT(151, png_uint_32, png_get_PLTE,
2207 (png_const_structp png_ptr, png_const_infop info_ptr,
2208 png_colorp *palette, int *num_palette));
2209
2210PNG_EXPORT(152, void, png_set_PLTE,
2211 (png_structp png_ptr, png_infop info_ptr,
2212 png_const_colorp palette, int num_palette));
2213
2214#ifdef PNG_sBIT_SUPPORTED
2215PNG_EXPORT(153, png_uint_32, png_get_sBIT,
2216 (png_const_structp png_ptr, png_infop info_ptr,
2217 png_color_8p *sig_bit));
2218#endif
2219
2220#ifdef PNG_sBIT_SUPPORTED
2221PNG_EXPORT(154, void, png_set_sBIT,
2222 (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit));
2223#endif
2224
2225#ifdef PNG_sRGB_SUPPORTED
2226PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr,
2227 png_const_infop info_ptr, int *file_srgb_intent));
2228#endif
2229
2230#ifdef PNG_sRGB_SUPPORTED
2231PNG_EXPORT(156, void, png_set_sRGB,
2232 (png_structp png_ptr, png_infop info_ptr, int srgb_intent));
2233PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr,
2234 png_infop info_ptr, int srgb_intent));
2235#endif
2236
2237#ifdef PNG_iCCP_SUPPORTED
2238PNG_EXPORT(158, png_uint_32, png_get_iCCP,
2239 (png_const_structp png_ptr, png_const_infop info_ptr,
2240 png_charpp name, int *compression_type, png_bytepp profile,
2241 png_uint_32 *proflen));
2242#endif
2243
2244#ifdef PNG_iCCP_SUPPORTED
2245PNG_EXPORT(159, void, png_set_iCCP,
2246 (png_structp png_ptr, png_infop info_ptr,
2247 png_const_charp name, int compression_type, png_const_bytep profile,
2248 png_uint_32 proflen));
2249#endif
2250
2251#ifdef PNG_sPLT_SUPPORTED
2252PNG_EXPORT(160, png_uint_32, png_get_sPLT,
2253 (png_const_structp png_ptr, png_const_infop info_ptr,
2254 png_sPLT_tpp entries));
2255#endif
2256
2257#ifdef PNG_sPLT_SUPPORTED
2258PNG_EXPORT(161, void, png_set_sPLT,
2259 (png_structp png_ptr, png_infop info_ptr,
2260 png_const_sPLT_tp entries, int nentries));
2261#endif
2262
2263#ifdef PNG_TEXT_SUPPORTED
2264/* png_get_text also returns the number of text chunks in *num_text */
2265PNG_EXPORT(162, png_uint_32, png_get_text,
2266 (png_const_structp png_ptr, png_const_infop info_ptr,
2267 png_textp *text_ptr, int *num_text));
2268#endif
2269
2270/* Note while png_set_text() will accept a structure whose text,
2271 * language, and translated keywords are NULL pointers, the structure
2272 * returned by png_get_text will always contain regular
2273 * zero-terminated C strings. They might be empty strings but
2274 * they will never be NULL pointers.
2275 */
2276
2277#ifdef PNG_TEXT_SUPPORTED
2278PNG_EXPORT(163, void, png_set_text,
2279 (png_structp png_ptr, png_infop info_ptr,
2280 png_const_textp text_ptr, int num_text));
2281#endif
2282
2283#ifdef PNG_tIME_SUPPORTED
2284PNG_EXPORT(164, png_uint_32, png_get_tIME,
2285 (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time));
2286#endif
2287
2288#ifdef PNG_tIME_SUPPORTED
2289PNG_EXPORT(165, void, png_set_tIME,
2290 (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time));
2291#endif
2292
2293#ifdef PNG_tRNS_SUPPORTED
2294PNG_EXPORT(166, png_uint_32, png_get_tRNS,
2295 (png_const_structp png_ptr, png_infop info_ptr,
2296 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color));
2297#endif
2298
2299#ifdef PNG_tRNS_SUPPORTED
2300PNG_EXPORT(167, void, png_set_tRNS,
2301 (png_structp png_ptr, png_infop info_ptr,
2302 png_const_bytep trans_alpha, int num_trans,
2303 png_const_color_16p trans_color));
2304#endif
2305
2306#ifdef PNG_sCAL_SUPPORTED
2307PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL,
2308 (png_const_structp png_ptr, png_const_infop info_ptr,
2309 int *unit, double *width, double *height));
2310#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
2311/* NOTE: this API is currently implemented using floating point arithmetic,
2312 * consequently it can only be used on systems with floating point support.
2313 * In any case the range of values supported by png_fixed_point is small and it
2314 * is highly recommended that png_get_sCAL_s be used instead.
2315 */
2316PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,
2317 (png_structp png_ptr, png_const_infop info_ptr, int *unit,
2318 png_fixed_point *width,
2319 png_fixed_point *height));
2320#endif
2321PNG_EXPORT(169, png_uint_32, png_get_sCAL_s,
2322 (png_const_structp png_ptr, png_const_infop info_ptr,
2323 int *unit, png_charpp swidth, png_charpp sheight));
2324
2325PNG_FP_EXPORT(170, void, png_set_sCAL,
2326 (png_structp png_ptr, png_infop info_ptr,
2327 int unit, double width, double height));
2328PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr,
2329 png_infop info_ptr, int unit, png_fixed_point width,
2330 png_fixed_point height));
2331PNG_EXPORT(171, void, png_set_sCAL_s,
2332 (png_structp png_ptr, png_infop info_ptr,
2333 int unit, png_const_charp swidth, png_const_charp sheight));
2334#endif /* PNG_sCAL_SUPPORTED */
2335
2336#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2337/* Provide a list of chunks and how they are to be handled, if the built-in
2338 handling or default unknown chunk handling is not desired. Any chunks not
2339 listed will be handled in the default manner. The IHDR and IEND chunks
2340 must not be listed. Because this turns off the default handling for chunks
2341 that would otherwise be recognized the behavior of libpng transformations may
2342 well become incorrect!
2343 keep = 0: PNG_HANDLE_CHUNK_AS_DEFAULT: follow default behavior
2344 = 1: PNG_HANDLE_CHUNK_NEVER: do not keep
2345 = 2: PNG_HANDLE_CHUNK_IF_SAFE: keep only if safe-to-copy
2346 = 3: PNG_HANDLE_CHUNK_ALWAYS: keep even if unsafe-to-copy
2347*/
2348PNG_EXPORT(172, void, png_set_keep_unknown_chunks,
2349 (png_structp png_ptr, int keep,
2350 png_const_bytep chunk_list, int num_chunks));
2351
2352/* The handling code is returned; the result is therefore true (non-zero) if
2353 * special handling is required, false for the default handling.
2354 */
2355PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr,
2356 png_const_bytep chunk_name));
2357#endif
2358#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
2359PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr,
2360 png_infop info_ptr, png_const_unknown_chunkp unknowns,
2361 int num_unknowns));
2362PNG_EXPORT(175, void, png_set_unknown_chunk_location,
2363 (png_structp png_ptr, png_infop info_ptr, int chunk, int location));
2364PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr,
2365 png_const_infop info_ptr, png_unknown_chunkpp entries));
2366#endif
2367
2368/* Png_free_data() will turn off the "valid" flag for anything it frees.
2369 * If you need to turn it off for a chunk that your application has freed,
2370 * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK);
2371 */
2372PNG_EXPORT(177, void, png_set_invalid,
2373 (png_structp png_ptr, png_infop info_ptr, int mask));
2374
2375#ifdef PNG_INFO_IMAGE_SUPPORTED
2376/* The "params" pointer is currently not used and is for future expansion. */
2377PNG_EXPORT(178, void, png_read_png, (png_structp png_ptr, png_infop info_ptr,
2378 int transforms, png_voidp params));
2379PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr,
2380 int transforms, png_voidp params));
2381#endif
2382
2383PNG_EXPORT(180, png_const_charp, png_get_copyright,
2384 (png_const_structp png_ptr));
2385PNG_EXPORT(181, png_const_charp, png_get_header_ver,
2386 (png_const_structp png_ptr));
2387PNG_EXPORT(182, png_const_charp, png_get_header_version,
2388 (png_const_structp png_ptr));
2389PNG_EXPORT(183, png_const_charp, png_get_libpng_ver,
2390 (png_const_structp png_ptr));
2391
2392#ifdef PNG_MNG_FEATURES_SUPPORTED
2393PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr,
2394 png_uint_32 mng_features_permitted));
2395#endif
2396
2397/* For use in png_set_keep_unknown, added to version 1.2.6 */
2398#define PNG_HANDLE_CHUNK_AS_DEFAULT 0
2399#define PNG_HANDLE_CHUNK_NEVER 1
2400#define PNG_HANDLE_CHUNK_IF_SAFE 2
2401#define PNG_HANDLE_CHUNK_ALWAYS 3
2402
2403/* Strip the prepended error numbers ("#nnn ") from error and warning
2404 * messages before passing them to the error or warning handler.
2405 */
2406#ifdef PNG_ERROR_NUMBERS_SUPPORTED
2407PNG_EXPORT(185, void, png_set_strip_error_numbers,
2408 (png_structp png_ptr,
2409 png_uint_32 strip_mode));
2410#endif
2411
2412/* Added in libpng-1.2.6 */
2413#ifdef PNG_SET_USER_LIMITS_SUPPORTED
2414PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr,
2415 png_uint_32 user_width_max, png_uint_32 user_height_max));
2416PNG_EXPORT(187, png_uint_32, png_get_user_width_max,
2417 (png_const_structp png_ptr));
2418PNG_EXPORT(188, png_uint_32, png_get_user_height_max,
2419 (png_const_structp png_ptr));
2420/* Added in libpng-1.4.0 */
2421PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr,
2422 png_uint_32 user_chunk_cache_max));
2423PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max,
2424 (png_const_structp png_ptr));
2425/* Added in libpng-1.4.1 */
2426PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr,
2427 png_alloc_size_t user_chunk_cache_max));
2428PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max,
2429 (png_const_structp png_ptr));
2430#endif
2431
2432#if defined(PNG_INCH_CONVERSIONS_SUPPORTED)
2433PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch,
2434 (png_const_structp png_ptr, png_const_infop info_ptr));
2435
2436PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch,
2437 (png_const_structp png_ptr, png_const_infop info_ptr));
2438
2439PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch,
2440 (png_const_structp png_ptr, png_const_infop info_ptr));
2441
2442PNG_FP_EXPORT(196, float, png_get_x_offset_inches,
2443 (png_const_structp png_ptr, png_const_infop info_ptr));
2444#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
2445PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed,
2446 (png_structp png_ptr, png_const_infop info_ptr));
2447#endif
2448
2449PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr,
2450 png_const_infop info_ptr));
2451#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
2452PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed,
2453 (png_structp png_ptr, png_const_infop info_ptr));
2454#endif
2455
2456# ifdef PNG_pHYs_SUPPORTED
2457PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr,
2458 png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,
2459 int *unit_type));
2460# endif /* PNG_pHYs_SUPPORTED */
2461#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
2462
2463/* Added in libpng-1.4.0 */
2464#ifdef PNG_IO_STATE_SUPPORTED
2465PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr));
2466
2467PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name,
2468 (png_structp png_ptr), PNG_DEPRECATED);
2469PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
2470 (png_const_structp png_ptr));
2471
2472/* The flags returned by png_get_io_state() are the following: */
2473# define PNG_IO_NONE 0x0000 /* no I/O at this moment */
2474# define PNG_IO_READING 0x0001 /* currently reading */
2475# define PNG_IO_WRITING 0x0002 /* currently writing */
2476# define PNG_IO_SIGNATURE 0x0010 /* currently at the file signature */
2477# define PNG_IO_CHUNK_HDR 0x0020 /* currently at the chunk header */
2478# define PNG_IO_CHUNK_DATA 0x0040 /* currently at the chunk data */
2479# define PNG_IO_CHUNK_CRC 0x0080 /* currently at the chunk crc */
2480# define PNG_IO_MASK_OP 0x000f /* current operation: reading/writing */
2481# define PNG_IO_MASK_LOC 0x00f0 /* current location: sig/hdr/data/crc */
2482#endif /* ?PNG_IO_STATE_SUPPORTED */
2483
2484/* Interlace support. The following macros are always defined so that if
2485 * libpng interlace handling is turned off the macros may be used to handle
2486 * interlaced images within the application.
2487 */
2488#define PNG_INTERLACE_ADAM7_PASSES 7
2489
2490/* Two macros to return the first row and first column of the original,
2491 * full, image which appears in a given pass. 'pass' is in the range 0
2492 * to 6 and the result is in the range 0 to 7.
2493 */
2494#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7)
2495#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7)
2496
2497/* A macro to return the offset between pixels in the output row for a pair of
2498 * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that
2499 * follows. Note that ROW_OFFSET is the offset from one row to the next whereas
2500 * COL_OFFSET is from one column to the next, within a row.
2501 */
2502#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)
2503#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))
2504
2505/* Two macros to help evaluate the number of rows or columns in each
2506 * pass. This is expressed as a shift - effectively log2 of the number or
2507 * rows or columns in each 8x8 tile of the original image.
2508 */
2509#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
2510#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
2511
2512/* Hence two macros to determine the number of rows or columns in a given
2513 * pass of an image given its height or width. In fact these macros may
2514 * return non-zero even though the sub-image is empty, because the other
2515 * dimension may be empty for a small image.
2516 */
2517#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
2518 -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
2519#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
2520 -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
2521
2522/* For the reader row callbacks (both progressive and sequential) it is
2523 * necessary to find the row in the output image given a row in an interlaced
2524 * image, so two more macros:
2525 */
2526#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
2527 (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
2528#define PNG_COL_FROM_PASS_COL(xIn, pass) \
2529 (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
2530
2531/* Two macros which return a boolean (0 or 1) saying whether the given row
2532 * or column is in a particular pass. These use a common utility macro that
2533 * returns a mask for a given pass - the offset 'off' selects the row or
2534 * column version. The mask has the appropriate bit set for each column in
2535 * the tile.
2536 */
2537#define PNG_PASS_MASK(pass,off) ( \
2538 ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \
2539 ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))
2540
2541#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
2542 ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
2543#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
2544 ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
2545
2546#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
2547/* With these routines we avoid an integer divide, which will be slower on
2548 * most machines. However, it does take more operations than the corresponding
2549 * divide method, so it may be slower on a few RISC systems. There are two
2550 * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
2551 *
2552 * Note that the rounding factors are NOT supposed to be the same! 128 and
2553 * 32768 are correct for the NODIV code; 127 and 32767 are correct for the
2554 * standard method.
2555 *
2556 * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
2557 */
2558
2559 /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
2560
2561# define png_composite(composite, fg, alpha, bg) \
2562 { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
2563 * (png_uint_16)(alpha) \
2564 + (png_uint_16)(bg)*(png_uint_16)(255 \
2565 - (png_uint_16)(alpha)) + 128); \
2566 (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
2567
2568# define png_composite_16(composite, fg, alpha, bg) \
2569 { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \
2570 * (png_uint_32)(alpha) \
2571 + (png_uint_32)(bg)*(65535 \
2572 - (png_uint_32)(alpha)) + 32768); \
2573 (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
2574
2575#else /* Standard method using integer division */
2576
2577# define png_composite(composite, fg, alpha, bg) \
2578 (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
2579 (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
2580 127) / 255)
2581
2582# define png_composite_16(composite, fg, alpha, bg) \
2583 (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
2584 (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) + \
2585 32767) / 65535)
2586#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
2587
2588#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
2589PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf));
2590PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf));
2591PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf));
2592#endif
2593
2594PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr,
2595 png_const_bytep buf));
2596/* No png_get_int_16 -- may be added if there's a real need for it. */
2597
2598/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */
2599#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
2600PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i));
2601#endif
2602#ifdef PNG_SAVE_INT_32_SUPPORTED
2603PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i));
2604#endif
2605
2606/* Place a 16-bit number into a buffer in PNG byte order.
2607 * The parameter is declared unsigned int, not png_uint_16,
2608 * just to avoid potential problems on pre-ANSI C compilers.
2609 */
2610#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
2611PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
2612/* No png_save_int_16 -- may be added if there's a real need for it. */
2613#endif
2614
2615#ifdef PNG_USE_READ_MACROS
2616/* Inline macros to do direct reads of bytes from the input buffer.
2617 * The png_get_int_32() routine assumes we are using two's complement
2618 * format for negative values, which is almost certainly true.
2619 */
2620# define png_get_uint_32(buf) \
2621 (((png_uint_32)(*(buf)) << 24) + \
2622 ((png_uint_32)(*((buf) + 1)) << 16) + \
2623 ((png_uint_32)(*((buf) + 2)) << 8) + \
2624 ((png_uint_32)(*((buf) + 3))))
2625
2626 /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
2627 * function) incorrectly returned a value of type png_uint_32.
2628 */
2629# define png_get_uint_16(buf) \
2630 ((png_uint_16) \
2631 (((unsigned int)(*(buf)) << 8) + \
2632 ((unsigned int)(*((buf) + 1)))))
2633
2634# define png_get_int_32(buf) \
2635 ((png_int_32)((*(buf) & 0x80) \
2636 ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
2637 : (png_int_32)png_get_uint_32(buf)))
2638#endif
2639
2640/* Maintainer: Put new public prototypes here ^, in libpng.3, and project
2641 * defs
2642 */
2643
2644/* The last ordinal number (this is the *last* one already used; the next
2645 * one to use is one more than this.) Maintainer, remember to add an entry to
2646 * scripts/symbols.def as well.
2647 */
2648#ifdef PNG_EXPORT_LAST_ORDINAL
2649 PNG_EXPORT_LAST_ORDINAL(233);
2650#endif
2651
2652#ifdef __cplusplus
2653}
2654#endif
2655
2656#endif /* PNG_VERSION_INFO_ONLY */
2657/* Do not put anything past this line */
2658#endif /* PNG_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.jpg b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.jpg
new file mode 100644
index 0000000..70ba8d8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.jpg
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.png
new file mode 100644
index 0000000..49798c8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngbar.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngconf.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngconf.h
new file mode 100644
index 0000000..3fea47b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngconf.h
@@ -0,0 +1,596 @@
1
2/* pngconf.h - machine configurable file for libpng
3 *
4 * libpng version 1.5.9 - February 18, 2012
5 *
6 * Copyright (c) 1998-2012 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 *
10 * This code is released under the libpng license.
11 * For conditions of distribution and use, see the disclaimer
12 * and license in png.h
13 *
14 */
15
16/* Any machine specific code is near the front of this file, so if you
17 * are configuring libpng for a machine, you may want to read the section
18 * starting here down to where it starts to typedef png_color, png_text,
19 * and png_info.
20 */
21
22#ifndef PNGCONF_H
23#define PNGCONF_H
24
25#ifndef PNG_BUILDING_SYMBOL_TABLE
26/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C
27 * definition file for machine specific limits, this may impact the
28 * correctness of the definitons below (see uses of INT_MAX).
29 */
30# ifndef PNG_NO_LIMITS_H
31# include <limits.h>
32# endif
33
34/* For the memory copy APIs (i.e. the standard definitions of these),
35 * because this file defines png_memcpy and so on the base APIs must
36 * be defined here.
37 */
38# ifdef BSD
39# include <strings.h>
40# else
41# include <string.h>
42# endif
43
44/* For png_FILE_p - this provides the standard definition of a
45 * FILE
46 */
47# ifdef PNG_STDIO_SUPPORTED
48# include <stdio.h>
49# endif
50#endif
51
52/* This controls optimization of the reading of 16 and 32 bit values
53 * from PNG files. It can be set on a per-app-file basis - it
54 * just changes whether a macro is used to the function is called.
55 * The library builder sets the default, if read functions are not
56 * built into the library the macro implementation is forced on.
57 */
58#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED
59# define PNG_USE_READ_MACROS
60#endif
61#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS)
62# if PNG_DEFAULT_READ_MACROS
63# define PNG_USE_READ_MACROS
64# endif
65#endif
66
67/* COMPILER SPECIFIC OPTIONS.
68 *
69 * These options are provided so that a variety of difficult compilers
70 * can be used. Some are fixed at build time (e.g. PNG_API_RULE
71 * below) but still have compiler specific implementations, others
72 * may be changed on a per-file basis when compiling against libpng.
73 */
74
75/* The PNGARG macro protects us against machines that don't have function
76 * prototypes (ie K&R style headers). If your compiler does not handle
77 * function prototypes, define this macro and use the included ansi2knr.
78 * I've always been able to use _NO_PROTO as the indicator, but you may
79 * need to drag the empty declaration out in front of here, or change the
80 * ifdef to suit your own needs.
81 */
82#ifndef PNGARG
83
84# ifdef OF /* zlib prototype munger */
85# define PNGARG(arglist) OF(arglist)
86# else
87
88# ifdef _NO_PROTO
89# define PNGARG(arglist) ()
90# else
91# define PNGARG(arglist) arglist
92# endif /* _NO_PROTO */
93
94# endif /* OF */
95
96#endif /* PNGARG */
97
98/* Function calling conventions.
99 * =============================
100 * Normally it is not necessary to specify to the compiler how to call
101 * a function - it just does it - however on x86 systems derived from
102 * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems
103 * and some others) there are multiple ways to call a function and the
104 * default can be changed on the compiler command line. For this reason
105 * libpng specifies the calling convention of every exported function and
106 * every function called via a user supplied function pointer. This is
107 * done in this file by defining the following macros:
108 *
109 * PNGAPI Calling convention for exported functions.
110 * PNGCBAPI Calling convention for user provided (callback) functions.
111 * PNGCAPI Calling convention used by the ANSI-C library (required
112 * for longjmp callbacks and sometimes used internally to
113 * specify the calling convention for zlib).
114 *
115 * These macros should never be overridden. If it is necessary to
116 * change calling convention in a private build this can be done
117 * by setting PNG_API_RULE (which defaults to 0) to one of the values
118 * below to select the correct 'API' variants.
119 *
120 * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout.
121 * This is correct in every known environment.
122 * PNG_API_RULE=1 Use the operating system convention for PNGAPI and
123 * the 'C' calling convention (from PNGCAPI) for
124 * callbacks (PNGCBAPI). This is no longer required
125 * in any known environment - if it has to be used
126 * please post an explanation of the problem to the
127 * libpng mailing list.
128 *
129 * These cases only differ if the operating system does not use the C
130 * calling convention, at present this just means the above cases
131 * (x86 DOS/Windows sytems) and, even then, this does not apply to
132 * Cygwin running on those systems.
133 *
134 * Note that the value must be defined in pnglibconf.h so that what
135 * the application uses to call the library matches the conventions
136 * set when building the library.
137 */
138
139/* Symbol export
140 * =============
141 * When building a shared library it is almost always necessary to tell
142 * the compiler which symbols to export. The png.h macro 'PNG_EXPORT'
143 * is used to mark the symbols. On some systems these symbols can be
144 * extracted at link time and need no special processing by the compiler,
145 * on other systems the symbols are flagged by the compiler and just
146 * the declaration requires a special tag applied (unfortunately) in a
147 * compiler dependent way. Some systems can do either.
148 *
149 * A small number of older systems also require a symbol from a DLL to
150 * be flagged to the program that calls it. This is a problem because
151 * we do not know in the header file included by application code that
152 * the symbol will come from a shared library, as opposed to a statically
153 * linked one. For this reason the application must tell us by setting
154 * the magic flag PNG_USE_DLL to turn on the special processing before
155 * it includes png.h.
156 *
157 * Four additional macros are used to make this happen:
158 *
159 * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from
160 * the build or imported if PNG_USE_DLL is set - compiler
161 * and system specific.
162 *
163 * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to
164 * 'type', compiler specific.
165 *
166 * PNG_DLL_EXPORT Set to the magic to use during a libpng build to
167 * make a symbol exported from the DLL. Not used in the
168 * public header files; see pngpriv.h for how it is used
169 * in the libpng build.
170 *
171 * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come
172 * from a DLL - used to define PNG_IMPEXP when
173 * PNG_USE_DLL is set.
174 */
175
176/* System specific discovery.
177 * ==========================
178 * This code is used at build time to find PNG_IMPEXP, the API settings
179 * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
180 * import processing is possible. On Windows/x86 systems it also sets
181 * compiler-specific macros to the values required to change the calling
182 * conventions of the various functions.
183 */
184#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
185 defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\
186 ( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\
187 defined(_M_X64) || defined(_M_IA64) )
188 /* Windows system (DOS doesn't support DLLs) running on x86/x64. Includes
189 * builds under Cygwin or MinGW. Also includes Watcom builds but these need
190 * special treatment because they are not compatible with GCC or Visual C
191 * because of different calling conventions.
192 */
193# if PNG_API_RULE == 2
194 /* If this line results in an error, either because __watcall is not
195 * understood or because of a redefine just below you cannot use *this*
196 * build of the library with the compiler you are using. *This* build was
197 * build using Watcom and applications must also be built using Watcom!
198 */
199# define PNGCAPI __watcall
200# endif
201
202# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
203# define PNGCAPI __cdecl
204# if PNG_API_RULE == 1
205# define PNGAPI __stdcall
206# endif
207# else
208 /* An older compiler, or one not detected (erroneously) above,
209 * if necessary override on the command line to get the correct
210 * variants for the compiler.
211 */
212# ifndef PNGCAPI
213# define PNGCAPI _cdecl
214# endif
215# if PNG_API_RULE == 1 && !defined(PNGAPI)
216# define PNGAPI _stdcall
217# endif
218# endif /* compiler/api */
219 /* NOTE: PNGCBAPI always defaults to PNGCAPI. */
220
221# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
222 ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed
223# endif
224
225# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
226 (defined(__BORLANDC__) && __BORLANDC__ < 0x500)
227 /* older Borland and MSC
228 * compilers used '__export' and required this to be after
229 * the type.
230 */
231# ifndef PNG_EXPORT_TYPE
232# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
233# endif
234# define PNG_DLL_EXPORT __export
235# else /* newer compiler */
236# define PNG_DLL_EXPORT __declspec(dllexport)
237# ifndef PNG_DLL_IMPORT
238# define PNG_DLL_IMPORT __declspec(dllimport)
239# endif
240# endif /* compiler */
241
242#else /* !Windows/x86 */
243# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
244# define PNGAPI _System
245# else /* !Windows/x86 && !OS/2 */
246 /* Use the defaults, or define PNG*API on the command line (but
247 * this will have to be done for every compile!)
248 */
249# endif /* other system, !OS/2 */
250#endif /* !Windows/x86 */
251
252/* Now do all the defaulting . */
253#ifndef PNGCAPI
254# define PNGCAPI
255#endif
256#ifndef PNGCBAPI
257# define PNGCBAPI PNGCAPI
258#endif
259#ifndef PNGAPI
260# define PNGAPI PNGCAPI
261#endif
262
263/* PNG_IMPEXP may be set on the compilation system command line or (if not set)
264 * then in an internal header file when building the library, otherwise (when
265 * using the library) it is set here.
266 */
267#ifndef PNG_IMPEXP
268# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
269 /* This forces use of a DLL, disallowing static linking */
270# define PNG_IMPEXP PNG_DLL_IMPORT
271# endif
272
273# ifndef PNG_IMPEXP
274# define PNG_IMPEXP
275# endif
276#endif
277
278/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
279 * 'attributes' as a storage class - the attributes go at the start of the
280 * function definition, and attributes are always appended regardless of the
281 * compiler. This considerably simplifies these macros but may cause problems
282 * if any compilers both need function attributes and fail to handle them as
283 * a storage class (this is unlikely.)
284 */
285#ifndef PNG_FUNCTION
286# define PNG_FUNCTION(type, name, args, attributes) attributes type name args
287#endif
288
289#ifndef PNG_EXPORT_TYPE
290# define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
291#endif
292
293 /* The ordinal value is only relevant when preprocessing png.h for symbol
294 * table entries, so we discard it here. See the .dfn files in the
295 * scripts directory.
296 */
297#ifndef PNG_EXPORTA
298
299# define PNG_EXPORTA(ordinal, type, name, args, attributes)\
300 PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
301 extern attributes)
302#endif
303
304/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
305 * so make something non-empty to satisfy the requirement:
306 */
307#define PNG_EMPTY /*empty list*/
308
309#define PNG_EXPORT(ordinal, type, name, args)\
310 PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
311
312/* Use PNG_REMOVED to comment out a removed interface. */
313#ifndef PNG_REMOVED
314# define PNG_REMOVED(ordinal, type, name, args, attributes)
315#endif
316
317#ifndef PNG_CALLBACK
318# define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args)
319#endif
320
321/* Support for compiler specific function attributes. These are used
322 * so that where compiler support is available incorrect use of API
323 * functions in png.h will generate compiler warnings.
324 *
325 * Added at libpng-1.2.41.
326 */
327
328#ifndef PNG_NO_PEDANTIC_WARNINGS
329# ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED
330# define PNG_PEDANTIC_WARNINGS_SUPPORTED
331# endif
332#endif
333
334#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED
335 /* Support for compiler specific function attributes. These are used
336 * so that where compiler support is available incorrect use of API
337 * functions in png.h will generate compiler warnings. Added at libpng
338 * version 1.2.41.
339 */
340# if defined(__GNUC__)
341# ifndef PNG_USE_RESULT
342# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
343# endif
344# ifndef PNG_NORETURN
345# define PNG_NORETURN __attribute__((__noreturn__))
346# endif
347# ifndef PNG_ALLOCATED
348# define PNG_ALLOCATED __attribute__((__malloc__))
349# endif
350# ifndef PNG_DEPRECATED
351# define PNG_DEPRECATED __attribute__((__deprecated__))
352# endif
353# ifndef PNG_PRIVATE
354# if 0 /* Doesn't work so we use deprecated instead*/
355# define PNG_PRIVATE \
356 __attribute__((warning("This function is not exported by libpng.")))
357# else
358# define PNG_PRIVATE \
359 __attribute__((__deprecated__))
360# endif
361# endif
362# endif /* __GNUC__ */
363
364# if defined(_MSC_VER) && (_MSC_VER >= 1300)
365# ifndef PNG_USE_RESULT
366# define PNG_USE_RESULT /* not supported */
367# endif
368# ifndef PNG_NORETURN
369# define PNG_NORETURN __declspec(noreturn)
370# endif
371# ifndef PNG_ALLOCATED
372# if (_MSC_VER >= 1400)
373# define PNG_ALLOCATED __declspec(restrict)
374# endif
375# endif
376# ifndef PNG_DEPRECATED
377# define PNG_DEPRECATED __declspec(deprecated)
378# endif
379# ifndef PNG_PRIVATE
380# define PNG_PRIVATE __declspec(deprecated)
381# endif
382# endif /* _MSC_VER */
383#endif /* PNG_PEDANTIC_WARNINGS */
384
385#ifndef PNG_DEPRECATED
386# define PNG_DEPRECATED /* Use of this function is deprecated */
387#endif
388#ifndef PNG_USE_RESULT
389# define PNG_USE_RESULT /* The result of this function must be checked */
390#endif
391#ifndef PNG_NORETURN
392# define PNG_NORETURN /* This function does not return */
393#endif
394#ifndef PNG_ALLOCATED
395# define PNG_ALLOCATED /* The result of the function is new memory */
396#endif
397#ifndef PNG_PRIVATE
398# define PNG_PRIVATE /* This is a private libpng function */
399#endif
400#ifndef PNG_FP_EXPORT /* A floating point API. */
401# ifdef PNG_FLOATING_POINT_SUPPORTED
402# define PNG_FP_EXPORT(ordinal, type, name, args)\
403 PNG_EXPORT(ordinal, type, name, args)
404# else /* No floating point APIs */
405# define PNG_FP_EXPORT(ordinal, type, name, args)
406# endif
407#endif
408#ifndef PNG_FIXED_EXPORT /* A fixed point API. */
409# ifdef PNG_FIXED_POINT_SUPPORTED
410# define PNG_FIXED_EXPORT(ordinal, type, name, args)\
411 PNG_EXPORT(ordinal, type, name, args)
412# else /* No fixed point APIs */
413# define PNG_FIXED_EXPORT(ordinal, type, name, args)
414# endif
415#endif
416
417/* The following uses const char * instead of char * for error
418 * and warning message functions, so some compilers won't complain.
419 * If you do not want to use const, define PNG_NO_CONST here.
420 *
421 * This should not change how the APIs are called, so it can be done
422 * on a per-file basis in the application.
423 */
424#ifndef PNG_CONST
425# ifndef PNG_NO_CONST
426# define PNG_CONST const
427# else
428# define PNG_CONST
429# endif
430#endif
431
432/* Some typedefs to get us started. These should be safe on most of the
433 * common platforms. The typedefs should be at least as large as the
434 * numbers suggest (a png_uint_32 must be at least 32 bits long), but they
435 * don't have to be exactly that size. Some compilers dislike passing
436 * unsigned shorts as function parameters, so you may be better off using
437 * unsigned int for png_uint_16.
438 */
439
440#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL)
441typedef unsigned int png_uint_32;
442typedef int png_int_32;
443#else
444typedef unsigned long png_uint_32;
445typedef long png_int_32;
446#endif
447typedef unsigned short png_uint_16;
448typedef short png_int_16;
449typedef unsigned char png_byte;
450
451#ifdef PNG_NO_SIZE_T
452typedef unsigned int png_size_t;
453#else
454typedef size_t png_size_t;
455#endif
456#define png_sizeof(x) (sizeof (x))
457
458/* The following is needed for medium model support. It cannot be in the
459 * pngpriv.h header. Needs modification for other compilers besides
460 * MSC. Model independent support declares all arrays and pointers to be
461 * large using the far keyword. The zlib version used must also support
462 * model independent data. As of version zlib 1.0.4, the necessary changes
463 * have been made in zlib. The USE_FAR_KEYWORD define triggers other
464 * changes that are needed. (Tim Wegner)
465 */
466
467/* Separate compiler dependencies (problem here is that zlib.h always
468 * defines FAR. (SJT)
469 */
470#ifdef __BORLANDC__
471# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
472# define LDATA 1
473# else
474# define LDATA 0
475# endif
476 /* GRR: why is Cygwin in here? Cygwin is not Borland C... */
477# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
478# define PNG_MAX_MALLOC_64K /* only used in build */
479# if (LDATA != 1)
480# ifndef FAR
481# define FAR __far
482# endif
483# define USE_FAR_KEYWORD
484# endif /* LDATA != 1 */
485 /* Possibly useful for moving data out of default segment.
486 * Uncomment it if you want. Could also define FARDATA as
487 * const if your compiler supports it. (SJT)
488# define FARDATA FAR
489 */
490# endif /* __WIN32__, __FLAT__, __CYGWIN__ */
491#endif /* __BORLANDC__ */
492
493
494/* Suggest testing for specific compiler first before testing for
495 * FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
496 * making reliance oncertain keywords suspect. (SJT)
497 */
498
499/* MSC Medium model */
500#ifdef FAR
501# ifdef M_I86MM
502# define USE_FAR_KEYWORD
503# define FARDATA FAR
504# include <dos.h>
505# endif
506#endif
507
508/* SJT: default case */
509#ifndef FAR
510# define FAR
511#endif
512
513/* At this point FAR is always defined */
514#ifndef FARDATA
515# define FARDATA
516#endif
517
518/* Typedef for floating-point numbers that are converted
519 * to fixed-point with a multiple of 100,000, e.g., gamma
520 */
521typedef png_int_32 png_fixed_point;
522
523/* Add typedefs for pointers */
524typedef void FAR * png_voidp;
525typedef PNG_CONST void FAR * png_const_voidp;
526typedef png_byte FAR * png_bytep;
527typedef PNG_CONST png_byte FAR * png_const_bytep;
528typedef png_uint_32 FAR * png_uint_32p;
529typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p;
530typedef png_int_32 FAR * png_int_32p;
531typedef PNG_CONST png_int_32 FAR * png_const_int_32p;
532typedef png_uint_16 FAR * png_uint_16p;
533typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p;
534typedef png_int_16 FAR * png_int_16p;
535typedef PNG_CONST png_int_16 FAR * png_const_int_16p;
536typedef char FAR * png_charp;
537typedef PNG_CONST char FAR * png_const_charp;
538typedef png_fixed_point FAR * png_fixed_point_p;
539typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p;
540typedef png_size_t FAR * png_size_tp;
541typedef PNG_CONST png_size_t FAR * png_const_size_tp;
542
543#ifdef PNG_STDIO_SUPPORTED
544typedef FILE * png_FILE_p;
545#endif
546
547#ifdef PNG_FLOATING_POINT_SUPPORTED
548typedef double FAR * png_doublep;
549typedef PNG_CONST double FAR * png_const_doublep;
550#endif
551
552/* Pointers to pointers; i.e. arrays */
553typedef png_byte FAR * FAR * png_bytepp;
554typedef png_uint_32 FAR * FAR * png_uint_32pp;
555typedef png_int_32 FAR * FAR * png_int_32pp;
556typedef png_uint_16 FAR * FAR * png_uint_16pp;
557typedef png_int_16 FAR * FAR * png_int_16pp;
558typedef PNG_CONST char FAR * FAR * png_const_charpp;
559typedef char FAR * FAR * png_charpp;
560typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
561#ifdef PNG_FLOATING_POINT_SUPPORTED
562typedef double FAR * FAR * png_doublepp;
563#endif
564
565/* Pointers to pointers to pointers; i.e., pointer to array */
566typedef char FAR * FAR * FAR * png_charppp;
567
568/* png_alloc_size_t is guaranteed to be no smaller than png_size_t,
569 * and no smaller than png_uint_32. Casts from png_size_t or png_uint_32
570 * to png_alloc_size_t are not necessary; in fact, it is recommended
571 * not to use them at all so that the compiler can complain when something
572 * turns out to be problematic.
573 * Casts in the other direction (from png_alloc_size_t to png_size_t or
574 * png_uint_32) should be explicitly applied; however, we do not expect
575 * to encounter practical situations that require such conversions.
576 */
577#if defined(__TURBOC__) && !defined(__FLAT__)
578 typedef unsigned long png_alloc_size_t;
579#else
580# if defined(_MSC_VER) && defined(MAXSEG_64K)
581 typedef unsigned long png_alloc_size_t;
582# else
583 /* This is an attempt to detect an old Windows system where (int) is
584 * actually 16 bits, in that case png_malloc must have an argument with a
585 * bigger size to accomodate the requirements of the library.
586 */
587# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \
588 (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL)
589 typedef DWORD png_alloc_size_t;
590# else
591 typedef png_size_t png_alloc_size_t;
592# endif
593# endif
594#endif
595
596#endif /* PNGCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngdebug.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngdebug.h
new file mode 100644
index 0000000..96c1ea4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngdebug.h
@@ -0,0 +1,157 @@
1
2/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
3 *
4 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7 *
8 * Last changed in libpng 1.5.0 [January 6, 2011]
9 *
10 * This code is released under the libpng license.
11 * For conditions of distribution and use, see the disclaimer
12 * and license in png.h
13 */
14
15/* Define PNG_DEBUG at compile time for debugging information. Higher
16 * numbers for PNG_DEBUG mean more debugging information. This has
17 * only been added since version 0.95 so it is not implemented throughout
18 * libpng yet, but more support will be added as needed.
19 *
20 * png_debug[1-2]?(level, message ,arg{0-2})
21 * Expands to a statement (either a simple expression or a compound
22 * do..while(0) statement) that outputs a message with parameter
23 * substitution if PNG_DEBUG is defined to 2 or more. If PNG_DEBUG
24 * is undefined, 0 or 1 every png_debug expands to a simple expression
25 * (actually ((void)0)).
26 *
27 * level: level of detail of message, starting at 0. A level 'n'
28 * message is preceded by 'n' tab characters (not implemented
29 * on Microsoft compilers unless PNG_DEBUG_FILE is also
30 * defined, to allow debug DLL compilation with no standard IO).
31 * message: a printf(3) style text string. A trailing '\n' is added
32 * to the message.
33 * arg: 0 to 2 arguments for printf(3) style substitution in message.
34 */
35#ifndef PNGDEBUG_H
36#define PNGDEBUG_H
37/* These settings control the formatting of messages in png.c and pngerror.c */
38/* Moved to pngdebug.h at 1.5.0 */
39# ifndef PNG_LITERAL_SHARP
40# define PNG_LITERAL_SHARP 0x23
41# endif
42# ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
43# define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
44# endif
45# ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
46# define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
47# endif
48# ifndef PNG_STRING_NEWLINE
49# define PNG_STRING_NEWLINE "\n"
50# endif
51
52#ifdef PNG_DEBUG
53# if (PNG_DEBUG > 0)
54# if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
55# include <crtdbg.h>
56# if (PNG_DEBUG > 1)
57# ifndef _DEBUG
58# define _DEBUG
59# endif
60# ifndef png_debug
61# define png_debug(l,m) _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE)
62# endif
63# ifndef png_debug1
64# define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1)
65# endif
66# ifndef png_debug2
67# define png_debug2(l,m,p1,p2) \
68 _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2)
69# endif
70# endif
71# else /* PNG_DEBUG_FILE || !_MSC_VER */
72# ifndef PNG_STDIO_SUPPORTED
73# include <stdio.h> /* not included yet */
74# endif
75# ifndef PNG_DEBUG_FILE
76# define PNG_DEBUG_FILE stderr
77# endif /* PNG_DEBUG_FILE */
78
79# if (PNG_DEBUG > 1)
80/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
81 * non-ISO compilers
82 */
83# ifdef __STDC__
84# ifndef png_debug
85# define png_debug(l,m) \
86 do { \
87 int num_tabs=l; \
88 fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
89 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
90 } while (0)
91# endif
92# ifndef png_debug1
93# define png_debug1(l,m,p1) \
94 do { \
95 int num_tabs=l; \
96 fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
97 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
98 } while (0)
99# endif
100# ifndef png_debug2
101# define png_debug2(l,m,p1,p2) \
102 do { \
103 int num_tabs=l; \
104 fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
105 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
106 } while (0)
107# endif
108# else /* __STDC __ */
109# ifndef png_debug
110# define png_debug(l,m) \
111 do { \
112 int num_tabs=l; \
113 char format[256]; \
114 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
115 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
116 m,PNG_STRING_NEWLINE); \
117 fprintf(PNG_DEBUG_FILE,format); \
118 } while (0)
119# endif
120# ifndef png_debug1
121# define png_debug1(l,m,p1) \
122 do { \
123 int num_tabs=l; \
124 char format[256]; \
125 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
126 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
127 m,PNG_STRING_NEWLINE); \
128 fprintf(PNG_DEBUG_FILE,format,p1); \
129 } while (0)
130# endif
131# ifndef png_debug2
132# define png_debug2(l,m,p1,p2) \
133 do { \
134 int num_tabs=l; \
135 char format[256]; \
136 snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
137 (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
138 m,PNG_STRING_NEWLINE); \
139 fprintf(PNG_DEBUG_FILE,format,p1,p2); \
140 } while (0)
141# endif
142# endif /* __STDC __ */
143# endif /* (PNG_DEBUG > 1) */
144
145# endif /* _MSC_VER */
146# endif /* (PNG_DEBUG > 0) */
147#endif /* PNG_DEBUG */
148#ifndef png_debug
149# define png_debug(l, m) ((void)0)
150#endif
151#ifndef png_debug1
152# define png_debug1(l, m, p1) ((void)0)
153#endif
154#ifndef png_debug2
155# define png_debug2(l, m, p1, p2) ((void)0)
156#endif
157#endif /* PNGDEBUG_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngerror.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngerror.c
new file mode 100644
index 0000000..9df97f5
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngerror.c
@@ -0,0 +1,685 @@
1
2/* pngerror.c - stub functions for i/o and memory allocation
3 *
4 * Last changed in libpng 1.5.8 [February 1, 2011]
5 * Copyright (c) 1998-2012 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file provides a location for all error handling. Users who
14 * need special error handling are expected to write replacement functions
15 * and use png_set_error_fn() to use those functions. See the instructions
16 * at each function.
17 */
18
19#include "pngpriv.h"
20
21#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22
23static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr,
24 png_const_charp error_message)),PNG_NORETURN);
25
26#ifdef PNG_WARNINGS_SUPPORTED
27static void /* PRIVATE */
28png_default_warning PNGARG((png_structp png_ptr,
29 png_const_charp warning_message));
30#endif /* PNG_WARNINGS_SUPPORTED */
31
32/* This function is called whenever there is a fatal error. This function
33 * should not be changed. If there is a need to handle errors differently,
34 * you should supply a replacement error function and use png_set_error_fn()
35 * to replace the error function at run-time.
36 */
37#ifdef PNG_ERROR_TEXT_SUPPORTED
38PNG_FUNCTION(void,PNGAPI
39png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN)
40{
41#ifdef PNG_ERROR_NUMBERS_SUPPORTED
42 char msg[16];
43 if (png_ptr != NULL)
44 {
45 if (png_ptr->flags&
46 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
47 {
48 if (*error_message == PNG_LITERAL_SHARP)
49 {
50 /* Strip "#nnnn " from beginning of error message. */
51 int offset;
52 for (offset = 1; offset<15; offset++)
53 if (error_message[offset] == ' ')
54 break;
55
56 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
57 {
58 int i;
59 for (i = 0; i < offset - 1; i++)
60 msg[i] = error_message[i + 1];
61 msg[i - 1] = '\0';
62 error_message = msg;
63 }
64
65 else
66 error_message += offset;
67 }
68
69 else
70 {
71 if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
72 {
73 msg[0] = '0';
74 msg[1] = '\0';
75 error_message = msg;
76 }
77 }
78 }
79 }
80#endif
81 if (png_ptr != NULL && png_ptr->error_fn != NULL)
82 (*(png_ptr->error_fn))(png_ptr, error_message);
83
84 /* If the custom handler doesn't exist, or if it returns,
85 use the default handler, which will not return. */
86 png_default_error(png_ptr, error_message);
87}
88#else
89PNG_FUNCTION(void,PNGAPI
90png_err,(png_structp png_ptr),PNG_NORETURN)
91{
92 /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed
93 * erroneously as '\0', instead of the empty string "". This was
94 * apparently an error, introduced in libpng-1.2.20, and png_default_error
95 * will crash in this case.
96 */
97 if (png_ptr != NULL && png_ptr->error_fn != NULL)
98 (*(png_ptr->error_fn))(png_ptr, "");
99
100 /* If the custom handler doesn't exist, or if it returns,
101 use the default handler, which will not return. */
102 png_default_error(png_ptr, "");
103}
104#endif /* PNG_ERROR_TEXT_SUPPORTED */
105
106/* Utility to safely appends strings to a buffer. This never errors out so
107 * error checking is not required in the caller.
108 */
109size_t
110png_safecat(png_charp buffer, size_t bufsize, size_t pos,
111 png_const_charp string)
112{
113 if (buffer != NULL && pos < bufsize)
114 {
115 if (string != NULL)
116 while (*string != '\0' && pos < bufsize-1)
117 buffer[pos++] = *string++;
118
119 buffer[pos] = '\0';
120 }
121
122 return pos;
123}
124
125#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
126/* Utility to dump an unsigned value into a buffer, given a start pointer and
127 * and end pointer (which should point just *beyond* the end of the buffer!)
128 * Returns the pointer to the start of the formatted string.
129 */
130png_charp
131png_format_number(png_const_charp start, png_charp end, int format,
132 png_alloc_size_t number)
133{
134 int count = 0; /* number of digits output */
135 int mincount = 1; /* minimum number required */
136 int output = 0; /* digit output (for the fixed point format) */
137
138 *--end = '\0';
139
140 /* This is written so that the loop always runs at least once, even with
141 * number zero.
142 */
143 while (end > start && (number != 0 || count < mincount))
144 {
145
146 static const char digits[] = "0123456789ABCDEF";
147
148 switch (format)
149 {
150 case PNG_NUMBER_FORMAT_fixed:
151 /* Needs five digits (the fraction) */
152 mincount = 5;
153 if (output || number % 10 != 0)
154 {
155 *--end = digits[number % 10];
156 output = 1;
157 }
158 number /= 10;
159 break;
160
161 case PNG_NUMBER_FORMAT_02u:
162 /* Expects at least 2 digits. */
163 mincount = 2;
164 /* fall through */
165
166 case PNG_NUMBER_FORMAT_u:
167 *--end = digits[number % 10];
168 number /= 10;
169 break;
170
171 case PNG_NUMBER_FORMAT_02x:
172 /* This format expects at least two digits */
173 mincount = 2;
174 /* fall through */
175
176 case PNG_NUMBER_FORMAT_x:
177 *--end = digits[number & 0xf];
178 number >>= 4;
179 break;
180
181 default: /* an error */
182 number = 0;
183 break;
184 }
185
186 /* Keep track of the number of digits added */
187 ++count;
188
189 /* Float a fixed number here: */
190 if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
191 {
192 /* End of the fraction, but maybe nothing was output? In that case
193 * drop the decimal point. If the number is a true zero handle that
194 * here.
195 */
196 if (output)
197 *--end = '.';
198 else if (number == 0) /* and !output */
199 *--end = '0';
200 }
201 }
202
203 return end;
204}
205#endif
206
207#ifdef PNG_WARNINGS_SUPPORTED
208/* This function is called whenever there is a non-fatal error. This function
209 * should not be changed. If there is a need to handle warnings differently,
210 * you should supply a replacement warning function and use
211 * png_set_error_fn() to replace the warning function at run-time.
212 */
213void PNGAPI
214png_warning(png_structp png_ptr, png_const_charp warning_message)
215{
216 int offset = 0;
217 if (png_ptr != NULL)
218 {
219#ifdef PNG_ERROR_NUMBERS_SUPPORTED
220 if (png_ptr->flags&
221 (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
222#endif
223 {
224 if (*warning_message == PNG_LITERAL_SHARP)
225 {
226 for (offset = 1; offset < 15; offset++)
227 if (warning_message[offset] == ' ')
228 break;
229 }
230 }
231 }
232 if (png_ptr != NULL && png_ptr->warning_fn != NULL)
233 (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
234 else
235 png_default_warning(png_ptr, warning_message + offset);
236}
237
238/* These functions support 'formatted' warning messages with up to
239 * PNG_WARNING_PARAMETER_COUNT parameters. In the format string the parameter
240 * is introduced by @<number>, where 'number' starts at 1. This follows the
241 * standard established by X/Open for internationalizable error messages.
242 */
243void
244png_warning_parameter(png_warning_parameters p, int number,
245 png_const_charp string)
246{
247 if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
248 (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
249}
250
251void
252png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
253 png_alloc_size_t value)
254{
255 char buffer[PNG_NUMBER_BUFFER_SIZE];
256 png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
257}
258
259void
260png_warning_parameter_signed(png_warning_parameters p, int number, int format,
261 png_int_32 value)
262{
263 png_alloc_size_t u;
264 png_charp str;
265 char buffer[PNG_NUMBER_BUFFER_SIZE];
266
267 /* Avoid overflow by doing the negate in a png_alloc_size_t: */
268 u = (png_alloc_size_t)value;
269 if (value < 0)
270 u = ~u + 1;
271
272 str = PNG_FORMAT_NUMBER(buffer, format, u);
273
274 if (value < 0 && str > buffer)
275 *--str = '-';
276
277 png_warning_parameter(p, number, str);
278}
279
280void
281png_formatted_warning(png_structp png_ptr, png_warning_parameters p,
282 png_const_charp message)
283{
284 /* The internal buffer is just 192 bytes - enough for all our messages,
285 * overflow doesn't happen because this code checks! If someone figures
286 * out how to send us a message longer than 192 bytes, all that will
287 * happen is that the message will be truncated appropriately.
288 */
289 size_t i = 0; /* Index in the msg[] buffer: */
290 char msg[192];
291
292 /* Each iteration through the following loop writes at most one character
293 * to msg[i++] then returns here to validate that there is still space for
294 * the trailing '\0'. It may (in the case of a parameter) read more than
295 * one character from message[]; it must check for '\0' and continue to the
296 * test if it finds the end of string.
297 */
298 while (i<(sizeof msg)-1 && *message != '\0')
299 {
300 /* '@' at end of string is now just printed (previously it was skipped);
301 * it is an error in the calling code to terminate the string with @.
302 */
303 if (p != NULL && *message == '@' && message[1] != '\0')
304 {
305 int parameter_char = *++message; /* Consume the '@' */
306 static const char valid_parameters[] = "123456789";
307 int parameter = 0;
308
309 /* Search for the parameter digit, the index in the string is the
310 * parameter to use.
311 */
312 while (valid_parameters[parameter] != parameter_char &&
313 valid_parameters[parameter] != '\0')
314 ++parameter;
315
316 /* If the parameter digit is out of range it will just get printed. */
317 if (parameter < PNG_WARNING_PARAMETER_COUNT)
318 {
319 /* Append this parameter */
320 png_const_charp parm = p[parameter];
321 png_const_charp pend = p[parameter] + (sizeof p[parameter]);
322
323 /* No need to copy the trailing '\0' here, but there is no guarantee
324 * that parm[] has been initialized, so there is no guarantee of a
325 * trailing '\0':
326 */
327 while (i<(sizeof msg)-1 && *parm != '\0' && parm < pend)
328 msg[i++] = *parm++;
329
330 /* Consume the parameter digit too: */
331 ++message;
332 continue;
333 }
334
335 /* else not a parameter and there is a character after the @ sign; just
336 * copy that. This is known not to be '\0' because of the test above.
337 */
338 }
339
340 /* At this point *message can't be '\0', even in the bad parameter case
341 * above where there is a lone '@' at the end of the message string.
342 */
343 msg[i++] = *message++;
344 }
345
346 /* i is always less than (sizeof msg), so: */
347 msg[i] = '\0';
348
349 /* And this is the formatted message, it may be larger than
350 * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these are
351 * not (currently) formatted.
352 */
353 png_warning(png_ptr, msg);
354}
355#endif /* PNG_WARNINGS_SUPPORTED */
356
357#ifdef PNG_BENIGN_ERRORS_SUPPORTED
358void PNGAPI
359png_benign_error(png_structp png_ptr, png_const_charp error_message)
360{
361 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
362 png_warning(png_ptr, error_message);
363 else
364 png_error(png_ptr, error_message);
365}
366#endif
367
368/* These utilities are used internally to build an error message that relates
369 * to the current chunk. The chunk name comes from png_ptr->chunk_name,
370 * this is used to prefix the message. The message is limited in length
371 * to 63 bytes, the name characters are output as hex digits wrapped in []
372 * if the character is invalid.
373 */
374#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
375static PNG_CONST char png_digit[16] = {
376 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
377 'A', 'B', 'C', 'D', 'E', 'F'
378};
379
380#define PNG_MAX_ERROR_TEXT 64
381#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
382static void /* PRIVATE */
383png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
384 error_message)
385{
386 png_uint_32 chunk_name = png_ptr->chunk_name;
387 int iout = 0, ishift = 24;
388
389 while (ishift >= 0)
390 {
391 int c = (int)(chunk_name >> ishift) & 0xff;
392
393 ishift -= 8;
394 if (isnonalpha(c))
395 {
396 buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
397 buffer[iout++] = png_digit[(c & 0xf0) >> 4];
398 buffer[iout++] = png_digit[c & 0x0f];
399 buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
400 }
401
402 else
403 {
404 buffer[iout++] = (char)c;
405 }
406 }
407
408 if (error_message == NULL)
409 buffer[iout] = '\0';
410
411 else
412 {
413 int iin = 0;
414
415 buffer[iout++] = ':';
416 buffer[iout++] = ' ';
417
418 while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
419 buffer[iout++] = error_message[iin++];
420
421 /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
422 buffer[iout] = '\0';
423 }
424}
425#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
426
427#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
428PNG_FUNCTION(void,PNGAPI
429png_chunk_error,(png_structp png_ptr, png_const_charp error_message),
430 PNG_NORETURN)
431{
432 char msg[18+PNG_MAX_ERROR_TEXT];
433 if (png_ptr == NULL)
434 png_error(png_ptr, error_message);
435
436 else
437 {
438 png_format_buffer(png_ptr, msg, error_message);
439 png_error(png_ptr, msg);
440 }
441}
442#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
443
444#ifdef PNG_WARNINGS_SUPPORTED
445void PNGAPI
446png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
447{
448 char msg[18+PNG_MAX_ERROR_TEXT];
449 if (png_ptr == NULL)
450 png_warning(png_ptr, warning_message);
451
452 else
453 {
454 png_format_buffer(png_ptr, msg, warning_message);
455 png_warning(png_ptr, msg);
456 }
457}
458#endif /* PNG_WARNINGS_SUPPORTED */
459
460#ifdef PNG_READ_SUPPORTED
461#ifdef PNG_BENIGN_ERRORS_SUPPORTED
462void PNGAPI
463png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
464{
465 if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
466 png_chunk_warning(png_ptr, error_message);
467
468 else
469 png_chunk_error(png_ptr, error_message);
470}
471#endif
472#endif /* PNG_READ_SUPPORTED */
473
474#ifdef PNG_ERROR_TEXT_SUPPORTED
475#ifdef PNG_FLOATING_POINT_SUPPORTED
476PNG_FUNCTION(void,
477png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN)
478{
479# define fixed_message "fixed point overflow in "
480# define fixed_message_ln ((sizeof fixed_message)-1)
481 int iin;
482 char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
483 png_memcpy(msg, fixed_message, fixed_message_ln);
484 iin = 0;
485 if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
486 {
487 msg[fixed_message_ln + iin] = name[iin];
488 ++iin;
489 }
490 msg[fixed_message_ln + iin] = 0;
491 png_error(png_ptr, msg);
492}
493#endif
494#endif
495
496#ifdef PNG_SETJMP_SUPPORTED
497/* This API only exists if ANSI-C style error handling is used,
498 * otherwise it is necessary for png_default_error to be overridden.
499 */
500jmp_buf* PNGAPI
501png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn,
502 size_t jmp_buf_size)
503{
504 if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf))
505 return NULL;
506
507 png_ptr->longjmp_fn = longjmp_fn;
508 return &png_ptr->longjmp_buffer;
509}
510#endif
511
512/* This is the default error handling function. Note that replacements for
513 * this function MUST NOT RETURN, or the program will likely crash. This
514 * function is used by default, or if the program supplies NULL for the
515 * error function pointer in png_set_error_fn().
516 */
517static PNG_FUNCTION(void /* PRIVATE */,
518png_default_error,(png_structp png_ptr, png_const_charp error_message),
519 PNG_NORETURN)
520{
521#ifdef PNG_CONSOLE_IO_SUPPORTED
522#ifdef PNG_ERROR_NUMBERS_SUPPORTED
523 /* Check on NULL only added in 1.5.4 */
524 if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)
525 {
526 /* Strip "#nnnn " from beginning of error message. */
527 int offset;
528 char error_number[16];
529 for (offset = 0; offset<15; offset++)
530 {
531 error_number[offset] = error_message[offset + 1];
532 if (error_message[offset] == ' ')
533 break;
534 }
535
536 if ((offset > 1) && (offset < 15))
537 {
538 error_number[offset - 1] = '\0';
539 fprintf(stderr, "libpng error no. %s: %s",
540 error_number, error_message + offset + 1);
541 fprintf(stderr, PNG_STRING_NEWLINE);
542 }
543
544 else
545 {
546 fprintf(stderr, "libpng error: %s, offset=%d",
547 error_message, offset);
548 fprintf(stderr, PNG_STRING_NEWLINE);
549 }
550 }
551 else
552#endif
553 {
554 fprintf(stderr, "libpng error: %s", error_message ? error_message :
555 "undefined");
556 fprintf(stderr, PNG_STRING_NEWLINE);
557 }
558#else
559 PNG_UNUSED(error_message) /* Make compiler happy */
560#endif
561 png_longjmp(png_ptr, 1);
562}
563
564PNG_FUNCTION(void,PNGAPI
565png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN)
566{
567#ifdef PNG_SETJMP_SUPPORTED
568 if (png_ptr && png_ptr->longjmp_fn)
569 {
570# ifdef USE_FAR_KEYWORD
571 {
572 jmp_buf tmp_jmpbuf;
573 png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
574 png_ptr->longjmp_fn(tmp_jmpbuf, val);
575 }
576
577# else
578 png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val);
579# endif
580 }
581#endif
582 /* Here if not setjmp support or if png_ptr is null. */
583 PNG_ABORT();
584}
585
586#ifdef PNG_WARNINGS_SUPPORTED
587/* This function is called when there is a warning, but the library thinks
588 * it can continue anyway. Replacement functions don't have to do anything
589 * here if you don't want them to. In the default configuration, png_ptr is
590 * not used, but it is passed in case it may be useful.
591 */
592static void /* PRIVATE */
593png_default_warning(png_structp png_ptr, png_const_charp warning_message)
594{
595#ifdef PNG_CONSOLE_IO_SUPPORTED
596# ifdef PNG_ERROR_NUMBERS_SUPPORTED
597 if (*warning_message == PNG_LITERAL_SHARP)
598 {
599 int offset;
600 char warning_number[16];
601 for (offset = 0; offset < 15; offset++)
602 {
603 warning_number[offset] = warning_message[offset + 1];
604 if (warning_message[offset] == ' ')
605 break;
606 }
607
608 if ((offset > 1) && (offset < 15))
609 {
610 warning_number[offset + 1] = '\0';
611 fprintf(stderr, "libpng warning no. %s: %s",
612 warning_number, warning_message + offset);
613 fprintf(stderr, PNG_STRING_NEWLINE);
614 }
615
616 else
617 {
618 fprintf(stderr, "libpng warning: %s",
619 warning_message);
620 fprintf(stderr, PNG_STRING_NEWLINE);
621 }
622 }
623 else
624# endif
625
626 {
627 fprintf(stderr, "libpng warning: %s", warning_message);
628 fprintf(stderr, PNG_STRING_NEWLINE);
629 }
630#else
631 PNG_UNUSED(warning_message) /* Make compiler happy */
632#endif
633 PNG_UNUSED(png_ptr) /* Make compiler happy */
634}
635#endif /* PNG_WARNINGS_SUPPORTED */
636
637/* This function is called when the application wants to use another method
638 * of handling errors and warnings. Note that the error function MUST NOT
639 * return to the calling routine or serious problems will occur. The return
640 * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1)
641 */
642void PNGAPI
643png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
644 png_error_ptr error_fn, png_error_ptr warning_fn)
645{
646 if (png_ptr == NULL)
647 return;
648
649 png_ptr->error_ptr = error_ptr;
650 png_ptr->error_fn = error_fn;
651#ifdef PNG_WARNINGS_SUPPORTED
652 png_ptr->warning_fn = warning_fn;
653#else
654 PNG_UNUSED(warning_fn)
655#endif
656}
657
658
659/* This function returns a pointer to the error_ptr associated with the user
660 * functions. The application should free any memory associated with this
661 * pointer before png_write_destroy and png_read_destroy are called.
662 */
663png_voidp PNGAPI
664png_get_error_ptr(png_const_structp png_ptr)
665{
666 if (png_ptr == NULL)
667 return NULL;
668
669 return ((png_voidp)png_ptr->error_ptr);
670}
671
672
673#ifdef PNG_ERROR_NUMBERS_SUPPORTED
674void PNGAPI
675png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
676{
677 if (png_ptr != NULL)
678 {
679 png_ptr->flags &=
680 ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
681 PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
682 }
683}
684#endif
685#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngget.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngget.c
new file mode 100644
index 0000000..1889e99
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngget.c
@@ -0,0 +1,1124 @@
1
2/* pngget.c - retrieval of values from info struct
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 */
14
15#include "pngpriv.h"
16
17#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
18
19png_uint_32 PNGAPI
20png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr,
21 png_uint_32 flag)
22{
23 if (png_ptr != NULL && info_ptr != NULL)
24 return(info_ptr->valid & flag);
25
26 return(0);
27}
28
29png_size_t PNGAPI
30png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr)
31{
32 if (png_ptr != NULL && info_ptr != NULL)
33 return(info_ptr->rowbytes);
34
35 return(0);
36}
37
38#ifdef PNG_INFO_IMAGE_SUPPORTED
39png_bytepp PNGAPI
40png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr)
41{
42 if (png_ptr != NULL && info_ptr != NULL)
43 return(info_ptr->row_pointers);
44
45 return(0);
46}
47#endif
48
49#ifdef PNG_EASY_ACCESS_SUPPORTED
50/* Easy access to info, added in libpng-0.99 */
51png_uint_32 PNGAPI
52png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr)
53{
54 if (png_ptr != NULL && info_ptr != NULL)
55 return info_ptr->width;
56
57 return (0);
58}
59
60png_uint_32 PNGAPI
61png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr)
62{
63 if (png_ptr != NULL && info_ptr != NULL)
64 return info_ptr->height;
65
66 return (0);
67}
68
69png_byte PNGAPI
70png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr)
71{
72 if (png_ptr != NULL && info_ptr != NULL)
73 return info_ptr->bit_depth;
74
75 return (0);
76}
77
78png_byte PNGAPI
79png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr)
80{
81 if (png_ptr != NULL && info_ptr != NULL)
82 return info_ptr->color_type;
83
84 return (0);
85}
86
87png_byte PNGAPI
88png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr)
89{
90 if (png_ptr != NULL && info_ptr != NULL)
91 return info_ptr->filter_type;
92
93 return (0);
94}
95
96png_byte PNGAPI
97png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr)
98{
99 if (png_ptr != NULL && info_ptr != NULL)
100 return info_ptr->interlace_type;
101
102 return (0);
103}
104
105png_byte PNGAPI
106png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr)
107{
108 if (png_ptr != NULL && info_ptr != NULL)
109 return info_ptr->compression_type;
110
111 return (0);
112}
113
114png_uint_32 PNGAPI
115png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
116{
117#ifdef PNG_pHYs_SUPPORTED
118 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
119 {
120 png_debug1(1, "in %s retrieval function",
121 "png_get_x_pixels_per_meter");
122
123 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
124 return (info_ptr->x_pixels_per_unit);
125 }
126#endif
127
128 return (0);
129}
130
131png_uint_32 PNGAPI
132png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
133{
134#ifdef PNG_pHYs_SUPPORTED
135 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
136 {
137 png_debug1(1, "in %s retrieval function",
138 "png_get_y_pixels_per_meter");
139
140 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
141 return (info_ptr->y_pixels_per_unit);
142 }
143#endif
144
145 return (0);
146}
147
148png_uint_32 PNGAPI
149png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
150{
151#ifdef PNG_pHYs_SUPPORTED
152 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
153 {
154 png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
155
156 if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
157 info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
158 return (info_ptr->x_pixels_per_unit);
159 }
160#endif
161
162 return (0);
163}
164
165#ifdef PNG_FLOATING_POINT_SUPPORTED
166float PNGAPI
167png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr)
168{
169#ifdef PNG_READ_pHYs_SUPPORTED
170 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
171 {
172 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
173
174 if (info_ptr->x_pixels_per_unit != 0)
175 return ((float)((float)info_ptr->y_pixels_per_unit
176 /(float)info_ptr->x_pixels_per_unit));
177 }
178#endif
179
180 return ((float)0.0);
181}
182#endif
183
184#ifdef PNG_FIXED_POINT_SUPPORTED
185png_fixed_point PNGAPI
186png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr,
187 png_const_infop info_ptr)
188{
189#ifdef PNG_READ_pHYs_SUPPORTED
190 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
191 && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
192 && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
193 && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
194 {
195 png_fixed_point res;
196
197 png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
198
199 /* The following casts work because a PNG 4 byte integer only has a valid
200 * range of 0..2^31-1; otherwise the cast might overflow.
201 */
202 if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
203 (png_int_32)info_ptr->x_pixels_per_unit))
204 return res;
205 }
206#endif
207
208 return 0;
209}
210#endif
211
212png_int_32 PNGAPI
213png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
214{
215#ifdef PNG_oFFs_SUPPORTED
216 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
217 {
218 png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
219
220 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
221 return (info_ptr->x_offset);
222 }
223#endif
224
225 return (0);
226}
227
228png_int_32 PNGAPI
229png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
230{
231#ifdef PNG_oFFs_SUPPORTED
232 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
233 {
234 png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
235
236 if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
237 return (info_ptr->y_offset);
238 }
239#endif
240
241 return (0);
242}
243
244png_int_32 PNGAPI
245png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
246{
247#ifdef PNG_oFFs_SUPPORTED
248 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
249 {
250 png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
251
252 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
253 return (info_ptr->x_offset);
254 }
255#endif
256
257 return (0);
258}
259
260png_int_32 PNGAPI
261png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
262{
263#ifdef PNG_oFFs_SUPPORTED
264 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
265 {
266 png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
267
268 if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
269 return (info_ptr->y_offset);
270 }
271#endif
272
273 return (0);
274}
275
276#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
277static png_uint_32
278ppi_from_ppm(png_uint_32 ppm)
279{
280#if 0
281 /* The conversion is *(2.54/100), in binary (32 digits):
282 * .00000110100000001001110101001001
283 */
284 png_uint_32 t1001, t1101;
285 ppm >>= 1; /* .1 */
286 t1001 = ppm + (ppm >> 3); /* .1001 */
287 t1101 = t1001 + (ppm >> 1); /* .1101 */
288 ppm >>= 20; /* .000000000000000000001 */
289 t1101 += t1101 >> 15; /* .1101000000000001101 */
290 t1001 >>= 11; /* .000000000001001 */
291 t1001 += t1001 >> 12; /* .000000000001001000000001001 */
292 ppm += t1001; /* .000000000001001000001001001 */
293 ppm += t1101; /* .110100000001001110101001001 */
294 return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
295#else
296 /* The argument is a PNG unsigned integer, so it is not permitted
297 * to be bigger than 2^31.
298 */
299 png_fixed_point result;
300 if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
301 5000))
302 return result;
303
304 /* Overflow. */
305 return 0;
306#endif
307}
308
309png_uint_32 PNGAPI
310png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
311{
312 return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
313}
314
315png_uint_32 PNGAPI
316png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
317{
318 return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
319}
320
321png_uint_32 PNGAPI
322png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
323{
324 return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
325}
326
327#ifdef PNG_FIXED_POINT_SUPPORTED
328static png_fixed_point
329png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
330{
331 /* Convert from metres * 1,000,000 to inches * 100,000, meters to
332 * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
333 * Notice that this can overflow - a warning is output and 0 is
334 * returned.
335 */
336 return png_muldiv_warn(png_ptr, microns, 500, 127);
337}
338
339png_fixed_point PNGAPI
340png_get_x_offset_inches_fixed(png_structp png_ptr,
341 png_const_infop info_ptr)
342{
343 return png_fixed_inches_from_microns(png_ptr,
344 png_get_x_offset_microns(png_ptr, info_ptr));
345}
346#endif
347
348#ifdef PNG_FIXED_POINT_SUPPORTED
349png_fixed_point PNGAPI
350png_get_y_offset_inches_fixed(png_structp png_ptr,
351 png_const_infop info_ptr)
352{
353 return png_fixed_inches_from_microns(png_ptr,
354 png_get_y_offset_microns(png_ptr, info_ptr));
355}
356#endif
357
358#ifdef PNG_FLOATING_POINT_SUPPORTED
359float PNGAPI
360png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
361{
362 /* To avoid the overflow do the conversion directly in floating
363 * point.
364 */
365 return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
366}
367#endif
368
369#ifdef PNG_FLOATING_POINT_SUPPORTED
370float PNGAPI
371png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
372{
373 /* To avoid the overflow do the conversion directly in floating
374 * point.
375 */
376 return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
377}
378#endif
379
380#ifdef PNG_pHYs_SUPPORTED
381png_uint_32 PNGAPI
382png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr,
383 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
384{
385 png_uint_32 retval = 0;
386
387 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
388 {
389 png_debug1(1, "in %s retrieval function", "pHYs");
390
391 if (res_x != NULL)
392 {
393 *res_x = info_ptr->x_pixels_per_unit;
394 retval |= PNG_INFO_pHYs;
395 }
396
397 if (res_y != NULL)
398 {
399 *res_y = info_ptr->y_pixels_per_unit;
400 retval |= PNG_INFO_pHYs;
401 }
402
403 if (unit_type != NULL)
404 {
405 *unit_type = (int)info_ptr->phys_unit_type;
406 retval |= PNG_INFO_pHYs;
407
408 if (*unit_type == 1)
409 {
410 if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
411 if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
412 }
413 }
414 }
415
416 return (retval);
417}
418#endif /* PNG_pHYs_SUPPORTED */
419#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
420
421/* png_get_channels really belongs in here, too, but it's been around longer */
422
423#endif /* PNG_EASY_ACCESS_SUPPORTED */
424
425png_byte PNGAPI
426png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr)
427{
428 if (png_ptr != NULL && info_ptr != NULL)
429 return(info_ptr->channels);
430
431 return (0);
432}
433
434png_const_bytep PNGAPI
435png_get_signature(png_const_structp png_ptr, png_infop info_ptr)
436{
437 if (png_ptr != NULL && info_ptr != NULL)
438 return(info_ptr->signature);
439
440 return (NULL);
441}
442
443#ifdef PNG_bKGD_SUPPORTED
444png_uint_32 PNGAPI
445png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr,
446 png_color_16p *background)
447{
448 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
449 && background != NULL)
450 {
451 png_debug1(1, "in %s retrieval function", "bKGD");
452
453 *background = &(info_ptr->background);
454 return (PNG_INFO_bKGD);
455 }
456
457 return (0);
458}
459#endif
460
461#ifdef PNG_cHRM_SUPPORTED
462/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the
463 * same time to correct the rgb grayscale coefficient defaults obtained from the
464 * cHRM chunk in 1.5.4
465 */
466png_uint_32 PNGFAPI
467png_get_cHRM_XYZ_fixed(png_structp png_ptr, png_const_infop info_ptr,
468 png_fixed_point *int_red_X, png_fixed_point *int_red_Y,
469 png_fixed_point *int_red_Z, png_fixed_point *int_green_X,
470 png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,
471 png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,
472 png_fixed_point *int_blue_Z)
473{
474 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
475 {
476 png_xy xy;
477 png_XYZ XYZ;
478
479 png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
480
481 xy.whitex = info_ptr->x_white;
482 xy.whitey = info_ptr->y_white;
483 xy.redx = info_ptr->x_red;
484 xy.redy = info_ptr->y_red;
485 xy.greenx = info_ptr->x_green;
486 xy.greeny = info_ptr->y_green;
487 xy.bluex = info_ptr->x_blue;
488 xy.bluey = info_ptr->y_blue;
489
490 /* The *_checked function handles error reporting, so just return 0 if
491 * there is a failure here.
492 */
493 if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy))
494 {
495 if (int_red_X != NULL)
496 *int_red_X = XYZ.redX;
497 if (int_red_Y != NULL)
498 *int_red_Y = XYZ.redY;
499 if (int_red_Z != NULL)
500 *int_red_Z = XYZ.redZ;
501 if (int_green_X != NULL)
502 *int_green_X = XYZ.greenX;
503 if (int_green_Y != NULL)
504 *int_green_Y = XYZ.greenY;
505 if (int_green_Z != NULL)
506 *int_green_Z = XYZ.greenZ;
507 if (int_blue_X != NULL)
508 *int_blue_X = XYZ.blueX;
509 if (int_blue_Y != NULL)
510 *int_blue_Y = XYZ.blueY;
511 if (int_blue_Z != NULL)
512 *int_blue_Z = XYZ.blueZ;
513
514 return (PNG_INFO_cHRM);
515 }
516 }
517
518 return (0);
519}
520
521# ifdef PNG_FLOATING_POINT_SUPPORTED
522png_uint_32 PNGAPI
523png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr,
524 double *white_x, double *white_y, double *red_x, double *red_y,
525 double *green_x, double *green_y, double *blue_x, double *blue_y)
526{
527 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
528 {
529 png_debug1(1, "in %s retrieval function", "cHRM");
530
531 if (white_x != NULL)
532 *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
533 if (white_y != NULL)
534 *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
535 if (red_x != NULL)
536 *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
537 if (red_y != NULL)
538 *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
539 if (green_x != NULL)
540 *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
541 if (green_y != NULL)
542 *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
543 if (blue_x != NULL)
544 *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
545 if (blue_y != NULL)
546 *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
547 return (PNG_INFO_cHRM);
548 }
549
550 return (0);
551}
552
553png_uint_32 PNGAPI
554png_get_cHRM_XYZ(png_structp png_ptr, png_const_infop info_ptr,
555 double *red_X, double *red_Y, double *red_Z, double *green_X,
556 double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
557 double *blue_Z)
558{
559 png_XYZ XYZ;
560
561 if (png_get_cHRM_XYZ_fixed(png_ptr, info_ptr,
562 &XYZ.redX, &XYZ.redY, &XYZ.redZ, &XYZ.greenX, &XYZ.greenY, &XYZ.greenZ,
563 &XYZ.blueX, &XYZ.blueY, &XYZ.blueZ) & PNG_INFO_cHRM)
564 {
565 if (red_X != NULL)
566 *red_X = png_float(png_ptr, XYZ.redX, "cHRM red X");
567 if (red_Y != NULL)
568 *red_Y = png_float(png_ptr, XYZ.redY, "cHRM red Y");
569 if (red_Z != NULL)
570 *red_Z = png_float(png_ptr, XYZ.redZ, "cHRM red Z");
571 if (green_X != NULL)
572 *green_X = png_float(png_ptr, XYZ.greenX, "cHRM green X");
573 if (green_Y != NULL)
574 *green_Y = png_float(png_ptr, XYZ.greenY, "cHRM green Y");
575 if (green_Z != NULL)
576 *green_Z = png_float(png_ptr, XYZ.greenZ, "cHRM green Z");
577 if (blue_X != NULL)
578 *blue_X = png_float(png_ptr, XYZ.blueX, "cHRM blue X");
579 if (blue_Y != NULL)
580 *blue_Y = png_float(png_ptr, XYZ.blueY, "cHRM blue Y");
581 if (blue_Z != NULL)
582 *blue_Z = png_float(png_ptr, XYZ.blueZ, "cHRM blue Z");
583 return (PNG_INFO_cHRM);
584 }
585
586 return (0);
587}
588# endif
589
590# ifdef PNG_FIXED_POINT_SUPPORTED
591png_uint_32 PNGAPI
592png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
593 png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
594 png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
595 png_fixed_point *blue_x, png_fixed_point *blue_y)
596{
597 png_debug1(1, "in %s retrieval function", "cHRM");
598
599 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
600 {
601 if (white_x != NULL)
602 *white_x = info_ptr->x_white;
603 if (white_y != NULL)
604 *white_y = info_ptr->y_white;
605 if (red_x != NULL)
606 *red_x = info_ptr->x_red;
607 if (red_y != NULL)
608 *red_y = info_ptr->y_red;
609 if (green_x != NULL)
610 *green_x = info_ptr->x_green;
611 if (green_y != NULL)
612 *green_y = info_ptr->y_green;
613 if (blue_x != NULL)
614 *blue_x = info_ptr->x_blue;
615 if (blue_y != NULL)
616 *blue_y = info_ptr->y_blue;
617 return (PNG_INFO_cHRM);
618 }
619
620 return (0);
621}
622# endif
623#endif
624
625#ifdef PNG_gAMA_SUPPORTED
626png_uint_32 PNGFAPI
627png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
628 png_fixed_point *file_gamma)
629{
630 png_debug1(1, "in %s retrieval function", "gAMA");
631
632 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
633 && file_gamma != NULL)
634 {
635 *file_gamma = info_ptr->gamma;
636 return (PNG_INFO_gAMA);
637 }
638
639 return (0);
640}
641# ifdef PNG_FLOATING_POINT_SUPPORTED
642png_uint_32 PNGAPI
643png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr,
644 double *file_gamma)
645{
646 png_fixed_point igamma;
647 png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
648
649 if (ok)
650 *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
651
652 return ok;
653}
654
655# endif
656#endif
657
658#ifdef PNG_sRGB_SUPPORTED
659png_uint_32 PNGAPI
660png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr,
661 int *file_srgb_intent)
662{
663 png_debug1(1, "in %s retrieval function", "sRGB");
664
665 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
666 && file_srgb_intent != NULL)
667 {
668 *file_srgb_intent = (int)info_ptr->srgb_intent;
669 return (PNG_INFO_sRGB);
670 }
671
672 return (0);
673}
674#endif
675
676#ifdef PNG_iCCP_SUPPORTED
677png_uint_32 PNGAPI
678png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
679 png_charpp name, int *compression_type,
680 png_bytepp profile, png_uint_32 *proflen)
681{
682 png_debug1(1, "in %s retrieval function", "iCCP");
683
684 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
685 && name != NULL && compression_type != NULL && profile != NULL &&
686 proflen != NULL)
687 {
688 *name = info_ptr->iccp_name;
689 *profile = info_ptr->iccp_profile;
690 /* Compression_type is a dummy so the API won't have to change
691 * if we introduce multiple compression types later.
692 */
693 *proflen = info_ptr->iccp_proflen;
694 *compression_type = info_ptr->iccp_compression;
695 return (PNG_INFO_iCCP);
696 }
697
698 return (0);
699}
700#endif
701
702#ifdef PNG_sPLT_SUPPORTED
703png_uint_32 PNGAPI
704png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr,
705 png_sPLT_tpp spalettes)
706{
707 if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
708 {
709 *spalettes = info_ptr->splt_palettes;
710 return ((png_uint_32)info_ptr->splt_palettes_num);
711 }
712
713 return (0);
714}
715#endif
716
717#ifdef PNG_hIST_SUPPORTED
718png_uint_32 PNGAPI
719png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr,
720 png_uint_16p *hist)
721{
722 png_debug1(1, "in %s retrieval function", "hIST");
723
724 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
725 && hist != NULL)
726 {
727 *hist = info_ptr->hist;
728 return (PNG_INFO_hIST);
729 }
730
731 return (0);
732}
733#endif
734
735png_uint_32 PNGAPI
736png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
737 png_uint_32 *width, png_uint_32 *height, int *bit_depth,
738 int *color_type, int *interlace_type, int *compression_type,
739 int *filter_type)
740
741{
742 png_debug1(1, "in %s retrieval function", "IHDR");
743
744 if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
745 height == NULL || bit_depth == NULL || color_type == NULL)
746 return (0);
747
748 *width = info_ptr->width;
749 *height = info_ptr->height;
750 *bit_depth = info_ptr->bit_depth;
751 *color_type = info_ptr->color_type;
752
753 if (compression_type != NULL)
754 *compression_type = info_ptr->compression_type;
755
756 if (filter_type != NULL)
757 *filter_type = info_ptr->filter_type;
758
759 if (interlace_type != NULL)
760 *interlace_type = info_ptr->interlace_type;
761
762 /* This is redundant if we can be sure that the info_ptr values were all
763 * assigned in png_set_IHDR(). We do the check anyhow in case an
764 * application has ignored our advice not to mess with the members
765 * of info_ptr directly.
766 */
767 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
768 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
769 info_ptr->compression_type, info_ptr->filter_type);
770
771 return (1);
772}
773
774#ifdef PNG_oFFs_SUPPORTED
775png_uint_32 PNGAPI
776png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr,
777 png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
778{
779 png_debug1(1, "in %s retrieval function", "oFFs");
780
781 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
782 && offset_x != NULL && offset_y != NULL && unit_type != NULL)
783 {
784 *offset_x = info_ptr->x_offset;
785 *offset_y = info_ptr->y_offset;
786 *unit_type = (int)info_ptr->offset_unit_type;
787 return (PNG_INFO_oFFs);
788 }
789
790 return (0);
791}
792#endif
793
794#ifdef PNG_pCAL_SUPPORTED
795png_uint_32 PNGAPI
796png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr,
797 png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
798 png_charp *units, png_charpp *params)
799{
800 png_debug1(1, "in %s retrieval function", "pCAL");
801
802 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
803 && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
804 nparams != NULL && units != NULL && params != NULL)
805 {
806 *purpose = info_ptr->pcal_purpose;
807 *X0 = info_ptr->pcal_X0;
808 *X1 = info_ptr->pcal_X1;
809 *type = (int)info_ptr->pcal_type;
810 *nparams = (int)info_ptr->pcal_nparams;
811 *units = info_ptr->pcal_units;
812 *params = info_ptr->pcal_params;
813 return (PNG_INFO_pCAL);
814 }
815
816 return (0);
817}
818#endif
819
820#ifdef PNG_sCAL_SUPPORTED
821# ifdef PNG_FIXED_POINT_SUPPORTED
822# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
823png_uint_32 PNGAPI
824png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr,
825 int *unit, png_fixed_point *width, png_fixed_point *height)
826{
827 if (png_ptr != NULL && info_ptr != NULL &&
828 (info_ptr->valid & PNG_INFO_sCAL))
829 {
830 *unit = info_ptr->scal_unit;
831 /*TODO: make this work without FP support */
832 *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
833 *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
834 "sCAL height");
835 return (PNG_INFO_sCAL);
836 }
837
838 return(0);
839}
840# endif /* FLOATING_ARITHMETIC */
841# endif /* FIXED_POINT */
842# ifdef PNG_FLOATING_POINT_SUPPORTED
843png_uint_32 PNGAPI
844png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr,
845 int *unit, double *width, double *height)
846{
847 if (png_ptr != NULL && info_ptr != NULL &&
848 (info_ptr->valid & PNG_INFO_sCAL))
849 {
850 *unit = info_ptr->scal_unit;
851 *width = atof(info_ptr->scal_s_width);
852 *height = atof(info_ptr->scal_s_height);
853 return (PNG_INFO_sCAL);
854 }
855
856 return(0);
857}
858# endif /* FLOATING POINT */
859png_uint_32 PNGAPI
860png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr,
861 int *unit, png_charpp width, png_charpp height)
862{
863 if (png_ptr != NULL && info_ptr != NULL &&
864 (info_ptr->valid & PNG_INFO_sCAL))
865 {
866 *unit = info_ptr->scal_unit;
867 *width = info_ptr->scal_s_width;
868 *height = info_ptr->scal_s_height;
869 return (PNG_INFO_sCAL);
870 }
871
872 return(0);
873}
874#endif /* sCAL */
875
876#ifdef PNG_pHYs_SUPPORTED
877png_uint_32 PNGAPI
878png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr,
879 png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
880{
881 png_uint_32 retval = 0;
882
883 png_debug1(1, "in %s retrieval function", "pHYs");
884
885 if (png_ptr != NULL && info_ptr != NULL &&
886 (info_ptr->valid & PNG_INFO_pHYs))
887 {
888 if (res_x != NULL)
889 {
890 *res_x = info_ptr->x_pixels_per_unit;
891 retval |= PNG_INFO_pHYs;
892 }
893
894 if (res_y != NULL)
895 {
896 *res_y = info_ptr->y_pixels_per_unit;
897 retval |= PNG_INFO_pHYs;
898 }
899
900 if (unit_type != NULL)
901 {
902 *unit_type = (int)info_ptr->phys_unit_type;
903 retval |= PNG_INFO_pHYs;
904 }
905 }
906
907 return (retval);
908}
909#endif /* pHYs */
910
911png_uint_32 PNGAPI
912png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr,
913 png_colorp *palette, int *num_palette)
914{
915 png_debug1(1, "in %s retrieval function", "PLTE");
916
917 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
918 && palette != NULL)
919 {
920 *palette = info_ptr->palette;
921 *num_palette = info_ptr->num_palette;
922 png_debug1(3, "num_palette = %d", *num_palette);
923 return (PNG_INFO_PLTE);
924 }
925
926 return (0);
927}
928
929#ifdef PNG_sBIT_SUPPORTED
930png_uint_32 PNGAPI
931png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr,
932 png_color_8p *sig_bit)
933{
934 png_debug1(1, "in %s retrieval function", "sBIT");
935
936 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
937 && sig_bit != NULL)
938 {
939 *sig_bit = &(info_ptr->sig_bit);
940 return (PNG_INFO_sBIT);
941 }
942
943 return (0);
944}
945#endif
946
947#ifdef PNG_TEXT_SUPPORTED
948png_uint_32 PNGAPI
949png_get_text(png_const_structp png_ptr, png_const_infop info_ptr,
950 png_textp *text_ptr, int *num_text)
951{
952 if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
953 {
954 png_debug1(1, "in 0x%lx retrieval function",
955 (unsigned long)png_ptr->chunk_name);
956
957 if (text_ptr != NULL)
958 *text_ptr = info_ptr->text;
959
960 if (num_text != NULL)
961 *num_text = info_ptr->num_text;
962
963 return ((png_uint_32)info_ptr->num_text);
964 }
965
966 if (num_text != NULL)
967 *num_text = 0;
968
969 return(0);
970}
971#endif
972
973#ifdef PNG_tIME_SUPPORTED
974png_uint_32 PNGAPI
975png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
976{
977 png_debug1(1, "in %s retrieval function", "tIME");
978
979 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
980 && mod_time != NULL)
981 {
982 *mod_time = &(info_ptr->mod_time);
983 return (PNG_INFO_tIME);
984 }
985
986 return (0);
987}
988#endif
989
990#ifdef PNG_tRNS_SUPPORTED
991png_uint_32 PNGAPI
992png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr,
993 png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
994{
995 png_uint_32 retval = 0;
996 if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
997 {
998 png_debug1(1, "in %s retrieval function", "tRNS");
999
1000 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1001 {
1002 if (trans_alpha != NULL)
1003 {
1004 *trans_alpha = info_ptr->trans_alpha;
1005 retval |= PNG_INFO_tRNS;
1006 }
1007
1008 if (trans_color != NULL)
1009 *trans_color = &(info_ptr->trans_color);
1010 }
1011
1012 else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
1013 {
1014 if (trans_color != NULL)
1015 {
1016 *trans_color = &(info_ptr->trans_color);
1017 retval |= PNG_INFO_tRNS;
1018 }
1019
1020 if (trans_alpha != NULL)
1021 *trans_alpha = NULL;
1022 }
1023
1024 if (num_trans != NULL)
1025 {
1026 *num_trans = info_ptr->num_trans;
1027 retval |= PNG_INFO_tRNS;
1028 }
1029 }
1030
1031 return (retval);
1032}
1033#endif
1034
1035#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1036int PNGAPI
1037png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr,
1038 png_unknown_chunkpp unknowns)
1039{
1040 if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
1041 {
1042 *unknowns = info_ptr->unknown_chunks;
1043 return info_ptr->unknown_chunks_num;
1044 }
1045
1046 return (0);
1047}
1048#endif
1049
1050#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1051png_byte PNGAPI
1052png_get_rgb_to_gray_status (png_const_structp png_ptr)
1053{
1054 return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
1055}
1056#endif
1057
1058#ifdef PNG_USER_CHUNKS_SUPPORTED
1059png_voidp PNGAPI
1060png_get_user_chunk_ptr(png_const_structp png_ptr)
1061{
1062 return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
1063}
1064#endif
1065
1066png_size_t PNGAPI
1067png_get_compression_buffer_size(png_const_structp png_ptr)
1068{
1069 return (png_ptr ? png_ptr->zbuf_size : 0);
1070}
1071
1072#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1073/* These functions were added to libpng 1.2.6 and were enabled
1074 * by default in libpng-1.4.0 */
1075png_uint_32 PNGAPI
1076png_get_user_width_max (png_const_structp png_ptr)
1077{
1078 return (png_ptr ? png_ptr->user_width_max : 0);
1079}
1080
1081png_uint_32 PNGAPI
1082png_get_user_height_max (png_const_structp png_ptr)
1083{
1084 return (png_ptr ? png_ptr->user_height_max : 0);
1085}
1086
1087/* This function was added to libpng 1.4.0 */
1088png_uint_32 PNGAPI
1089png_get_chunk_cache_max (png_const_structp png_ptr)
1090{
1091 return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
1092}
1093
1094/* This function was added to libpng 1.4.1 */
1095png_alloc_size_t PNGAPI
1096png_get_chunk_malloc_max (png_const_structp png_ptr)
1097{
1098 return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
1099}
1100#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1101
1102/* These functions were added to libpng 1.4.0 */
1103#ifdef PNG_IO_STATE_SUPPORTED
1104png_uint_32 PNGAPI
1105png_get_io_state (png_structp png_ptr)
1106{
1107 return png_ptr->io_state;
1108}
1109
1110png_uint_32 PNGAPI
1111png_get_io_chunk_type (png_const_structp png_ptr)
1112{
1113 return png_ptr->chunk_name;
1114}
1115
1116png_const_bytep PNGAPI
1117png_get_io_chunk_name (png_structp png_ptr)
1118{
1119 PNG_CSTRING_FROM_CHUNK(png_ptr->io_chunk_string, png_ptr->chunk_name);
1120 return png_ptr->io_chunk_string;
1121}
1122#endif /* ?PNG_IO_STATE_SUPPORTED */
1123
1124#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnginfo.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnginfo.h
new file mode 100644
index 0000000..bbfb105
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnginfo.h
@@ -0,0 +1,269 @@
1
2/* pnginfo.h - header file for PNG reference library
3 *
4 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7 *
8 * Last changed in libpng 1.5.0 [January 6, 2011]
9 *
10 * This code is released under the libpng license.
11 * For conditions of distribution and use, see the disclaimer
12 * and license in png.h
13 */
14
15 /* png_info is a structure that holds the information in a PNG file so
16 * that the application can find out the characteristics of the image.
17 * If you are reading the file, this structure will tell you what is
18 * in the PNG file. If you are writing the file, fill in the information
19 * you want to put into the PNG file, using png_set_*() functions, then
20 * call png_write_info().
21 *
22 * The names chosen should be very close to the PNG specification, so
23 * consult that document for information about the meaning of each field.
24 *
25 * With libpng < 0.95, it was only possible to directly set and read the
26 * the values in the png_info_struct, which meant that the contents and
27 * order of the values had to remain fixed. With libpng 0.95 and later,
28 * however, there are now functions that abstract the contents of
29 * png_info_struct from the application, so this makes it easier to use
30 * libpng with dynamic libraries, and even makes it possible to use
31 * libraries that don't have all of the libpng ancillary chunk-handing
32 * functionality. In libpng-1.5.0 this was moved into a separate private
33 * file that is not visible to applications.
34 *
35 * The following members may have allocated storage attached that should be
36 * cleaned up before the structure is discarded: palette, trans, text,
37 * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
38 * splt_palettes, scal_unit, row_pointers, and unknowns. By default, these
39 * are automatically freed when the info structure is deallocated, if they were
40 * allocated internally by libpng. This behavior can be changed by means
41 * of the png_data_freer() function.
42 *
43 * More allocation details: all the chunk-reading functions that
44 * change these members go through the corresponding png_set_*
45 * functions. A function to clear these members is available: see
46 * png_free_data(). The png_set_* functions do not depend on being
47 * able to point info structure members to any of the storage they are
48 * passed (they make their own copies), EXCEPT that the png_set_text
49 * functions use the same storage passed to them in the text_ptr or
50 * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
51 * functions do not make their own copies.
52 */
53#ifndef PNGINFO_H
54#define PNGINFO_H
55
56struct png_info_def
57{
58 /* the following are necessary for every PNG file */
59 png_uint_32 width; /* width of image in pixels (from IHDR) */
60 png_uint_32 height; /* height of image in pixels (from IHDR) */
61 png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
62 png_size_t rowbytes; /* bytes needed to hold an untransformed row */
63 png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
64 png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
65 png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
66 png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
67 png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
68 /* The following three should have been named *_method not *_type */
69 png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
70 png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
71 png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
72
73 /* The following is informational only on read, and not used on writes. */
74 png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
75 png_byte pixel_depth; /* number of bits per pixel */
76 png_byte spare_byte; /* to align the data, and for future use */
77 png_byte signature[8]; /* magic bytes read by libpng from start of file */
78
79 /* The rest of the data is optional. If you are reading, check the
80 * valid field to see if the information in these are valid. If you
81 * are writing, set the valid field to those chunks you want written,
82 * and initialize the appropriate fields below.
83 */
84
85#if defined(PNG_gAMA_SUPPORTED)
86 /* The gAMA chunk describes the gamma characteristics of the system
87 * on which the image was created, normally in the range [1.0, 2.5].
88 * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
89 */
90 png_fixed_point gamma;
91#endif
92
93#ifdef PNG_sRGB_SUPPORTED
94 /* GR-P, 0.96a */
95 /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
96 png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
97#endif
98
99#ifdef PNG_TEXT_SUPPORTED
100 /* The tEXt, and zTXt chunks contain human-readable textual data in
101 * uncompressed, compressed, and optionally compressed forms, respectively.
102 * The data in "text" is an array of pointers to uncompressed,
103 * null-terminated C strings. Each chunk has a keyword that describes the
104 * textual data contained in that chunk. Keywords are not required to be
105 * unique, and the text string may be empty. Any number of text chunks may
106 * be in an image.
107 */
108 int num_text; /* number of comments read or comments to write */
109 int max_text; /* current size of text array */
110 png_textp text; /* array of comments read or comments to write */
111#endif /* PNG_TEXT_SUPPORTED */
112
113#ifdef PNG_tIME_SUPPORTED
114 /* The tIME chunk holds the last time the displayed image data was
115 * modified. See the png_time struct for the contents of this struct.
116 */
117 png_time mod_time;
118#endif
119
120#ifdef PNG_sBIT_SUPPORTED
121 /* The sBIT chunk specifies the number of significant high-order bits
122 * in the pixel data. Values are in the range [1, bit_depth], and are
123 * only specified for the channels in the pixel data. The contents of
124 * the low-order bits is not specified. Data is valid if
125 * (valid & PNG_INFO_sBIT) is non-zero.
126 */
127 png_color_8 sig_bit; /* significant bits in color channels */
128#endif
129
130#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
131defined(PNG_READ_BACKGROUND_SUPPORTED)
132 /* The tRNS chunk supplies transparency data for paletted images and
133 * other image types that don't need a full alpha channel. There are
134 * "num_trans" transparency values for a paletted image, stored in the
135 * same order as the palette colors, starting from index 0. Values
136 * for the data are in the range [0, 255], ranging from fully transparent
137 * to fully opaque, respectively. For non-paletted images, there is a
138 * single color specified that should be treated as fully transparent.
139 * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
140 */
141 png_bytep trans_alpha; /* alpha values for paletted image */
142 png_color_16 trans_color; /* transparent color for non-palette image */
143#endif
144
145#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
146 /* The bKGD chunk gives the suggested image background color if the
147 * display program does not have its own background color and the image
148 * is needs to composited onto a background before display. The colors
149 * in "background" are normally in the same color space/depth as the
150 * pixel data. Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
151 */
152 png_color_16 background;
153#endif
154
155#ifdef PNG_oFFs_SUPPORTED
156 /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
157 * and downwards from the top-left corner of the display, page, or other
158 * application-specific co-ordinate space. See the PNG_OFFSET_ defines
159 * below for the unit types. Valid if (valid & PNG_INFO_oFFs) non-zero.
160 */
161 png_int_32 x_offset; /* x offset on page */
162 png_int_32 y_offset; /* y offset on page */
163 png_byte offset_unit_type; /* offset units type */
164#endif
165
166#ifdef PNG_pHYs_SUPPORTED
167 /* The pHYs chunk gives the physical pixel density of the image for
168 * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
169 * defines below). Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
170 */
171 png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
172 png_uint_32 y_pixels_per_unit; /* vertical pixel density */
173 png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
174#endif
175
176#ifdef PNG_hIST_SUPPORTED
177 /* The hIST chunk contains the relative frequency or importance of the
178 * various palette entries, so that a viewer can intelligently select a
179 * reduced-color palette, if required. Data is an array of "num_palette"
180 * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
181 * is non-zero.
182 */
183 png_uint_16p hist;
184#endif
185
186#ifdef PNG_cHRM_SUPPORTED
187 /* The cHRM chunk describes the CIE color characteristics of the monitor
188 * on which the PNG was created. This data allows the viewer to do gamut
189 * mapping of the input image to ensure that the viewer sees the same
190 * colors in the image as the creator. Values are in the range
191 * [0.0, 0.8]. Data valid if (valid & PNG_INFO_cHRM) non-zero.
192 */
193 png_fixed_point x_white;
194 png_fixed_point y_white;
195 png_fixed_point x_red;
196 png_fixed_point y_red;
197 png_fixed_point x_green;
198 png_fixed_point y_green;
199 png_fixed_point x_blue;
200 png_fixed_point y_blue;
201#endif
202
203#ifdef PNG_pCAL_SUPPORTED
204 /* The pCAL chunk describes a transformation between the stored pixel
205 * values and original physical data values used to create the image.
206 * The integer range [0, 2^bit_depth - 1] maps to the floating-point
207 * range given by [pcal_X0, pcal_X1], and are further transformed by a
208 * (possibly non-linear) transformation function given by "pcal_type"
209 * and "pcal_params" into "pcal_units". Please see the PNG_EQUATION_
210 * defines below, and the PNG-Group's PNG extensions document for a
211 * complete description of the transformations and how they should be
212 * implemented, and for a description of the ASCII parameter strings.
213 * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
214 */
215 png_charp pcal_purpose; /* pCAL chunk description string */
216 png_int_32 pcal_X0; /* minimum value */
217 png_int_32 pcal_X1; /* maximum value */
218 png_charp pcal_units; /* Latin-1 string giving physical units */
219 png_charpp pcal_params; /* ASCII strings containing parameter values */
220 png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
221 png_byte pcal_nparams; /* number of parameters given in pcal_params */
222#endif
223
224/* New members added in libpng-1.0.6 */
225 png_uint_32 free_me; /* flags items libpng is responsible for freeing */
226
227#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
228 defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
229 /* Storage for unknown chunks that the library doesn't recognize. */
230 png_unknown_chunkp unknown_chunks;
231 int unknown_chunks_num;
232#endif
233
234#ifdef PNG_iCCP_SUPPORTED
235 /* iCCP chunk data. */
236 png_charp iccp_name; /* profile name */
237 png_bytep iccp_profile; /* International Color Consortium profile data */
238 png_uint_32 iccp_proflen; /* ICC profile data length */
239 png_byte iccp_compression; /* Always zero */
240#endif
241
242#ifdef PNG_sPLT_SUPPORTED
243 /* Data on sPLT chunks (there may be more than one). */
244 png_sPLT_tp splt_palettes;
245 png_uint_32 splt_palettes_num;
246#endif
247
248#ifdef PNG_sCAL_SUPPORTED
249 /* The sCAL chunk describes the actual physical dimensions of the
250 * subject matter of the graphic. The chunk contains a unit specification
251 * a byte value, and two ASCII strings representing floating-point
252 * values. The values are width and height corresponsing to one pixel
253 * in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
254 * non-zero.
255 */
256 png_byte scal_unit; /* unit of physical scale */
257 png_charp scal_s_width; /* string containing height */
258 png_charp scal_s_height; /* string containing width */
259#endif
260
261#ifdef PNG_INFO_IMAGE_SUPPORTED
262 /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
263 non-zero */
264 /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
265 png_bytepp row_pointers; /* the image bits */
266#endif
267
268};
269#endif /* PNGINFO_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnglibconf.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnglibconf.h
new file mode 100644
index 0000000..d207232
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pnglibconf.h
@@ -0,0 +1,187 @@
1
2/* libpng STANDARD API DEFINITION */
3
4/* pnglibconf.h - library build configuration */
5
6/* libpng version 1.5.4 - last changed on June 22, 2011 */
7
8/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
9
10/* This code is released under the libpng license. */
11/* For conditions of distribution and use, see the disclaimer */
12/* and license in png.h */
13
14/* pnglibconf.h */
15/* Derived from: scripts/pnglibconf.dfa */
16/* If you edit this file by hand you must obey the rules expressed in */
17/* pnglibconf.dfa with respect to the dependencies between the following */
18/* symbols. It is much better to generate a new file using */
19/* scripts/libpngconf.mak */
20
21#ifndef PNGLCONF_H
22#define PNGLCONF_H
23/* settings */
24#define PNG_API_RULE 0
25#define PNG_CALLOC_SUPPORTED
26#define PNG_COST_SHIFT 3
27#define PNG_DEFAULT_READ_MACROS 1
28#define PNG_GAMMA_THRESHOLD_FIXED 5000
29#define PNG_MAX_GAMMA_8 11
30#define PNG_QUANTIZE_BLUE_BITS 5
31#define PNG_QUANTIZE_GREEN_BITS 5
32#define PNG_QUANTIZE_RED_BITS 5
33#define PNG_sCAL_PRECISION 5
34#define PNG_USER_CHUNK_CACHE_MAX 0
35#define PNG_USER_CHUNK_MALLOC_MAX 0
36#define PNG_USER_HEIGHT_MAX 1000000
37#define PNG_USER_WIDTH_MAX 1000000
38#define PNG_WEIGHT_SHIFT 8
39#define PNG_ZBUF_SIZE 8192
40/* end of settings */
41/* options */
42#define PNG_16BIT_SUPPORTED
43#define PNG_ALIGN_MEMORY_SUPPORTED
44#define PNG_BENIGN_ERRORS_SUPPORTED
45#define PNG_bKGD_SUPPORTED
46#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
47#define PNG_CHECK_cHRM_SUPPORTED
48#define PNG_cHRM_SUPPORTED
49#define PNG_CONSOLE_IO_SUPPORTED
50#define PNG_CONVERT_tIME_SUPPORTED
51#define PNG_EASY_ACCESS_SUPPORTED
52/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
53#define PNG_ERROR_TEXT_SUPPORTED
54#define PNG_FIXED_POINT_SUPPORTED
55#define PNG_FLOATING_ARITHMETIC_SUPPORTED
56#define PNG_FLOATING_POINT_SUPPORTED
57#define PNG_gAMA_SUPPORTED
58#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
59#define PNG_hIST_SUPPORTED
60#define PNG_iCCP_SUPPORTED
61#define PNG_INCH_CONVERSIONS_SUPPORTED
62#define PNG_INFO_IMAGE_SUPPORTED
63#define PNG_IO_STATE_SUPPORTED
64#define PNG_iTXt_SUPPORTED
65#define PNG_MNG_FEATURES_SUPPORTED
66#define PNG_oFFs_SUPPORTED
67#define PNG_pCAL_SUPPORTED
68#define PNG_pHYs_SUPPORTED
69#define PNG_POINTER_INDEXING_SUPPORTED
70#define PNG_PROGRESSIVE_READ_SUPPORTED
71#define PNG_READ_16BIT_SUPPORTED
72#define PNG_READ_ALPHA_MODE_SUPPORTED
73#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
74#define PNG_READ_BACKGROUND_SUPPORTED
75#define PNG_READ_BGR_SUPPORTED
76#define PNG_READ_bKGD_SUPPORTED
77#define PNG_READ_cHRM_SUPPORTED
78#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
79#define PNG_READ_COMPRESSED_TEXT_SUPPORTED
80#define PNG_READ_EXPAND_16_SUPPORTED
81#define PNG_READ_EXPAND_SUPPORTED
82#define PNG_READ_FILLER_SUPPORTED
83#define PNG_READ_gAMA_SUPPORTED
84#define PNG_READ_GAMMA_SUPPORTED
85#define PNG_READ_GRAY_TO_RGB_SUPPORTED
86#define PNG_READ_hIST_SUPPORTED
87#define PNG_READ_iCCP_SUPPORTED
88#define PNG_READ_INTERLACING_SUPPORTED
89#define PNG_READ_INT_FUNCTIONS_SUPPORTED
90#define PNG_READ_INVERT_ALPHA_SUPPORTED
91#define PNG_READ_INVERT_SUPPORTED
92#define PNG_READ_iTXt_SUPPORTED
93#define PNG_READ_oFFs_SUPPORTED
94#define PNG_READ_OPT_PLTE_SUPPORTED
95#define PNG_READ_PACK_SUPPORTED
96#define PNG_READ_PACKSWAP_SUPPORTED
97#define PNG_READ_pCAL_SUPPORTED
98#define PNG_READ_pHYs_SUPPORTED
99#define PNG_READ_QUANTIZE_SUPPORTED
100#define PNG_READ_RGB_TO_GRAY_SUPPORTED
101#define PNG_READ_sBIT_SUPPORTED
102#define PNG_READ_SCALE_16_TO_8_SUPPORTED
103#define PNG_READ_sCAL_SUPPORTED
104#define PNG_READ_SHIFT_SUPPORTED
105#define PNG_READ_sPLT_SUPPORTED
106#define PNG_READ_sRGB_SUPPORTED
107#define PNG_READ_STRIP_16_TO_8_SUPPORTED
108#define PNG_READ_STRIP_ALPHA_SUPPORTED
109#define PNG_READ_SUPPORTED
110#define PNG_READ_SWAP_ALPHA_SUPPORTED
111#define PNG_READ_SWAP_SUPPORTED
112#define PNG_READ_tEXt_SUPPORTED
113#define PNG_READ_TEXT_SUPPORTED
114#define PNG_READ_tIME_SUPPORTED
115#define PNG_READ_TRANSFORMS_SUPPORTED
116#define PNG_READ_tRNS_SUPPORTED
117#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
118#define PNG_READ_USER_CHUNKS_SUPPORTED
119#define PNG_READ_USER_TRANSFORM_SUPPORTED
120#define PNG_READ_zTXt_SUPPORTED
121#define PNG_SAVE_INT_32_SUPPORTED
122#define PNG_sBIT_SUPPORTED
123#define PNG_sCAL_SUPPORTED
124#define PNG_SEQUENTIAL_READ_SUPPORTED
125#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
126#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
127#define PNG_SETJMP_SUPPORTED
128#define PNG_SET_USER_LIMITS_SUPPORTED
129#define PNG_sPLT_SUPPORTED
130#define PNG_sRGB_SUPPORTED
131#define PNG_STDIO_SUPPORTED
132#define PNG_tEXt_SUPPORTED
133#define PNG_TEXT_SUPPORTED
134#define PNG_TIME_RFC1123_SUPPORTED
135#define PNG_tIME_SUPPORTED
136#define PNG_tRNS_SUPPORTED
137#define PNG_UNKNOWN_CHUNKS_SUPPORTED
138#define PNG_USER_CHUNKS_SUPPORTED
139#define PNG_USER_LIMITS_SUPPORTED
140#define PNG_USER_MEM_SUPPORTED
141#define PNG_USER_TRANSFORM_INFO_SUPPORTED
142#define PNG_USER_TRANSFORM_PTR_SUPPORTED
143#define PNG_WARNINGS_SUPPORTED
144#define PNG_WRITE_16BIT_SUPPORTED
145#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
146#define PNG_WRITE_BGR_SUPPORTED
147#define PNG_WRITE_bKGD_SUPPORTED
148#define PNG_WRITE_cHRM_SUPPORTED
149#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
150#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
151#define PNG_WRITE_FILLER_SUPPORTED
152#define PNG_WRITE_FILTER_SUPPORTED
153#define PNG_WRITE_FLUSH_SUPPORTED
154#define PNG_WRITE_gAMA_SUPPORTED
155#define PNG_WRITE_hIST_SUPPORTED
156#define PNG_WRITE_iCCP_SUPPORTED
157#define PNG_WRITE_INTERLACING_SUPPORTED
158#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
159#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
160#define PNG_WRITE_INVERT_SUPPORTED
161#define PNG_WRITE_iTXt_SUPPORTED
162#define PNG_WRITE_oFFs_SUPPORTED
163#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
164#define PNG_WRITE_PACK_SUPPORTED
165#define PNG_WRITE_PACKSWAP_SUPPORTED
166#define PNG_WRITE_pCAL_SUPPORTED
167#define PNG_WRITE_pHYs_SUPPORTED
168#define PNG_WRITE_sBIT_SUPPORTED
169#define PNG_WRITE_sCAL_SUPPORTED
170#define PNG_WRITE_SHIFT_SUPPORTED
171#define PNG_WRITE_sPLT_SUPPORTED
172#define PNG_WRITE_sRGB_SUPPORTED
173#define PNG_WRITE_SUPPORTED
174#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
175#define PNG_WRITE_SWAP_SUPPORTED
176#define PNG_WRITE_tEXt_SUPPORTED
177#define PNG_WRITE_TEXT_SUPPORTED
178#define PNG_WRITE_tIME_SUPPORTED
179#define PNG_WRITE_TRANSFORMS_SUPPORTED
180#define PNG_WRITE_tRNS_SUPPORTED
181#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
182#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
183#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
184#define PNG_WRITE_zTXt_SUPPORTED
185#define PNG_zTXt_SUPPORTED
186/* end of options */
187#endif /* PNGLCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngmem.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngmem.c
new file mode 100644
index 0000000..25b5c73
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngmem.c
@@ -0,0 +1,667 @@
1
2/* pngmem.c - stub functions for memory allocation
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file provides a location for all memory allocation. Users who
14 * need special memory handling are expected to supply replacement
15 * functions for png_malloc() and png_free(), and to use
16 * png_create_read_struct_2() and png_create_write_struct_2() to
17 * identify the replacement functions.
18 */
19
20#include "pngpriv.h"
21
22#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
23
24/* Borland DOS special memory handler */
25#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
26/* If you change this, be sure to change the one in png.h also */
27
28/* Allocate memory for a png_struct. The malloc and memset can be replaced
29 by a single call to calloc() if this is thought to improve performance. */
30PNG_FUNCTION(png_voidp /* PRIVATE */,
31png_create_struct,(int type),PNG_ALLOCATED)
32{
33# ifdef PNG_USER_MEM_SUPPORTED
34 return (png_create_struct_2(type, NULL, NULL));
35}
36
37/* Alternate version of png_create_struct, for use with user-defined malloc. */
38PNG_FUNCTION(png_voidp /* PRIVATE */,
39png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
40 PNG_ALLOCATED)
41{
42# endif /* PNG_USER_MEM_SUPPORTED */
43 png_size_t size;
44 png_voidp struct_ptr;
45
46 if (type == PNG_STRUCT_INFO)
47 size = png_sizeof(png_info);
48
49 else if (type == PNG_STRUCT_PNG)
50 size = png_sizeof(png_struct);
51
52 else
53 return (png_get_copyright(NULL));
54
55# ifdef PNG_USER_MEM_SUPPORTED
56 if (malloc_fn != NULL)
57 {
58 png_struct dummy_struct;
59 memset(&dummy_struct, 0, sizeof dummy_struct);
60 dummy_struct.mem_ptr=mem_ptr;
61 struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size);
62 }
63
64 else
65# endif /* PNG_USER_MEM_SUPPORTED */
66 struct_ptr = (png_voidp)farmalloc(size);
67 if (struct_ptr != NULL)
68 png_memset(struct_ptr, 0, size);
69
70 return (struct_ptr);
71}
72
73/* Free memory allocated by a png_create_struct() call */
74void /* PRIVATE */
75png_destroy_struct(png_voidp struct_ptr)
76{
77# ifdef PNG_USER_MEM_SUPPORTED
78 png_destroy_struct_2(struct_ptr, NULL, NULL);
79}
80
81/* Free memory allocated by a png_create_struct() call */
82void /* PRIVATE */
83png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
84 png_voidp mem_ptr)
85{
86# endif
87 if (struct_ptr != NULL)
88 {
89# ifdef PNG_USER_MEM_SUPPORTED
90 if (free_fn != NULL)
91 {
92 png_struct dummy_struct;
93 memset(&dummy_struct, 0, sizeof dummy_struct);
94 dummy_struct.mem_ptr=mem_ptr;
95 (*(free_fn))(&dummy_struct, struct_ptr);
96 return;
97 }
98
99# endif /* PNG_USER_MEM_SUPPORTED */
100 farfree (struct_ptr);
101 }
102}
103
104/* Allocate memory. For reasonable files, size should never exceed
105 * 64K. However, zlib may allocate more then 64K if you don't tell
106 * it not to. See zconf.h and png.h for more information. zlib does
107 * need to allocate exactly 64K, so whatever you call here must
108 * have the ability to do that.
109 *
110 * Borland seems to have a problem in DOS mode for exactly 64K.
111 * It gives you a segment with an offset of 8 (perhaps to store its
112 * memory stuff). zlib doesn't like this at all, so we have to
113 * detect and deal with it. This code should not be needed in
114 * Windows or OS/2 modes, and only in 16 bit mode. This code has
115 * been updated by Alexander Lehmann for version 0.89 to waste less
116 * memory.
117 *
118 * Note that we can't use png_size_t for the "size" declaration,
119 * since on some systems a png_size_t is a 16-bit quantity, and as a
120 * result, we would be truncating potentially larger memory requests
121 * (which should cause a fatal error) and introducing major problems.
122 */
123PNG_FUNCTION(png_voidp,PNGAPI
124png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
125{
126 png_voidp ret;
127
128 ret = (png_malloc(png_ptr, size));
129
130 if (ret != NULL)
131 png_memset(ret,0,(png_size_t)size);
132
133 return (ret);
134}
135
136PNG_FUNCTION(png_voidp,PNGAPI
137png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
138{
139 png_voidp ret;
140
141 if (png_ptr == NULL || size == 0)
142 return (NULL);
143
144# ifdef PNG_USER_MEM_SUPPORTED
145 if (png_ptr->malloc_fn != NULL)
146 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
147
148 else
149 ret = (png_malloc_default(png_ptr, size));
150
151 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
152 png_error(png_ptr, "Out of memory");
153
154 return (ret);
155}
156
157PNG_FUNCTION(png_voidp,PNGAPI
158png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
159{
160 png_voidp ret;
161# endif /* PNG_USER_MEM_SUPPORTED */
162
163 if (png_ptr == NULL || size == 0)
164 return (NULL);
165
166# ifdef PNG_MAX_MALLOC_64K
167 if (size > (png_uint_32)65536L)
168 {
169 png_warning(png_ptr, "Cannot Allocate > 64K");
170 ret = NULL;
171 }
172
173 else
174# endif
175
176 if (size != (size_t)size)
177 ret = NULL;
178
179 else if (size == (png_uint_32)65536L)
180 {
181 if (png_ptr->offset_table == NULL)
182 {
183 /* Try to see if we need to do any of this fancy stuff */
184 ret = farmalloc(size);
185 if (ret == NULL || ((png_size_t)ret & 0xffff))
186 {
187 int num_blocks;
188 png_uint_32 total_size;
189 png_bytep table;
190 int i, mem_level, window_bits;
191 png_byte huge * hptr;
192 int window_bits
193
194 if (ret != NULL)
195 {
196 farfree(ret);
197 ret = NULL;
198 }
199
200 window_bits =
201 png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ?
202 png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits;
203
204 if (window_bits > 14)
205 num_blocks = (int)(1 << (window_bits - 14));
206
207 else
208 num_blocks = 1;
209
210 mem_level =
211 png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ?
212 png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level;
213
214 if (mem_level >= 7)
215 num_blocks += (int)(1 << (mem_level - 7));
216
217 else
218 num_blocks++;
219
220 total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
221
222 table = farmalloc(total_size);
223
224 if (table == NULL)
225 {
226# ifndef PNG_USER_MEM_SUPPORTED
227 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
228 png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */
229
230 else
231 png_warning(png_ptr, "Out Of Memory");
232# endif
233 return (NULL);
234 }
235
236 if ((png_size_t)table & 0xfff0)
237 {
238# ifndef PNG_USER_MEM_SUPPORTED
239 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
240 png_error(png_ptr,
241 "Farmalloc didn't return normalized pointer");
242
243 else
244 png_warning(png_ptr,
245 "Farmalloc didn't return normalized pointer");
246# endif
247 return (NULL);
248 }
249
250 png_ptr->offset_table = table;
251 png_ptr->offset_table_ptr = farmalloc(num_blocks *
252 png_sizeof(png_bytep));
253
254 if (png_ptr->offset_table_ptr == NULL)
255 {
256# ifndef PNG_USER_MEM_SUPPORTED
257 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
258 png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */
259
260 else
261 png_warning(png_ptr, "Out Of memory");
262# endif
263 return (NULL);
264 }
265
266 hptr = (png_byte huge *)table;
267 if ((png_size_t)hptr & 0xf)
268 {
269 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
270 hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
271 }
272
273 for (i = 0; i < num_blocks; i++)
274 {
275 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
276 hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
277 }
278
279 png_ptr->offset_table_number = num_blocks;
280 png_ptr->offset_table_count = 0;
281 png_ptr->offset_table_count_free = 0;
282 }
283 }
284
285 if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
286 {
287# ifndef PNG_USER_MEM_SUPPORTED
288 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
289 png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */
290
291 else
292 png_warning(png_ptr, "Out of Memory");
293# endif
294 return (NULL);
295 }
296
297 ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
298 }
299
300 else
301 ret = farmalloc(size);
302
303# ifndef PNG_USER_MEM_SUPPORTED
304 if (ret == NULL)
305 {
306 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
307 png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
308
309 else
310 png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
311 }
312# endif
313
314 return (ret);
315}
316
317/* Free a pointer allocated by png_malloc(). In the default
318 * configuration, png_ptr is not used, but is passed in case it
319 * is needed. If ptr is NULL, return without taking any action.
320 */
321void PNGAPI
322png_free(png_structp png_ptr, png_voidp ptr)
323{
324 if (png_ptr == NULL || ptr == NULL)
325 return;
326
327# ifdef PNG_USER_MEM_SUPPORTED
328 if (png_ptr->free_fn != NULL)
329 {
330 (*(png_ptr->free_fn))(png_ptr, ptr);
331 return;
332 }
333
334 else
335 png_free_default(png_ptr, ptr);
336}
337
338void PNGAPI
339png_free_default(png_structp png_ptr, png_voidp ptr)
340{
341# endif /* PNG_USER_MEM_SUPPORTED */
342
343 if (png_ptr == NULL || ptr == NULL)
344 return;
345
346 if (png_ptr->offset_table != NULL)
347 {
348 int i;
349
350 for (i = 0; i < png_ptr->offset_table_count; i++)
351 {
352 if (ptr == png_ptr->offset_table_ptr[i])
353 {
354 ptr = NULL;
355 png_ptr->offset_table_count_free++;
356 break;
357 }
358 }
359 if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
360 {
361 farfree(png_ptr->offset_table);
362 farfree(png_ptr->offset_table_ptr);
363 png_ptr->offset_table = NULL;
364 png_ptr->offset_table_ptr = NULL;
365 }
366 }
367
368 if (ptr != NULL)
369 farfree(ptr);
370}
371
372#else /* Not the Borland DOS special memory handler */
373
374/* Allocate memory for a png_struct or a png_info. The malloc and
375 memset can be replaced by a single call to calloc() if this is thought
376 to improve performance noticably. */
377PNG_FUNCTION(png_voidp /* PRIVATE */,
378png_create_struct,(int type),PNG_ALLOCATED)
379{
380# ifdef PNG_USER_MEM_SUPPORTED
381 return (png_create_struct_2(type, NULL, NULL));
382}
383
384/* Allocate memory for a png_struct or a png_info. The malloc and
385 memset can be replaced by a single call to calloc() if this is thought
386 to improve performance noticably. */
387PNG_FUNCTION(png_voidp /* PRIVATE */,
388png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
389 PNG_ALLOCATED)
390{
391# endif /* PNG_USER_MEM_SUPPORTED */
392 png_size_t size;
393 png_voidp struct_ptr;
394
395 if (type == PNG_STRUCT_INFO)
396 size = png_sizeof(png_info);
397
398 else if (type == PNG_STRUCT_PNG)
399 size = png_sizeof(png_struct);
400
401 else
402 return (NULL);
403
404# ifdef PNG_USER_MEM_SUPPORTED
405 if (malloc_fn != NULL)
406 {
407 png_struct dummy_struct;
408 png_structp png_ptr = &dummy_struct;
409 png_ptr->mem_ptr=mem_ptr;
410 struct_ptr = (*(malloc_fn))(png_ptr, size);
411
412 if (struct_ptr != NULL)
413 png_memset(struct_ptr, 0, size);
414
415 return (struct_ptr);
416 }
417# endif /* PNG_USER_MEM_SUPPORTED */
418
419# if defined(__TURBOC__) && !defined(__FLAT__)
420 struct_ptr = (png_voidp)farmalloc(size);
421# else
422# if defined(_MSC_VER) && defined(MAXSEG_64K)
423 struct_ptr = (png_voidp)halloc(size, 1);
424# else
425 struct_ptr = (png_voidp)malloc(size);
426# endif
427# endif
428
429 if (struct_ptr != NULL)
430 png_memset(struct_ptr, 0, size);
431
432 return (struct_ptr);
433}
434
435
436/* Free memory allocated by a png_create_struct() call */
437void /* PRIVATE */
438png_destroy_struct(png_voidp struct_ptr)
439{
440# ifdef PNG_USER_MEM_SUPPORTED
441 png_destroy_struct_2(struct_ptr, NULL, NULL);
442}
443
444/* Free memory allocated by a png_create_struct() call */
445void /* PRIVATE */
446png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
447 png_voidp mem_ptr)
448{
449# endif /* PNG_USER_MEM_SUPPORTED */
450 if (struct_ptr != NULL)
451 {
452# ifdef PNG_USER_MEM_SUPPORTED
453 if (free_fn != NULL)
454 {
455 png_struct dummy_struct;
456 png_structp png_ptr = &dummy_struct;
457 png_ptr->mem_ptr=mem_ptr;
458 (*(free_fn))(png_ptr, struct_ptr);
459 return;
460 }
461# endif /* PNG_USER_MEM_SUPPORTED */
462# if defined(__TURBOC__) && !defined(__FLAT__)
463 farfree(struct_ptr);
464
465# else
466# if defined(_MSC_VER) && defined(MAXSEG_64K)
467 hfree(struct_ptr);
468
469# else
470 free(struct_ptr);
471
472# endif
473# endif
474 }
475}
476
477/* Allocate memory. For reasonable files, size should never exceed
478 * 64K. However, zlib may allocate more then 64K if you don't tell
479 * it not to. See zconf.h and png.h for more information. zlib does
480 * need to allocate exactly 64K, so whatever you call here must
481 * have the ability to do that.
482 */
483
484PNG_FUNCTION(png_voidp,PNGAPI
485png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
486{
487 png_voidp ret;
488
489 ret = (png_malloc(png_ptr, size));
490
491 if (ret != NULL)
492 png_memset(ret,0,(png_size_t)size);
493
494 return (ret);
495}
496
497PNG_FUNCTION(png_voidp,PNGAPI
498png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
499{
500 png_voidp ret;
501
502# ifdef PNG_USER_MEM_SUPPORTED
503 if (png_ptr == NULL || size == 0)
504 return (NULL);
505
506 if (png_ptr->malloc_fn != NULL)
507 ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
508
509 else
510 ret = (png_malloc_default(png_ptr, size));
511
512 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
513 png_error(png_ptr, "Out of Memory");
514
515 return (ret);
516}
517
518PNG_FUNCTION(png_voidp,PNGAPI
519png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
520{
521 png_voidp ret;
522# endif /* PNG_USER_MEM_SUPPORTED */
523
524 if (png_ptr == NULL || size == 0)
525 return (NULL);
526
527# ifdef PNG_MAX_MALLOC_64K
528 if (size > (png_uint_32)65536L)
529 {
530# ifndef PNG_USER_MEM_SUPPORTED
531 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
532 png_error(png_ptr, "Cannot Allocate > 64K");
533
534 else
535# endif
536 return NULL;
537 }
538# endif
539
540 /* Check for overflow */
541# if defined(__TURBOC__) && !defined(__FLAT__)
542
543 if (size != (unsigned long)size)
544 ret = NULL;
545
546 else
547 ret = farmalloc(size);
548
549# else
550# if defined(_MSC_VER) && defined(MAXSEG_64K)
551 if (size != (unsigned long)size)
552 ret = NULL;
553
554 else
555 ret = halloc(size, 1);
556
557# else
558 if (size != (size_t)size)
559 ret = NULL;
560
561 else
562 ret = malloc((size_t)size);
563# endif
564# endif
565
566# ifndef PNG_USER_MEM_SUPPORTED
567 if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
568 png_error(png_ptr, "Out of Memory");
569# endif
570
571 return (ret);
572}
573
574/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
575 * without taking any action.
576 */
577void PNGAPI
578png_free(png_structp png_ptr, png_voidp ptr)
579{
580 if (png_ptr == NULL || ptr == NULL)
581 return;
582
583# ifdef PNG_USER_MEM_SUPPORTED
584 if (png_ptr->free_fn != NULL)
585 {
586 (*(png_ptr->free_fn))(png_ptr, ptr);
587 return;
588 }
589
590 else
591 png_free_default(png_ptr, ptr);
592}
593
594void PNGAPI
595png_free_default(png_structp png_ptr, png_voidp ptr)
596{
597 if (png_ptr == NULL || ptr == NULL)
598 return;
599
600# endif /* PNG_USER_MEM_SUPPORTED */
601
602# if defined(__TURBOC__) && !defined(__FLAT__)
603 farfree(ptr);
604
605# else
606# if defined(_MSC_VER) && defined(MAXSEG_64K)
607 hfree(ptr);
608
609# else
610 free(ptr);
611
612# endif
613# endif
614}
615#endif /* Not Borland DOS special memory handler */
616
617/* This function was added at libpng version 1.2.3. The png_malloc_warn()
618 * function will set up png_malloc() to issue a png_warning and return NULL
619 * instead of issuing a png_error, if it fails to allocate the requested
620 * memory.
621 */
622PNG_FUNCTION(png_voidp,PNGAPI
623png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
624{
625 png_voidp ptr;
626 png_uint_32 save_flags;
627 if (png_ptr == NULL)
628 return (NULL);
629
630 save_flags = png_ptr->flags;
631 png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
632 ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
633 png_ptr->flags=save_flags;
634 return(ptr);
635}
636
637
638#ifdef PNG_USER_MEM_SUPPORTED
639/* This function is called when the application wants to use another method
640 * of allocating and freeing memory.
641 */
642void PNGAPI
643png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
644 malloc_fn, png_free_ptr free_fn)
645{
646 if (png_ptr != NULL)
647 {
648 png_ptr->mem_ptr = mem_ptr;
649 png_ptr->malloc_fn = malloc_fn;
650 png_ptr->free_fn = free_fn;
651 }
652}
653
654/* This function returns a pointer to the mem_ptr associated with the user
655 * functions. The application should free any memory associated with this
656 * pointer before png_write_destroy and png_read_destroy are called.
657 */
658png_voidp PNGAPI
659png_get_mem_ptr(png_const_structp png_ptr)
660{
661 if (png_ptr == NULL)
662 return (NULL);
663
664 return ((png_voidp)png_ptr->mem_ptr);
665}
666#endif /* PNG_USER_MEM_SUPPORTED */
667#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngnow.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngnow.png
new file mode 100644
index 0000000..82793eb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngnow.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpread.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpread.c
new file mode 100644
index 0000000..eda5a6c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpread.c
@@ -0,0 +1,1843 @@
1
2/* pngpread.c - read a png file in push mode
3 *
4 * Last changed in libpng 1.5.9 [February 18, 2012]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
17
18/* Push model modes */
19#define PNG_READ_SIG_MODE 0
20#define PNG_READ_CHUNK_MODE 1
21#define PNG_READ_IDAT_MODE 2
22#define PNG_SKIP_MODE 3
23#define PNG_READ_tEXt_MODE 4
24#define PNG_READ_zTXt_MODE 5
25#define PNG_READ_DONE_MODE 6
26#define PNG_READ_iTXt_MODE 7
27#define PNG_ERROR_MODE 8
28
29void PNGAPI
30png_process_data(png_structp png_ptr, png_infop info_ptr,
31 png_bytep buffer, png_size_t buffer_size)
32{
33 if (png_ptr == NULL || info_ptr == NULL)
34 return;
35
36 png_push_restore_buffer(png_ptr, buffer, buffer_size);
37
38 while (png_ptr->buffer_size)
39 {
40 png_process_some_data(png_ptr, info_ptr);
41 }
42}
43
44png_size_t PNGAPI
45png_process_data_pause(png_structp png_ptr, int save)
46{
47 if (png_ptr != NULL)
48 {
49 /* It's easiest for the caller if we do the save, then the caller doesn't
50 * have to supply the same data again:
51 */
52 if (save)
53 png_push_save_buffer(png_ptr);
54 else
55 {
56 /* This includes any pending saved bytes: */
57 png_size_t remaining = png_ptr->buffer_size;
58 png_ptr->buffer_size = 0;
59
60 /* So subtract the saved buffer size, unless all the data
61 * is actually 'saved', in which case we just return 0
62 */
63 if (png_ptr->save_buffer_size < remaining)
64 return remaining - png_ptr->save_buffer_size;
65 }
66 }
67
68 return 0;
69}
70
71png_uint_32 PNGAPI
72png_process_data_skip(png_structp png_ptr)
73{
74 png_uint_32 remaining = 0;
75
76 if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE &&
77 png_ptr->skip_length > 0)
78 {
79 /* At the end of png_process_data the buffer size must be 0 (see the loop
80 * above) so we can detect a broken call here:
81 */
82 if (png_ptr->buffer_size != 0)
83 png_error(png_ptr,
84 "png_process_data_skip called inside png_process_data");
85
86 /* If is impossible for there to be a saved buffer at this point -
87 * otherwise we could not be in SKIP mode. This will also happen if
88 * png_process_skip is called inside png_process_data (but only very
89 * rarely.)
90 */
91 if (png_ptr->save_buffer_size != 0)
92 png_error(png_ptr, "png_process_data_skip called with saved data");
93
94 remaining = png_ptr->skip_length;
95 png_ptr->skip_length = 0;
96 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
97 }
98
99 return remaining;
100}
101
102/* What we do with the incoming data depends on what we were previously
103 * doing before we ran out of data...
104 */
105void /* PRIVATE */
106png_process_some_data(png_structp png_ptr, png_infop info_ptr)
107{
108 if (png_ptr == NULL)
109 return;
110
111 switch (png_ptr->process_mode)
112 {
113 case PNG_READ_SIG_MODE:
114 {
115 png_push_read_sig(png_ptr, info_ptr);
116 break;
117 }
118
119 case PNG_READ_CHUNK_MODE:
120 {
121 png_push_read_chunk(png_ptr, info_ptr);
122 break;
123 }
124
125 case PNG_READ_IDAT_MODE:
126 {
127 png_push_read_IDAT(png_ptr);
128 break;
129 }
130
131#ifdef PNG_READ_tEXt_SUPPORTED
132 case PNG_READ_tEXt_MODE:
133 {
134 png_push_read_tEXt(png_ptr, info_ptr);
135 break;
136 }
137
138#endif
139#ifdef PNG_READ_zTXt_SUPPORTED
140 case PNG_READ_zTXt_MODE:
141 {
142 png_push_read_zTXt(png_ptr, info_ptr);
143 break;
144 }
145
146#endif
147#ifdef PNG_READ_iTXt_SUPPORTED
148 case PNG_READ_iTXt_MODE:
149 {
150 png_push_read_iTXt(png_ptr, info_ptr);
151 break;
152 }
153
154#endif
155 case PNG_SKIP_MODE:
156 {
157 png_push_crc_finish(png_ptr);
158 break;
159 }
160
161 default:
162 {
163 png_ptr->buffer_size = 0;
164 break;
165 }
166 }
167}
168
169/* Read any remaining signature bytes from the stream and compare them with
170 * the correct PNG signature. It is possible that this routine is called
171 * with bytes already read from the signature, either because they have been
172 * checked by the calling application, or because of multiple calls to this
173 * routine.
174 */
175void /* PRIVATE */
176png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
177{
178 png_size_t num_checked = png_ptr->sig_bytes,
179 num_to_check = 8 - num_checked;
180
181 if (png_ptr->buffer_size < num_to_check)
182 {
183 num_to_check = png_ptr->buffer_size;
184 }
185
186 png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
187 num_to_check);
188 png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
189
190 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
191 {
192 if (num_checked < 4 &&
193 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
194 png_error(png_ptr, "Not a PNG file");
195
196 else
197 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
198 }
199 else
200 {
201 if (png_ptr->sig_bytes >= 8)
202 {
203 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
204 }
205 }
206}
207
208void /* PRIVATE */
209png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
210{
211 png_uint_32 chunk_name;
212
213 /* First we make sure we have enough data for the 4 byte chunk name
214 * and the 4 byte chunk length before proceeding with decoding the
215 * chunk data. To fully decode each of these chunks, we also make
216 * sure we have enough data in the buffer for the 4 byte CRC at the
217 * end of every chunk (except IDAT, which is handled separately).
218 */
219 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
220 {
221 png_byte chunk_length[4];
222 png_byte chunk_tag[4];
223
224 if (png_ptr->buffer_size < 8)
225 {
226 png_push_save_buffer(png_ptr);
227 return;
228 }
229
230 png_push_fill_buffer(png_ptr, chunk_length, 4);
231 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
232 png_reset_crc(png_ptr);
233 png_crc_read(png_ptr, chunk_tag, 4);
234 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
235 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
236 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
237 }
238
239 chunk_name = png_ptr->chunk_name;
240
241 if (chunk_name == png_IDAT)
242 {
243 /* This is here above the if/else case statement below because if the
244 * unknown handling marks 'IDAT' as unknown then the IDAT handling case is
245 * completely skipped.
246 *
247 * TODO: there must be a better way of doing this.
248 */
249 if (png_ptr->mode & PNG_AFTER_IDAT)
250 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
251 }
252
253 if (chunk_name == png_IHDR)
254 {
255 if (png_ptr->push_length != 13)
256 png_error(png_ptr, "Invalid IHDR length");
257
258 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
259 {
260 png_push_save_buffer(png_ptr);
261 return;
262 }
263
264 png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
265 }
266
267 else if (chunk_name == png_IEND)
268 {
269 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
270 {
271 png_push_save_buffer(png_ptr);
272 return;
273 }
274
275 png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
276
277 png_ptr->process_mode = PNG_READ_DONE_MODE;
278 png_push_have_end(png_ptr, info_ptr);
279 }
280
281#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
282 else if (png_chunk_unknown_handling(png_ptr, chunk_name))
283 {
284 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
285 {
286 png_push_save_buffer(png_ptr);
287 return;
288 }
289
290 if (chunk_name == png_IDAT)
291 png_ptr->mode |= PNG_HAVE_IDAT;
292
293 png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
294
295 if (chunk_name == png_PLTE)
296 png_ptr->mode |= PNG_HAVE_PLTE;
297
298 else if (chunk_name == png_IDAT)
299 {
300 if (!(png_ptr->mode & PNG_HAVE_IHDR))
301 png_error(png_ptr, "Missing IHDR before IDAT");
302
303 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
304 !(png_ptr->mode & PNG_HAVE_PLTE))
305 png_error(png_ptr, "Missing PLTE before IDAT");
306 }
307 }
308
309#endif
310 else if (chunk_name == png_PLTE)
311 {
312 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
313 {
314 png_push_save_buffer(png_ptr);
315 return;
316 }
317 png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
318 }
319
320 else if (chunk_name == png_IDAT)
321 {
322 /* If we reach an IDAT chunk, this means we have read all of the
323 * header chunks, and we can start reading the image (or if this
324 * is called after the image has been read - we have an error).
325 */
326
327 if (!(png_ptr->mode & PNG_HAVE_IHDR))
328 png_error(png_ptr, "Missing IHDR before IDAT");
329
330 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
331 !(png_ptr->mode & PNG_HAVE_PLTE))
332 png_error(png_ptr, "Missing PLTE before IDAT");
333
334 if (png_ptr->mode & PNG_HAVE_IDAT)
335 {
336 if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
337 if (png_ptr->push_length == 0)
338 return;
339
340 if (png_ptr->mode & PNG_AFTER_IDAT)
341 png_benign_error(png_ptr, "Too many IDATs found");
342 }
343
344 png_ptr->idat_size = png_ptr->push_length;
345 png_ptr->mode |= PNG_HAVE_IDAT;
346 png_ptr->process_mode = PNG_READ_IDAT_MODE;
347 png_push_have_info(png_ptr, info_ptr);
348 png_ptr->zstream.avail_out =
349 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
350 png_ptr->iwidth) + 1;
351 png_ptr->zstream.next_out = png_ptr->row_buf;
352 return;
353 }
354
355#ifdef PNG_READ_gAMA_SUPPORTED
356 else if (png_ptr->chunk_name == png_gAMA)
357 {
358 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
359 {
360 png_push_save_buffer(png_ptr);
361 return;
362 }
363
364 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
365 }
366
367#endif
368#ifdef PNG_READ_sBIT_SUPPORTED
369 else if (png_ptr->chunk_name == png_sBIT)
370 {
371 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
372 {
373 png_push_save_buffer(png_ptr);
374 return;
375 }
376
377 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
378 }
379
380#endif
381#ifdef PNG_READ_cHRM_SUPPORTED
382 else if (png_ptr->chunk_name == png_cHRM)
383 {
384 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
385 {
386 png_push_save_buffer(png_ptr);
387 return;
388 }
389
390 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
391 }
392
393#endif
394#ifdef PNG_READ_sRGB_SUPPORTED
395 else if (chunk_name == png_sRGB)
396 {
397 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
398 {
399 png_push_save_buffer(png_ptr);
400 return;
401 }
402
403 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
404 }
405
406#endif
407#ifdef PNG_READ_iCCP_SUPPORTED
408 else if (png_ptr->chunk_name == png_iCCP)
409 {
410 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
411 {
412 png_push_save_buffer(png_ptr);
413 return;
414 }
415
416 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
417 }
418
419#endif
420#ifdef PNG_READ_sPLT_SUPPORTED
421 else if (chunk_name == png_sPLT)
422 {
423 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
424 {
425 png_push_save_buffer(png_ptr);
426 return;
427 }
428
429 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
430 }
431
432#endif
433#ifdef PNG_READ_tRNS_SUPPORTED
434 else if (chunk_name == png_tRNS)
435 {
436 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
437 {
438 png_push_save_buffer(png_ptr);
439 return;
440 }
441
442 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
443 }
444
445#endif
446#ifdef PNG_READ_bKGD_SUPPORTED
447 else if (chunk_name == png_bKGD)
448 {
449 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
450 {
451 png_push_save_buffer(png_ptr);
452 return;
453 }
454
455 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
456 }
457
458#endif
459#ifdef PNG_READ_hIST_SUPPORTED
460 else if (chunk_name == png_hIST)
461 {
462 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
463 {
464 png_push_save_buffer(png_ptr);
465 return;
466 }
467
468 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
469 }
470
471#endif
472#ifdef PNG_READ_pHYs_SUPPORTED
473 else if (chunk_name == png_pHYs)
474 {
475 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
476 {
477 png_push_save_buffer(png_ptr);
478 return;
479 }
480
481 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
482 }
483
484#endif
485#ifdef PNG_READ_oFFs_SUPPORTED
486 else if (chunk_name == png_oFFs)
487 {
488 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
489 {
490 png_push_save_buffer(png_ptr);
491 return;
492 }
493
494 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
495 }
496#endif
497
498#ifdef PNG_READ_pCAL_SUPPORTED
499 else if (chunk_name == png_pCAL)
500 {
501 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
502 {
503 png_push_save_buffer(png_ptr);
504 return;
505 }
506
507 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
508 }
509
510#endif
511#ifdef PNG_READ_sCAL_SUPPORTED
512 else if (chunk_name == png_sCAL)
513 {
514 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
515 {
516 png_push_save_buffer(png_ptr);
517 return;
518 }
519
520 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
521 }
522
523#endif
524#ifdef PNG_READ_tIME_SUPPORTED
525 else if (chunk_name == png_tIME)
526 {
527 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
528 {
529 png_push_save_buffer(png_ptr);
530 return;
531 }
532
533 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
534 }
535
536#endif
537#ifdef PNG_READ_tEXt_SUPPORTED
538 else if (chunk_name == png_tEXt)
539 {
540 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
541 {
542 png_push_save_buffer(png_ptr);
543 return;
544 }
545
546 png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
547 }
548
549#endif
550#ifdef PNG_READ_zTXt_SUPPORTED
551 else if (chunk_name == png_zTXt)
552 {
553 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
554 {
555 png_push_save_buffer(png_ptr);
556 return;
557 }
558
559 png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
560 }
561
562#endif
563#ifdef PNG_READ_iTXt_SUPPORTED
564 else if (chunk_name == png_iTXt)
565 {
566 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
567 {
568 png_push_save_buffer(png_ptr);
569 return;
570 }
571
572 png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
573 }
574
575#endif
576 else
577 {
578 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
579 {
580 png_push_save_buffer(png_ptr);
581 return;
582 }
583 png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
584 }
585
586 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
587}
588
589void /* PRIVATE */
590png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
591{
592 png_ptr->process_mode = PNG_SKIP_MODE;
593 png_ptr->skip_length = skip;
594}
595
596void /* PRIVATE */
597png_push_crc_finish(png_structp png_ptr)
598{
599 if (png_ptr->skip_length && png_ptr->save_buffer_size)
600 {
601 png_size_t save_size = png_ptr->save_buffer_size;
602 png_uint_32 skip_length = png_ptr->skip_length;
603
604 /* We want the smaller of 'skip_length' and 'save_buffer_size', but
605 * they are of different types and we don't know which variable has the
606 * fewest bits. Carefully select the smaller and cast it to the type of
607 * the larger - this cannot overflow. Do not cast in the following test
608 * - it will break on either 16 or 64 bit platforms.
609 */
610 if (skip_length < save_size)
611 save_size = (png_size_t)skip_length;
612
613 else
614 skip_length = (png_uint_32)save_size;
615
616 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
617
618 png_ptr->skip_length -= skip_length;
619 png_ptr->buffer_size -= save_size;
620 png_ptr->save_buffer_size -= save_size;
621 png_ptr->save_buffer_ptr += save_size;
622 }
623 if (png_ptr->skip_length && png_ptr->current_buffer_size)
624 {
625 png_size_t save_size = png_ptr->current_buffer_size;
626 png_uint_32 skip_length = png_ptr->skip_length;
627
628 /* We want the smaller of 'skip_length' and 'current_buffer_size', here,
629 * the same problem exists as above and the same solution.
630 */
631 if (skip_length < save_size)
632 save_size = (png_size_t)skip_length;
633
634 else
635 skip_length = (png_uint_32)save_size;
636
637 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
638
639 png_ptr->skip_length -= skip_length;
640 png_ptr->buffer_size -= save_size;
641 png_ptr->current_buffer_size -= save_size;
642 png_ptr->current_buffer_ptr += save_size;
643 }
644 if (!png_ptr->skip_length)
645 {
646 if (png_ptr->buffer_size < 4)
647 {
648 png_push_save_buffer(png_ptr);
649 return;
650 }
651
652 png_crc_finish(png_ptr, 0);
653 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
654 }
655}
656
657void PNGCBAPI
658png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
659{
660 png_bytep ptr;
661
662 if (png_ptr == NULL)
663 return;
664
665 ptr = buffer;
666 if (png_ptr->save_buffer_size)
667 {
668 png_size_t save_size;
669
670 if (length < png_ptr->save_buffer_size)
671 save_size = length;
672
673 else
674 save_size = png_ptr->save_buffer_size;
675
676 png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
677 length -= save_size;
678 ptr += save_size;
679 png_ptr->buffer_size -= save_size;
680 png_ptr->save_buffer_size -= save_size;
681 png_ptr->save_buffer_ptr += save_size;
682 }
683 if (length && png_ptr->current_buffer_size)
684 {
685 png_size_t save_size;
686
687 if (length < png_ptr->current_buffer_size)
688 save_size = length;
689
690 else
691 save_size = png_ptr->current_buffer_size;
692
693 png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
694 png_ptr->buffer_size -= save_size;
695 png_ptr->current_buffer_size -= save_size;
696 png_ptr->current_buffer_ptr += save_size;
697 }
698}
699
700void /* PRIVATE */
701png_push_save_buffer(png_structp png_ptr)
702{
703 if (png_ptr->save_buffer_size)
704 {
705 if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
706 {
707 png_size_t i, istop;
708 png_bytep sp;
709 png_bytep dp;
710
711 istop = png_ptr->save_buffer_size;
712 for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
713 i < istop; i++, sp++, dp++)
714 {
715 *dp = *sp;
716 }
717 }
718 }
719 if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
720 png_ptr->save_buffer_max)
721 {
722 png_size_t new_max;
723 png_bytep old_buffer;
724
725 if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
726 (png_ptr->current_buffer_size + 256))
727 {
728 png_error(png_ptr, "Potential overflow of save_buffer");
729 }
730
731 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
732 old_buffer = png_ptr->save_buffer;
733 png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, new_max);
734
735 if (png_ptr->save_buffer == NULL)
736 {
737 png_free(png_ptr, old_buffer);
738 png_error(png_ptr, "Insufficient memory for save_buffer");
739 }
740
741 png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
742 png_free(png_ptr, old_buffer);
743 png_ptr->save_buffer_max = new_max;
744 }
745 if (png_ptr->current_buffer_size)
746 {
747 png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
748 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
749 png_ptr->save_buffer_size += png_ptr->current_buffer_size;
750 png_ptr->current_buffer_size = 0;
751 }
752 png_ptr->save_buffer_ptr = png_ptr->save_buffer;
753 png_ptr->buffer_size = 0;
754}
755
756void /* PRIVATE */
757png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
758 png_size_t buffer_length)
759{
760 png_ptr->current_buffer = buffer;
761 png_ptr->current_buffer_size = buffer_length;
762 png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
763 png_ptr->current_buffer_ptr = png_ptr->current_buffer;
764}
765
766void /* PRIVATE */
767png_push_read_IDAT(png_structp png_ptr)
768{
769 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
770 {
771 png_byte chunk_length[4];
772 png_byte chunk_tag[4];
773
774 /* TODO: this code can be commoned up with the same code in push_read */
775 if (png_ptr->buffer_size < 8)
776 {
777 png_push_save_buffer(png_ptr);
778 return;
779 }
780
781 png_push_fill_buffer(png_ptr, chunk_length, 4);
782 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
783 png_reset_crc(png_ptr);
784 png_crc_read(png_ptr, chunk_tag, 4);
785 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
786 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
787
788 if (png_ptr->chunk_name != png_IDAT)
789 {
790 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
791
792 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
793 png_error(png_ptr, "Not enough compressed data");
794
795 return;
796 }
797
798 png_ptr->idat_size = png_ptr->push_length;
799 }
800
801 if (png_ptr->idat_size && png_ptr->save_buffer_size)
802 {
803 png_size_t save_size = png_ptr->save_buffer_size;
804 png_uint_32 idat_size = png_ptr->idat_size;
805
806 /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
807 * are of different types and we don't know which variable has the fewest
808 * bits. Carefully select the smaller and cast it to the type of the
809 * larger - this cannot overflow. Do not cast in the following test - it
810 * will break on either 16 or 64 bit platforms.
811 */
812 if (idat_size < save_size)
813 save_size = (png_size_t)idat_size;
814
815 else
816 idat_size = (png_uint_32)save_size;
817
818 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
819
820 png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
821
822 png_ptr->idat_size -= idat_size;
823 png_ptr->buffer_size -= save_size;
824 png_ptr->save_buffer_size -= save_size;
825 png_ptr->save_buffer_ptr += save_size;
826 }
827
828 if (png_ptr->idat_size && png_ptr->current_buffer_size)
829 {
830 png_size_t save_size = png_ptr->current_buffer_size;
831 png_uint_32 idat_size = png_ptr->idat_size;
832
833 /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
834 * are of different types and we don't know which variable has the fewest
835 * bits. Carefully select the smaller and cast it to the type of the
836 * larger - this cannot overflow.
837 */
838 if (idat_size < save_size)
839 save_size = (png_size_t)idat_size;
840
841 else
842 idat_size = (png_uint_32)save_size;
843
844 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
845
846 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
847
848 png_ptr->idat_size -= idat_size;
849 png_ptr->buffer_size -= save_size;
850 png_ptr->current_buffer_size -= save_size;
851 png_ptr->current_buffer_ptr += save_size;
852 }
853 if (!png_ptr->idat_size)
854 {
855 if (png_ptr->buffer_size < 4)
856 {
857 png_push_save_buffer(png_ptr);
858 return;
859 }
860
861 png_crc_finish(png_ptr, 0);
862 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
863 png_ptr->mode |= PNG_AFTER_IDAT;
864 }
865}
866
867void /* PRIVATE */
868png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
869 png_size_t buffer_length)
870{
871 /* The caller checks for a non-zero buffer length. */
872 if (!(buffer_length > 0) || buffer == NULL)
873 png_error(png_ptr, "No IDAT data (internal error)");
874
875 /* This routine must process all the data it has been given
876 * before returning, calling the row callback as required to
877 * handle the uncompressed results.
878 */
879 png_ptr->zstream.next_in = buffer;
880 png_ptr->zstream.avail_in = (uInt)buffer_length;
881
882 /* Keep going until the decompressed data is all processed
883 * or the stream marked as finished.
884 */
885 while (png_ptr->zstream.avail_in > 0 &&
886 !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
887 {
888 int ret;
889
890 /* We have data for zlib, but we must check that zlib
891 * has someplace to put the results. It doesn't matter
892 * if we don't expect any results -- it may be the input
893 * data is just the LZ end code.
894 */
895 if (!(png_ptr->zstream.avail_out > 0))
896 {
897 png_ptr->zstream.avail_out =
898 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
899 png_ptr->iwidth) + 1;
900
901 png_ptr->zstream.next_out = png_ptr->row_buf;
902 }
903
904 /* Using Z_SYNC_FLUSH here means that an unterminated
905 * LZ stream (a stream with a missing end code) can still
906 * be handled, otherwise (Z_NO_FLUSH) a future zlib
907 * implementation might defer output and therefore
908 * change the current behavior (see comments in inflate.c
909 * for why this doesn't happen at present with zlib 1.2.5).
910 */
911 ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
912
913 /* Check for any failure before proceeding. */
914 if (ret != Z_OK && ret != Z_STREAM_END)
915 {
916 /* Terminate the decompression. */
917 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
918
919 /* This may be a truncated stream (missing or
920 * damaged end code). Treat that as a warning.
921 */
922 if (png_ptr->row_number >= png_ptr->num_rows ||
923 png_ptr->pass > 6)
924 png_warning(png_ptr, "Truncated compressed data in IDAT");
925
926 else
927 png_error(png_ptr, "Decompression error in IDAT");
928
929 /* Skip the check on unprocessed input */
930 return;
931 }
932
933 /* Did inflate output any data? */
934 if (png_ptr->zstream.next_out != png_ptr->row_buf)
935 {
936 /* Is this unexpected data after the last row?
937 * If it is, artificially terminate the LZ output
938 * here.
939 */
940 if (png_ptr->row_number >= png_ptr->num_rows ||
941 png_ptr->pass > 6)
942 {
943 /* Extra data. */
944 png_warning(png_ptr, "Extra compressed data in IDAT");
945 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
946
947 /* Do no more processing; skip the unprocessed
948 * input check below.
949 */
950 return;
951 }
952
953 /* Do we have a complete row? */
954 if (png_ptr->zstream.avail_out == 0)
955 png_push_process_row(png_ptr);
956 }
957
958 /* And check for the end of the stream. */
959 if (ret == Z_STREAM_END)
960 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
961 }
962
963 /* All the data should have been processed, if anything
964 * is left at this point we have bytes of IDAT data
965 * after the zlib end code.
966 */
967 if (png_ptr->zstream.avail_in > 0)
968 png_warning(png_ptr, "Extra compression data in IDAT");
969}
970
971void /* PRIVATE */
972png_push_process_row(png_structp png_ptr)
973{
974 /* 1.5.6: row_info moved out of png_struct to a local here. */
975 png_row_info row_info;
976
977 row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */
978 row_info.color_type = png_ptr->color_type;
979 row_info.bit_depth = png_ptr->bit_depth;
980 row_info.channels = png_ptr->channels;
981 row_info.pixel_depth = png_ptr->pixel_depth;
982 row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
983
984 if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
985 {
986 if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
987 png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
988 png_ptr->prev_row + 1, png_ptr->row_buf[0]);
989 else
990 png_error(png_ptr, "bad adaptive filter value");
991 }
992
993 /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before
994 * 1.5.6, while the buffer really is this big in current versions of libpng
995 * it may not be in the future, so this was changed just to copy the
996 * interlaced row count:
997 */
998 png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
999
1000#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1001 if (png_ptr->transformations)
1002 png_do_read_transformations(png_ptr, &row_info);
1003#endif
1004
1005 /* The transformed pixel depth should match the depth now in row_info. */
1006 if (png_ptr->transformed_pixel_depth == 0)
1007 {
1008 png_ptr->transformed_pixel_depth = row_info.pixel_depth;
1009 if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)
1010 png_error(png_ptr, "progressive row overflow");
1011 }
1012
1013 else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)
1014 png_error(png_ptr, "internal progressive row size calculation error");
1015
1016
1017#ifdef PNG_READ_INTERLACING_SUPPORTED
1018 /* Blow up interlaced rows to full size */
1019 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
1020 {
1021 if (png_ptr->pass < 6)
1022 png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
1023 png_ptr->transformations);
1024
1025 switch (png_ptr->pass)
1026 {
1027 case 0:
1028 {
1029 int i;
1030 for (i = 0; i < 8 && png_ptr->pass == 0; i++)
1031 {
1032 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1033 png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */
1034 }
1035
1036 if (png_ptr->pass == 2) /* Pass 1 might be empty */
1037 {
1038 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
1039 {
1040 png_push_have_row(png_ptr, NULL);
1041 png_read_push_finish_row(png_ptr);
1042 }
1043 }
1044
1045 if (png_ptr->pass == 4 && png_ptr->height <= 4)
1046 {
1047 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1048 {
1049 png_push_have_row(png_ptr, NULL);
1050 png_read_push_finish_row(png_ptr);
1051 }
1052 }
1053
1054 if (png_ptr->pass == 6 && png_ptr->height <= 4)
1055 {
1056 png_push_have_row(png_ptr, NULL);
1057 png_read_push_finish_row(png_ptr);
1058 }
1059
1060 break;
1061 }
1062
1063 case 1:
1064 {
1065 int i;
1066 for (i = 0; i < 8 && png_ptr->pass == 1; i++)
1067 {
1068 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1069 png_read_push_finish_row(png_ptr);
1070 }
1071
1072 if (png_ptr->pass == 2) /* Skip top 4 generated rows */
1073 {
1074 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
1075 {
1076 png_push_have_row(png_ptr, NULL);
1077 png_read_push_finish_row(png_ptr);
1078 }
1079 }
1080
1081 break;
1082 }
1083
1084 case 2:
1085 {
1086 int i;
1087
1088 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
1089 {
1090 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1091 png_read_push_finish_row(png_ptr);
1092 }
1093
1094 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
1095 {
1096 png_push_have_row(png_ptr, NULL);
1097 png_read_push_finish_row(png_ptr);
1098 }
1099
1100 if (png_ptr->pass == 4) /* Pass 3 might be empty */
1101 {
1102 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1103 {
1104 png_push_have_row(png_ptr, NULL);
1105 png_read_push_finish_row(png_ptr);
1106 }
1107 }
1108
1109 break;
1110 }
1111
1112 case 3:
1113 {
1114 int i;
1115
1116 for (i = 0; i < 4 && png_ptr->pass == 3; i++)
1117 {
1118 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1119 png_read_push_finish_row(png_ptr);
1120 }
1121
1122 if (png_ptr->pass == 4) /* Skip top two generated rows */
1123 {
1124 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1125 {
1126 png_push_have_row(png_ptr, NULL);
1127 png_read_push_finish_row(png_ptr);
1128 }
1129 }
1130
1131 break;
1132 }
1133
1134 case 4:
1135 {
1136 int i;
1137
1138 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1139 {
1140 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1141 png_read_push_finish_row(png_ptr);
1142 }
1143
1144 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
1145 {
1146 png_push_have_row(png_ptr, NULL);
1147 png_read_push_finish_row(png_ptr);
1148 }
1149
1150 if (png_ptr->pass == 6) /* Pass 5 might be empty */
1151 {
1152 png_push_have_row(png_ptr, NULL);
1153 png_read_push_finish_row(png_ptr);
1154 }
1155
1156 break;
1157 }
1158
1159 case 5:
1160 {
1161 int i;
1162
1163 for (i = 0; i < 2 && png_ptr->pass == 5; i++)
1164 {
1165 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1166 png_read_push_finish_row(png_ptr);
1167 }
1168
1169 if (png_ptr->pass == 6) /* Skip top generated row */
1170 {
1171 png_push_have_row(png_ptr, NULL);
1172 png_read_push_finish_row(png_ptr);
1173 }
1174
1175 break;
1176 }
1177
1178 default:
1179 case 6:
1180 {
1181 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1182 png_read_push_finish_row(png_ptr);
1183
1184 if (png_ptr->pass != 6)
1185 break;
1186
1187 png_push_have_row(png_ptr, NULL);
1188 png_read_push_finish_row(png_ptr);
1189 }
1190 }
1191 }
1192 else
1193#endif
1194 {
1195 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
1196 png_read_push_finish_row(png_ptr);
1197 }
1198}
1199
1200void /* PRIVATE */
1201png_read_push_finish_row(png_structp png_ptr)
1202{
1203#ifdef PNG_READ_INTERLACING_SUPPORTED
1204 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1205
1206 /* Start of interlace block */
1207 static PNG_CONST png_byte FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
1208
1209 /* Offset to next interlace block */
1210 static PNG_CONST png_byte FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
1211
1212 /* Start of interlace block in the y direction */
1213 static PNG_CONST png_byte FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
1214
1215 /* Offset to next interlace block in the y direction */
1216 static PNG_CONST png_byte FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
1217
1218 /* Height of interlace block. This is not currently used - if you need
1219 * it, uncomment it here and in png.h
1220 static PNG_CONST png_byte FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
1221 */
1222#endif
1223
1224 png_ptr->row_number++;
1225 if (png_ptr->row_number < png_ptr->num_rows)
1226 return;
1227
1228#ifdef PNG_READ_INTERLACING_SUPPORTED
1229 if (png_ptr->interlaced)
1230 {
1231 png_ptr->row_number = 0;
1232 png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
1233
1234 do
1235 {
1236 png_ptr->pass++;
1237 if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
1238 (png_ptr->pass == 3 && png_ptr->width < 3) ||
1239 (png_ptr->pass == 5 && png_ptr->width < 2))
1240 png_ptr->pass++;
1241
1242 if (png_ptr->pass > 7)
1243 png_ptr->pass--;
1244
1245 if (png_ptr->pass >= 7)
1246 break;
1247
1248 png_ptr->iwidth = (png_ptr->width +
1249 png_pass_inc[png_ptr->pass] - 1 -
1250 png_pass_start[png_ptr->pass]) /
1251 png_pass_inc[png_ptr->pass];
1252
1253 if (png_ptr->transformations & PNG_INTERLACE)
1254 break;
1255
1256 png_ptr->num_rows = (png_ptr->height +
1257 png_pass_yinc[png_ptr->pass] - 1 -
1258 png_pass_ystart[png_ptr->pass]) /
1259 png_pass_yinc[png_ptr->pass];
1260
1261 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
1262 }
1263#endif /* PNG_READ_INTERLACING_SUPPORTED */
1264}
1265
1266#ifdef PNG_READ_tEXt_SUPPORTED
1267void /* PRIVATE */
1268png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1269 length)
1270{
1271 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1272 {
1273 PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
1274 png_error(png_ptr, "Out of place tEXt");
1275 /* NOT REACHED */
1276 }
1277
1278#ifdef PNG_MAX_MALLOC_64K
1279 png_ptr->skip_length = 0; /* This may not be necessary */
1280
1281 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
1282 {
1283 png_warning(png_ptr, "tEXt chunk too large to fit in memory");
1284 png_ptr->skip_length = length - (png_uint_32)65535L;
1285 length = (png_uint_32)65535L;
1286 }
1287#endif
1288
1289 png_ptr->current_text = (png_charp)png_malloc(png_ptr, length + 1);
1290 png_ptr->current_text[length] = '\0';
1291 png_ptr->current_text_ptr = png_ptr->current_text;
1292 png_ptr->current_text_size = (png_size_t)length;
1293 png_ptr->current_text_left = (png_size_t)length;
1294 png_ptr->process_mode = PNG_READ_tEXt_MODE;
1295}
1296
1297void /* PRIVATE */
1298png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
1299{
1300 if (png_ptr->buffer_size && png_ptr->current_text_left)
1301 {
1302 png_size_t text_size;
1303
1304 if (png_ptr->buffer_size < png_ptr->current_text_left)
1305 text_size = png_ptr->buffer_size;
1306
1307 else
1308 text_size = png_ptr->current_text_left;
1309
1310 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1311 png_ptr->current_text_left -= text_size;
1312 png_ptr->current_text_ptr += text_size;
1313 }
1314 if (!(png_ptr->current_text_left))
1315 {
1316 png_textp text_ptr;
1317 png_charp text;
1318 png_charp key;
1319 int ret;
1320
1321 if (png_ptr->buffer_size < 4)
1322 {
1323 png_push_save_buffer(png_ptr);
1324 return;
1325 }
1326
1327 png_push_crc_finish(png_ptr);
1328
1329#ifdef PNG_MAX_MALLOC_64K
1330 if (png_ptr->skip_length)
1331 return;
1332#endif
1333
1334 key = png_ptr->current_text;
1335
1336 for (text = key; *text; text++)
1337 /* Empty loop */ ;
1338
1339 if (text < key + png_ptr->current_text_size)
1340 text++;
1341
1342 text_ptr = (png_textp)png_malloc(png_ptr, png_sizeof(png_text));
1343 text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
1344 text_ptr->key = key;
1345 text_ptr->itxt_length = 0;
1346 text_ptr->lang = NULL;
1347 text_ptr->lang_key = NULL;
1348 text_ptr->text = text;
1349
1350 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1351
1352 png_free(png_ptr, key);
1353 png_free(png_ptr, text_ptr);
1354 png_ptr->current_text = NULL;
1355
1356 if (ret)
1357 png_warning(png_ptr, "Insufficient memory to store text chunk");
1358 }
1359}
1360#endif
1361
1362#ifdef PNG_READ_zTXt_SUPPORTED
1363void /* PRIVATE */
1364png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1365 length)
1366{
1367 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1368 {
1369 PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
1370 png_error(png_ptr, "Out of place zTXt");
1371 /* NOT REACHED */
1372 }
1373
1374#ifdef PNG_MAX_MALLOC_64K
1375 /* We can't handle zTXt chunks > 64K, since we don't have enough space
1376 * to be able to store the uncompressed data. Actually, the threshold
1377 * is probably around 32K, but it isn't as definite as 64K is.
1378 */
1379 if (length > (png_uint_32)65535L)
1380 {
1381 png_warning(png_ptr, "zTXt chunk too large to fit in memory");
1382 png_push_crc_skip(png_ptr, length);
1383 return;
1384 }
1385#endif
1386
1387 png_ptr->current_text = (png_charp)png_malloc(png_ptr, length + 1);
1388 png_ptr->current_text[length] = '\0';
1389 png_ptr->current_text_ptr = png_ptr->current_text;
1390 png_ptr->current_text_size = (png_size_t)length;
1391 png_ptr->current_text_left = (png_size_t)length;
1392 png_ptr->process_mode = PNG_READ_zTXt_MODE;
1393}
1394
1395void /* PRIVATE */
1396png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
1397{
1398 if (png_ptr->buffer_size && png_ptr->current_text_left)
1399 {
1400 png_size_t text_size;
1401
1402 if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
1403 text_size = png_ptr->buffer_size;
1404
1405 else
1406 text_size = png_ptr->current_text_left;
1407
1408 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1409 png_ptr->current_text_left -= text_size;
1410 png_ptr->current_text_ptr += text_size;
1411 }
1412 if (!(png_ptr->current_text_left))
1413 {
1414 png_textp text_ptr;
1415 png_charp text;
1416 png_charp key;
1417 int ret;
1418 png_size_t text_size, key_size;
1419
1420 if (png_ptr->buffer_size < 4)
1421 {
1422 png_push_save_buffer(png_ptr);
1423 return;
1424 }
1425
1426 png_push_crc_finish(png_ptr);
1427
1428 key = png_ptr->current_text;
1429
1430 for (text = key; *text; text++)
1431 /* Empty loop */ ;
1432
1433 /* zTXt can't have zero text */
1434 if (text >= key + png_ptr->current_text_size)
1435 {
1436 png_ptr->current_text = NULL;
1437 png_free(png_ptr, key);
1438 return;
1439 }
1440
1441 text++;
1442
1443 if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
1444 {
1445 png_ptr->current_text = NULL;
1446 png_free(png_ptr, key);
1447 return;
1448 }
1449
1450 text++;
1451
1452 png_ptr->zstream.next_in = (png_bytep)text;
1453 png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
1454 (text - key));
1455 png_ptr->zstream.next_out = png_ptr->zbuf;
1456 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1457
1458 key_size = text - key;
1459 text_size = 0;
1460 text = NULL;
1461 ret = Z_STREAM_END;
1462
1463 while (png_ptr->zstream.avail_in)
1464 {
1465 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
1466 if (ret != Z_OK && ret != Z_STREAM_END)
1467 {
1468 inflateReset(&png_ptr->zstream);
1469 png_ptr->zstream.avail_in = 0;
1470 png_ptr->current_text = NULL;
1471 png_free(png_ptr, key);
1472 png_free(png_ptr, text);
1473 return;
1474 }
1475
1476 if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
1477 {
1478 if (text == NULL)
1479 {
1480 text = (png_charp)png_malloc(png_ptr,
1481 (png_ptr->zbuf_size
1482 - png_ptr->zstream.avail_out + key_size + 1));
1483
1484 png_memcpy(text + key_size, png_ptr->zbuf,
1485 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1486
1487 png_memcpy(text, key, key_size);
1488
1489 text_size = key_size + png_ptr->zbuf_size -
1490 png_ptr->zstream.avail_out;
1491
1492 *(text + text_size) = '\0';
1493 }
1494
1495 else
1496 {
1497 png_charp tmp;
1498
1499 tmp = text;
1500 text = (png_charp)png_malloc(png_ptr, text_size +
1501 (png_ptr->zbuf_size
1502 - png_ptr->zstream.avail_out + 1));
1503
1504 png_memcpy(text, tmp, text_size);
1505 png_free(png_ptr, tmp);
1506
1507 png_memcpy(text + text_size, png_ptr->zbuf,
1508 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
1509
1510 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
1511 *(text + text_size) = '\0';
1512 }
1513
1514 if (ret != Z_STREAM_END)
1515 {
1516 png_ptr->zstream.next_out = png_ptr->zbuf;
1517 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1518 }
1519 }
1520 else
1521 {
1522 break;
1523 }
1524
1525 if (ret == Z_STREAM_END)
1526 break;
1527 }
1528
1529 inflateReset(&png_ptr->zstream);
1530 png_ptr->zstream.avail_in = 0;
1531
1532 if (ret != Z_STREAM_END)
1533 {
1534 png_ptr->current_text = NULL;
1535 png_free(png_ptr, key);
1536 png_free(png_ptr, text);
1537 return;
1538 }
1539
1540 png_ptr->current_text = NULL;
1541 png_free(png_ptr, key);
1542 key = text;
1543 text += key_size;
1544
1545 text_ptr = (png_textp)png_malloc(png_ptr,
1546 png_sizeof(png_text));
1547 text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
1548 text_ptr->key = key;
1549 text_ptr->itxt_length = 0;
1550 text_ptr->lang = NULL;
1551 text_ptr->lang_key = NULL;
1552 text_ptr->text = text;
1553
1554 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1555
1556 png_free(png_ptr, key);
1557 png_free(png_ptr, text_ptr);
1558
1559 if (ret)
1560 png_warning(png_ptr, "Insufficient memory to store text chunk");
1561 }
1562}
1563#endif
1564
1565#ifdef PNG_READ_iTXt_SUPPORTED
1566void /* PRIVATE */
1567png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
1568 length)
1569{
1570 if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
1571 {
1572 PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
1573 png_error(png_ptr, "Out of place iTXt");
1574 /* NOT REACHED */
1575 }
1576
1577#ifdef PNG_MAX_MALLOC_64K
1578 png_ptr->skip_length = 0; /* This may not be necessary */
1579
1580 if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
1581 {
1582 png_warning(png_ptr, "iTXt chunk too large to fit in memory");
1583 png_ptr->skip_length = length - (png_uint_32)65535L;
1584 length = (png_uint_32)65535L;
1585 }
1586#endif
1587
1588 png_ptr->current_text = (png_charp)png_malloc(png_ptr, length + 1);
1589 png_ptr->current_text[length] = '\0';
1590 png_ptr->current_text_ptr = png_ptr->current_text;
1591 png_ptr->current_text_size = (png_size_t)length;
1592 png_ptr->current_text_left = (png_size_t)length;
1593 png_ptr->process_mode = PNG_READ_iTXt_MODE;
1594}
1595
1596void /* PRIVATE */
1597png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
1598{
1599
1600 if (png_ptr->buffer_size && png_ptr->current_text_left)
1601 {
1602 png_size_t text_size;
1603
1604 if (png_ptr->buffer_size < png_ptr->current_text_left)
1605 text_size = png_ptr->buffer_size;
1606
1607 else
1608 text_size = png_ptr->current_text_left;
1609
1610 png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
1611 png_ptr->current_text_left -= text_size;
1612 png_ptr->current_text_ptr += text_size;
1613 }
1614
1615 if (!(png_ptr->current_text_left))
1616 {
1617 png_textp text_ptr;
1618 png_charp key;
1619 int comp_flag;
1620 png_charp lang;
1621 png_charp lang_key;
1622 png_charp text;
1623 int ret;
1624
1625 if (png_ptr->buffer_size < 4)
1626 {
1627 png_push_save_buffer(png_ptr);
1628 return;
1629 }
1630
1631 png_push_crc_finish(png_ptr);
1632
1633#ifdef PNG_MAX_MALLOC_64K
1634 if (png_ptr->skip_length)
1635 return;
1636#endif
1637
1638 key = png_ptr->current_text;
1639
1640 for (lang = key; *lang; lang++)
1641 /* Empty loop */ ;
1642
1643 if (lang < key + png_ptr->current_text_size - 3)
1644 lang++;
1645
1646 comp_flag = *lang++;
1647 lang++; /* Skip comp_type, always zero */
1648
1649 for (lang_key = lang; *lang_key; lang_key++)
1650 /* Empty loop */ ;
1651
1652 lang_key++; /* Skip NUL separator */
1653
1654 text=lang_key;
1655
1656 if (lang_key < key + png_ptr->current_text_size - 1)
1657 {
1658 for (; *text; text++)
1659 /* Empty loop */ ;
1660 }
1661
1662 if (text < key + png_ptr->current_text_size)
1663 text++;
1664
1665 text_ptr = (png_textp)png_malloc(png_ptr,
1666 png_sizeof(png_text));
1667
1668 text_ptr->compression = comp_flag + 2;
1669 text_ptr->key = key;
1670 text_ptr->lang = lang;
1671 text_ptr->lang_key = lang_key;
1672 text_ptr->text = text;
1673 text_ptr->text_length = 0;
1674 text_ptr->itxt_length = png_strlen(text);
1675
1676 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
1677
1678 png_ptr->current_text = NULL;
1679
1680 png_free(png_ptr, text_ptr);
1681 if (ret)
1682 png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
1683 }
1684}
1685#endif
1686
1687/* This function is called when we haven't found a handler for this
1688 * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
1689 * name or a critical chunk), the chunk is (currently) silently ignored.
1690 */
1691void /* PRIVATE */
1692png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
1693 length)
1694{
1695 png_uint_32 skip = 0;
1696 png_uint_32 chunk_name = png_ptr->chunk_name;
1697
1698 if (PNG_CHUNK_CRITICAL(chunk_name))
1699 {
1700#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1701 if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
1702 PNG_HANDLE_CHUNK_ALWAYS
1703#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1704 && png_ptr->read_user_chunk_fn == NULL
1705#endif
1706 )
1707#endif
1708 png_chunk_error(png_ptr, "unknown critical chunk");
1709
1710 PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
1711 }
1712
1713#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1714 /* TODO: the code below is apparently just using the
1715 * png_struct::unknown_chunk member as a temporarily variable, it should be
1716 * possible to eliminate both it and the temporary buffer.
1717 */
1718 if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
1719 {
1720#ifdef PNG_MAX_MALLOC_64K
1721 if (length > 65535)
1722 {
1723 png_warning(png_ptr, "unknown chunk too large to fit in memory");
1724 skip = length - 65535;
1725 length = 65535;
1726 }
1727#endif
1728 /* This is just a record for the user; libpng doesn't use the character
1729 * form of the name.
1730 */
1731 PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
1732
1733 png_ptr->unknown_chunk.size = length;
1734
1735 if (length == 0)
1736 png_ptr->unknown_chunk.data = NULL;
1737
1738 else
1739 {
1740 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
1741 png_ptr->unknown_chunk.size);
1742 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data,
1743 png_ptr->unknown_chunk.size);
1744 }
1745
1746#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1747 if (png_ptr->read_user_chunk_fn != NULL)
1748 {
1749 /* Callback to user unknown chunk handler */
1750 int ret;
1751 ret = (*(png_ptr->read_user_chunk_fn))
1752 (png_ptr, &png_ptr->unknown_chunk);
1753
1754 if (ret < 0)
1755 png_chunk_error(png_ptr, "error in user chunk");
1756
1757 if (ret == 0)
1758 {
1759 if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
1760 if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
1761 PNG_HANDLE_CHUNK_ALWAYS)
1762 png_chunk_error(png_ptr, "unknown critical chunk");
1763 png_set_unknown_chunks(png_ptr, info_ptr,
1764 &png_ptr->unknown_chunk, 1);
1765 }
1766 }
1767
1768 else
1769#endif
1770 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
1771 png_free(png_ptr, png_ptr->unknown_chunk.data);
1772 png_ptr->unknown_chunk.data = NULL;
1773 }
1774
1775 else
1776#endif
1777 skip=length;
1778 png_push_crc_skip(png_ptr, skip);
1779}
1780
1781void /* PRIVATE */
1782png_push_have_info(png_structp png_ptr, png_infop info_ptr)
1783{
1784 if (png_ptr->info_fn != NULL)
1785 (*(png_ptr->info_fn))(png_ptr, info_ptr);
1786}
1787
1788void /* PRIVATE */
1789png_push_have_end(png_structp png_ptr, png_infop info_ptr)
1790{
1791 if (png_ptr->end_fn != NULL)
1792 (*(png_ptr->end_fn))(png_ptr, info_ptr);
1793}
1794
1795void /* PRIVATE */
1796png_push_have_row(png_structp png_ptr, png_bytep row)
1797{
1798 if (png_ptr->row_fn != NULL)
1799 (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
1800 (int)png_ptr->pass);
1801}
1802
1803#ifdef PNG_READ_INTERLACING_SUPPORTED
1804void PNGAPI
1805png_progressive_combine_row (png_structp png_ptr, png_bytep old_row,
1806 png_const_bytep new_row)
1807{
1808 if (png_ptr == NULL)
1809 return;
1810
1811 /* new_row is a flag here - if it is NULL then the app callback was called
1812 * from an empty row (see the calls to png_struct::row_fn below), otherwise
1813 * it must be png_ptr->row_buf+1
1814 */
1815 if (new_row != NULL)
1816 png_combine_row(png_ptr, old_row, 1/*display*/);
1817}
1818#endif /* PNG_READ_INTERLACING_SUPPORTED */
1819
1820void PNGAPI
1821png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
1822 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
1823 png_progressive_end_ptr end_fn)
1824{
1825 if (png_ptr == NULL)
1826 return;
1827
1828 png_ptr->info_fn = info_fn;
1829 png_ptr->row_fn = row_fn;
1830 png_ptr->end_fn = end_fn;
1831
1832 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
1833}
1834
1835png_voidp PNGAPI
1836png_get_progressive_ptr(png_const_structp png_ptr)
1837{
1838 if (png_ptr == NULL)
1839 return (NULL);
1840
1841 return png_ptr->io_ptr;
1842}
1843#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpriv.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpriv.h
new file mode 100644
index 0000000..5f751de
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngpriv.h
@@ -0,0 +1,1629 @@
1
2/* pngpriv.h - private declarations for use inside libpng
3 *
4 * For conditions of distribution and use, see copyright notice in png.h
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * Last changed in libpng 1.5.7 [December 15, 2011]
10 *
11 * This code is released under the libpng license.
12 * For conditions of distribution and use, see the disclaimer
13 * and license in png.h
14 */
15
16/* The symbols declared in this file (including the functions declared
17 * as PNG_EXTERN) are PRIVATE. They are not part of the libpng public
18 * interface, and are not recommended for use by regular applications.
19 * Some of them may become public in the future; others may stay private,
20 * change in an incompatible way, or even disappear.
21 * Although the libpng users are not forbidden to include this header,
22 * they should be well aware of the issues that may arise from doing so.
23 */
24
25#ifndef PNGPRIV_H
26#define PNGPRIV_H
27
28/* Feature Test Macros. The following are defined here to ensure that correctly
29 * implemented libraries reveal the APIs libpng needs to build and hide those
30 * that are not needed and potentially damaging to the compilation.
31 *
32 * Feature Test Macros must be defined before any system header is included (see
33 * POSIX 1003.1 2.8.2 "POSIX Symbols."
34 *
35 * These macros only have an effect if the operating system supports either
36 * POSIX 1003.1 or C99, or both. On other operating systems (particularly
37 * Windows/Visual Studio) there is no effect; the OS specific tests below are
38 * still required (as of 2011-05-02.)
39 */
40#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
41
42/* This is required for the definition of abort(), used as a last ditch
43 * error handler when all else fails.
44 */
45#include <stdlib.h>
46
47/* This is used to find 'offsetof', used below for alignment tests. */
48#include <stddef.h>
49
50#define PNGLIB_BUILD /*libpng is being built, not used*/
51
52#ifdef PNG_USER_CONFIG
53# include "pngusr.h"
54 /* These should have been defined in pngusr.h */
55# ifndef PNG_USER_PRIVATEBUILD
56# define PNG_USER_PRIVATEBUILD "Custom libpng build"
57# endif
58# ifndef PNG_USER_DLLFNAME_POSTFIX
59# define PNG_USER_DLLFNAME_POSTFIX "Cb"
60# endif
61#endif
62
63/* Is this a build of a DLL where compilation of the object modules requires
64 * different preprocessor settings to those required for a simple library? If
65 * so PNG_BUILD_DLL must be set.
66 *
67 * If libpng is used inside a DLL but that DLL does not export the libpng APIs
68 * PNG_BUILD_DLL must not be set. To avoid the code below kicking in build a
69 * static library of libpng then link the DLL against that.
70 */
71#ifndef PNG_BUILD_DLL
72# ifdef DLL_EXPORT
73 /* This is set by libtool when files are compiled for a DLL; libtool
74 * always compiles twice, even on systems where it isn't necessary. Set
75 * PNG_BUILD_DLL in case it is necessary:
76 */
77# define PNG_BUILD_DLL
78# else
79# ifdef _WINDLL
80 /* This is set by the Microsoft Visual Studio IDE in projects that
81 * build a DLL. It can't easily be removed from those projects (it
82 * isn't visible in the Visual Studio UI) so it is a fairly reliable
83 * indication that PNG_IMPEXP needs to be set to the DLL export
84 * attributes.
85 */
86# define PNG_BUILD_DLL
87# else
88# ifdef __DLL__
89 /* This is set by the Borland C system when compiling for a DLL
90 * (as above.)
91 */
92# define PNG_BUILD_DLL
93# else
94 /* Add additional compiler cases here. */
95# endif
96# endif
97# endif
98#endif /* Setting PNG_BUILD_DLL if required */
99
100/* See pngconf.h for more details: the builder of the library may set this on
101 * the command line to the right thing for the specific compilation system or it
102 * may be automagically set above (at present we know of no system where it does
103 * need to be set on the command line.)
104 *
105 * PNG_IMPEXP must be set here when building the library to prevent pngconf.h
106 * setting it to the "import" setting for a DLL build.
107 */
108#ifndef PNG_IMPEXP
109# ifdef PNG_BUILD_DLL
110# define PNG_IMPEXP PNG_DLL_EXPORT
111# else
112 /* Not building a DLL, or the DLL doesn't require specific export
113 * definitions.
114 */
115# define PNG_IMPEXP
116# endif
117#endif
118
119/* No warnings for private or deprecated functions in the build: */
120#ifndef PNG_DEPRECATED
121# define PNG_DEPRECATED
122#endif
123#ifndef PNG_PRIVATE
124# define PNG_PRIVATE
125#endif
126
127#include "png.h"
128#include "pnginfo.h"
129#include "pngstruct.h"
130
131/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */
132#ifndef PNG_DLL_EXPORT
133# define PNG_DLL_EXPORT
134#endif
135
136/* This is used for 16 bit gamma tables - only the top level pointers are const,
137 * this could be changed:
138 */
139typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
140
141/* Added at libpng-1.2.9 */
142/* Moved to pngpriv.h at libpng-1.5.0 */
143
144/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
145 * script. We may need it here to get the correct configuration on things
146 * like limits.
147 */
148#ifdef PNG_CONFIGURE_LIBPNG
149# ifdef HAVE_CONFIG_H
150# include "config.h"
151# endif
152#endif
153
154/* Moved to pngpriv.h at libpng-1.5.0 */
155/* NOTE: some of these may have been used in external applications as
156 * these definitions were exposed in pngconf.h prior to 1.5.
157 */
158
159/* If you are running on a machine where you cannot allocate more
160 * than 64K of memory at once, uncomment this. While libpng will not
161 * normally need that much memory in a chunk (unless you load up a very
162 * large file), zlib needs to know how big of a chunk it can use, and
163 * libpng thus makes sure to check any memory allocation to verify it
164 * will fit into memory.
165 *
166 * zlib provides 'MAXSEG_64K' which, if defined, indicates the
167 * same limit and pngconf.h (already included) sets the limit
168 * if certain operating systems are detected.
169 */
170#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
171# define PNG_MAX_MALLOC_64K
172#endif
173
174#ifndef PNG_UNUSED
175/* Unused formal parameter warnings are silenced using the following macro
176 * which is expected to have no bad effects on performance (optimizing
177 * compilers will probably remove it entirely). Note that if you replace
178 * it with something other than whitespace, you must include the terminating
179 * semicolon.
180 */
181# define PNG_UNUSED(param) (void)param;
182#endif
183
184/* Just a little check that someone hasn't tried to define something
185 * contradictory.
186 */
187#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
188# undef PNG_ZBUF_SIZE
189# define PNG_ZBUF_SIZE 65536L
190#endif
191
192/* PNG_STATIC is used to mark internal file scope functions if they need to be
193 * accessed for implementation tests (see the code in tests/?*).
194 */
195#ifndef PNG_STATIC
196# define PNG_STATIC static
197#endif
198
199/* C99 restrict is used where possible, to do this 'restrict' is defined as
200 * empty if we can't be sure it is supported. configure builds have already
201 * done this work.
202 */
203#ifdef PNG_CONFIGURE_LIBPNG
204# define PNG_RESTRICT restrict
205#else
206 /* Modern compilers support restrict, but assume not for anything not
207 * recognized here:
208 */
209# if defined __GNUC__ || defined _MSC_VER || defined __WATCOMC__
210# define PNG_RESTRICT restrict
211# else
212# define PNG_RESTRICT
213# endif
214#endif
215
216/* If warnings or errors are turned off the code is disabled or redirected here.
217 * From 1.5.4 functions have been added to allow very limited formatting of
218 * error and warning messages - this code will also be disabled here.
219 */
220#ifdef PNG_WARNINGS_SUPPORTED
221# define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
222#else
223# define png_warning(s1,s2) ((void)(s1))
224# define png_chunk_warning(s1,s2) ((void)(s1))
225# define png_warning_parameter(p,number,string) ((void)0)
226# define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
227# define png_warning_parameter_signed(p,number,format,value) ((void)0)
228# define png_formatted_warning(pp,p,message) ((void)(pp))
229# define PNG_WARNING_PARAMETERS(p)
230#endif
231#ifndef PNG_ERROR_TEXT_SUPPORTED
232# define png_error(s1,s2) png_err(s1)
233# define png_chunk_error(s1,s2) png_err(s1)
234# define png_fixed_error(s1,s2) png_err(s1)
235#endif
236
237/* C allows up-casts from (void*) to any pointer and (const void*) to any
238 * pointer to a const object. C++ regards this as a type error and requires an
239 * explicit, static, cast and provides the static_cast<> rune to ensure that
240 * const is not cast away.
241 */
242#ifdef __cplusplus
243# define png_voidcast(type, value) static_cast<type>(value)
244#else
245# define png_voidcast(type, value) (value)
246#endif /* __cplusplus */
247
248#ifndef PNG_EXTERN
249/* The functions exported by PNG_EXTERN are internal functions, which
250 * aren't usually used outside the library (as far as I know), so it is
251 * debatable if they should be exported at all. In the future, when it
252 * is possible to have run-time registry of chunk-handling functions,
253 * some of these might be made available again.
254 *
255 * 1.5.7: turned the use of 'extern' back on, since it is localized to pngpriv.h
256 * it should be safe now (it is unclear why it was turned off.)
257 */
258# define PNG_EXTERN extern
259#endif
260
261/* Some fixed point APIs are still required even if not exported because
262 * they get used by the corresponding floating point APIs. This magic
263 * deals with this:
264 */
265#ifdef PNG_FIXED_POINT_SUPPORTED
266# define PNGFAPI PNGAPI
267#else
268# define PNGFAPI /* PRIVATE */
269#endif
270
271/* Other defines specific to compilers can go here. Try to keep
272 * them inside an appropriate ifdef/endif pair for portability.
273 */
274#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
275 defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
276 /* png.c requires the following ANSI-C constants if the conversion of
277 * floating point to ASCII is implemented therein:
278 *
279 * DBL_DIG Maximum number of decimal digits (can be set to any constant)
280 * DBL_MIN Smallest normalized fp number (can be set to an arbitrary value)
281 * DBL_MAX Maximum floating point number (can be set to an arbitrary value)
282 */
283# include <float.h>
284
285# if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
286 defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
287 /* We need to check that <math.h> hasn't already been included earlier
288 * as it seems it doesn't agree with <fp.h>, yet we should really use
289 * <fp.h> if possible.
290 */
291# if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
292# include <fp.h>
293# endif
294# else
295# include <math.h>
296# endif
297# if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
298 /* Amiga SAS/C: We must include builtin FPU functions when compiling using
299 * MATH=68881
300 */
301# include <m68881.h>
302# endif
303#endif
304
305/* This provides the non-ANSI (far) memory allocation routines. */
306#if defined(__TURBOC__) && defined(__MSDOS__)
307# include <mem.h>
308# include <alloc.h>
309#endif
310
311#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
312 defined(_WIN32) || defined(__WIN32__)
313# include <windows.h> /* defines _WINDOWS_ macro */
314#endif
315
316/* Moved here around 1.5.0beta36 from pngconf.h */
317/* Users may want to use these so they are not private. Any library
318 * functions that are passed far data must be model-independent.
319 */
320
321/* Memory model/platform independent fns */
322#ifndef PNG_ABORT
323# ifdef _WINDOWS_
324# define PNG_ABORT() ExitProcess(0)
325# else
326# define PNG_ABORT() abort()
327# endif
328#endif
329
330#ifdef USE_FAR_KEYWORD
331/* Use this to make far-to-near assignments */
332# define CHECK 1
333# define NOCHECK 0
334# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
335# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
336# define png_strlen _fstrlen
337# define png_memcmp _fmemcmp /* SJT: added */
338# define png_memcpy _fmemcpy
339# define png_memset _fmemset
340#else
341# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */
342# define CVT_PTR(ptr) (ptr)
343# define CVT_PTR_NOCHECK(ptr) (ptr)
344# define png_strlen lstrlenA
345# define png_memcmp memcmp
346# define png_memcpy CopyMemory
347# define png_memset memset
348# else
349# define CVT_PTR(ptr) (ptr)
350# define CVT_PTR_NOCHECK(ptr) (ptr)
351# define png_strlen strlen
352# define png_memcmp memcmp /* SJT: added */
353# define png_memcpy memcpy
354# define png_memset memset
355# endif
356#endif
357
358/* These macros may need to be architecture dependent. */
359#define PNG_ALIGN_NONE 0 /* do not use data alignment */
360#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */
361#ifdef offsetof
362# define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */
363#else
364# define PNG_ALIGN_OFFSET -1 /* prevent the use of this */
365#endif
366#define PNG_ALIGN_SIZE 3 /* use sizeof to determine alignment */
367
368#ifndef PNG_ALIGN_TYPE
369 /* Default to using aligned access optimizations and requiring alignment to a
370 * multiple of the data type size. Override in a compiler specific fashion
371 * if necessary by inserting tests here:
372 */
373# define PNG_ALIGN_TYPE PNG_ALIGN_SIZE
374#endif
375
376#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE
377 /* This is used because in some compiler implementations non-aligned
378 * structure members are supported, so the offsetof approach below fails.
379 * Set PNG_ALIGN_TO_SIZE=0 for compiler combinations where unaligned access
380 * is good for performance. Do not do this unless you have tested the result
381 * and understand it.
382 */
383# define png_alignof(type) (sizeof (type))
384#else
385# if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET
386# define png_alignof(type) offsetof(struct{char c; type t;}, t)
387# else
388# if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS
389# define png_alignof(type) (1)
390# endif
391 /* Else leave png_alignof undefined to prevent use thereof */
392# endif
393#endif
394
395/* This implicitly assumes alignment is always to a power of 2. */
396#ifdef png_alignof
397# define png_isaligned(ptr, type)\
398 ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)
399#else
400# define png_isaligned(ptr, type) 0
401#endif
402
403/* End of memory model/platform independent support */
404/* End of 1.5.0beta36 move from pngconf.h */
405
406/* CONSTANTS and UTILITY MACROS
407 * These are used internally by libpng and not exposed in the API
408 */
409
410/* Various modes of operation. Note that after an init, mode is set to
411 * zero automatically when the structure is created. Three of these
412 * are defined in png.h because they need to be visible to applications
413 * that call png_set_unknown_chunk().
414 */
415/* #define PNG_HAVE_IHDR 0x01 (defined in png.h) */
416/* #define PNG_HAVE_PLTE 0x02 (defined in png.h) */
417#define PNG_HAVE_IDAT 0x04
418/* #define PNG_AFTER_IDAT 0x08 (defined in png.h) */
419#define PNG_HAVE_IEND 0x10
420#define PNG_HAVE_gAMA 0x20
421#define PNG_HAVE_cHRM 0x40
422#define PNG_HAVE_sRGB 0x80
423#define PNG_HAVE_CHUNK_HEADER 0x100
424#define PNG_WROTE_tIME 0x200
425#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
426#define PNG_BACKGROUND_IS_GRAY 0x800
427#define PNG_HAVE_PNG_SIGNATURE 0x1000
428#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
429
430/* Flags for the transformations the PNG library does on the image data */
431#define PNG_BGR 0x0001
432#define PNG_INTERLACE 0x0002
433#define PNG_PACK 0x0004
434#define PNG_SHIFT 0x0008
435#define PNG_SWAP_BYTES 0x0010
436#define PNG_INVERT_MONO 0x0020
437#define PNG_QUANTIZE 0x0040
438#define PNG_COMPOSE 0x0080 /* Was PNG_BACKGROUND */
439#define PNG_BACKGROUND_EXPAND 0x0100
440#define PNG_EXPAND_16 0x0200 /* Added to libpng 1.5.2 */
441#define PNG_16_TO_8 0x0400 /* Becomes 'chop' in 1.5.4 */
442#define PNG_RGBA 0x0800
443#define PNG_EXPAND 0x1000
444#define PNG_GAMMA 0x2000
445#define PNG_GRAY_TO_RGB 0x4000
446#define PNG_FILLER 0x8000
447#define PNG_PACKSWAP 0x10000
448#define PNG_SWAP_ALPHA 0x20000
449#define PNG_STRIP_ALPHA 0x40000
450#define PNG_INVERT_ALPHA 0x80000
451#define PNG_USER_TRANSFORM 0x100000
452#define PNG_RGB_TO_GRAY_ERR 0x200000
453#define PNG_RGB_TO_GRAY_WARN 0x400000
454#define PNG_RGB_TO_GRAY 0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */
455#define PNG_ENCODE_ALPHA 0x800000 /* Added to libpng-1.5.4 */
456#define PNG_ADD_ALPHA 0x1000000 /* Added to libpng-1.2.7 */
457#define PNG_EXPAND_tRNS 0x2000000 /* Added to libpng-1.2.9 */
458#define PNG_SCALE_16_TO_8 0x4000000 /* Added to libpng-1.5.4 */
459 /* 0x8000000 unused */
460 /* 0x10000000 unused */
461 /* 0x20000000 unused */
462 /* 0x40000000 unused */
463/* Flags for png_create_struct */
464#define PNG_STRUCT_PNG 0x0001
465#define PNG_STRUCT_INFO 0x0002
466
467/* Scaling factor for filter heuristic weighting calculations */
468#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
469#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
470
471/* Flags for the png_ptr->flags rather than declaring a byte for each one */
472#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
473#define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
474#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
475#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
476#define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
477#define PNG_FLAG_ZLIB_FINISHED 0x0020
478#define PNG_FLAG_ROW_INIT 0x0040
479#define PNG_FLAG_FILLER_AFTER 0x0080
480#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
481#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
482#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
483#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
484#define PNG_FLAG_ASSUME_sRGB 0x1000 /* Added to libpng-1.5.4 */
485#define PNG_FLAG_OPTIMIZE_ALPHA 0x2000 /* Added to libpng-1.5.4 */
486#define PNG_FLAG_DETECT_UNINITIALIZED 0x4000 /* Added to libpng-1.5.4 */
487#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000
488#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000
489#define PNG_FLAG_LIBRARY_MISMATCH 0x20000
490#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000
491#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000
492#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000
493 /* 0x200000 unused */
494 /* 0x400000 unused */
495#define PNG_FLAG_BENIGN_ERRORS_WARN 0x800000 /* Added to libpng-1.4.0 */
496#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY 0x1000000 /* 5 lines added */
497#define PNG_FLAG_ZTXT_CUSTOM_LEVEL 0x2000000 /* to libpng-1.5.4 */
498#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL 0x4000000
499#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000
500#define PNG_FLAG_ZTXT_CUSTOM_METHOD 0x10000000
501 /* 0x20000000 unused */
502 /* 0x40000000 unused */
503
504#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
505 PNG_FLAG_CRC_ANCILLARY_NOWARN)
506
507#define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
508 PNG_FLAG_CRC_CRITICAL_IGNORE)
509
510#define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
511 PNG_FLAG_CRC_CRITICAL_MASK)
512
513/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
514 * can handle at once. This type need be no larger than 16 bits (so maximum of
515 * 65535), this define allows us to discover how big it is, but limited by the
516 * maximuum for png_size_t. The value can be overriden in a library build
517 * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
518 * lower value (e.g. 255 works). A lower value may help memory usage (slightly)
519 * and may even improve performance on some systems (and degrade it on others.)
520 */
521#ifndef ZLIB_IO_MAX
522# define ZLIB_IO_MAX ((uInt)-1)
523#endif
524
525/* Save typing and make code easier to understand */
526
527#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
528 abs((int)((c1).green) - (int)((c2).green)) + \
529 abs((int)((c1).blue) - (int)((c2).blue)))
530
531/* Added to libpng-1.2.6 JB */
532#define PNG_ROWBYTES(pixel_bits, width) \
533 ((pixel_bits) >= 8 ? \
534 ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
535 (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
536
537/* PNG_OUT_OF_RANGE returns true if value is outside the range
538 * ideal-delta..ideal+delta. Each argument is evaluated twice.
539 * "ideal" and "delta" should be constants, normally simple
540 * integers, "value" a variable. Added to libpng-1.2.6 JB
541 */
542#define PNG_OUT_OF_RANGE(value, ideal, delta) \
543 ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
544
545/* Conversions between fixed and floating point, only defined if
546 * required (to make sure the code doesn't accidentally use float
547 * when it is supposedly disabled.)
548 */
549#ifdef PNG_FLOATING_POINT_SUPPORTED
550/* The floating point conversion can't overflow, though it can and
551 * does lose accuracy relative to the original fixed point value.
552 * In practice this doesn't matter because png_fixed_point only
553 * stores numbers with very low precision. The png_ptr and s
554 * arguments are unused by default but are there in case error
555 * checking becomes a requirement.
556 */
557#define png_float(png_ptr, fixed, s) (.00001 * (fixed))
558
559/* The fixed point conversion performs range checking and evaluates
560 * its argument multiple times, so must be used with care. The
561 * range checking uses the PNG specification values for a signed
562 * 32 bit fixed point value except that the values are deliberately
563 * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
564 * (2^31-1) * 100000). 's' is a string that describes the value being
565 * converted.
566 *
567 * NOTE: this macro will raise a png_error if the range check fails,
568 * therefore it is normally only appropriate to use this on values
569 * that come from API calls or other sources where an out of range
570 * error indicates a programming error, not a data error!
571 *
572 * NOTE: by default this is off - the macro is not used - because the
573 * function call saves a lot of code.
574 */
575#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
576#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
577 ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
578#else
579PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp,
580 png_const_charp text));
581#endif
582#endif
583
584/* Constants for known chunk types. If you need to add a chunk, define the name
585 * here. For historical reasons these constants have the form png_<name>; i.e.
586 * the prefix is lower case. Please use decimal values as the parameters to
587 * match the ISO PNG specification and to avoid relying on the C locale
588 * interpretation of character values.
589 *
590 * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values
591 * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string
592 * to be generated if required.
593 *
594 * PNG_32b correctly produces a value shifted by up to 24 bits, even on
595 * architectures where (int) is only 16 bits.
596 */
597#define PNG_32b(b,s) ((png_uint_32)(b) << (s))
598#define PNG_CHUNK(b1,b2,b3,b4) \
599 (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
600
601#define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
602#define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
603#define png_IEND PNG_CHUNK( 73, 69, 78, 68)
604#define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
605#define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
606#define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
607#define png_gAMA PNG_CHUNK(103, 65, 77, 65)
608#define png_hIST PNG_CHUNK(104, 73, 83, 84)
609#define png_iCCP PNG_CHUNK(105, 67, 67, 80)
610#define png_iTXt PNG_CHUNK(105, 84, 88, 116)
611#define png_oFFs PNG_CHUNK(111, 70, 70, 115)
612#define png_pCAL PNG_CHUNK(112, 67, 65, 76)
613#define png_sCAL PNG_CHUNK(115, 67, 65, 76)
614#define png_pHYs PNG_CHUNK(112, 72, 89, 115)
615#define png_sBIT PNG_CHUNK(115, 66, 73, 84)
616#define png_sPLT PNG_CHUNK(115, 80, 76, 84)
617#define png_sRGB PNG_CHUNK(115, 82, 71, 66)
618#define png_sTER PNG_CHUNK(115, 84, 69, 82)
619#define png_tEXt PNG_CHUNK(116, 69, 88, 116)
620#define png_tIME PNG_CHUNK(116, 73, 77, 69)
621#define png_tRNS PNG_CHUNK(116, 82, 78, 83)
622#define png_zTXt PNG_CHUNK(122, 84, 88, 116)
623
624/* The following will work on (signed char*) strings, whereas the get_uint_32
625 * macro will fail on top-bit-set values because of the sign extension.
626 */
627#define PNG_CHUNK_FROM_STRING(s)\
628 PNG_CHUNK(0xff&(s)[0], 0xff&(s)[1], 0xff&(s)[2], 0xff&(s)[3])
629
630/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is
631 * signed and the argument is a (char[]) This macro will fail miserably on
632 * systems where (char) is more than 8 bits.
633 */
634#define PNG_STRING_FROM_CHUNK(s,c)\
635 (void)(((char*)(s))[0]=(char)((c)>>24), ((char*)(s))[1]=(char)((c)>>16),\
636 ((char*)(s))[2]=(char)((c)>>8), ((char*)(s))[3]=(char)((c)))
637
638/* Do the same but terminate with a null character. */
639#define PNG_CSTRING_FROM_CHUNK(s,c)\
640 (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)
641
642/* Test on flag values as defined in the spec (section 5.4): */
643#define PNG_CHUNK_ANCILLIARY(c) (1 & ((c) >> 29))
644#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLIARY(c))
645#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
646#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
647#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
648
649/* Gamma values (new at libpng-1.5.4): */
650#define PNG_GAMMA_MAC_OLD 151724 /* Assume '1.8' is really 2.2/1.45! */
651#define PNG_GAMMA_MAC_INVERSE 65909
652#define PNG_GAMMA_sRGB_INVERSE 45455
653
654
655/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
656#ifdef __cplusplus
657extern "C" {
658#endif /* __cplusplus */
659
660/* These functions are used internally in the code. They generally
661 * shouldn't be used unless you are writing code to add or replace some
662 * functionality in libpng. More information about most functions can
663 * be found in the files where the functions are located.
664 */
665
666/* Check the user version string for compatibility, returns false if the version
667 * numbers aren't compatible.
668 */
669PNG_EXTERN int png_user_version_check(png_structp png_ptr,
670 png_const_charp user_png_ver);
671
672/* Allocate memory for an internal libpng struct */
673PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)),
674 PNG_ALLOCATED);
675
676/* Free memory from internal libpng struct */
677PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
678
679PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2,
680 PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)),
681 PNG_ALLOCATED);
682PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
683 png_free_ptr free_fn, png_voidp mem_ptr));
684
685/* Free any memory that info_ptr points to and reset struct. */
686PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
687 png_infop info_ptr));
688
689/* Function to allocate memory for zlib. PNGAPI is disallowed. */
690PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items,
691 uInt size)),PNG_ALLOCATED);
692
693/* Function to free memory for zlib. PNGAPI is disallowed. */
694PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
695
696/* Next four functions are used internally as callbacks. PNGCBAPI is required
697 * but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3, changed to
698 * PNGCBAPI at 1.5.0
699 */
700
701PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr,
702 png_bytep data, png_size_t length));
703
704#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
705PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
706 png_bytep buffer, png_size_t length));
707#endif
708
709PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr,
710 png_bytep data, png_size_t length));
711
712#ifdef PNG_WRITE_FLUSH_SUPPORTED
713# ifdef PNG_STDIO_SUPPORTED
714PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr));
715# endif
716#endif
717
718/* Reset the CRC variable */
719PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
720
721/* Write the "data" buffer to whatever output you are using */
722PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
723 png_const_bytep data, png_size_t length));
724
725/* Read and check the PNG file signature */
726PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
727
728/* Read the chunk header (length + type name) */
729PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
730
731/* Read data from whatever input you are using into the "data" buffer */
732PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
733 png_size_t length));
734
735/* Read bytes into buf, and update png_ptr->crc */
736PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
737 png_size_t length));
738
739/* Decompress data in a chunk that uses compression */
740#if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED)
741PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
742 int comp_type, png_size_t chunklength, png_size_t prefix_length,
743 png_size_t *data_length));
744#endif
745
746/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
747PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
748
749/* Read the CRC from the file and compare it to the libpng calculated CRC */
750PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
751
752/* Calculate the CRC over a section of data. Note that we are only
753 * passing a maximum of 64K on systems that have this as a memory limit,
754 * since this is the maximum buffer size we can specify.
755 */
756PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr,
757 png_const_bytep ptr, png_size_t length));
758
759#ifdef PNG_WRITE_FLUSH_SUPPORTED
760PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
761#endif
762
763/* Write various chunks */
764
765/* Write the IHDR chunk, and update the png_struct with the necessary
766 * information.
767 */
768PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
769 png_uint_32 height,
770 int bit_depth, int color_type, int compression_method, int filter_method,
771 int interlace_method));
772
773PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr,
774 png_const_colorp palette, png_uint_32 num_pal));
775
776PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
777 png_size_t length));
778
779PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
780
781#ifdef PNG_WRITE_gAMA_SUPPORTED
782# ifdef PNG_FLOATING_POINT_SUPPORTED
783PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
784# endif
785# ifdef PNG_FIXED_POINT_SUPPORTED
786PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr,
787 png_fixed_point file_gamma));
788# endif
789#endif
790
791#ifdef PNG_WRITE_sBIT_SUPPORTED
792PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr,
793 png_const_color_8p sbit, int color_type));
794#endif
795
796#ifdef PNG_WRITE_cHRM_SUPPORTED
797# ifdef PNG_FLOATING_POINT_SUPPORTED
798PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
799 double white_x, double white_y,
800 double red_x, double red_y, double green_x, double green_y,
801 double blue_x, double blue_y));
802# endif
803PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
804 png_fixed_point int_white_x, png_fixed_point int_white_y,
805 png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
806 int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
807 png_fixed_point int_blue_y));
808#endif
809
810#ifdef PNG_WRITE_sRGB_SUPPORTED
811PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
812 int intent));
813#endif
814
815#ifdef PNG_WRITE_iCCP_SUPPORTED
816PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
817 png_const_charp name, int compression_type,
818 png_const_charp profile, int proflen));
819 /* Note to maintainer: profile should be png_bytep */
820#endif
821
822#ifdef PNG_WRITE_sPLT_SUPPORTED
823PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
824 png_const_sPLT_tp palette));
825#endif
826
827#ifdef PNG_WRITE_tRNS_SUPPORTED
828PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr,
829 png_const_bytep trans, png_const_color_16p values, int number,
830 int color_type));
831#endif
832
833#ifdef PNG_WRITE_bKGD_SUPPORTED
834PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
835 png_const_color_16p values, int color_type));
836#endif
837
838#ifdef PNG_WRITE_hIST_SUPPORTED
839PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr,
840 png_const_uint_16p hist, int num_hist));
841#endif
842
843/* Chunks that have keywords */
844#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
845 defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
846PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
847 png_const_charp key, png_charpp new_key));
848#endif
849
850#ifdef PNG_WRITE_tEXt_SUPPORTED
851PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key,
852 png_const_charp text, png_size_t text_len));
853#endif
854
855#ifdef PNG_WRITE_zTXt_SUPPORTED
856PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key,
857 png_const_charp text, png_size_t text_len, int compression));
858#endif
859
860#ifdef PNG_WRITE_iTXt_SUPPORTED
861PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
862 int compression, png_const_charp key, png_const_charp lang,
863 png_const_charp lang_key, png_const_charp text));
864#endif
865
866#ifdef PNG_TEXT_SUPPORTED /* Added at version 1.0.14 and 1.2.4 */
867PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
868 png_infop info_ptr, png_const_textp text_ptr, int num_text));
869#endif
870
871#ifdef PNG_WRITE_oFFs_SUPPORTED
872PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
873 png_int_32 x_offset, png_int_32 y_offset, int unit_type));
874#endif
875
876#ifdef PNG_WRITE_pCAL_SUPPORTED
877PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
878 png_int_32 X0, png_int_32 X1, int type, int nparams,
879 png_const_charp units, png_charpp params));
880#endif
881
882#ifdef PNG_WRITE_pHYs_SUPPORTED
883PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
884 png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
885 int unit_type));
886#endif
887
888#ifdef PNG_WRITE_tIME_SUPPORTED
889PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
890 png_const_timep mod_time));
891#endif
892
893#ifdef PNG_WRITE_sCAL_SUPPORTED
894PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
895 int unit, png_const_charp width, png_const_charp height));
896#endif
897
898/* Called when finished processing a row of data */
899PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
900
901/* Internal use only. Called before first row of data */
902PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
903
904/* Combine a row of data, dealing with alpha, etc. if requested. 'row' is an
905 * array of png_ptr->width pixels. If the image is not interlaced or this
906 * is the final pass this just does a png_memcpy, otherwise the "display" flag
907 * is used to determine whether to copy pixels that are not in the current pass.
908 *
909 * Because 'png_do_read_interlace' (below) replicates pixels this allows this
910 * function to achieve the documented 'blocky' appearance during interlaced read
911 * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row'
912 * are not changed if they are not in the current pass, when display is 0.
913 *
914 * 'display' must be 0 or 1, otherwise the memcpy will be done regardless.
915 *
916 * The API always reads from the png_struct row buffer and always assumes that
917 * it is full width (png_do_read_interlace has already been called.)
918 *
919 * This function is only ever used to write to row buffers provided by the
920 * caller of the relevant libpng API and the row must have already been
921 * transformed by the read transformations.
922 *
923 * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed
924 * bitmasks for use within the code, otherwise runtime generated masks are used.
925 * The default is compile time masks.
926 */
927#ifndef PNG_USE_COMPILE_TIME_MASKS
928# define PNG_USE_COMPILE_TIME_MASKS 1
929#endif
930PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
931 int display));
932
933#ifdef PNG_READ_INTERLACING_SUPPORTED
934/* Expand an interlaced row: the 'row_info' describes the pass data that has
935 * been read in and must correspond to the pixels in 'row', the pixels are
936 * expanded (moved apart) in 'row' to match the final layout, when doing this
937 * the pixels are *replicated* to the intervening space. This is essential for
938 * the correct operation of png_combine_row, above.
939 */
940PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
941 png_bytep row, int pass, png_uint_32 transformations));
942#endif
943
944/* GRR TO DO (2.0 or whenever): simplify other internal calling interfaces */
945
946#ifdef PNG_WRITE_INTERLACING_SUPPORTED
947/* Grab pixels out of a row for an interlaced pass */
948PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
949 png_bytep row, int pass));
950#endif
951
952/* Unfilter a row: check the filter value before calling this, there is no point
953 * calling it for PNG_FILTER_VALUE_NONE.
954 */
955PNG_EXTERN void png_read_filter_row PNGARG((png_structp pp, png_row_infop row_info,
956 png_bytep row, png_const_bytep prev_row, int filter));
957
958PNG_EXTERN void png_read_filter_row_up_neon PNGARG((png_row_infop row_info,
959 png_bytep row, png_const_bytep prev_row));
960PNG_EXTERN void png_read_filter_row_sub3_neon PNGARG((png_row_infop row_info,
961 png_bytep row, png_const_bytep prev_row));
962PNG_EXTERN void png_read_filter_row_sub4_neon PNGARG((png_row_infop row_info,
963 png_bytep row, png_const_bytep prev_row));
964PNG_EXTERN void png_read_filter_row_avg3_neon PNGARG((png_row_infop row_info,
965 png_bytep row, png_const_bytep prev_row));
966PNG_EXTERN void png_read_filter_row_avg4_neon PNGARG((png_row_infop row_info,
967 png_bytep row, png_const_bytep prev_row));
968PNG_EXTERN void png_read_filter_row_paeth3_neon PNGARG((png_row_infop row_info,
969 png_bytep row, png_const_bytep prev_row));
970PNG_EXTERN void png_read_filter_row_paeth4_neon PNGARG((png_row_infop row_info,
971 png_bytep row, png_const_bytep prev_row));
972
973/* Choose the best filter to use and filter the row data */
974PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
975 png_row_infop row_info));
976
977/* Finish a row while reading, dealing with interlacing passes, etc. */
978PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
979
980/* Initialize the row buffers, etc. */
981PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
982
983#ifdef PNG_READ_TRANSFORMS_SUPPORTED
984/* Optional call to update the users info structure */
985PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
986 png_infop info_ptr));
987#endif
988
989/* These are the functions that do the transformations */
990#ifdef PNG_READ_FILLER_SUPPORTED
991PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
992 png_bytep row, png_uint_32 filler, png_uint_32 flags));
993#endif
994
995#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
996PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
997 png_bytep row));
998#endif
999
1000#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
1001PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
1002 png_bytep row));
1003#endif
1004
1005#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
1006PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
1007 png_bytep row));
1008#endif
1009
1010#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
1011PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
1012 png_bytep row));
1013#endif
1014
1015#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
1016 defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
1017PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
1018 png_bytep row, int at_start));
1019#endif
1020
1021#ifdef PNG_16BIT_SUPPORTED
1022#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
1023PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info,
1024 png_bytep row));
1025#endif
1026#endif
1027
1028#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
1029 defined(PNG_WRITE_PACKSWAP_SUPPORTED)
1030PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info,
1031 png_bytep row));
1032#endif
1033
1034#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1035PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr,
1036 png_row_infop row_info, png_bytep row));
1037#endif
1038
1039#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1040PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
1041 png_bytep row));
1042#endif
1043
1044#ifdef PNG_READ_PACK_SUPPORTED
1045PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info,
1046 png_bytep row));
1047#endif
1048
1049#ifdef PNG_READ_SHIFT_SUPPORTED
1050PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info,
1051 png_bytep row, png_const_color_8p sig_bits));
1052#endif
1053
1054#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
1055PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info,
1056 png_bytep row));
1057#endif
1058
1059#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1060PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info,
1061 png_bytep row));
1062#endif
1063
1064#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1065PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info,
1066 png_bytep row));
1067#endif
1068
1069#ifdef PNG_READ_QUANTIZE_SUPPORTED
1070PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info,
1071 png_bytep row, png_const_bytep palette_lookup,
1072 png_const_bytep quantize_lookup));
1073
1074# ifdef PNG_CORRECT_PALETTE_SUPPORTED
1075PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
1076 png_colorp palette, int num_palette));
1077# endif
1078#endif
1079
1080#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
1081PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info,
1082 png_bytep row));
1083#endif
1084
1085#ifdef PNG_WRITE_PACK_SUPPORTED
1086PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
1087 png_bytep row, png_uint_32 bit_depth));
1088#endif
1089
1090#ifdef PNG_WRITE_SHIFT_SUPPORTED
1091PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info,
1092 png_bytep row, png_const_color_8p bit_depth));
1093#endif
1094
1095#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
1096 defined(PNG_READ_ALPHA_MODE_SUPPORTED)
1097PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info,
1098 png_bytep row, png_structp png_ptr));
1099#endif
1100
1101#ifdef PNG_READ_GAMMA_SUPPORTED
1102PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info,
1103 png_bytep row, png_structp png_ptr));
1104#endif
1105
1106#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1107PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info,
1108 png_bytep row, png_structp png_ptr));
1109#endif
1110
1111#ifdef PNG_READ_EXPAND_SUPPORTED
1112PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
1113 png_bytep row, png_const_colorp palette, png_const_bytep trans,
1114 int num_trans));
1115PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
1116 png_bytep row, png_const_color_16p trans_color));
1117#endif
1118
1119#ifdef PNG_READ_EXPAND_16_SUPPORTED
1120PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
1121 png_bytep row));
1122#endif
1123
1124/* The following decodes the appropriate chunks, and does error correction,
1125 * then calls the appropriate callback for the chunk if it is valid.
1126 */
1127
1128/* Decode the IHDR chunk */
1129PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
1130 png_uint_32 length));
1131PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
1132 png_uint_32 length));
1133PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
1134 png_uint_32 length));
1135
1136#ifdef PNG_READ_bKGD_SUPPORTED
1137PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
1138 png_uint_32 length));
1139#endif
1140
1141#ifdef PNG_READ_cHRM_SUPPORTED
1142PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
1143 png_uint_32 length));
1144#endif
1145
1146#ifdef PNG_READ_gAMA_SUPPORTED
1147PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
1148 png_uint_32 length));
1149#endif
1150
1151#ifdef PNG_READ_hIST_SUPPORTED
1152PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
1153 png_uint_32 length));
1154#endif
1155
1156#ifdef PNG_READ_iCCP_SUPPORTED
1157PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
1158 png_uint_32 length));
1159#endif /* PNG_READ_iCCP_SUPPORTED */
1160
1161#ifdef PNG_READ_iTXt_SUPPORTED
1162PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
1163 png_uint_32 length));
1164#endif
1165
1166#ifdef PNG_READ_oFFs_SUPPORTED
1167PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
1168 png_uint_32 length));
1169#endif
1170
1171#ifdef PNG_READ_pCAL_SUPPORTED
1172PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
1173 png_uint_32 length));
1174#endif
1175
1176#ifdef PNG_READ_pHYs_SUPPORTED
1177PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
1178 png_uint_32 length));
1179#endif
1180
1181#ifdef PNG_READ_sBIT_SUPPORTED
1182PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
1183 png_uint_32 length));
1184#endif
1185
1186#ifdef PNG_READ_sCAL_SUPPORTED
1187PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
1188 png_uint_32 length));
1189#endif
1190
1191#ifdef PNG_READ_sPLT_SUPPORTED
1192PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
1193 png_uint_32 length));
1194#endif /* PNG_READ_sPLT_SUPPORTED */
1195
1196#ifdef PNG_READ_sRGB_SUPPORTED
1197PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
1198 png_uint_32 length));
1199#endif
1200
1201#ifdef PNG_READ_tEXt_SUPPORTED
1202PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
1203 png_uint_32 length));
1204#endif
1205
1206#ifdef PNG_READ_tIME_SUPPORTED
1207PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
1208 png_uint_32 length));
1209#endif
1210
1211#ifdef PNG_READ_tRNS_SUPPORTED
1212PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
1213 png_uint_32 length));
1214#endif
1215
1216#ifdef PNG_READ_zTXt_SUPPORTED
1217PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
1218 png_uint_32 length));
1219#endif
1220
1221#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1222PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
1223 png_infop info_ptr, png_uint_32 length));
1224#endif
1225
1226PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
1227 png_uint_32 chunk_name));
1228
1229#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1230/* Exactly as png_handle_as_unknown() except that the argument is a 32-bit chunk
1231 * name, not a string.
1232 */
1233PNG_EXTERN int png_chunk_unknown_handling PNGARG((png_structp png_ptr,
1234 png_uint_32 chunk_name));
1235#endif
1236
1237/* Handle the transformations for reading and writing */
1238#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1239PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr,
1240 png_row_infop row_info));
1241#endif
1242#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
1243PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr,
1244 png_row_infop row_info));
1245#endif
1246
1247#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1248PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
1249#endif
1250
1251#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1252PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
1253 png_infop info_ptr));
1254PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
1255 png_infop info_ptr));
1256PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
1257PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
1258 png_uint_32 length));
1259PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
1260PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
1261PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
1262 png_bytep buffer, png_size_t buffer_length));
1263PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
1264PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
1265 png_bytep buffer, png_size_t buffer_length));
1266PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
1267PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
1268 png_infop info_ptr, png_uint_32 length));
1269PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
1270 png_infop info_ptr));
1271PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
1272 png_infop info_ptr));
1273PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
1274PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
1275 png_infop info_ptr));
1276PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
1277 png_infop info_ptr));
1278PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
1279# ifdef PNG_READ_tEXt_SUPPORTED
1280PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
1281 png_infop info_ptr, png_uint_32 length));
1282PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
1283 png_infop info_ptr));
1284# endif
1285# ifdef PNG_READ_zTXt_SUPPORTED
1286PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
1287 png_infop info_ptr, png_uint_32 length));
1288PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
1289 png_infop info_ptr));
1290# endif
1291# ifdef PNG_READ_iTXt_SUPPORTED
1292PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
1293 png_infop info_ptr, png_uint_32 length));
1294PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
1295 png_infop info_ptr));
1296# endif
1297
1298#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1299
1300#ifdef PNG_MNG_FEATURES_SUPPORTED
1301PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
1302 png_bytep row));
1303PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
1304 png_bytep row));
1305#endif
1306
1307/* Added at libpng version 1.4.0 */
1308#ifdef PNG_CHECK_cHRM_SUPPORTED
1309PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
1310 png_fixed_point int_white_x, png_fixed_point int_white_y,
1311 png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
1312 int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
1313 png_fixed_point int_blue_y));
1314#endif
1315
1316#ifdef PNG_CHECK_cHRM_SUPPORTED
1317/* Added at libpng version 1.2.34 and 1.4.0 */
1318/* Currently only used by png_check_cHRM_fixed */
1319PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
1320 unsigned long *hi_product, unsigned long *lo_product));
1321#endif
1322
1323#ifdef PNG_cHRM_SUPPORTED
1324/* Added at libpng version 1.5.5 */
1325typedef struct png_xy
1326{
1327 png_fixed_point redx, redy;
1328 png_fixed_point greenx, greeny;
1329 png_fixed_point bluex, bluey;
1330 png_fixed_point whitex, whitey;
1331} png_xy;
1332
1333typedef struct png_XYZ
1334{
1335 png_fixed_point redX, redY, redZ;
1336 png_fixed_point greenX, greenY, greenZ;
1337 png_fixed_point blueX, blueY, blueZ;
1338} png_XYZ;
1339
1340/* The conversion APIs return 0 on success, non-zero on a parameter error. They
1341 * allow conversion between the above representations of a color encoding. When
1342 * converting from XYZ end points to chromaticities the absolute magnitude of
1343 * the end points is lost, when converting back the sum of the Y values of the
1344 * three end points will be 1.0
1345 */
1346PNG_EXTERN int png_xy_from_XYZ PNGARG((png_xy *xy, png_XYZ XYZ));
1347PNG_EXTERN int png_XYZ_from_xy PNGARG((png_XYZ *XYZ, png_xy xy));
1348PNG_EXTERN int png_XYZ_from_xy_checked PNGARG((png_structp png_ptr,
1349 png_XYZ *XYZ, png_xy xy));
1350#endif
1351
1352/* Added at libpng version 1.4.0 */
1353PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr,
1354 png_uint_32 width, png_uint_32 height, int bit_depth,
1355 int color_type, int interlace_type, int compression_type,
1356 int filter_type));
1357
1358/* Free all memory used by the read (old method - NOT DLL EXPORTED) */
1359PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
1360 png_infop info_ptr, png_infop end_info_ptr));
1361
1362/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
1363PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
1364
1365#ifdef USE_FAR_KEYWORD /* memory model conversion function */
1366PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
1367 int check));
1368#endif /* USE_FAR_KEYWORD */
1369
1370#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
1371PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
1372 png_const_charp name),PNG_NORETURN);
1373#endif
1374
1375/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite
1376 * the end. Always leaves the buffer nul terminated. Never errors out (and
1377 * there is no error code.)
1378 */
1379PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos,
1380 png_const_charp string);
1381
1382/* Various internal functions to handle formatted warning messages, currently
1383 * only implemented for warnings.
1384 */
1385#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
1386/* Utility to dump an unsigned value into a buffer, given a start pointer and
1387 * and end pointer (which should point just *beyond* the end of the buffer!)
1388 * Returns the pointer to the start of the formatted string. This utility only
1389 * does unsigned values.
1390 */
1391PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end,
1392 int format, png_alloc_size_t number);
1393
1394/* Convenience macro that takes an array: */
1395#define PNG_FORMAT_NUMBER(buffer,format,number) \
1396 png_format_number(buffer, buffer + (sizeof buffer), format, number)
1397
1398/* Suggested size for a number buffer (enough for 64 bits and a sign!) */
1399#define PNG_NUMBER_BUFFER_SIZE 24
1400
1401/* These are the integer formats currently supported, the name is formed from
1402 * the standard printf(3) format string.
1403 */
1404#define PNG_NUMBER_FORMAT_u 1 /* chose unsigned API! */
1405#define PNG_NUMBER_FORMAT_02u 2
1406#define PNG_NUMBER_FORMAT_d 1 /* chose signed API! */
1407#define PNG_NUMBER_FORMAT_02d 2
1408#define PNG_NUMBER_FORMAT_x 3
1409#define PNG_NUMBER_FORMAT_02x 4
1410#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */
1411#endif
1412
1413#ifdef PNG_WARNINGS_SUPPORTED
1414/* New defines and members adding in libpng-1.5.4 */
1415# define PNG_WARNING_PARAMETER_SIZE 32
1416# define PNG_WARNING_PARAMETER_COUNT 8
1417
1418/* An l-value of this type has to be passed to the APIs below to cache the
1419 * values of the parameters to a formatted warning message.
1420 */
1421typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][
1422 PNG_WARNING_PARAMETER_SIZE];
1423
1424PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number,
1425 png_const_charp string);
1426 /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,
1427 * including the trailing '\0'.
1428 */
1429PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p,
1430 int number, int format, png_alloc_size_t value);
1431 /* Use png_alloc_size_t because it is an unsigned type as big as any we
1432 * need to output. Use the following for a signed value.
1433 */
1434PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p,
1435 int number, int format, png_int_32 value);
1436
1437PNG_EXTERN void png_formatted_warning(png_structp png_ptr,
1438 png_warning_parameters p, png_const_charp message);
1439 /* 'message' follows the X/Open approach of using @1, @2 to insert
1440 * parameters previously supplied using the above functions. Errors in
1441 * specifying the paramters will simple result in garbage substitutions.
1442 */
1443#endif
1444
1445/* ASCII to FP interfaces, currently only implemented if sCAL
1446 * support is required.
1447 */
1448#if defined(PNG_READ_sCAL_SUPPORTED)
1449/* MAX_DIGITS is actually the maximum number of characters in an sCAL
1450 * width or height, derived from the precision (number of significant
1451 * digits - a build time settable option) and assumpitions about the
1452 * maximum ridiculous exponent.
1453 */
1454#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
1455
1456#ifdef PNG_FLOATING_POINT_SUPPORTED
1457PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii,
1458 png_size_t size, double fp, unsigned int precision));
1459#endif /* FLOATING_POINT */
1460
1461#ifdef PNG_FIXED_POINT_SUPPORTED
1462PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr,
1463 png_charp ascii, png_size_t size, png_fixed_point fp));
1464#endif /* FIXED_POINT */
1465#endif /* READ_sCAL */
1466
1467#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
1468/* An internal API to validate the format of a floating point number.
1469 * The result is the index of the next character. If the number is
1470 * not valid it will be the index of a character in the supposed number.
1471 *
1472 * The format of a number is defined in the PNG extensions specification
1473 * and this API is strictly conformant to that spec, not anyone elses!
1474 *
1475 * The format as a regular expression is:
1476 *
1477 * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
1478 *
1479 * or:
1480 *
1481 * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
1482 *
1483 * The complexity is that either integer or fraction must be present and the
1484 * fraction is permitted to have no digits only if the integer is present.
1485 *
1486 * NOTE: The dangling E problem.
1487 * There is a PNG valid floating point number in the following:
1488 *
1489 * PNG floating point numb1.ers are not greedy.
1490 *
1491 * Working this out requires *TWO* character lookahead (because of the
1492 * sign), the parser does not do this - it will fail at the 'r' - this
1493 * doesn't matter for PNG sCAL chunk values, but it requires more care
1494 * if the value were ever to be embedded in something more complex. Use
1495 * ANSI-C strtod if you need the lookahead.
1496 */
1497/* State table for the parser. */
1498#define PNG_FP_INTEGER 0 /* before or in integer */
1499#define PNG_FP_FRACTION 1 /* before or in fraction */
1500#define PNG_FP_EXPONENT 2 /* before or in exponent */
1501#define PNG_FP_STATE 3 /* mask for the above */
1502#define PNG_FP_SAW_SIGN 4 /* Saw +/- in current state */
1503#define PNG_FP_SAW_DIGIT 8 /* Saw a digit in current state */
1504#define PNG_FP_SAW_DOT 16 /* Saw a dot in current state */
1505#define PNG_FP_SAW_E 32 /* Saw an E (or e) in current state */
1506#define PNG_FP_SAW_ANY 60 /* Saw any of the above 4 */
1507
1508/* These three values don't affect the parser. They are set but not used.
1509 */
1510#define PNG_FP_WAS_VALID 64 /* Preceding substring is a valid fp number */
1511#define PNG_FP_NEGATIVE 128 /* A negative number, including "-0" */
1512#define PNG_FP_NONZERO 256 /* A non-zero value */
1513#define PNG_FP_STICKY 448 /* The above three flags */
1514
1515/* This is available for the caller to store in 'state' if required. Do not
1516 * call the parser after setting it (the parser sometimes clears it.)
1517 */
1518#define PNG_FP_INVALID 512 /* Available for callers as a distinct value */
1519
1520/* Result codes for the parser (boolean - true meants ok, false means
1521 * not ok yet.)
1522 */
1523#define PNG_FP_MAYBE 0 /* The number may be valid in the future */
1524#define PNG_FP_OK 1 /* The number is valid */
1525
1526/* Tests on the sticky non-zero and negative flags. To pass these checks
1527 * the state must also indicate that the whole number is valid - this is
1528 * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this
1529 * is equivalent to PNG_FP_OK above.)
1530 */
1531#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)
1532 /* NZ_MASK: the string is valid and a non-zero negative value */
1533#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)
1534 /* Z MASK: the string is valid and a non-zero value. */
1535 /* PNG_FP_SAW_DIGIT: the string is valid. */
1536#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)
1537#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
1538#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
1539
1540/* The actual parser. This can be called repeatedly, it updates
1541 * the index into the string and the state variable (which must
1542 * be initialzed to 0). It returns a result code, as above. There
1543 * is no point calling the parser any more if it fails to advance to
1544 * the end of the string - it is stuck on an invalid character (or
1545 * terminated by '\0').
1546 *
1547 * Note that the pointer will consume an E or even an E+ then leave
1548 * a 'maybe' state even though a preceding integer.fraction is valid.
1549 * The PNG_FP_WAS_VALID flag indicates that a preceding substring was
1550 * a valid number. It's possible to recover from this by calling
1551 * the parser again (from the start, with state 0) but with a string
1552 * that omits the last character (i.e. set the size to the index of
1553 * the problem character.) This has not been tested within libpng.
1554 */
1555PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string,
1556 png_size_t size, int *statep, png_size_tp whereami));
1557
1558/* This is the same but it checks a complete string and returns true
1559 * only if it just contains a floating point number. As of 1.5.4 this
1560 * function also returns the state at the end of parsing the number if
1561 * it was valid (otherwise it returns 0.) This can be used for testing
1562 * for negative or zero values using the sticky flag.
1563 */
1564PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string,
1565 png_size_t size));
1566#endif /* pCAL || sCAL */
1567
1568#if defined(PNG_READ_GAMMA_SUPPORTED) ||\
1569 defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
1570/* Added at libpng version 1.5.0 */
1571/* This is a utility to provide a*times/div (rounded) and indicate
1572 * if there is an overflow. The result is a boolean - false (0)
1573 * for overflow, true (1) if no overflow, in which case *res
1574 * holds the result.
1575 */
1576PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
1577 png_int_32 multiplied_by, png_int_32 divided_by));
1578#endif
1579
1580#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
1581/* Same deal, but issue a warning on overflow and return 0. */
1582PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
1583 png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
1584#endif
1585
1586#ifdef PNG_READ_GAMMA_SUPPORTED
1587/* Calculate a reciprocal - used for gamma values. This returns
1588 * 0 if the argument is 0 in order to maintain an undefined value,
1589 * there are no warnings.
1590 */
1591PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a));
1592
1593/* The same but gives a reciprocal of the product of two fixed point
1594 * values. Accuracy is suitable for gamma calculations but this is
1595 * not exact - use png_muldiv for that.
1596 */
1597PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a,
1598 png_fixed_point b));
1599#endif
1600
1601#ifdef PNG_READ_GAMMA_SUPPORTED
1602/* Internal fixed point gamma correction. These APIs are called as
1603 * required to convert single values - they don't need to be fast,
1604 * they are not used when processing image pixel values.
1605 *
1606 * While the input is an 'unsigned' value it must actually be the
1607 * correct bit value - 0..255 or 0..65535 as required.
1608 */
1609PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
1610 unsigned int value, png_fixed_point gamma_value));
1611PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
1612PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
1613 png_fixed_point gamma_value));
1614PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
1615 png_fixed_point gamma_value));
1616PNG_EXTERN void png_destroy_gamma_table(png_structp png_ptr);
1617PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
1618 int bit_depth));
1619#endif
1620
1621/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
1622
1623#include "pngdebug.h"
1624
1625#ifdef __cplusplus
1626}
1627#endif
1628
1629#endif /* PNGPRIV_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngread.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngread.c
new file mode 100644
index 0000000..e2641d5
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngread.c
@@ -0,0 +1,1308 @@
1
2/* pngread.c - read a PNG file
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file contains routines that an application calls directly to
14 * read a PNG file or stream.
15 */
16
17#include "pngpriv.h"
18
19#ifdef PNG_READ_SUPPORTED
20
21/* Create a PNG structure for reading, and allocate any memory needed. */
22PNG_FUNCTION(png_structp,PNGAPI
23png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
24 png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)
25{
26
27#ifdef PNG_USER_MEM_SUPPORTED
28 return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
29 warn_fn, NULL, NULL, NULL));
30}
31
32/* Alternate create PNG structure for reading, and allocate any memory
33 * needed.
34 */
35PNG_FUNCTION(png_structp,PNGAPI
36png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
37 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
38 png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
39{
40#endif /* PNG_USER_MEM_SUPPORTED */
41
42#ifdef PNG_SETJMP_SUPPORTED
43 volatile
44#endif
45 png_structp png_ptr;
46 volatile int png_cleanup_needed = 0;
47
48#ifdef PNG_SETJMP_SUPPORTED
49#ifdef USE_FAR_KEYWORD
50 jmp_buf tmp_jmpbuf;
51#endif
52#endif
53
54 png_debug(1, "in png_create_read_struct");
55
56#ifdef PNG_USER_MEM_SUPPORTED
57 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
58 malloc_fn, mem_ptr);
59#else
60 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
61#endif
62 if (png_ptr == NULL)
63 return (NULL);
64
65 /* Added at libpng-1.2.6 */
66#ifdef PNG_USER_LIMITS_SUPPORTED
67 png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
68 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
69
70# ifdef PNG_USER_CHUNK_CACHE_MAX
71 /* Added at libpng-1.2.43 and 1.4.0 */
72 png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
73# endif
74
75# ifdef PNG_SET_USER_CHUNK_MALLOC_MAX
76 /* Added at libpng-1.2.43 and 1.4.1 */
77 png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
78# endif
79#endif
80
81#ifdef PNG_SETJMP_SUPPORTED
82/* Applications that neglect to set up their own setjmp() and then
83 * encounter a png_error() will longjmp here. Since the jmpbuf is
84 * then meaningless we abort instead of returning.
85 */
86#ifdef USE_FAR_KEYWORD
87 if (setjmp(tmp_jmpbuf))
88#else
89 if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */
90#endif
91 PNG_ABORT();
92#ifdef USE_FAR_KEYWORD
93 png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
94#endif
95#endif /* PNG_SETJMP_SUPPORTED */
96
97#ifdef PNG_USER_MEM_SUPPORTED
98 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
99#endif
100
101 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
102
103 /* Call the general version checker (shared with read and write code): */
104 if (!png_user_version_check(png_ptr, user_png_ver))
105 png_cleanup_needed = 1;
106
107 if (!png_cleanup_needed)
108 {
109 /* Initialize zbuf - compression buffer */
110 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
111 png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size);
112
113 if (png_ptr->zbuf == NULL)
114 png_cleanup_needed = 1;
115 }
116
117 png_ptr->zstream.zalloc = png_zalloc;
118 png_ptr->zstream.zfree = png_zfree;
119 png_ptr->zstream.opaque = (voidpf)png_ptr;
120
121 if (!png_cleanup_needed)
122 {
123 switch (inflateInit(&png_ptr->zstream))
124 {
125 case Z_OK:
126 break; /* Do nothing */
127
128 case Z_MEM_ERROR:
129 png_warning(png_ptr, "zlib memory error");
130 png_cleanup_needed = 1;
131 break;
132
133 case Z_STREAM_ERROR:
134 png_warning(png_ptr, "zlib stream error");
135 png_cleanup_needed = 1;
136 break;
137
138 case Z_VERSION_ERROR:
139 png_warning(png_ptr, "zlib version error");
140 png_cleanup_needed = 1;
141 break;
142
143 default: png_warning(png_ptr, "Unknown zlib error");
144 png_cleanup_needed = 1;
145 }
146 }
147
148 if (png_cleanup_needed)
149 {
150 /* Clean up PNG structure and deallocate any memory. */
151 png_free(png_ptr, png_ptr->zbuf);
152 png_ptr->zbuf = NULL;
153#ifdef PNG_USER_MEM_SUPPORTED
154 png_destroy_struct_2((png_voidp)png_ptr,
155 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
156#else
157 png_destroy_struct((png_voidp)png_ptr);
158#endif
159 return (NULL);
160 }
161
162 png_ptr->zstream.next_out = png_ptr->zbuf;
163 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
164
165 png_set_read_fn(png_ptr, NULL, NULL);
166
167
168 return (png_ptr);
169}
170
171
172#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
173/* Read the information before the actual image data. This has been
174 * changed in v0.90 to allow reading a file that already has the magic
175 * bytes read from the stream. You can tell libpng how many bytes have
176 * been read from the beginning of the stream (up to the maximum of 8)
177 * via png_set_sig_bytes(), and we will only check the remaining bytes
178 * here. The application can then have access to the signature bytes we
179 * read if it is determined that this isn't a valid PNG file.
180 */
181void PNGAPI
182png_read_info(png_structp png_ptr, png_infop info_ptr)
183{
184 png_debug(1, "in png_read_info");
185
186 if (png_ptr == NULL || info_ptr == NULL)
187 return;
188
189 /* Read and check the PNG file signature. */
190 png_read_sig(png_ptr, info_ptr);
191
192 for (;;)
193 {
194 png_uint_32 length = png_read_chunk_header(png_ptr);
195 png_uint_32 chunk_name = png_ptr->chunk_name;
196
197 /* This should be a binary subdivision search or a hash for
198 * matching the chunk name rather than a linear search.
199 */
200 if (chunk_name == png_IDAT)
201 if (png_ptr->mode & PNG_AFTER_IDAT)
202 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
203
204 if (chunk_name == png_IHDR)
205 png_handle_IHDR(png_ptr, info_ptr, length);
206
207 else if (chunk_name == png_IEND)
208 png_handle_IEND(png_ptr, info_ptr, length);
209
210#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
211 else if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
212 PNG_HANDLE_CHUNK_AS_DEFAULT)
213 {
214 if (chunk_name == png_IDAT)
215 png_ptr->mode |= PNG_HAVE_IDAT;
216
217 png_handle_unknown(png_ptr, info_ptr, length);
218
219 if (chunk_name == png_PLTE)
220 png_ptr->mode |= PNG_HAVE_PLTE;
221
222 else if (chunk_name == png_IDAT)
223 {
224 if (!(png_ptr->mode & PNG_HAVE_IHDR))
225 png_error(png_ptr, "Missing IHDR before IDAT");
226
227 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
228 !(png_ptr->mode & PNG_HAVE_PLTE))
229 png_error(png_ptr, "Missing PLTE before IDAT");
230
231 break;
232 }
233 }
234#endif
235 else if (chunk_name == png_PLTE)
236 png_handle_PLTE(png_ptr, info_ptr, length);
237
238 else if (chunk_name == png_IDAT)
239 {
240 if (!(png_ptr->mode & PNG_HAVE_IHDR))
241 png_error(png_ptr, "Missing IHDR before IDAT");
242
243 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
244 !(png_ptr->mode & PNG_HAVE_PLTE))
245 png_error(png_ptr, "Missing PLTE before IDAT");
246
247 png_ptr->idat_size = length;
248 png_ptr->mode |= PNG_HAVE_IDAT;
249 break;
250 }
251
252#ifdef PNG_READ_bKGD_SUPPORTED
253 else if (chunk_name == png_bKGD)
254 png_handle_bKGD(png_ptr, info_ptr, length);
255#endif
256
257#ifdef PNG_READ_cHRM_SUPPORTED
258 else if (chunk_name == png_cHRM)
259 png_handle_cHRM(png_ptr, info_ptr, length);
260#endif
261
262#ifdef PNG_READ_gAMA_SUPPORTED
263 else if (chunk_name == png_gAMA)
264 png_handle_gAMA(png_ptr, info_ptr, length);
265#endif
266
267#ifdef PNG_READ_hIST_SUPPORTED
268 else if (chunk_name == png_hIST)
269 png_handle_hIST(png_ptr, info_ptr, length);
270#endif
271
272#ifdef PNG_READ_oFFs_SUPPORTED
273 else if (chunk_name == png_oFFs)
274 png_handle_oFFs(png_ptr, info_ptr, length);
275#endif
276
277#ifdef PNG_READ_pCAL_SUPPORTED
278 else if (chunk_name == png_pCAL)
279 png_handle_pCAL(png_ptr, info_ptr, length);
280#endif
281
282#ifdef PNG_READ_sCAL_SUPPORTED
283 else if (chunk_name == png_sCAL)
284 png_handle_sCAL(png_ptr, info_ptr, length);
285#endif
286
287#ifdef PNG_READ_pHYs_SUPPORTED
288 else if (chunk_name == png_pHYs)
289 png_handle_pHYs(png_ptr, info_ptr, length);
290#endif
291
292#ifdef PNG_READ_sBIT_SUPPORTED
293 else if (chunk_name == png_sBIT)
294 png_handle_sBIT(png_ptr, info_ptr, length);
295#endif
296
297#ifdef PNG_READ_sRGB_SUPPORTED
298 else if (chunk_name == png_sRGB)
299 png_handle_sRGB(png_ptr, info_ptr, length);
300#endif
301
302#ifdef PNG_READ_iCCP_SUPPORTED
303 else if (chunk_name == png_iCCP)
304 png_handle_iCCP(png_ptr, info_ptr, length);
305#endif
306
307#ifdef PNG_READ_sPLT_SUPPORTED
308 else if (chunk_name == png_sPLT)
309 png_handle_sPLT(png_ptr, info_ptr, length);
310#endif
311
312#ifdef PNG_READ_tEXt_SUPPORTED
313 else if (chunk_name == png_tEXt)
314 png_handle_tEXt(png_ptr, info_ptr, length);
315#endif
316
317#ifdef PNG_READ_tIME_SUPPORTED
318 else if (chunk_name == png_tIME)
319 png_handle_tIME(png_ptr, info_ptr, length);
320#endif
321
322#ifdef PNG_READ_tRNS_SUPPORTED
323 else if (chunk_name == png_tRNS)
324 png_handle_tRNS(png_ptr, info_ptr, length);
325#endif
326
327#ifdef PNG_READ_zTXt_SUPPORTED
328 else if (chunk_name == png_zTXt)
329 png_handle_zTXt(png_ptr, info_ptr, length);
330#endif
331
332#ifdef PNG_READ_iTXt_SUPPORTED
333 else if (chunk_name == png_iTXt)
334 png_handle_iTXt(png_ptr, info_ptr, length);
335#endif
336
337 else
338 png_handle_unknown(png_ptr, info_ptr, length);
339 }
340}
341#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
342
343/* Optional call to update the users info_ptr structure */
344void PNGAPI
345png_read_update_info(png_structp png_ptr, png_infop info_ptr)
346{
347 png_debug(1, "in png_read_update_info");
348
349 if (png_ptr == NULL)
350 return;
351
352 png_read_start_row(png_ptr);
353
354#ifdef PNG_READ_TRANSFORMS_SUPPORTED
355 png_read_transform_info(png_ptr, info_ptr);
356#else
357 PNG_UNUSED(info_ptr)
358#endif
359}
360
361#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
362/* Initialize palette, background, etc, after transformations
363 * are set, but before any reading takes place. This allows
364 * the user to obtain a gamma-corrected palette, for example.
365 * If the user doesn't call this, we will do it ourselves.
366 */
367void PNGAPI
368png_start_read_image(png_structp png_ptr)
369{
370 png_debug(1, "in png_start_read_image");
371
372 if (png_ptr != NULL)
373 png_read_start_row(png_ptr);
374}
375#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
376
377#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
378void PNGAPI
379png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
380{
381 int ret;
382
383 png_row_info row_info;
384
385 if (png_ptr == NULL)
386 return;
387
388 png_debug2(1, "in png_read_row (row %lu, pass %d)",
389 (unsigned long)png_ptr->row_number, png_ptr->pass);
390
391 /* png_read_start_row sets the information (in particular iwidth) for this
392 * interlace pass.
393 */
394 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
395 png_read_start_row(png_ptr);
396
397 /* 1.5.6: row_info moved out of png_struct to a local here. */
398 row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */
399 row_info.color_type = png_ptr->color_type;
400 row_info.bit_depth = png_ptr->bit_depth;
401 row_info.channels = png_ptr->channels;
402 row_info.pixel_depth = png_ptr->pixel_depth;
403 row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
404
405 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
406 {
407 /* Check for transforms that have been set but were defined out */
408#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
409 if (png_ptr->transformations & PNG_INVERT_MONO)
410 png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined");
411#endif
412
413#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
414 if (png_ptr->transformations & PNG_FILLER)
415 png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined");
416#endif
417
418#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
419 !defined(PNG_READ_PACKSWAP_SUPPORTED)
420 if (png_ptr->transformations & PNG_PACKSWAP)
421 png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined");
422#endif
423
424#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
425 if (png_ptr->transformations & PNG_PACK)
426 png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined");
427#endif
428
429#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
430 if (png_ptr->transformations & PNG_SHIFT)
431 png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined");
432#endif
433
434#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
435 if (png_ptr->transformations & PNG_BGR)
436 png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined");
437#endif
438
439#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
440 if (png_ptr->transformations & PNG_SWAP_BYTES)
441 png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined");
442#endif
443 }
444
445#ifdef PNG_READ_INTERLACING_SUPPORTED
446 /* If interlaced and we do not need a new row, combine row and return.
447 * Notice that the pixels we have from previous rows have been transformed
448 * already; we can only combine like with like (transformed or
449 * untransformed) and, because of the libpng API for interlaced images, this
450 * means we must transform before de-interlacing.
451 */
452 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
453 {
454 switch (png_ptr->pass)
455 {
456 case 0:
457 if (png_ptr->row_number & 0x07)
458 {
459 if (dsp_row != NULL)
460 png_combine_row(png_ptr, dsp_row, 1/*display*/);
461 png_read_finish_row(png_ptr);
462 return;
463 }
464 break;
465
466 case 1:
467 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
468 {
469 if (dsp_row != NULL)
470 png_combine_row(png_ptr, dsp_row, 1/*display*/);
471
472 png_read_finish_row(png_ptr);
473 return;
474 }
475 break;
476
477 case 2:
478 if ((png_ptr->row_number & 0x07) != 4)
479 {
480 if (dsp_row != NULL && (png_ptr->row_number & 4))
481 png_combine_row(png_ptr, dsp_row, 1/*display*/);
482
483 png_read_finish_row(png_ptr);
484 return;
485 }
486 break;
487
488 case 3:
489 if ((png_ptr->row_number & 3) || png_ptr->width < 3)
490 {
491 if (dsp_row != NULL)
492 png_combine_row(png_ptr, dsp_row, 1/*display*/);
493
494 png_read_finish_row(png_ptr);
495 return;
496 }
497 break;
498
499 case 4:
500 if ((png_ptr->row_number & 3) != 2)
501 {
502 if (dsp_row != NULL && (png_ptr->row_number & 2))
503 png_combine_row(png_ptr, dsp_row, 1/*display*/);
504
505 png_read_finish_row(png_ptr);
506 return;
507 }
508 break;
509 case 5:
510 if ((png_ptr->row_number & 1) || png_ptr->width < 2)
511 {
512 if (dsp_row != NULL)
513 png_combine_row(png_ptr, dsp_row, 1/*display*/);
514
515 png_read_finish_row(png_ptr);
516 return;
517 }
518 break;
519
520 default:
521 case 6:
522 if (!(png_ptr->row_number & 1))
523 {
524 png_read_finish_row(png_ptr);
525 return;
526 }
527 break;
528 }
529 }
530#endif
531
532 if (!(png_ptr->mode & PNG_HAVE_IDAT))
533 png_error(png_ptr, "Invalid attempt to read row data");
534
535 png_ptr->zstream.next_out = png_ptr->row_buf;
536 png_ptr->zstream.avail_out =
537 (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,
538 png_ptr->iwidth) + 1);
539
540 do
541 {
542 if (!(png_ptr->zstream.avail_in))
543 {
544 while (!png_ptr->idat_size)
545 {
546 png_crc_finish(png_ptr, 0);
547
548 png_ptr->idat_size = png_read_chunk_header(png_ptr);
549 if (png_ptr->chunk_name != png_IDAT)
550 png_error(png_ptr, "Not enough image data");
551 }
552 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
553 png_ptr->zstream.next_in = png_ptr->zbuf;
554 if (png_ptr->zbuf_size > png_ptr->idat_size)
555 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
556 png_crc_read(png_ptr, png_ptr->zbuf,
557 (png_size_t)png_ptr->zstream.avail_in);
558 png_ptr->idat_size -= png_ptr->zstream.avail_in;
559 }
560
561 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
562
563 if (ret == Z_STREAM_END)
564 {
565 if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
566 png_ptr->idat_size)
567 png_benign_error(png_ptr, "Extra compressed data");
568 png_ptr->mode |= PNG_AFTER_IDAT;
569 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
570 break;
571 }
572
573 if (ret != Z_OK)
574 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
575 "Decompression error");
576
577 } while (png_ptr->zstream.avail_out);
578
579 if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
580 {
581 if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
582 png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
583 png_ptr->prev_row + 1, png_ptr->row_buf[0]);
584 else
585 png_error(png_ptr, "bad adaptive filter value");
586 }
587
588 /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before
589 * 1.5.6, while the buffer really is this big in current versions of libpng
590 * it may not be in the future, so this was changed just to copy the
591 * interlaced count:
592 */
593 png_memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
594
595#ifdef PNG_MNG_FEATURES_SUPPORTED
596 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
597 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
598 {
599 /* Intrapixel differencing */
600 png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1);
601 }
602#endif
603
604
605#ifdef PNG_READ_TRANSFORMS_SUPPORTED
606 if (png_ptr->transformations)
607 png_do_read_transformations(png_ptr, &row_info);
608#endif
609
610 /* The transformed pixel depth should match the depth now in row_info. */
611 if (png_ptr->transformed_pixel_depth == 0)
612 {
613 png_ptr->transformed_pixel_depth = row_info.pixel_depth;
614 if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)
615 png_error(png_ptr, "sequential row overflow");
616 }
617
618 else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)
619 png_error(png_ptr, "internal sequential row size calculation error");
620
621#ifdef PNG_READ_INTERLACING_SUPPORTED
622 /* Blow up interlaced rows to full size */
623 if (png_ptr->interlaced &&
624 (png_ptr->transformations & PNG_INTERLACE))
625 {
626 if (png_ptr->pass < 6)
627 png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
628 png_ptr->transformations);
629
630 if (dsp_row != NULL)
631 png_combine_row(png_ptr, dsp_row, 1/*display*/);
632
633 if (row != NULL)
634 png_combine_row(png_ptr, row, 0/*row*/);
635 }
636
637 else
638#endif
639 {
640 if (row != NULL)
641 png_combine_row(png_ptr, row, -1/*ignored*/);
642
643 if (dsp_row != NULL)
644 png_combine_row(png_ptr, dsp_row, -1/*ignored*/);
645 }
646 png_read_finish_row(png_ptr);
647
648 if (png_ptr->read_row_fn != NULL)
649 (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
650}
651#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
652
653#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
654/* Read one or more rows of image data. If the image is interlaced,
655 * and png_set_interlace_handling() has been called, the rows need to
656 * contain the contents of the rows from the previous pass. If the
657 * image has alpha or transparency, and png_handle_alpha()[*] has been
658 * called, the rows contents must be initialized to the contents of the
659 * screen.
660 *
661 * "row" holds the actual image, and pixels are placed in it
662 * as they arrive. If the image is displayed after each pass, it will
663 * appear to "sparkle" in. "display_row" can be used to display a
664 * "chunky" progressive image, with finer detail added as it becomes
665 * available. If you do not want this "chunky" display, you may pass
666 * NULL for display_row. If you do not want the sparkle display, and
667 * you have not called png_handle_alpha(), you may pass NULL for rows.
668 * If you have called png_handle_alpha(), and the image has either an
669 * alpha channel or a transparency chunk, you must provide a buffer for
670 * rows. In this case, you do not have to provide a display_row buffer
671 * also, but you may. If the image is not interlaced, or if you have
672 * not called png_set_interlace_handling(), the display_row buffer will
673 * be ignored, so pass NULL to it.
674 *
675 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
676 */
677
678void PNGAPI
679png_read_rows(png_structp png_ptr, png_bytepp row,
680 png_bytepp display_row, png_uint_32 num_rows)
681{
682 png_uint_32 i;
683 png_bytepp rp;
684 png_bytepp dp;
685
686 png_debug(1, "in png_read_rows");
687
688 if (png_ptr == NULL)
689 return;
690
691 rp = row;
692 dp = display_row;
693 if (rp != NULL && dp != NULL)
694 for (i = 0; i < num_rows; i++)
695 {
696 png_bytep rptr = *rp++;
697 png_bytep dptr = *dp++;
698
699 png_read_row(png_ptr, rptr, dptr);
700 }
701
702 else if (rp != NULL)
703 for (i = 0; i < num_rows; i++)
704 {
705 png_bytep rptr = *rp;
706 png_read_row(png_ptr, rptr, NULL);
707 rp++;
708 }
709
710 else if (dp != NULL)
711 for (i = 0; i < num_rows; i++)
712 {
713 png_bytep dptr = *dp;
714 png_read_row(png_ptr, NULL, dptr);
715 dp++;
716 }
717}
718#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
719
720#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
721/* Read the entire image. If the image has an alpha channel or a tRNS
722 * chunk, and you have called png_handle_alpha()[*], you will need to
723 * initialize the image to the current image that PNG will be overlaying.
724 * We set the num_rows again here, in case it was incorrectly set in
725 * png_read_start_row() by a call to png_read_update_info() or
726 * png_start_read_image() if png_set_interlace_handling() wasn't called
727 * prior to either of these functions like it should have been. You can
728 * only call this function once. If you desire to have an image for
729 * each pass of a interlaced image, use png_read_rows() instead.
730 *
731 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
732 */
733void PNGAPI
734png_read_image(png_structp png_ptr, png_bytepp image)
735{
736 png_uint_32 i, image_height;
737 int pass, j;
738 png_bytepp rp;
739
740 png_debug(1, "in png_read_image");
741
742 if (png_ptr == NULL)
743 return;
744
745#ifdef PNG_READ_INTERLACING_SUPPORTED
746 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
747 {
748 pass = png_set_interlace_handling(png_ptr);
749 /* And make sure transforms are initialized. */
750 png_start_read_image(png_ptr);
751 }
752 else
753 {
754 if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE))
755 {
756 /* Caller called png_start_read_image or png_read_update_info without
757 * first turning on the PNG_INTERLACE transform. We can fix this here,
758 * but the caller should do it!
759 */
760 png_warning(png_ptr, "Interlace handling should be turned on when "
761 "using png_read_image");
762 /* Make sure this is set correctly */
763 png_ptr->num_rows = png_ptr->height;
764 }
765
766 /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in
767 * the above error case.
768 */
769 pass = png_set_interlace_handling(png_ptr);
770 }
771#else
772 if (png_ptr->interlaced)
773 png_error(png_ptr,
774 "Cannot read interlaced image -- interlace handler disabled");
775
776 pass = 1;
777#endif
778
779 image_height=png_ptr->height;
780
781 for (j = 0; j < pass; j++)
782 {
783 rp = image;
784 for (i = 0; i < image_height; i++)
785 {
786 png_read_row(png_ptr, *rp, NULL);
787 rp++;
788 }
789 }
790}
791#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
792
793#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
794/* Read the end of the PNG file. Will not read past the end of the
795 * file, will verify the end is accurate, and will read any comments
796 * or time information at the end of the file, if info is not NULL.
797 */
798void PNGAPI
799png_read_end(png_structp png_ptr, png_infop info_ptr)
800{
801 png_debug(1, "in png_read_end");
802
803 if (png_ptr == NULL)
804 return;
805
806 png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
807
808 do
809 {
810 png_uint_32 length = png_read_chunk_header(png_ptr);
811 png_uint_32 chunk_name = png_ptr->chunk_name;
812
813 if (chunk_name == png_IHDR)
814 png_handle_IHDR(png_ptr, info_ptr, length);
815
816 else if (chunk_name == png_IEND)
817 png_handle_IEND(png_ptr, info_ptr, length);
818
819#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
820 else if (png_chunk_unknown_handling(png_ptr, chunk_name) !=
821 PNG_HANDLE_CHUNK_AS_DEFAULT)
822 {
823 if (chunk_name == png_IDAT)
824 {
825 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
826 png_benign_error(png_ptr, "Too many IDATs found");
827 }
828 png_handle_unknown(png_ptr, info_ptr, length);
829 if (chunk_name == png_PLTE)
830 png_ptr->mode |= PNG_HAVE_PLTE;
831 }
832#endif
833
834 else if (chunk_name == png_IDAT)
835 {
836 /* Zero length IDATs are legal after the last IDAT has been
837 * read, but not after other chunks have been read.
838 */
839 if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
840 png_benign_error(png_ptr, "Too many IDATs found");
841
842 png_crc_finish(png_ptr, length);
843 }
844 else if (chunk_name == png_PLTE)
845 png_handle_PLTE(png_ptr, info_ptr, length);
846
847#ifdef PNG_READ_bKGD_SUPPORTED
848 else if (chunk_name == png_bKGD)
849 png_handle_bKGD(png_ptr, info_ptr, length);
850#endif
851
852#ifdef PNG_READ_cHRM_SUPPORTED
853 else if (chunk_name == png_cHRM)
854 png_handle_cHRM(png_ptr, info_ptr, length);
855#endif
856
857#ifdef PNG_READ_gAMA_SUPPORTED
858 else if (chunk_name == png_gAMA)
859 png_handle_gAMA(png_ptr, info_ptr, length);
860#endif
861
862#ifdef PNG_READ_hIST_SUPPORTED
863 else if (chunk_name == png_hIST)
864 png_handle_hIST(png_ptr, info_ptr, length);
865#endif
866
867#ifdef PNG_READ_oFFs_SUPPORTED
868 else if (chunk_name == png_oFFs)
869 png_handle_oFFs(png_ptr, info_ptr, length);
870#endif
871
872#ifdef PNG_READ_pCAL_SUPPORTED
873 else if (chunk_name == png_pCAL)
874 png_handle_pCAL(png_ptr, info_ptr, length);
875#endif
876
877#ifdef PNG_READ_sCAL_SUPPORTED
878 else if (chunk_name == png_sCAL)
879 png_handle_sCAL(png_ptr, info_ptr, length);
880#endif
881
882#ifdef PNG_READ_pHYs_SUPPORTED
883 else if (chunk_name == png_pHYs)
884 png_handle_pHYs(png_ptr, info_ptr, length);
885#endif
886
887#ifdef PNG_READ_sBIT_SUPPORTED
888 else if (chunk_name == png_sBIT)
889 png_handle_sBIT(png_ptr, info_ptr, length);
890#endif
891
892#ifdef PNG_READ_sRGB_SUPPORTED
893 else if (chunk_name == png_sRGB)
894 png_handle_sRGB(png_ptr, info_ptr, length);
895#endif
896
897#ifdef PNG_READ_iCCP_SUPPORTED
898 else if (chunk_name == png_iCCP)
899 png_handle_iCCP(png_ptr, info_ptr, length);
900#endif
901
902#ifdef PNG_READ_sPLT_SUPPORTED
903 else if (chunk_name == png_sPLT)
904 png_handle_sPLT(png_ptr, info_ptr, length);
905#endif
906
907#ifdef PNG_READ_tEXt_SUPPORTED
908 else if (chunk_name == png_tEXt)
909 png_handle_tEXt(png_ptr, info_ptr, length);
910#endif
911
912#ifdef PNG_READ_tIME_SUPPORTED
913 else if (chunk_name == png_tIME)
914 png_handle_tIME(png_ptr, info_ptr, length);
915#endif
916
917#ifdef PNG_READ_tRNS_SUPPORTED
918 else if (chunk_name == png_tRNS)
919 png_handle_tRNS(png_ptr, info_ptr, length);
920#endif
921
922#ifdef PNG_READ_zTXt_SUPPORTED
923 else if (chunk_name == png_zTXt)
924 png_handle_zTXt(png_ptr, info_ptr, length);
925#endif
926
927#ifdef PNG_READ_iTXt_SUPPORTED
928 else if (chunk_name == png_iTXt)
929 png_handle_iTXt(png_ptr, info_ptr, length);
930#endif
931
932 else
933 png_handle_unknown(png_ptr, info_ptr, length);
934 } while (!(png_ptr->mode & PNG_HAVE_IEND));
935}
936#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
937
938/* Free all memory used by the read */
939void PNGAPI
940png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
941 png_infopp end_info_ptr_ptr)
942{
943 png_structp png_ptr = NULL;
944 png_infop info_ptr = NULL, end_info_ptr = NULL;
945#ifdef PNG_USER_MEM_SUPPORTED
946 png_free_ptr free_fn = NULL;
947 png_voidp mem_ptr = NULL;
948#endif
949
950 png_debug(1, "in png_destroy_read_struct");
951
952 if (png_ptr_ptr != NULL)
953 png_ptr = *png_ptr_ptr;
954 if (png_ptr == NULL)
955 return;
956
957#ifdef PNG_USER_MEM_SUPPORTED
958 free_fn = png_ptr->free_fn;
959 mem_ptr = png_ptr->mem_ptr;
960#endif
961
962 if (info_ptr_ptr != NULL)
963 info_ptr = *info_ptr_ptr;
964
965 if (end_info_ptr_ptr != NULL)
966 end_info_ptr = *end_info_ptr_ptr;
967
968 png_read_destroy(png_ptr, info_ptr, end_info_ptr);
969
970 if (info_ptr != NULL)
971 {
972#ifdef PNG_TEXT_SUPPORTED
973 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
974#endif
975
976#ifdef PNG_USER_MEM_SUPPORTED
977 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
978 (png_voidp)mem_ptr);
979#else
980 png_destroy_struct((png_voidp)info_ptr);
981#endif
982 *info_ptr_ptr = NULL;
983 }
984
985 if (end_info_ptr != NULL)
986 {
987#ifdef PNG_READ_TEXT_SUPPORTED
988 png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
989#endif
990#ifdef PNG_USER_MEM_SUPPORTED
991 png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
992 (png_voidp)mem_ptr);
993#else
994 png_destroy_struct((png_voidp)end_info_ptr);
995#endif
996 *end_info_ptr_ptr = NULL;
997 }
998
999 if (png_ptr != NULL)
1000 {
1001#ifdef PNG_USER_MEM_SUPPORTED
1002 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
1003 (png_voidp)mem_ptr);
1004#else
1005 png_destroy_struct((png_voidp)png_ptr);
1006#endif
1007 *png_ptr_ptr = NULL;
1008 }
1009}
1010
1011/* Free all memory used by the read (old method) */
1012void /* PRIVATE */
1013png_read_destroy(png_structp png_ptr, png_infop info_ptr,
1014 png_infop end_info_ptr)
1015{
1016#ifdef PNG_SETJMP_SUPPORTED
1017 jmp_buf tmp_jmp;
1018#endif
1019 png_error_ptr error_fn;
1020#ifdef PNG_WARNINGS_SUPPORTED
1021 png_error_ptr warning_fn;
1022#endif
1023 png_voidp error_ptr;
1024#ifdef PNG_USER_MEM_SUPPORTED
1025 png_free_ptr free_fn;
1026#endif
1027
1028 png_debug(1, "in png_read_destroy");
1029
1030 if (info_ptr != NULL)
1031 png_info_destroy(png_ptr, info_ptr);
1032
1033 if (end_info_ptr != NULL)
1034 png_info_destroy(png_ptr, end_info_ptr);
1035
1036#ifdef PNG_READ_GAMMA_SUPPORTED
1037 png_destroy_gamma_table(png_ptr);
1038#endif
1039
1040 png_free(png_ptr, png_ptr->zbuf);
1041 png_free(png_ptr, png_ptr->big_row_buf);
1042 png_free(png_ptr, png_ptr->big_prev_row);
1043 png_free(png_ptr, png_ptr->chunkdata);
1044
1045#ifdef PNG_READ_QUANTIZE_SUPPORTED
1046 png_free(png_ptr, png_ptr->palette_lookup);
1047 png_free(png_ptr, png_ptr->quantize_index);
1048#endif
1049
1050 if (png_ptr->free_me & PNG_FREE_PLTE)
1051 png_zfree(png_ptr, png_ptr->palette);
1052 png_ptr->free_me &= ~PNG_FREE_PLTE;
1053
1054#if defined(PNG_tRNS_SUPPORTED) || \
1055 defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
1056 if (png_ptr->free_me & PNG_FREE_TRNS)
1057 png_free(png_ptr, png_ptr->trans_alpha);
1058 png_ptr->free_me &= ~PNG_FREE_TRNS;
1059#endif
1060
1061#ifdef PNG_READ_hIST_SUPPORTED
1062 if (png_ptr->free_me & PNG_FREE_HIST)
1063 png_free(png_ptr, png_ptr->hist);
1064 png_ptr->free_me &= ~PNG_FREE_HIST;
1065#endif
1066
1067 inflateEnd(&png_ptr->zstream);
1068
1069#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1070 png_free(png_ptr, png_ptr->save_buffer);
1071#endif
1072
1073#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
1074#ifdef PNG_TEXT_SUPPORTED
1075 png_free(png_ptr, png_ptr->current_text);
1076#endif /* PNG_TEXT_SUPPORTED */
1077#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
1078
1079 /* Save the important info out of the png_struct, in case it is
1080 * being used again.
1081 */
1082#ifdef PNG_SETJMP_SUPPORTED
1083 png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
1084#endif
1085
1086 error_fn = png_ptr->error_fn;
1087#ifdef PNG_WARNINGS_SUPPORTED
1088 warning_fn = png_ptr->warning_fn;
1089#endif
1090 error_ptr = png_ptr->error_ptr;
1091#ifdef PNG_USER_MEM_SUPPORTED
1092 free_fn = png_ptr->free_fn;
1093#endif
1094
1095 png_memset(png_ptr, 0, png_sizeof(png_struct));
1096
1097 png_ptr->error_fn = error_fn;
1098#ifdef PNG_WARNINGS_SUPPORTED
1099 png_ptr->warning_fn = warning_fn;
1100#endif
1101 png_ptr->error_ptr = error_ptr;
1102#ifdef PNG_USER_MEM_SUPPORTED
1103 png_ptr->free_fn = free_fn;
1104#endif
1105
1106#ifdef PNG_SETJMP_SUPPORTED
1107 png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf));
1108#endif
1109
1110}
1111
1112void PNGAPI
1113png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
1114{
1115 if (png_ptr == NULL)
1116 return;
1117
1118 png_ptr->read_row_fn = read_row_fn;
1119}
1120
1121
1122#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
1123#ifdef PNG_INFO_IMAGE_SUPPORTED
1124void PNGAPI
1125png_read_png(png_structp png_ptr, png_infop info_ptr,
1126 int transforms,
1127 voidp params)
1128{
1129 int row;
1130
1131 if (png_ptr == NULL || info_ptr == NULL)
1132 return;
1133
1134 /* png_read_info() gives us all of the information from the
1135 * PNG file before the first IDAT (image data chunk).
1136 */
1137 png_read_info(png_ptr, info_ptr);
1138 if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
1139 png_error(png_ptr, "Image is too high to process with png_read_png()");
1140
1141 /* -------------- image transformations start here ------------------- */
1142
1143#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1144 /* Tell libpng to strip 16-bit/color files down to 8 bits per color.
1145 */
1146 if (transforms & PNG_TRANSFORM_SCALE_16)
1147 {
1148 /* Added at libpng-1.5.4. "strip_16" produces the same result that it
1149 * did in earlier versions, while "scale_16" is now more accurate.
1150 */
1151 png_set_scale_16(png_ptr);
1152 }
1153#endif
1154
1155#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1156 /* If both SCALE and STRIP are required pngrtran will effectively cancel the
1157 * latter by doing SCALE first. This is ok and allows apps not to check for
1158 * which is supported to get the right answer.
1159 */
1160 if (transforms & PNG_TRANSFORM_STRIP_16)
1161 png_set_strip_16(png_ptr);
1162#endif
1163
1164#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1165 /* Strip alpha bytes from the input data without combining with
1166 * the background (not recommended).
1167 */
1168 if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
1169 png_set_strip_alpha(png_ptr);
1170#endif
1171
1172#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
1173 /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single
1174 * byte into separate bytes (useful for paletted and grayscale images).
1175 */
1176 if (transforms & PNG_TRANSFORM_PACKING)
1177 png_set_packing(png_ptr);
1178#endif
1179
1180#ifdef PNG_READ_PACKSWAP_SUPPORTED
1181 /* Change the order of packed pixels to least significant bit first
1182 * (not useful if you are using png_set_packing).
1183 */
1184 if (transforms & PNG_TRANSFORM_PACKSWAP)
1185 png_set_packswap(png_ptr);
1186#endif
1187
1188#ifdef PNG_READ_EXPAND_SUPPORTED
1189 /* Expand paletted colors into true RGB triplets
1190 * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
1191 * Expand paletted or RGB images with transparency to full alpha
1192 * channels so the data will be available as RGBA quartets.
1193 */
1194 if (transforms & PNG_TRANSFORM_EXPAND)
1195 if ((png_ptr->bit_depth < 8) ||
1196 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
1197 (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
1198 png_set_expand(png_ptr);
1199#endif
1200
1201 /* We don't handle background color or gamma transformation or quantizing.
1202 */
1203
1204#ifdef PNG_READ_INVERT_SUPPORTED
1205 /* Invert monochrome files to have 0 as white and 1 as black
1206 */
1207 if (transforms & PNG_TRANSFORM_INVERT_MONO)
1208 png_set_invert_mono(png_ptr);
1209#endif
1210
1211#ifdef PNG_READ_SHIFT_SUPPORTED
1212 /* If you want to shift the pixel values from the range [0,255] or
1213 * [0,65535] to the original [0,7] or [0,31], or whatever range the
1214 * colors were originally in:
1215 */
1216 if ((transforms & PNG_TRANSFORM_SHIFT)
1217 && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
1218 {
1219 png_color_8p sig_bit;
1220
1221 png_get_sBIT(png_ptr, info_ptr, &sig_bit);
1222 png_set_shift(png_ptr, sig_bit);
1223 }
1224#endif
1225
1226#ifdef PNG_READ_BGR_SUPPORTED
1227 /* Flip the RGB pixels to BGR (or RGBA to BGRA) */
1228 if (transforms & PNG_TRANSFORM_BGR)
1229 png_set_bgr(png_ptr);
1230#endif
1231
1232#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
1233 /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
1234 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1235 png_set_swap_alpha(png_ptr);
1236#endif
1237
1238#ifdef PNG_READ_SWAP_SUPPORTED
1239 /* Swap bytes of 16-bit files to least significant byte first */
1240 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1241 png_set_swap(png_ptr);
1242#endif
1243
1244/* Added at libpng-1.2.41 */
1245#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
1246 /* Invert the alpha channel from opacity to transparency */
1247 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1248 png_set_invert_alpha(png_ptr);
1249#endif
1250
1251/* Added at libpng-1.2.41 */
1252#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1253 /* Expand grayscale image to RGB */
1254 if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
1255 png_set_gray_to_rgb(png_ptr);
1256#endif
1257
1258/* Added at libpng-1.5.4 */
1259#ifdef PNG_READ_EXPAND_16_SUPPORTED
1260 if (transforms & PNG_TRANSFORM_EXPAND_16)
1261 png_set_expand_16(png_ptr);
1262#endif
1263
1264 /* We don't handle adding filler bytes */
1265
1266 /* We use png_read_image and rely on that for interlace handling, but we also
1267 * call png_read_update_info therefore must turn on interlace handling now:
1268 */
1269 (void)png_set_interlace_handling(png_ptr);
1270
1271 /* Optional call to gamma correct and add the background to the palette
1272 * and update info structure. REQUIRED if you are expecting libpng to
1273 * update the palette for you (i.e., you selected such a transform above).
1274 */
1275 png_read_update_info(png_ptr, info_ptr);
1276
1277 /* -------------- image transformations end here ------------------- */
1278
1279 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1280 if (info_ptr->row_pointers == NULL)
1281 {
1282 png_uint_32 iptr;
1283
1284 info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
1285 info_ptr->height * png_sizeof(png_bytep));
1286 for (iptr=0; iptr<info_ptr->height; iptr++)
1287 info_ptr->row_pointers[iptr] = NULL;
1288
1289 info_ptr->free_me |= PNG_FREE_ROWS;
1290
1291 for (row = 0; row < (int)info_ptr->height; row++)
1292 info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
1293 png_get_rowbytes(png_ptr, info_ptr));
1294 }
1295
1296 png_read_image(png_ptr, info_ptr->row_pointers);
1297 info_ptr->valid |= PNG_INFO_IDAT;
1298
1299 /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
1300 png_read_end(png_ptr, info_ptr);
1301
1302 PNG_UNUSED(transforms) /* Quiet compiler warnings */
1303 PNG_UNUSED(params)
1304
1305}
1306#endif /* PNG_INFO_IMAGE_SUPPORTED */
1307#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
1308#endif /* PNG_READ_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrio.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrio.c
new file mode 100644
index 0000000..d0d9d8a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrio.c
@@ -0,0 +1,176 @@
1
2/* pngrio.c - functions for data input
3 *
4 * Last changed in libpng 1.5.0 [January 6, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file provides a location for all input. Users who need
14 * special handling are expected to write a function that has the same
15 * arguments as this and performs a similar function, but that possibly
16 * has a different input method. Note that you shouldn't change this
17 * function, but rather write a replacement function and then make
18 * libpng use it at run time with png_set_read_fn(...).
19 */
20
21#include "pngpriv.h"
22
23#ifdef PNG_READ_SUPPORTED
24
25/* Read the data from whatever input you are using. The default routine
26 * reads from a file pointer. Note that this routine sometimes gets called
27 * with very small lengths, so you should implement some kind of simple
28 * buffering if you are using unbuffered reads. This should never be asked
29 * to read more then 64K on a 16 bit machine.
30 */
31void /* PRIVATE */
32png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
33{
34 png_debug1(4, "reading %d bytes", (int)length);
35
36 if (png_ptr->read_data_fn != NULL)
37 (*(png_ptr->read_data_fn))(png_ptr, data, length);
38
39 else
40 png_error(png_ptr, "Call to NULL read function");
41}
42
43#ifdef PNG_STDIO_SUPPORTED
44/* This is the function that does the actual reading of data. If you are
45 * not reading from a standard C stream, you should create a replacement
46 * read_data function and use it at run time with png_set_read_fn(), rather
47 * than changing the library.
48 */
49# ifndef USE_FAR_KEYWORD
50void PNGCBAPI
51png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
52{
53 png_size_t check;
54
55 if (png_ptr == NULL)
56 return;
57
58 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
59 * instead of an int, which is what fread() actually returns.
60 */
61 check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr);
62
63 if (check != length)
64 png_error(png_ptr, "Read Error");
65}
66# else
67/* This is the model-independent version. Since the standard I/O library
68 can't handle far buffers in the medium and small models, we have to copy
69 the data.
70*/
71
72#define NEAR_BUF_SIZE 1024
73#define MIN(a,b) (a <= b ? a : b)
74
75static void PNGCBAPI
76png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
77{
78 png_size_t check;
79 png_byte *n_data;
80 png_FILE_p io_ptr;
81
82 if (png_ptr == NULL)
83 return;
84
85 /* Check if data really is near. If so, use usual code. */
86 n_data = (png_byte *)CVT_PTR_NOCHECK(data);
87 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
88
89 if ((png_bytep)n_data == data)
90 {
91 check = fread(n_data, 1, length, io_ptr);
92 }
93
94 else
95 {
96 png_byte buf[NEAR_BUF_SIZE];
97 png_size_t read, remaining, err;
98 check = 0;
99 remaining = length;
100
101 do
102 {
103 read = MIN(NEAR_BUF_SIZE, remaining);
104 err = fread(buf, 1, read, io_ptr);
105 png_memcpy(data, buf, read); /* copy far buffer to near buffer */
106
107 if (err != read)
108 break;
109
110 else
111 check += err;
112
113 data += read;
114 remaining -= read;
115 }
116 while (remaining != 0);
117 }
118
119 if ((png_uint_32)check != (png_uint_32)length)
120 png_error(png_ptr, "read Error");
121}
122# endif
123#endif
124
125/* This function allows the application to supply a new input function
126 * for libpng if standard C streams aren't being used.
127 *
128 * This function takes as its arguments:
129 *
130 * png_ptr - pointer to a png input data structure
131 *
132 * io_ptr - pointer to user supplied structure containing info about
133 * the input functions. May be NULL.
134 *
135 * read_data_fn - pointer to a new input function that takes as its
136 * arguments a pointer to a png_struct, a pointer to
137 * a location where input data can be stored, and a 32-bit
138 * unsigned int that is the number of bytes to be read.
139 * To exit and output any fatal error messages the new write
140 * function should call png_error(png_ptr, "Error msg").
141 * May be NULL, in which case libpng's default function will
142 * be used.
143 */
144void PNGAPI
145png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
146 png_rw_ptr read_data_fn)
147{
148 if (png_ptr == NULL)
149 return;
150
151 png_ptr->io_ptr = io_ptr;
152
153#ifdef PNG_STDIO_SUPPORTED
154 if (read_data_fn != NULL)
155 png_ptr->read_data_fn = read_data_fn;
156
157 else
158 png_ptr->read_data_fn = png_default_read_data;
159#else
160 png_ptr->read_data_fn = read_data_fn;
161#endif
162
163 /* It is an error to write to a read device */
164 if (png_ptr->write_data_fn != NULL)
165 {
166 png_ptr->write_data_fn = NULL;
167 png_warning(png_ptr,
168 "Can't set both read_data_fn and write_data_fn in the"
169 " same structure");
170 }
171
172#ifdef PNG_WRITE_FLUSH_SUPPORTED
173 png_ptr->output_flush_fn = NULL;
174#endif
175}
176#endif /* PNG_READ_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrtran.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrtran.c
new file mode 100644
index 0000000..26083a0
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrtran.c
@@ -0,0 +1,5023 @@
1
2/* pngrtran.c - transforms the data in a row for PNG readers
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file contains functions optionally called by an application
14 * in order to tell libpng how to handle data when reading a PNG.
15 * Transformations that are used in both reading and writing are
16 * in pngtrans.c.
17 */
18
19#include "pngpriv.h"
20
21#ifdef PNG_READ_SUPPORTED
22
23/* Set the action on getting a CRC error for an ancillary or critical chunk. */
24void PNGAPI
25png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
26{
27 png_debug(1, "in png_set_crc_action");
28
29 if (png_ptr == NULL)
30 return;
31
32 /* Tell libpng how we react to CRC errors in critical chunks */
33 switch (crit_action)
34 {
35 case PNG_CRC_NO_CHANGE: /* Leave setting as is */
36 break;
37
38 case PNG_CRC_WARN_USE: /* Warn/use data */
39 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
40 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
41 break;
42
43 case PNG_CRC_QUIET_USE: /* Quiet/use data */
44 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
45 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
46 PNG_FLAG_CRC_CRITICAL_IGNORE;
47 break;
48
49 case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */
50 png_warning(png_ptr,
51 "Can't discard critical data on CRC error");
52 case PNG_CRC_ERROR_QUIT: /* Error/quit */
53
54 case PNG_CRC_DEFAULT:
55 default:
56 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
57 break;
58 }
59
60 /* Tell libpng how we react to CRC errors in ancillary chunks */
61 switch (ancil_action)
62 {
63 case PNG_CRC_NO_CHANGE: /* Leave setting as is */
64 break;
65
66 case PNG_CRC_WARN_USE: /* Warn/use data */
67 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
68 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
69 break;
70
71 case PNG_CRC_QUIET_USE: /* Quiet/use data */
72 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
73 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
74 PNG_FLAG_CRC_ANCILLARY_NOWARN;
75 break;
76
77 case PNG_CRC_ERROR_QUIT: /* Error/quit */
78 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
79 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
80 break;
81
82 case PNG_CRC_WARN_DISCARD: /* Warn/discard data */
83
84 case PNG_CRC_DEFAULT:
85 default:
86 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
87 break;
88 }
89}
90
91#ifdef PNG_READ_BACKGROUND_SUPPORTED
92/* Handle alpha and tRNS via a background color */
93void PNGFAPI
94png_set_background_fixed(png_structp png_ptr,
95 png_const_color_16p background_color, int background_gamma_code,
96 int need_expand, png_fixed_point background_gamma)
97{
98 png_debug(1, "in png_set_background_fixed");
99
100 if (png_ptr == NULL)
101 return;
102
103 if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
104 {
105 png_warning(png_ptr, "Application must supply a known background gamma");
106 return;
107 }
108
109 png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA;
110 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
111 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
112
113 png_memcpy(&(png_ptr->background), background_color,
114 png_sizeof(png_color_16));
115 png_ptr->background_gamma = background_gamma;
116 png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
117 if (need_expand)
118 png_ptr->transformations |= PNG_BACKGROUND_EXPAND;
119 else
120 png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
121}
122
123# ifdef PNG_FLOATING_POINT_SUPPORTED
124void PNGAPI
125png_set_background(png_structp png_ptr,
126 png_const_color_16p background_color, int background_gamma_code,
127 int need_expand, double background_gamma)
128{
129 png_set_background_fixed(png_ptr, background_color, background_gamma_code,
130 need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
131}
132# endif /* FLOATING_POINT */
133#endif /* READ_BACKGROUND */
134
135/* Scale 16-bit depth files to 8-bit depth. If both of these are set then the
136 * one that pngrtran does first (scale) happens. This is necessary to allow the
137 * TRANSFORM and API behavior to be somewhat consistent, and it's simpler.
138 */
139#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
140void PNGAPI
141png_set_scale_16(png_structp png_ptr)
142{
143 png_debug(1, "in png_set_scale_16");
144
145 if (png_ptr == NULL)
146 return;
147
148 png_ptr->transformations |= PNG_SCALE_16_TO_8;
149}
150#endif
151
152#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
153/* Chop 16-bit depth files to 8-bit depth */
154void PNGAPI
155png_set_strip_16(png_structp png_ptr)
156{
157 png_debug(1, "in png_set_strip_16");
158
159 if (png_ptr == NULL)
160 return;
161
162 png_ptr->transformations |= PNG_16_TO_8;
163}
164#endif
165
166#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
167void PNGAPI
168png_set_strip_alpha(png_structp png_ptr)
169{
170 png_debug(1, "in png_set_strip_alpha");
171
172 if (png_ptr == NULL)
173 return;
174
175 png_ptr->transformations |= PNG_STRIP_ALPHA;
176}
177#endif
178
179#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
180static png_fixed_point
181translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma,
182 int is_screen)
183{
184 /* Check for flag values. The main reason for having the old Mac value as a
185 * flag is that it is pretty near impossible to work out what the correct
186 * value is from Apple documentation - a working Mac system is needed to
187 * discover the value!
188 */
189 if (output_gamma == PNG_DEFAULT_sRGB ||
190 output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB)
191 {
192 /* If there is no sRGB support this just sets the gamma to the standard
193 * sRGB value. (This is a side effect of using this function!)
194 */
195# ifdef PNG_READ_sRGB_SUPPORTED
196 png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;
197# endif
198 if (is_screen)
199 output_gamma = PNG_GAMMA_sRGB;
200 else
201 output_gamma = PNG_GAMMA_sRGB_INVERSE;
202 }
203
204 else if (output_gamma == PNG_GAMMA_MAC_18 ||
205 output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18)
206 {
207 if (is_screen)
208 output_gamma = PNG_GAMMA_MAC_OLD;
209 else
210 output_gamma = PNG_GAMMA_MAC_INVERSE;
211 }
212
213 return output_gamma;
214}
215
216# ifdef PNG_FLOATING_POINT_SUPPORTED
217static png_fixed_point
218convert_gamma_value(png_structp png_ptr, double output_gamma)
219{
220 /* The following silently ignores cases where fixed point (times 100,000)
221 * gamma values are passed to the floating point API. This is safe and it
222 * means the fixed point constants work just fine with the floating point
223 * API. The alternative would just lead to undetected errors and spurious
224 * bug reports. Negative values fail inside the _fixed API unless they
225 * correspond to the flag values.
226 */
227 if (output_gamma > 0 && output_gamma < 128)
228 output_gamma *= PNG_FP_1;
229
230 /* This preserves -1 and -2 exactly: */
231 output_gamma = floor(output_gamma + .5);
232
233 if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN)
234 png_fixed_error(png_ptr, "gamma value");
235
236 return (png_fixed_point)output_gamma;
237}
238# endif
239#endif /* READ_ALPHA_MODE || READ_GAMMA */
240
241#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
242void PNGFAPI
243png_set_alpha_mode_fixed(png_structp png_ptr, int mode,
244 png_fixed_point output_gamma)
245{
246 int compose = 0;
247 png_fixed_point file_gamma;
248
249 png_debug(1, "in png_set_alpha_mode");
250
251 if (png_ptr == NULL)
252 return;
253
254 output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);
255
256 /* Validate the value to ensure it is in a reasonable range. The value
257 * is expected to be 1 or greater, but this range test allows for some
258 * viewing correction values. The intent is to weed out users of this API
259 * who use the inverse of the gamma value accidentally! Since some of these
260 * values are reasonable this may have to be changed.
261 */
262 if (output_gamma < 70000 || output_gamma > 300000)
263 png_error(png_ptr, "output gamma out of expected range");
264
265 /* The default file gamma is the inverse of the output gamma; the output
266 * gamma may be changed below so get the file value first:
267 */
268 file_gamma = png_reciprocal(output_gamma);
269
270 /* There are really 8 possibilities here, composed of any combination
271 * of:
272 *
273 * premultiply the color channels
274 * do not encode non-opaque pixels
275 * encode the alpha as well as the color channels
276 *
277 * The differences disappear if the input/output ('screen') gamma is 1.0,
278 * because then the encoding is a no-op and there is only the choice of
279 * premultiplying the color channels or not.
280 *
281 * png_set_alpha_mode and png_set_background interact because both use
282 * png_compose to do the work. Calling both is only useful when
283 * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along
284 * with a default gamma value. Otherwise PNG_COMPOSE must not be set.
285 */
286 switch (mode)
287 {
288 case PNG_ALPHA_PNG: /* default: png standard */
289 /* No compose, but it may be set by png_set_background! */
290 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
291 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
292 break;
293
294 case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */
295 compose = 1;
296 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
297 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
298 /* The output is linear: */
299 output_gamma = PNG_FP_1;
300 break;
301
302 case PNG_ALPHA_OPTIMIZED: /* associated, non-opaque pixels linear */
303 compose = 1;
304 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
305 png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;
306 /* output_gamma records the encoding of opaque pixels! */
307 break;
308
309 case PNG_ALPHA_BROKEN: /* associated, non-linear, alpha encoded */
310 compose = 1;
311 png_ptr->transformations |= PNG_ENCODE_ALPHA;
312 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
313 break;
314
315 default:
316 png_error(png_ptr, "invalid alpha mode");
317 }
318
319 /* Only set the default gamma if the file gamma has not been set (this has
320 * the side effect that the gamma in a second call to png_set_alpha_mode will
321 * be ignored.)
322 */
323 if (png_ptr->gamma == 0)
324 png_ptr->gamma = file_gamma;
325
326 /* But always set the output gamma: */
327 png_ptr->screen_gamma = output_gamma;
328
329 /* Finally, if pre-multiplying, set the background fields to achieve the
330 * desired result.
331 */
332 if (compose)
333 {
334 /* And obtain alpha pre-multiplication by composing on black: */
335 png_memset(&png_ptr->background, 0, sizeof png_ptr->background);
336 png_ptr->background_gamma = png_ptr->gamma; /* just in case */
337 png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
338 png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
339
340 if (png_ptr->transformations & PNG_COMPOSE)
341 png_error(png_ptr,
342 "conflicting calls to set alpha mode and background");
343
344 png_ptr->transformations |= PNG_COMPOSE;
345 }
346
347 /* New API, make sure apps call the correct initializers: */
348 png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
349}
350
351# ifdef PNG_FLOATING_POINT_SUPPORTED
352void PNGAPI
353png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma)
354{
355 png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
356 output_gamma));
357}
358# endif
359#endif
360
361#ifdef PNG_READ_QUANTIZE_SUPPORTED
362/* Dither file to 8-bit. Supply a palette, the current number
363 * of elements in the palette, the maximum number of elements
364 * allowed, and a histogram if possible. If the current number
365 * of colors is greater then the maximum number, the palette will be
366 * modified to fit in the maximum number. "full_quantize" indicates
367 * whether we need a quantizing cube set up for RGB images, or if we
368 * simply are reducing the number of colors in a paletted image.
369 */
370
371typedef struct png_dsort_struct
372{
373 struct png_dsort_struct FAR * next;
374 png_byte left;
375 png_byte right;
376} png_dsort;
377typedef png_dsort FAR * png_dsortp;
378typedef png_dsort FAR * FAR * png_dsortpp;
379
380void PNGAPI
381png_set_quantize(png_structp png_ptr, png_colorp palette,
382 int num_palette, int maximum_colors, png_const_uint_16p histogram,
383 int full_quantize)
384{
385 png_debug(1, "in png_set_quantize");
386
387 if (png_ptr == NULL)
388 return;
389
390 png_ptr->transformations |= PNG_QUANTIZE;
391
392 if (!full_quantize)
393 {
394 int i;
395
396 png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
397 (png_uint_32)(num_palette * png_sizeof(png_byte)));
398 for (i = 0; i < num_palette; i++)
399 png_ptr->quantize_index[i] = (png_byte)i;
400 }
401
402 if (num_palette > maximum_colors)
403 {
404 if (histogram != NULL)
405 {
406 /* This is easy enough, just throw out the least used colors.
407 * Perhaps not the best solution, but good enough.
408 */
409
410 int i;
411
412 /* Initialize an array to sort colors */
413 png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
414 (png_uint_32)(num_palette * png_sizeof(png_byte)));
415
416 /* Initialize the quantize_sort array */
417 for (i = 0; i < num_palette; i++)
418 png_ptr->quantize_sort[i] = (png_byte)i;
419
420 /* Find the least used palette entries by starting a
421 * bubble sort, and running it until we have sorted
422 * out enough colors. Note that we don't care about
423 * sorting all the colors, just finding which are
424 * least used.
425 */
426
427 for (i = num_palette - 1; i >= maximum_colors; i--)
428 {
429 int done; /* To stop early if the list is pre-sorted */
430 int j;
431
432 done = 1;
433 for (j = 0; j < i; j++)
434 {
435 if (histogram[png_ptr->quantize_sort[j]]
436 < histogram[png_ptr->quantize_sort[j + 1]])
437 {
438 png_byte t;
439
440 t = png_ptr->quantize_sort[j];
441 png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];
442 png_ptr->quantize_sort[j + 1] = t;
443 done = 0;
444 }
445 }
446
447 if (done)
448 break;
449 }
450
451 /* Swap the palette around, and set up a table, if necessary */
452 if (full_quantize)
453 {
454 int j = num_palette;
455
456 /* Put all the useful colors within the max, but don't
457 * move the others.
458 */
459 for (i = 0; i < maximum_colors; i++)
460 {
461 if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
462 {
463 do
464 j--;
465 while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
466
467 palette[i] = palette[j];
468 }
469 }
470 }
471 else
472 {
473 int j = num_palette;
474
475 /* Move all the used colors inside the max limit, and
476 * develop a translation table.
477 */
478 for (i = 0; i < maximum_colors; i++)
479 {
480 /* Only move the colors we need to */
481 if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
482 {
483 png_color tmp_color;
484
485 do
486 j--;
487 while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
488
489 tmp_color = palette[j];
490 palette[j] = palette[i];
491 palette[i] = tmp_color;
492 /* Indicate where the color went */
493 png_ptr->quantize_index[j] = (png_byte)i;
494 png_ptr->quantize_index[i] = (png_byte)j;
495 }
496 }
497
498 /* Find closest color for those colors we are not using */
499 for (i = 0; i < num_palette; i++)
500 {
501 if ((int)png_ptr->quantize_index[i] >= maximum_colors)
502 {
503 int min_d, k, min_k, d_index;
504
505 /* Find the closest color to one we threw out */
506 d_index = png_ptr->quantize_index[i];
507 min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
508 for (k = 1, min_k = 0; k < maximum_colors; k++)
509 {
510 int d;
511
512 d = PNG_COLOR_DIST(palette[d_index], palette[k]);
513
514 if (d < min_d)
515 {
516 min_d = d;
517 min_k = k;
518 }
519 }
520 /* Point to closest color */
521 png_ptr->quantize_index[i] = (png_byte)min_k;
522 }
523 }
524 }
525 png_free(png_ptr, png_ptr->quantize_sort);
526 png_ptr->quantize_sort = NULL;
527 }
528 else
529 {
530 /* This is much harder to do simply (and quickly). Perhaps
531 * we need to go through a median cut routine, but those
532 * don't always behave themselves with only a few colors
533 * as input. So we will just find the closest two colors,
534 * and throw out one of them (chosen somewhat randomly).
535 * [We don't understand this at all, so if someone wants to
536 * work on improving it, be our guest - AED, GRP]
537 */
538 int i;
539 int max_d;
540 int num_new_palette;
541 png_dsortp t;
542 png_dsortpp hash;
543
544 t = NULL;
545
546 /* Initialize palette index arrays */
547 png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
548 (png_uint_32)(num_palette * png_sizeof(png_byte)));
549 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
550 (png_uint_32)(num_palette * png_sizeof(png_byte)));
551
552 /* Initialize the sort array */
553 for (i = 0; i < num_palette; i++)
554 {
555 png_ptr->index_to_palette[i] = (png_byte)i;
556 png_ptr->palette_to_index[i] = (png_byte)i;
557 }
558
559 hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
560 png_sizeof(png_dsortp)));
561
562 num_new_palette = num_palette;
563
564 /* Initial wild guess at how far apart the farthest pixel
565 * pair we will be eliminating will be. Larger
566 * numbers mean more areas will be allocated, Smaller
567 * numbers run the risk of not saving enough data, and
568 * having to do this all over again.
569 *
570 * I have not done extensive checking on this number.
571 */
572 max_d = 96;
573
574 while (num_new_palette > maximum_colors)
575 {
576 for (i = 0; i < num_new_palette - 1; i++)
577 {
578 int j;
579
580 for (j = i + 1; j < num_new_palette; j++)
581 {
582 int d;
583
584 d = PNG_COLOR_DIST(palette[i], palette[j]);
585
586 if (d <= max_d)
587 {
588
589 t = (png_dsortp)png_malloc_warn(png_ptr,
590 (png_uint_32)(png_sizeof(png_dsort)));
591
592 if (t == NULL)
593 break;
594
595 t->next = hash[d];
596 t->left = (png_byte)i;
597 t->right = (png_byte)j;
598 hash[d] = t;
599 }
600 }
601 if (t == NULL)
602 break;
603 }
604
605 if (t != NULL)
606 for (i = 0; i <= max_d; i++)
607 {
608 if (hash[i] != NULL)
609 {
610 png_dsortp p;
611
612 for (p = hash[i]; p; p = p->next)
613 {
614 if ((int)png_ptr->index_to_palette[p->left]
615 < num_new_palette &&
616 (int)png_ptr->index_to_palette[p->right]
617 < num_new_palette)
618 {
619 int j, next_j;
620
621 if (num_new_palette & 0x01)
622 {
623 j = p->left;
624 next_j = p->right;
625 }
626 else
627 {
628 j = p->right;
629 next_j = p->left;
630 }
631
632 num_new_palette--;
633 palette[png_ptr->index_to_palette[j]]
634 = palette[num_new_palette];
635 if (!full_quantize)
636 {
637 int k;
638
639 for (k = 0; k < num_palette; k++)
640 {
641 if (png_ptr->quantize_index[k] ==
642 png_ptr->index_to_palette[j])
643 png_ptr->quantize_index[k] =
644 png_ptr->index_to_palette[next_j];
645
646 if ((int)png_ptr->quantize_index[k] ==
647 num_new_palette)
648 png_ptr->quantize_index[k] =
649 png_ptr->index_to_palette[j];
650 }
651 }
652
653 png_ptr->index_to_palette[png_ptr->palette_to_index
654 [num_new_palette]] = png_ptr->index_to_palette[j];
655
656 png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
657 = png_ptr->palette_to_index[num_new_palette];
658
659 png_ptr->index_to_palette[j] =
660 (png_byte)num_new_palette;
661
662 png_ptr->palette_to_index[num_new_palette] =
663 (png_byte)j;
664 }
665 if (num_new_palette <= maximum_colors)
666 break;
667 }
668 if (num_new_palette <= maximum_colors)
669 break;
670 }
671 }
672
673 for (i = 0; i < 769; i++)
674 {
675 if (hash[i] != NULL)
676 {
677 png_dsortp p = hash[i];
678 while (p)
679 {
680 t = p->next;
681 png_free(png_ptr, p);
682 p = t;
683 }
684 }
685 hash[i] = 0;
686 }
687 max_d += 96;
688 }
689 png_free(png_ptr, hash);
690 png_free(png_ptr, png_ptr->palette_to_index);
691 png_free(png_ptr, png_ptr->index_to_palette);
692 png_ptr->palette_to_index = NULL;
693 png_ptr->index_to_palette = NULL;
694 }
695 num_palette = maximum_colors;
696 }
697 if (png_ptr->palette == NULL)
698 {
699 png_ptr->palette = palette;
700 }
701 png_ptr->num_palette = (png_uint_16)num_palette;
702
703 if (full_quantize)
704 {
705 int i;
706 png_bytep distance;
707 int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +
708 PNG_QUANTIZE_BLUE_BITS;
709 int num_red = (1 << PNG_QUANTIZE_RED_BITS);
710 int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
711 int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
712 png_size_t num_entries = ((png_size_t)1 << total_bits);
713
714 png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
715 (png_uint_32)(num_entries * png_sizeof(png_byte)));
716
717 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
718 png_sizeof(png_byte)));
719
720 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
721
722 for (i = 0; i < num_palette; i++)
723 {
724 int ir, ig, ib;
725 int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));
726 int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));
727 int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));
728
729 for (ir = 0; ir < num_red; ir++)
730 {
731 /* int dr = abs(ir - r); */
732 int dr = ((ir > r) ? ir - r : r - ir);
733 int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +
734 PNG_QUANTIZE_GREEN_BITS));
735
736 for (ig = 0; ig < num_green; ig++)
737 {
738 /* int dg = abs(ig - g); */
739 int dg = ((ig > g) ? ig - g : g - ig);
740 int dt = dr + dg;
741 int dm = ((dr > dg) ? dr : dg);
742 int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);
743
744 for (ib = 0; ib < num_blue; ib++)
745 {
746 int d_index = index_g | ib;
747 /* int db = abs(ib - b); */
748 int db = ((ib > b) ? ib - b : b - ib);
749 int dmax = ((dm > db) ? dm : db);
750 int d = dmax + dt + db;
751
752 if (d < (int)distance[d_index])
753 {
754 distance[d_index] = (png_byte)d;
755 png_ptr->palette_lookup[d_index] = (png_byte)i;
756 }
757 }
758 }
759 }
760 }
761
762 png_free(png_ptr, distance);
763 }
764}
765#endif /* PNG_READ_QUANTIZE_SUPPORTED */
766
767#ifdef PNG_READ_GAMMA_SUPPORTED
768void PNGFAPI
769png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma,
770 png_fixed_point file_gamma)
771{
772 png_debug(1, "in png_set_gamma_fixed");
773
774 if (png_ptr == NULL)
775 return;
776
777 /* New in libpng-1.5.4 - reserve particular negative values as flags. */
778 scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
779 file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
780
781#if PNG_LIBPNG_VER >= 10600
782 /* Checking the gamma values for being >0 was added in 1.5.4 along with the
783 * premultiplied alpha support; this actually hides an undocumented feature
784 * of the previous implementation which allowed gamma processing to be
785 * disabled in background handling. There is no evidence (so far) that this
786 * was being used; however, png_set_background itself accepted and must still
787 * accept '0' for the gamma value it takes, because it isn't always used.
788 *
789 * Since this is an API change (albeit a very minor one that removes an
790 * undocumented API feature) it will not be made until libpng-1.6.0.
791 */
792 if (file_gamma <= 0)
793 png_error(png_ptr, "invalid file gamma in png_set_gamma");
794
795 if (scrn_gamma <= 0)
796 png_error(png_ptr, "invalid screen gamma in png_set_gamma");
797#endif
798
799 /* Set the gamma values unconditionally - this overrides the value in the PNG
800 * file if a gAMA chunk was present. png_set_alpha_mode provides a
801 * different, easier, way to default the file gamma.
802 */
803 png_ptr->gamma = file_gamma;
804 png_ptr->screen_gamma = scrn_gamma;
805}
806
807# ifdef PNG_FLOATING_POINT_SUPPORTED
808void PNGAPI
809png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
810{
811 png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
812 convert_gamma_value(png_ptr, file_gamma));
813}
814# endif /* FLOATING_POINT_SUPPORTED */
815#endif /* READ_GAMMA */
816
817#ifdef PNG_READ_EXPAND_SUPPORTED
818/* Expand paletted images to RGB, expand grayscale images of
819 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
820 * to alpha channels.
821 */
822void PNGAPI
823png_set_expand(png_structp png_ptr)
824{
825 png_debug(1, "in png_set_expand");
826
827 if (png_ptr == NULL)
828 return;
829
830 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
831 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
832}
833
834/* GRR 19990627: the following three functions currently are identical
835 * to png_set_expand(). However, it is entirely reasonable that someone
836 * might wish to expand an indexed image to RGB but *not* expand a single,
837 * fully transparent palette entry to a full alpha channel--perhaps instead
838 * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
839 * the transparent color with a particular RGB value, or drop tRNS entirely.
840 * IOW, a future version of the library may make the transformations flag
841 * a bit more fine-grained, with separate bits for each of these three
842 * functions.
843 *
844 * More to the point, these functions make it obvious what libpng will be
845 * doing, whereas "expand" can (and does) mean any number of things.
846 *
847 * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified
848 * to expand only the sample depth but not to expand the tRNS to alpha
849 * and its name was changed to png_set_expand_gray_1_2_4_to_8().
850 */
851
852/* Expand paletted images to RGB. */
853void PNGAPI
854png_set_palette_to_rgb(png_structp png_ptr)
855{
856 png_debug(1, "in png_set_palette_to_rgb");
857
858 if (png_ptr == NULL)
859 return;
860
861 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
862 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
863}
864
865/* Expand grayscale images of less than 8-bit depth to 8 bits. */
866void PNGAPI
867png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
868{
869 png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
870
871 if (png_ptr == NULL)
872 return;
873
874 png_ptr->transformations |= PNG_EXPAND;
875 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
876}
877
878
879
880/* Expand tRNS chunks to alpha channels. */
881void PNGAPI
882png_set_tRNS_to_alpha(png_structp png_ptr)
883{
884 png_debug(1, "in png_set_tRNS_to_alpha");
885
886 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
887 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
888}
889#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
890
891#ifdef PNG_READ_EXPAND_16_SUPPORTED
892/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
893 * it may not work correctly.)
894 */
895void PNGAPI
896png_set_expand_16(png_structp png_ptr)
897{
898 png_debug(1, "in png_set_expand_16");
899
900 if (png_ptr == NULL)
901 return;
902
903 png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
904 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
905
906 /* New API, make sure apps call the correct initializers: */
907 png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
908}
909#endif
910
911#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
912void PNGAPI
913png_set_gray_to_rgb(png_structp png_ptr)
914{
915 png_debug(1, "in png_set_gray_to_rgb");
916
917 if (png_ptr != NULL)
918 {
919 /* Because rgb must be 8 bits or more: */
920 png_set_expand_gray_1_2_4_to_8(png_ptr);
921 png_ptr->transformations |= PNG_GRAY_TO_RGB;
922 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
923 }
924}
925#endif
926
927#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
928void PNGFAPI
929png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
930 png_fixed_point red, png_fixed_point green)
931{
932 png_debug(1, "in png_set_rgb_to_gray");
933
934 if (png_ptr == NULL)
935 return;
936
937 switch(error_action)
938 {
939 case PNG_ERROR_ACTION_NONE:
940 png_ptr->transformations |= PNG_RGB_TO_GRAY;
941 break;
942
943 case PNG_ERROR_ACTION_WARN:
944 png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
945 break;
946
947 case PNG_ERROR_ACTION_ERROR:
948 png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
949 break;
950
951 default:
952 png_error(png_ptr, "invalid error action to rgb_to_gray");
953 break;
954 }
955 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
956#ifdef PNG_READ_EXPAND_SUPPORTED
957 png_ptr->transformations |= PNG_EXPAND;
958#else
959 {
960 png_warning(png_ptr,
961 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
962
963 png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
964 }
965#endif
966 {
967 if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)
968 {
969 png_uint_16 red_int, green_int;
970
971 /* NOTE: this calculation does not round, but this behavior is retained
972 * for consistency, the inaccuracy is very small. The code here always
973 * overwrites the coefficients, regardless of whether they have been
974 * defaulted or set already.
975 */
976 red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);
977 green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);
978
979 png_ptr->rgb_to_gray_red_coeff = red_int;
980 png_ptr->rgb_to_gray_green_coeff = green_int;
981 png_ptr->rgb_to_gray_coefficients_set = 1;
982 }
983
984 else
985 {
986 if (red >= 0 && green >= 0)
987 png_warning(png_ptr,
988 "ignoring out of range rgb_to_gray coefficients");
989
990 /* Use the defaults, from the cHRM chunk if set, else the historical
991 * values which are close to the sRGB/HDTV/ITU-Rec 709 values. See
992 * png_do_rgb_to_gray for more discussion of the values. In this case
993 * the coefficients are not marked as 'set' and are not overwritten if
994 * something has already provided a default.
995 */
996 if (png_ptr->rgb_to_gray_red_coeff == 0 &&
997 png_ptr->rgb_to_gray_green_coeff == 0)
998 {
999 png_ptr->rgb_to_gray_red_coeff = 6968;
1000 png_ptr->rgb_to_gray_green_coeff = 23434;
1001 /* png_ptr->rgb_to_gray_blue_coeff = 2366; */
1002 }
1003 }
1004 }
1005}
1006
1007#ifdef PNG_FLOATING_POINT_SUPPORTED
1008/* Convert a RGB image to a grayscale of the same width. This allows us,
1009 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
1010 */
1011
1012void PNGAPI
1013png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
1014 double green)
1015{
1016 if (png_ptr == NULL)
1017 return;
1018
1019 png_set_rgb_to_gray_fixed(png_ptr, error_action,
1020 png_fixed(png_ptr, red, "rgb to gray red coefficient"),
1021 png_fixed(png_ptr, green, "rgb to gray green coefficient"));
1022}
1023#endif /* FLOATING POINT */
1024
1025#endif
1026
1027#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
1028 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
1029void PNGAPI
1030png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
1031 read_user_transform_fn)
1032{
1033 png_debug(1, "in png_set_read_user_transform_fn");
1034
1035 if (png_ptr == NULL)
1036 return;
1037
1038#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1039 png_ptr->transformations |= PNG_USER_TRANSFORM;
1040 png_ptr->read_user_transform_fn = read_user_transform_fn;
1041#endif
1042}
1043#endif
1044
1045#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1046#ifdef PNG_READ_GAMMA_SUPPORTED
1047/* In the case of gamma transformations only do transformations on images where
1048 * the [file] gamma and screen_gamma are not close reciprocals, otherwise it
1049 * slows things down slightly, and also needlessly introduces small errors.
1050 */
1051static int /* PRIVATE */
1052png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma)
1053{
1054 /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma
1055 * correction as a difference of the overall transform from 1.0
1056 *
1057 * We want to compare the threshold with s*f - 1, if we get
1058 * overflow here it is because of wacky gamma values so we
1059 * turn on processing anyway.
1060 */
1061 png_fixed_point gtest;
1062 return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||
1063 png_gamma_significant(gtest);
1064}
1065#endif
1066
1067/* Initialize everything needed for the read. This includes modifying
1068 * the palette.
1069 */
1070
1071/*For the moment 'png_init_palette_transformations' and
1072 * 'png_init_rgb_transformations' only do some flag canceling optimizations.
1073 * The intent is that these two routines should have palette or rgb operations
1074 * extracted from 'png_init_read_transformations'.
1075 */
1076static void /* PRIVATE */
1077png_init_palette_transformations(png_structp png_ptr)
1078{
1079 /* Called to handle the (input) palette case. In png_do_read_transformations
1080 * the first step is to expand the palette if requested, so this code must
1081 * take care to only make changes that are invariant with respect to the
1082 * palette expansion, or only do them if there is no expansion.
1083 *
1084 * STRIP_ALPHA has already been handled in the caller (by setting num_trans
1085 * to 0.)
1086 */
1087 int input_has_alpha = 0;
1088 int input_has_transparency = 0;
1089
1090 if (png_ptr->num_trans > 0)
1091 {
1092 int i;
1093
1094 /* Ignore if all the entries are opaque (unlikely!) */
1095 for (i=0; i<png_ptr->num_trans; ++i)
1096 if (png_ptr->trans_alpha[i] == 255)
1097 continue;
1098 else if (png_ptr->trans_alpha[i] == 0)
1099 input_has_transparency = 1;
1100 else
1101 input_has_alpha = 1;
1102 }
1103
1104 /* If no alpha we can optimize. */
1105 if (!input_has_alpha)
1106 {
1107 /* Any alpha means background and associative alpha processing is
1108 * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
1109 * and ENCODE_ALPHA are irrelevant.
1110 */
1111 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1112 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1113
1114 if (!input_has_transparency)
1115 png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
1116 }
1117
1118#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
1119 /* png_set_background handling - deals with the complexity of whether the
1120 * background color is in the file format or the screen format in the case
1121 * where an 'expand' will happen.
1122 */
1123
1124 /* The following code cannot be entered in the alpha pre-multiplication case
1125 * because PNG_BACKGROUND_EXPAND is cancelled below.
1126 */
1127 if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
1128 (png_ptr->transformations & PNG_EXPAND))
1129 {
1130 {
1131 png_ptr->background.red =
1132 png_ptr->palette[png_ptr->background.index].red;
1133 png_ptr->background.green =
1134 png_ptr->palette[png_ptr->background.index].green;
1135 png_ptr->background.blue =
1136 png_ptr->palette[png_ptr->background.index].blue;
1137
1138#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
1139 if (png_ptr->transformations & PNG_INVERT_ALPHA)
1140 {
1141 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
1142 {
1143 /* Invert the alpha channel (in tRNS) unless the pixels are
1144 * going to be expanded, in which case leave it for later
1145 */
1146 int i, istop = png_ptr->num_trans;
1147
1148 for (i=0; i<istop; i++)
1149 png_ptr->trans_alpha[i] = (png_byte)(255 -
1150 png_ptr->trans_alpha[i]);
1151 }
1152 }
1153#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */
1154 }
1155 } /* background expand and (therefore) no alpha association. */
1156#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
1157}
1158
1159static void /* PRIVATE */
1160png_init_rgb_transformations(png_structp png_ptr)
1161{
1162 /* Added to libpng-1.5.4: check the color type to determine whether there
1163 * is any alpha or transparency in the image and simply cancel the
1164 * background and alpha mode stuff if there isn't.
1165 */
1166 int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0;
1167 int input_has_transparency = png_ptr->num_trans > 0;
1168
1169 /* If no alpha we can optimize. */
1170 if (!input_has_alpha)
1171 {
1172 /* Any alpha means background and associative alpha processing is
1173 * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
1174 * and ENCODE_ALPHA are irrelevant.
1175 */
1176# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1177 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1178 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1179# endif
1180
1181 if (!input_has_transparency)
1182 png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
1183 }
1184
1185#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
1186 /* png_set_background handling - deals with the complexity of whether the
1187 * background color is in the file format or the screen format in the case
1188 * where an 'expand' will happen.
1189 */
1190
1191 /* The following code cannot be entered in the alpha pre-multiplication case
1192 * because PNG_BACKGROUND_EXPAND is cancelled below.
1193 */
1194 if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
1195 (png_ptr->transformations & PNG_EXPAND) &&
1196 !(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
1197 /* i.e., GRAY or GRAY_ALPHA */
1198 {
1199 {
1200 /* Expand background and tRNS chunks */
1201 int gray = png_ptr->background.gray;
1202 int trans_gray = png_ptr->trans_color.gray;
1203
1204 switch (png_ptr->bit_depth)
1205 {
1206 case 1:
1207 gray *= 0xff;
1208 trans_gray *= 0xff;
1209 break;
1210
1211 case 2:
1212 gray *= 0x55;
1213 trans_gray *= 0x55;
1214 break;
1215
1216 case 4:
1217 gray *= 0x11;
1218 trans_gray *= 0x11;
1219 break;
1220
1221 default:
1222
1223 case 8:
1224 /* Already 8 bits, fall through */
1225
1226 case 16:
1227 /* Already a full 16 bits */
1228 break;
1229 }
1230
1231 png_ptr->background.red = png_ptr->background.green =
1232 png_ptr->background.blue = (png_uint_16)gray;
1233
1234 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
1235 {
1236 png_ptr->trans_color.red = png_ptr->trans_color.green =
1237 png_ptr->trans_color.blue = (png_uint_16)trans_gray;
1238 }
1239 }
1240 } /* background expand and (therefore) no alpha association. */
1241#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
1242}
1243
1244void /* PRIVATE */
1245png_init_read_transformations(png_structp png_ptr)
1246{
1247 png_debug(1, "in png_init_read_transformations");
1248
1249 /* This internal function is called from png_read_start_row in pngrutil.c
1250 * and it is called before the 'rowbytes' calculation is done, so the code
1251 * in here can change or update the transformations flags.
1252 *
1253 * First do updates that do not depend on the details of the PNG image data
1254 * being processed.
1255 */
1256
1257#ifdef PNG_READ_GAMMA_SUPPORTED
1258 /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds
1259 * png_set_alpha_mode and this is another source for a default file gamma so
1260 * the test needs to be performed later - here. In addition prior to 1.5.4
1261 * the tests were repeated for the PALETTE color type here - this is no
1262 * longer necessary (and doesn't seem to have been necessary before.)
1263 */
1264 {
1265 /* The following temporary indicates if overall gamma correction is
1266 * required.
1267 */
1268 int gamma_correction = 0;
1269
1270 if (png_ptr->gamma != 0) /* has been set */
1271 {
1272 if (png_ptr->screen_gamma != 0) /* screen set too */
1273 gamma_correction = png_gamma_threshold(png_ptr->gamma,
1274 png_ptr->screen_gamma);
1275
1276 else
1277 /* Assume the output matches the input; a long time default behavior
1278 * of libpng, although the standard has nothing to say about this.
1279 */
1280 png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma);
1281 }
1282
1283 else if (png_ptr->screen_gamma != 0)
1284 /* The converse - assume the file matches the screen, note that this
1285 * perhaps undesireable default can (from 1.5.4) be changed by calling
1286 * png_set_alpha_mode (even if the alpha handling mode isn't required
1287 * or isn't changed from the default.)
1288 */
1289 png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma);
1290
1291 else /* neither are set */
1292 /* Just in case the following prevents any processing - file and screen
1293 * are both assumed to be linear and there is no way to introduce a
1294 * third gamma value other than png_set_background with 'UNIQUE', and,
1295 * prior to 1.5.4
1296 */
1297 png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1;
1298
1299 /* Now turn the gamma transformation on or off as appropriate. Notice
1300 * that PNG_GAMMA just refers to the file->screen correction. Alpha
1301 * composition may independently cause gamma correction because it needs
1302 * linear data (e.g. if the file has a gAMA chunk but the screen gamma
1303 * hasn't been specified.) In any case this flag may get turned off in
1304 * the code immediately below if the transform can be handled outside the
1305 * row loop.
1306 */
1307 if (gamma_correction)
1308 png_ptr->transformations |= PNG_GAMMA;
1309
1310 else
1311 png_ptr->transformations &= ~PNG_GAMMA;
1312 }
1313#endif
1314
1315 /* Certain transformations have the effect of preventing other
1316 * transformations that happen afterward in png_do_read_transformations,
1317 * resolve the interdependencies here. From the code of
1318 * png_do_read_transformations the order is:
1319 *
1320 * 1) PNG_EXPAND (including PNG_EXPAND_tRNS)
1321 * 2) PNG_STRIP_ALPHA (if no compose)
1322 * 3) PNG_RGB_TO_GRAY
1323 * 4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
1324 * 5) PNG_COMPOSE
1325 * 6) PNG_GAMMA
1326 * 7) PNG_STRIP_ALPHA (if compose)
1327 * 8) PNG_ENCODE_ALPHA
1328 * 9) PNG_SCALE_16_TO_8
1329 * 10) PNG_16_TO_8
1330 * 11) PNG_QUANTIZE (converts to palette)
1331 * 12) PNG_EXPAND_16
1332 * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
1333 * 14) PNG_INVERT_MONO
1334 * 15) PNG_SHIFT
1335 * 16) PNG_PACK
1336 * 17) PNG_BGR
1337 * 18) PNG_PACKSWAP
1338 * 19) PNG_FILLER (includes PNG_ADD_ALPHA)
1339 * 20) PNG_INVERT_ALPHA
1340 * 21) PNG_SWAP_ALPHA
1341 * 22) PNG_SWAP_BYTES
1342 * 23) PNG_USER_TRANSFORM [must be last]
1343 */
1344#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1345 if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
1346 !(png_ptr->transformations & PNG_COMPOSE))
1347 {
1348 /* Stripping the alpha channel happens immediately after the 'expand'
1349 * transformations, before all other transformation, so it cancels out
1350 * the alpha handling. It has the side effect negating the effect of
1351 * PNG_EXPAND_tRNS too:
1352 */
1353 png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |
1354 PNG_EXPAND_tRNS);
1355 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1356
1357 /* Kill the tRNS chunk itself too. Prior to 1.5.4 this did not happen
1358 * so transparency information would remain just so long as it wasn't
1359 * expanded. This produces unexpected API changes if the set of things
1360 * that do PNG_EXPAND_tRNS changes (perfectly possible given the
1361 * documentation - which says ask for what you want, accept what you
1362 * get.) This makes the behavior consistent from 1.5.4:
1363 */
1364 png_ptr->num_trans = 0;
1365 }
1366#endif /* STRIP_ALPHA supported, no COMPOSE */
1367
1368#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1369 /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA
1370 * settings will have no effect.
1371 */
1372 if (!png_gamma_significant(png_ptr->screen_gamma))
1373 {
1374 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1375 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1376 }
1377#endif
1378
1379#if defined(PNG_READ_EXPAND_SUPPORTED) && \
1380 defined(PNG_READ_BACKGROUND_SUPPORTED) && \
1381 defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
1382 /* Detect gray background and attempt to enable optimization for
1383 * gray --> RGB case.
1384 *
1385 * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
1386 * RGB_ALPHA (in which case need_expand is superfluous anyway), the
1387 * background color might actually be gray yet not be flagged as such.
1388 * This is not a problem for the current code, which uses
1389 * PNG_BACKGROUND_IS_GRAY only to decide when to do the
1390 * png_do_gray_to_rgb() transformation.
1391 *
1392 * TODO: this code needs to be revised to avoid the complexity and
1393 * interdependencies. The color type of the background should be recorded in
1394 * png_set_background, along with the bit depth, then the code has a record
1395 * of exactly what color space the background is currently in.
1396 */
1397 if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
1398 {
1399 /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
1400 * the file was grayscale the background value is gray.
1401 */
1402 if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
1403 png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
1404 }
1405
1406 else if (png_ptr->transformations & PNG_COMPOSE)
1407 {
1408 /* PNG_COMPOSE: png_set_background was called with need_expand false,
1409 * so the color is in the color space of the output or png_set_alpha_mode
1410 * was called and the color is black. Ignore RGB_TO_GRAY because that
1411 * happens before GRAY_TO_RGB.
1412 */
1413 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
1414 {
1415 if (png_ptr->background.red == png_ptr->background.green &&
1416 png_ptr->background.red == png_ptr->background.blue)
1417 {
1418 png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
1419 png_ptr->background.gray = png_ptr->background.red;
1420 }
1421 }
1422 }
1423#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */
1424
1425 /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
1426 * can be performed directly on the palette, and some (such as rgb to gray)
1427 * can be optimized inside the palette. This is particularly true of the
1428 * composite (background and alpha) stuff, which can be pretty much all done
1429 * in the palette even if the result is expanded to RGB or gray afterward.
1430 *
1431 * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and
1432 * earlier and the palette stuff is actually handled on the first row. This
1433 * leads to the reported bug that the palette returned by png_get_PLTE is not
1434 * updated.
1435 */
1436 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1437 png_init_palette_transformations(png_ptr);
1438
1439 else
1440 png_init_rgb_transformations(png_ptr);
1441
1442#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
1443 defined(PNG_READ_EXPAND_16_SUPPORTED)
1444 if ((png_ptr->transformations & PNG_EXPAND_16) &&
1445 (png_ptr->transformations & PNG_COMPOSE) &&
1446 !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
1447 png_ptr->bit_depth != 16)
1448 {
1449 /* TODO: fix this. Because the expand_16 operation is after the compose
1450 * handling the background color must be 8, not 16, bits deep, but the
1451 * application will supply a 16-bit value so reduce it here.
1452 *
1453 * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at
1454 * present, so that case is ok (until do_expand_16 is moved.)
1455 *
1456 * NOTE: this discards the low 16 bits of the user supplied background
1457 * color, but until expand_16 works properly there is no choice!
1458 */
1459# define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16))
1460 CHOP(png_ptr->background.red);
1461 CHOP(png_ptr->background.green);
1462 CHOP(png_ptr->background.blue);
1463 CHOP(png_ptr->background.gray);
1464# undef CHOP
1465 }
1466#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */
1467
1468#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
1469 (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
1470 defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
1471 if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) &&
1472 (png_ptr->transformations & PNG_COMPOSE) &&
1473 !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
1474 png_ptr->bit_depth == 16)
1475 {
1476 /* On the other hand, if a 16-bit file is to be reduced to 8-bits per
1477 * component this will also happen after PNG_COMPOSE and so the background
1478 * color must be pre-expanded here.
1479 *
1480 * TODO: fix this too.
1481 */
1482 png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);
1483 png_ptr->background.green =
1484 (png_uint_16)(png_ptr->background.green * 257);
1485 png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);
1486 png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);
1487 }
1488#endif
1489
1490 /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the
1491 * background support (see the comments in scripts/pnglibconf.dfa), this
1492 * allows pre-multiplication of the alpha channel to be implemented as
1493 * compositing on black. This is probably sub-optimal and has been done in
1494 * 1.5.4 betas simply to enable external critique and testing (i.e. to
1495 * implement the new API quickly, without lots of internal changes.)
1496 */
1497
1498#ifdef PNG_READ_GAMMA_SUPPORTED
1499# ifdef PNG_READ_BACKGROUND_SUPPORTED
1500 /* Includes ALPHA_MODE */
1501 png_ptr->background_1 = png_ptr->background;
1502# endif
1503
1504 /* This needs to change - in the palette image case a whole set of tables are
1505 * built when it would be quicker to just calculate the correct value for
1506 * each palette entry directly. Also, the test is too tricky - why check
1507 * PNG_RGB_TO_GRAY if PNG_GAMMA is not set? The answer seems to be that
1508 * PNG_GAMMA is cancelled even if the gamma is known? The test excludes the
1509 * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction
1510 * the gamma tables will not be built even if composition is required on a
1511 * gamma encoded value.
1512 *
1513 * In 1.5.4 this is addressed below by an additional check on the individual
1514 * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the
1515 * tables.
1516 */
1517 if ((png_ptr->transformations & PNG_GAMMA)
1518 || ((png_ptr->transformations & PNG_RGB_TO_GRAY)
1519 && (png_gamma_significant(png_ptr->gamma) ||
1520 png_gamma_significant(png_ptr->screen_gamma)))
1521 || ((png_ptr->transformations & PNG_COMPOSE)
1522 && (png_gamma_significant(png_ptr->gamma)
1523 || png_gamma_significant(png_ptr->screen_gamma)
1524# ifdef PNG_READ_BACKGROUND_SUPPORTED
1525 || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE
1526 && png_gamma_significant(png_ptr->background_gamma))
1527# endif
1528 )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA)
1529 && png_gamma_significant(png_ptr->screen_gamma))
1530 )
1531 {
1532 png_build_gamma_table(png_ptr, png_ptr->bit_depth);
1533
1534#ifdef PNG_READ_BACKGROUND_SUPPORTED
1535 if (png_ptr->transformations & PNG_COMPOSE)
1536 {
1537 /* Issue a warning about this combination: because RGB_TO_GRAY is
1538 * optimized to do the gamma transform if present yet do_background has
1539 * to do the same thing if both options are set a
1540 * double-gamma-correction happens. This is true in all versions of
1541 * libpng to date.
1542 */
1543 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
1544 png_warning(png_ptr,
1545 "libpng does not support gamma+background+rgb_to_gray");
1546
1547 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1548 {
1549 /* We don't get to here unless there is a tRNS chunk with non-opaque
1550 * entries - see the checking code at the start of this function.
1551 */
1552 png_color back, back_1;
1553 png_colorp palette = png_ptr->palette;
1554 int num_palette = png_ptr->num_palette;
1555 int i;
1556 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
1557 {
1558
1559 back.red = png_ptr->gamma_table[png_ptr->background.red];
1560 back.green = png_ptr->gamma_table[png_ptr->background.green];
1561 back.blue = png_ptr->gamma_table[png_ptr->background.blue];
1562
1563 back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
1564 back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
1565 back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
1566 }
1567 else
1568 {
1569 png_fixed_point g, gs;
1570
1571 switch (png_ptr->background_gamma_type)
1572 {
1573 case PNG_BACKGROUND_GAMMA_SCREEN:
1574 g = (png_ptr->screen_gamma);
1575 gs = PNG_FP_1;
1576 break;
1577
1578 case PNG_BACKGROUND_GAMMA_FILE:
1579 g = png_reciprocal(png_ptr->gamma);
1580 gs = png_reciprocal2(png_ptr->gamma,
1581 png_ptr->screen_gamma);
1582 break;
1583
1584 case PNG_BACKGROUND_GAMMA_UNIQUE:
1585 g = png_reciprocal(png_ptr->background_gamma);
1586 gs = png_reciprocal2(png_ptr->background_gamma,
1587 png_ptr->screen_gamma);
1588 break;
1589 default:
1590 g = PNG_FP_1; /* back_1 */
1591 gs = PNG_FP_1; /* back */
1592 break;
1593 }
1594
1595 if (png_gamma_significant(gs))
1596 {
1597 back.red = png_gamma_8bit_correct(png_ptr->background.red,
1598 gs);
1599 back.green = png_gamma_8bit_correct(png_ptr->background.green,
1600 gs);
1601 back.blue = png_gamma_8bit_correct(png_ptr->background.blue,
1602 gs);
1603 }
1604
1605 else
1606 {
1607 back.red = (png_byte)png_ptr->background.red;
1608 back.green = (png_byte)png_ptr->background.green;
1609 back.blue = (png_byte)png_ptr->background.blue;
1610 }
1611
1612 if (png_gamma_significant(g))
1613 {
1614 back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
1615 g);
1616 back_1.green = png_gamma_8bit_correct(
1617 png_ptr->background.green, g);
1618 back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
1619 g);
1620 }
1621
1622 else
1623 {
1624 back_1.red = (png_byte)png_ptr->background.red;
1625 back_1.green = (png_byte)png_ptr->background.green;
1626 back_1.blue = (png_byte)png_ptr->background.blue;
1627 }
1628 }
1629
1630 for (i = 0; i < num_palette; i++)
1631 {
1632 if (i < (int)png_ptr->num_trans &&
1633 png_ptr->trans_alpha[i] != 0xff)
1634 {
1635 if (png_ptr->trans_alpha[i] == 0)
1636 {
1637 palette[i] = back;
1638 }
1639 else /* if (png_ptr->trans_alpha[i] != 0xff) */
1640 {
1641 png_byte v, w;
1642
1643 v = png_ptr->gamma_to_1[palette[i].red];
1644 png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);
1645 palette[i].red = png_ptr->gamma_from_1[w];
1646
1647 v = png_ptr->gamma_to_1[palette[i].green];
1648 png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);
1649 palette[i].green = png_ptr->gamma_from_1[w];
1650
1651 v = png_ptr->gamma_to_1[palette[i].blue];
1652 png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);
1653 palette[i].blue = png_ptr->gamma_from_1[w];
1654 }
1655 }
1656 else
1657 {
1658 palette[i].red = png_ptr->gamma_table[palette[i].red];
1659 palette[i].green = png_ptr->gamma_table[palette[i].green];
1660 palette[i].blue = png_ptr->gamma_table[palette[i].blue];
1661 }
1662 }
1663
1664 /* Prevent the transformations being done again.
1665 *
1666 * NOTE: this is highly dubious; it removes the transformations in
1667 * place. This seems inconsistent with the general treatment of the
1668 * transformations elsewhere.
1669 */
1670 png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);
1671 } /* color_type == PNG_COLOR_TYPE_PALETTE */
1672
1673 /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
1674 else /* color_type != PNG_COLOR_TYPE_PALETTE */
1675 {
1676 int gs_sig, g_sig;
1677 png_fixed_point g = PNG_FP_1; /* Correction to linear */
1678 png_fixed_point gs = PNG_FP_1; /* Correction to screen */
1679
1680 switch (png_ptr->background_gamma_type)
1681 {
1682 case PNG_BACKGROUND_GAMMA_SCREEN:
1683 g = png_ptr->screen_gamma;
1684 /* gs = PNG_FP_1; */
1685 break;
1686
1687 case PNG_BACKGROUND_GAMMA_FILE:
1688 g = png_reciprocal(png_ptr->gamma);
1689 gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma);
1690 break;
1691
1692 case PNG_BACKGROUND_GAMMA_UNIQUE:
1693 g = png_reciprocal(png_ptr->background_gamma);
1694 gs = png_reciprocal2(png_ptr->background_gamma,
1695 png_ptr->screen_gamma);
1696 break;
1697
1698 default:
1699 png_error(png_ptr, "invalid background gamma type");
1700 }
1701
1702 g_sig = png_gamma_significant(g);
1703 gs_sig = png_gamma_significant(gs);
1704
1705 if (g_sig)
1706 png_ptr->background_1.gray = png_gamma_correct(png_ptr,
1707 png_ptr->background.gray, g);
1708
1709 if (gs_sig)
1710 png_ptr->background.gray = png_gamma_correct(png_ptr,
1711 png_ptr->background.gray, gs);
1712
1713 if ((png_ptr->background.red != png_ptr->background.green) ||
1714 (png_ptr->background.red != png_ptr->background.blue) ||
1715 (png_ptr->background.red != png_ptr->background.gray))
1716 {
1717 /* RGB or RGBA with color background */
1718 if (g_sig)
1719 {
1720 png_ptr->background_1.red = png_gamma_correct(png_ptr,
1721 png_ptr->background.red, g);
1722
1723 png_ptr->background_1.green = png_gamma_correct(png_ptr,
1724 png_ptr->background.green, g);
1725
1726 png_ptr->background_1.blue = png_gamma_correct(png_ptr,
1727 png_ptr->background.blue, g);
1728 }
1729
1730 if (gs_sig)
1731 {
1732 png_ptr->background.red = png_gamma_correct(png_ptr,
1733 png_ptr->background.red, gs);
1734
1735 png_ptr->background.green = png_gamma_correct(png_ptr,
1736 png_ptr->background.green, gs);
1737
1738 png_ptr->background.blue = png_gamma_correct(png_ptr,
1739 png_ptr->background.blue, gs);
1740 }
1741 }
1742
1743 else
1744 {
1745 /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
1746 png_ptr->background_1.red = png_ptr->background_1.green
1747 = png_ptr->background_1.blue = png_ptr->background_1.gray;
1748
1749 png_ptr->background.red = png_ptr->background.green
1750 = png_ptr->background.blue = png_ptr->background.gray;
1751 }
1752
1753 /* The background is now in screen gamma: */
1754 png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN;
1755 } /* color_type != PNG_COLOR_TYPE_PALETTE */
1756 }/* png_ptr->transformations & PNG_BACKGROUND */
1757
1758 else
1759 /* Transformation does not include PNG_BACKGROUND */
1760#endif /* PNG_READ_BACKGROUND_SUPPORTED */
1761 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE
1762#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1763 /* RGB_TO_GRAY needs to have non-gamma-corrected values! */
1764 && ((png_ptr->transformations & PNG_EXPAND) == 0 ||
1765 (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
1766#endif
1767 )
1768 {
1769 png_colorp palette = png_ptr->palette;
1770 int num_palette = png_ptr->num_palette;
1771 int i;
1772
1773 /*NOTE: there are other transformations that should probably be in here
1774 * too.
1775 */
1776 for (i = 0; i < num_palette; i++)
1777 {
1778 palette[i].red = png_ptr->gamma_table[palette[i].red];
1779 palette[i].green = png_ptr->gamma_table[palette[i].green];
1780 palette[i].blue = png_ptr->gamma_table[palette[i].blue];
1781 }
1782
1783 /* Done the gamma correction. */
1784 png_ptr->transformations &= ~PNG_GAMMA;
1785 } /* color_type == PALETTE && !PNG_BACKGROUND transformation */
1786 }
1787#ifdef PNG_READ_BACKGROUND_SUPPORTED
1788 else
1789#endif
1790#endif /* PNG_READ_GAMMA_SUPPORTED */
1791
1792#ifdef PNG_READ_BACKGROUND_SUPPORTED
1793 /* No GAMMA transformation (see the hanging else 4 lines above) */
1794 if ((png_ptr->transformations & PNG_COMPOSE) &&
1795 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
1796 {
1797 int i;
1798 int istop = (int)png_ptr->num_trans;
1799 png_color back;
1800 png_colorp palette = png_ptr->palette;
1801
1802 back.red = (png_byte)png_ptr->background.red;
1803 back.green = (png_byte)png_ptr->background.green;
1804 back.blue = (png_byte)png_ptr->background.blue;
1805
1806 for (i = 0; i < istop; i++)
1807 {
1808 if (png_ptr->trans_alpha[i] == 0)
1809 {
1810 palette[i] = back;
1811 }
1812
1813 else if (png_ptr->trans_alpha[i] != 0xff)
1814 {
1815 /* The png_composite() macro is defined in png.h */
1816 png_composite(palette[i].red, palette[i].red,
1817 png_ptr->trans_alpha[i], back.red);
1818
1819 png_composite(palette[i].green, palette[i].green,
1820 png_ptr->trans_alpha[i], back.green);
1821
1822 png_composite(palette[i].blue, palette[i].blue,
1823 png_ptr->trans_alpha[i], back.blue);
1824 }
1825 }
1826
1827 png_ptr->transformations &= ~PNG_COMPOSE;
1828 }
1829#endif /* PNG_READ_BACKGROUND_SUPPORTED */
1830
1831#ifdef PNG_READ_SHIFT_SUPPORTED
1832 if ((png_ptr->transformations & PNG_SHIFT) &&
1833 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
1834 {
1835 int i;
1836 int istop = png_ptr->num_palette;
1837 int shift = 8 - png_ptr->sig_bit.red;
1838
1839 /* significant bits can be in the range 1 to 7 for a meaninful result, if
1840 * the number of significant bits is 0 then no shift is done (this is an
1841 * error condition which is silently ignored.)
1842 */
1843 if (shift > 0 && shift < 8) for (i=0; i<istop; ++i)
1844 {
1845 int component = png_ptr->palette[i].red;
1846
1847 component >>= shift;
1848 png_ptr->palette[i].red = (png_byte)component;
1849 }
1850
1851 shift = 8 - png_ptr->sig_bit.green;
1852 if (shift > 0 && shift < 8) for (i=0; i<istop; ++i)
1853 {
1854 int component = png_ptr->palette[i].green;
1855
1856 component >>= shift;
1857 png_ptr->palette[i].green = (png_byte)component;
1858 }
1859
1860 shift = 8 - png_ptr->sig_bit.blue;
1861 if (shift > 0 && shift < 8) for (i=0; i<istop; ++i)
1862 {
1863 int component = png_ptr->palette[i].blue;
1864
1865 component >>= shift;
1866 png_ptr->palette[i].blue = (png_byte)component;
1867 }
1868 }
1869#endif /* PNG_READ_SHIFT_SUPPORTED */
1870}
1871
1872/* Modify the info structure to reflect the transformations. The
1873 * info should be updated so a PNG file could be written with it,
1874 * assuming the transformations result in valid PNG data.
1875 */
1876void /* PRIVATE */
1877png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
1878{
1879 png_debug(1, "in png_read_transform_info");
1880
1881#ifdef PNG_READ_EXPAND_SUPPORTED
1882 if (png_ptr->transformations & PNG_EXPAND)
1883 {
1884 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1885 {
1886 /* This check must match what actually happens in
1887 * png_do_expand_palette; if it ever checks the tRNS chunk to see if
1888 * it is all opaque we must do the same (at present it does not.)
1889 */
1890 if (png_ptr->num_trans > 0)
1891 info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
1892
1893 else
1894 info_ptr->color_type = PNG_COLOR_TYPE_RGB;
1895
1896 info_ptr->bit_depth = 8;
1897 info_ptr->num_trans = 0;
1898 }
1899 else
1900 {
1901 if (png_ptr->num_trans)
1902 {
1903 if (png_ptr->transformations & PNG_EXPAND_tRNS)
1904 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
1905 }
1906 if (info_ptr->bit_depth < 8)
1907 info_ptr->bit_depth = 8;
1908
1909 info_ptr->num_trans = 0;
1910 }
1911 }
1912#endif
1913
1914#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
1915 defined(PNG_READ_ALPHA_MODE_SUPPORTED)
1916 /* The following is almost certainly wrong unless the background value is in
1917 * the screen space!
1918 */
1919 if (png_ptr->transformations & PNG_COMPOSE)
1920 info_ptr->background = png_ptr->background;
1921#endif
1922
1923#ifdef PNG_READ_GAMMA_SUPPORTED
1924 /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4),
1925 * however it seems that the code in png_init_read_transformations, which has
1926 * been called before this from png_read_update_info->png_read_start_row
1927 * sometimes does the gamma transform and cancels the flag.
1928 */
1929 info_ptr->gamma = png_ptr->gamma;
1930#endif
1931
1932 if (info_ptr->bit_depth == 16)
1933 {
1934# ifdef PNG_READ_16BIT_SUPPORTED
1935# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1936 if (png_ptr->transformations & PNG_SCALE_16_TO_8)
1937 info_ptr->bit_depth = 8;
1938# endif
1939
1940# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1941 if (png_ptr->transformations & PNG_16_TO_8)
1942 info_ptr->bit_depth = 8;
1943# endif
1944
1945# else
1946 /* No 16 bit support: force chopping 16-bit input down to 8, in this case
1947 * the app program can chose if both APIs are available by setting the
1948 * correct scaling to use.
1949 */
1950# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
1951 /* For compatibility with previous versions use the strip method by
1952 * default. This code works because if PNG_SCALE_16_TO_8 is already
1953 * set the code below will do that in preference to the chop.
1954 */
1955 png_ptr->transformations |= PNG_16_TO_8;
1956 info_ptr->bit_depth = 8;
1957# else
1958
1959# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
1960 png_ptr->transformations |= PNG_SCALE_16_TO_8;
1961 info_ptr->bit_depth = 8;
1962# else
1963
1964 CONFIGURATION ERROR: you must enable at least one 16 to 8 method
1965# endif
1966# endif
1967#endif /* !READ_16BIT_SUPPORTED */
1968 }
1969
1970#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1971 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
1972 info_ptr->color_type = (png_byte)(info_ptr->color_type |
1973 PNG_COLOR_MASK_COLOR);
1974#endif
1975
1976#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1977 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
1978 info_ptr->color_type = (png_byte)(info_ptr->color_type &
1979 ~PNG_COLOR_MASK_COLOR);
1980#endif
1981
1982#ifdef PNG_READ_QUANTIZE_SUPPORTED
1983 if (png_ptr->transformations & PNG_QUANTIZE)
1984 {
1985 if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
1986 (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
1987 png_ptr->palette_lookup && info_ptr->bit_depth == 8)
1988 {
1989 info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
1990 }
1991 }
1992#endif
1993
1994#ifdef PNG_READ_EXPAND_16_SUPPORTED
1995 if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 &&
1996 info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
1997 {
1998 info_ptr->bit_depth = 16;
1999 }
2000#endif
2001
2002#ifdef PNG_READ_PACK_SUPPORTED
2003 if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
2004 info_ptr->bit_depth = 8;
2005#endif
2006
2007 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
2008 info_ptr->channels = 1;
2009
2010 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
2011 info_ptr->channels = 3;
2012
2013 else
2014 info_ptr->channels = 1;
2015
2016#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
2017 if (png_ptr->transformations & PNG_STRIP_ALPHA)
2018 {
2019 info_ptr->color_type = (png_byte)(info_ptr->color_type &
2020 ~PNG_COLOR_MASK_ALPHA);
2021 info_ptr->num_trans = 0;
2022 }
2023#endif
2024
2025 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
2026 info_ptr->channels++;
2027
2028#ifdef PNG_READ_FILLER_SUPPORTED
2029 /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */
2030 if ((png_ptr->transformations & PNG_FILLER) &&
2031 ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
2032 (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
2033 {
2034 info_ptr->channels++;
2035 /* If adding a true alpha channel not just filler */
2036 if (png_ptr->transformations & PNG_ADD_ALPHA)
2037 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
2038 }
2039#endif
2040
2041#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
2042defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
2043 if (png_ptr->transformations & PNG_USER_TRANSFORM)
2044 {
2045 if (info_ptr->bit_depth < png_ptr->user_transform_depth)
2046 info_ptr->bit_depth = png_ptr->user_transform_depth;
2047
2048 if (info_ptr->channels < png_ptr->user_transform_channels)
2049 info_ptr->channels = png_ptr->user_transform_channels;
2050 }
2051#endif
2052
2053 info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
2054 info_ptr->bit_depth);
2055
2056 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
2057
2058 /* Adding in 1.5.4: cache the above value in png_struct so that we can later
2059 * check in png_rowbytes that the user buffer won't get overwritten. Note
2060 * that the field is not always set - if png_read_update_info isn't called
2061 * the application has to either not do any transforms or get the calculation
2062 * right itself.
2063 */
2064 png_ptr->info_rowbytes = info_ptr->rowbytes;
2065
2066#ifndef PNG_READ_EXPAND_SUPPORTED
2067 if (png_ptr)
2068 return;
2069#endif
2070}
2071
2072/* Transform the row. The order of transformations is significant,
2073 * and is very touchy. If you add a transformation, take care to
2074 * decide how it fits in with the other transformations here.
2075 */
2076void /* PRIVATE */
2077png_do_read_transformations(png_structp png_ptr, png_row_infop row_info)
2078{
2079 png_debug(1, "in png_do_read_transformations");
2080
2081 if (png_ptr->row_buf == NULL)
2082 {
2083 /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this
2084 * error is incredibly rare and incredibly easy to debug without this
2085 * information.
2086 */
2087 png_error(png_ptr, "NULL row buffer");
2088 }
2089
2090 /* The following is debugging; prior to 1.5.4 the code was never compiled in;
2091 * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
2092 * PNG_WARN_UNINITIALIZED_ROW removed. In 1.5 the new flag is set only for
2093 * selected new APIs to ensure that there is no API change.
2094 */
2095 if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
2096 !(png_ptr->flags & PNG_FLAG_ROW_INIT))
2097 {
2098 /* Application has failed to call either png_read_start_image() or
2099 * png_read_update_info() after setting transforms that expand pixels.
2100 * This check added to libpng-1.2.19 (but not enabled until 1.5.4).
2101 */
2102 png_error(png_ptr, "Uninitialized row");
2103 }
2104
2105#ifdef PNG_READ_EXPAND_SUPPORTED
2106 if (png_ptr->transformations & PNG_EXPAND)
2107 {
2108 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
2109 {
2110 png_do_expand_palette(row_info, png_ptr->row_buf + 1,
2111 png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
2112 }
2113
2114 else
2115 {
2116 if (png_ptr->num_trans &&
2117 (png_ptr->transformations & PNG_EXPAND_tRNS))
2118 png_do_expand(row_info, png_ptr->row_buf + 1,
2119 &(png_ptr->trans_color));
2120
2121 else
2122 png_do_expand(row_info, png_ptr->row_buf + 1,
2123 NULL);
2124 }
2125 }
2126#endif
2127
2128#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
2129 if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
2130 !(png_ptr->transformations & PNG_COMPOSE) &&
2131 (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
2132 row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
2133 png_do_strip_channel(row_info, png_ptr->row_buf + 1,
2134 0 /* at_start == false, because SWAP_ALPHA happens later */);
2135#endif
2136
2137#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
2138 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
2139 {
2140 int rgb_error =
2141 png_do_rgb_to_gray(png_ptr, row_info,
2142 png_ptr->row_buf + 1);
2143
2144 if (rgb_error)
2145 {
2146 png_ptr->rgb_to_gray_status=1;
2147 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
2148 PNG_RGB_TO_GRAY_WARN)
2149 png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
2150
2151 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
2152 PNG_RGB_TO_GRAY_ERR)
2153 png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
2154 }
2155 }
2156#endif
2157
2158/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
2159 *
2160 * In most cases, the "simple transparency" should be done prior to doing
2161 * gray-to-RGB, or you will have to test 3x as many bytes to check if a
2162 * pixel is transparent. You would also need to make sure that the
2163 * transparency information is upgraded to RGB.
2164 *
2165 * To summarize, the current flow is:
2166 * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
2167 * with background "in place" if transparent,
2168 * convert to RGB if necessary
2169 * - Gray + alpha -> composite with gray background and remove alpha bytes,
2170 * convert to RGB if necessary
2171 *
2172 * To support RGB backgrounds for gray images we need:
2173 * - Gray + simple transparency -> convert to RGB + simple transparency,
2174 * compare 3 or 6 bytes and composite with
2175 * background "in place" if transparent
2176 * (3x compare/pixel compared to doing
2177 * composite with gray bkgrnd)
2178 * - Gray + alpha -> convert to RGB + alpha, composite with background and
2179 * remove alpha bytes (3x float
2180 * operations/pixel compared with composite
2181 * on gray background)
2182 *
2183 * Greg's change will do this. The reason it wasn't done before is for
2184 * performance, as this increases the per-pixel operations. If we would check
2185 * in advance if the background was gray or RGB, and position the gray-to-RGB
2186 * transform appropriately, then it would save a lot of work/time.
2187 */
2188
2189#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2190 /* If gray -> RGB, do so now only if background is non-gray; else do later
2191 * for performance reasons
2192 */
2193 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
2194 !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
2195 png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
2196#endif
2197
2198#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
2199 (defined PNG_READ_ALPHA_MODE_SUPPORTED)
2200 if (png_ptr->transformations & PNG_COMPOSE)
2201 png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);
2202#endif
2203
2204#ifdef PNG_READ_GAMMA_SUPPORTED
2205 if ((png_ptr->transformations & PNG_GAMMA) &&
2206#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
2207 /* Because RGB_TO_GRAY does the gamma transform. */
2208 !(png_ptr->transformations & PNG_RGB_TO_GRAY) &&
2209#endif
2210#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
2211 (defined PNG_READ_ALPHA_MODE_SUPPORTED)
2212 /* Because PNG_COMPOSE does the gamma transform if there is something to
2213 * do (if there is an alpha channel or transparency.)
2214 */
2215 !((png_ptr->transformations & PNG_COMPOSE) &&
2216 ((png_ptr->num_trans != 0) ||
2217 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
2218#endif
2219 /* Because png_init_read_transformations transforms the palette, unless
2220 * RGB_TO_GRAY will do the transform.
2221 */
2222 (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
2223 png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);
2224#endif
2225
2226#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
2227 if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
2228 (png_ptr->transformations & PNG_COMPOSE) &&
2229 (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
2230 row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
2231 png_do_strip_channel(row_info, png_ptr->row_buf + 1,
2232 0 /* at_start == false, because SWAP_ALPHA happens later */);
2233#endif
2234
2235#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
2236 if ((png_ptr->transformations & PNG_ENCODE_ALPHA) &&
2237 (row_info->color_type & PNG_COLOR_MASK_ALPHA))
2238 png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);
2239#endif
2240
2241#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
2242 if (png_ptr->transformations & PNG_SCALE_16_TO_8)
2243 png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);
2244#endif
2245
2246#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
2247 /* There is no harm in doing both of these because only one has any effect,
2248 * by putting the 'scale' option first if the app asks for scale (either by
2249 * calling the API or in a TRANSFORM flag) this is what happens.
2250 */
2251 if (png_ptr->transformations & PNG_16_TO_8)
2252 png_do_chop(row_info, png_ptr->row_buf + 1);
2253#endif
2254
2255#ifdef PNG_READ_QUANTIZE_SUPPORTED
2256 if (png_ptr->transformations & PNG_QUANTIZE)
2257 {
2258 png_do_quantize(row_info, png_ptr->row_buf + 1,
2259 png_ptr->palette_lookup, png_ptr->quantize_index);
2260
2261 if (row_info->rowbytes == 0)
2262 png_error(png_ptr, "png_do_quantize returned rowbytes=0");
2263 }
2264#endif /* PNG_READ_QUANTIZE_SUPPORTED */
2265
2266#ifdef PNG_READ_EXPAND_16_SUPPORTED
2267 /* Do the expansion now, after all the arithmetic has been done. Notice
2268 * that previous transformations can handle the PNG_EXPAND_16 flag if this
2269 * is efficient (particularly true in the case of gamma correction, where
2270 * better accuracy results faster!)
2271 */
2272 if (png_ptr->transformations & PNG_EXPAND_16)
2273 png_do_expand_16(row_info, png_ptr->row_buf + 1);
2274#endif
2275
2276#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2277 /*NOTE: moved here in 1.5.4 (from much later in this list.) */
2278 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
2279 (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
2280 png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);
2281#endif
2282
2283#ifdef PNG_READ_INVERT_SUPPORTED
2284 if (png_ptr->transformations & PNG_INVERT_MONO)
2285 png_do_invert(row_info, png_ptr->row_buf + 1);
2286#endif
2287
2288#ifdef PNG_READ_SHIFT_SUPPORTED
2289 if (png_ptr->transformations & PNG_SHIFT)
2290 png_do_unshift(row_info, png_ptr->row_buf + 1,
2291 &(png_ptr->shift));
2292#endif
2293
2294#ifdef PNG_READ_PACK_SUPPORTED
2295 if (png_ptr->transformations & PNG_PACK)
2296 png_do_unpack(row_info, png_ptr->row_buf + 1);
2297#endif
2298
2299#ifdef PNG_READ_BGR_SUPPORTED
2300 if (png_ptr->transformations & PNG_BGR)
2301 png_do_bgr(row_info, png_ptr->row_buf + 1);
2302#endif
2303
2304#ifdef PNG_READ_PACKSWAP_SUPPORTED
2305 if (png_ptr->transformations & PNG_PACKSWAP)
2306 png_do_packswap(row_info, png_ptr->row_buf + 1);
2307#endif
2308
2309#ifdef PNG_READ_FILLER_SUPPORTED
2310 if (png_ptr->transformations & PNG_FILLER)
2311 png_do_read_filler(row_info, png_ptr->row_buf + 1,
2312 (png_uint_32)png_ptr->filler, png_ptr->flags);
2313#endif
2314
2315#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
2316 if (png_ptr->transformations & PNG_INVERT_ALPHA)
2317 png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);
2318#endif
2319
2320#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
2321 if (png_ptr->transformations & PNG_SWAP_ALPHA)
2322 png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);
2323#endif
2324
2325#ifdef PNG_READ_16BIT_SUPPORTED
2326#ifdef PNG_READ_SWAP_SUPPORTED
2327 if (png_ptr->transformations & PNG_SWAP_BYTES)
2328 png_do_swap(row_info, png_ptr->row_buf + 1);
2329#endif
2330#endif
2331
2332#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
2333 if (png_ptr->transformations & PNG_USER_TRANSFORM)
2334 {
2335 if (png_ptr->read_user_transform_fn != NULL)
2336 (*(png_ptr->read_user_transform_fn)) /* User read transform function */
2337 (png_ptr, /* png_ptr */
2338 row_info, /* row_info: */
2339 /* png_uint_32 width; width of row */
2340 /* png_size_t rowbytes; number of bytes in row */
2341 /* png_byte color_type; color type of pixels */
2342 /* png_byte bit_depth; bit depth of samples */
2343 /* png_byte channels; number of channels (1-4) */
2344 /* png_byte pixel_depth; bits per pixel (depth*channels) */
2345 png_ptr->row_buf + 1); /* start of pixel data for row */
2346#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
2347 if (png_ptr->user_transform_depth)
2348 row_info->bit_depth = png_ptr->user_transform_depth;
2349
2350 if (png_ptr->user_transform_channels)
2351 row_info->channels = png_ptr->user_transform_channels;
2352#endif
2353 row_info->pixel_depth = (png_byte)(row_info->bit_depth *
2354 row_info->channels);
2355
2356 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);
2357 }
2358#endif
2359}
2360
2361#ifdef PNG_READ_PACK_SUPPORTED
2362/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
2363 * without changing the actual values. Thus, if you had a row with
2364 * a bit depth of 1, you would end up with bytes that only contained
2365 * the numbers 0 or 1. If you would rather they contain 0 and 255, use
2366 * png_do_shift() after this.
2367 */
2368void /* PRIVATE */
2369png_do_unpack(png_row_infop row_info, png_bytep row)
2370{
2371 png_debug(1, "in png_do_unpack");
2372
2373 if (row_info->bit_depth < 8)
2374 {
2375 png_uint_32 i;
2376 png_uint_32 row_width=row_info->width;
2377
2378 switch (row_info->bit_depth)
2379 {
2380 case 1:
2381 {
2382 png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
2383 png_bytep dp = row + (png_size_t)row_width - 1;
2384 png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
2385 for (i = 0; i < row_width; i++)
2386 {
2387 *dp = (png_byte)((*sp >> shift) & 0x01);
2388
2389 if (shift == 7)
2390 {
2391 shift = 0;
2392 sp--;
2393 }
2394
2395 else
2396 shift++;
2397
2398 dp--;
2399 }
2400 break;
2401 }
2402
2403 case 2:
2404 {
2405
2406 png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
2407 png_bytep dp = row + (png_size_t)row_width - 1;
2408 png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
2409 for (i = 0; i < row_width; i++)
2410 {
2411 *dp = (png_byte)((*sp >> shift) & 0x03);
2412
2413 if (shift == 6)
2414 {
2415 shift = 0;
2416 sp--;
2417 }
2418
2419 else
2420 shift += 2;
2421
2422 dp--;
2423 }
2424 break;
2425 }
2426
2427 case 4:
2428 {
2429 png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
2430 png_bytep dp = row + (png_size_t)row_width - 1;
2431 png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
2432 for (i = 0; i < row_width; i++)
2433 {
2434 *dp = (png_byte)((*sp >> shift) & 0x0f);
2435
2436 if (shift == 4)
2437 {
2438 shift = 0;
2439 sp--;
2440 }
2441
2442 else
2443 shift = 4;
2444
2445 dp--;
2446 }
2447 break;
2448 }
2449
2450 default:
2451 break;
2452 }
2453 row_info->bit_depth = 8;
2454 row_info->pixel_depth = (png_byte)(8 * row_info->channels);
2455 row_info->rowbytes = row_width * row_info->channels;
2456 }
2457}
2458#endif
2459
2460#ifdef PNG_READ_SHIFT_SUPPORTED
2461/* Reverse the effects of png_do_shift. This routine merely shifts the
2462 * pixels back to their significant bits values. Thus, if you have
2463 * a row of bit depth 8, but only 5 are significant, this will shift
2464 * the values back to 0 through 31.
2465 */
2466void /* PRIVATE */
2467png_do_unshift(png_row_infop row_info, png_bytep row,
2468 png_const_color_8p sig_bits)
2469{
2470 int color_type;
2471
2472 png_debug(1, "in png_do_unshift");
2473
2474 /* The palette case has already been handled in the _init routine. */
2475 color_type = row_info->color_type;
2476
2477 if (color_type != PNG_COLOR_TYPE_PALETTE)
2478 {
2479 int shift[4];
2480 int channels = 0;
2481 int bit_depth = row_info->bit_depth;
2482
2483 if (color_type & PNG_COLOR_MASK_COLOR)
2484 {
2485 shift[channels++] = bit_depth - sig_bits->red;
2486 shift[channels++] = bit_depth - sig_bits->green;
2487 shift[channels++] = bit_depth - sig_bits->blue;
2488 }
2489
2490 else
2491 {
2492 shift[channels++] = bit_depth - sig_bits->gray;
2493 }
2494
2495 if (color_type & PNG_COLOR_MASK_ALPHA)
2496 {
2497 shift[channels++] = bit_depth - sig_bits->alpha;
2498 }
2499
2500 {
2501 int c, have_shift;
2502
2503 for (c = have_shift = 0; c < channels; ++c)
2504 {
2505 /* A shift of more than the bit depth is an error condition but it
2506 * gets ignored here.
2507 */
2508 if (shift[c] <= 0 || shift[c] >= bit_depth)
2509 shift[c] = 0;
2510
2511 else
2512 have_shift = 1;
2513 }
2514
2515 if (!have_shift)
2516 return;
2517 }
2518
2519 switch (bit_depth)
2520 {
2521 default:
2522 /* Must be 1bpp gray: should not be here! */
2523 /* NOTREACHED */
2524 break;
2525
2526 case 2:
2527 /* Must be 2bpp gray */
2528 /* assert(channels == 1 && shift[0] == 1) */
2529 {
2530 png_bytep bp = row;
2531 png_bytep bp_end = bp + row_info->rowbytes;
2532
2533 while (bp < bp_end)
2534 {
2535 int b = (*bp >> 1) & 0x55;
2536 *bp++ = (png_byte)b;
2537 }
2538 break;
2539 }
2540
2541 case 4:
2542 /* Must be 4bpp gray */
2543 /* assert(channels == 1) */
2544 {
2545 png_bytep bp = row;
2546 png_bytep bp_end = bp + row_info->rowbytes;
2547 int gray_shift = shift[0];
2548 int mask = 0xf >> gray_shift;
2549
2550 mask |= mask << 4;
2551
2552 while (bp < bp_end)
2553 {
2554 int b = (*bp >> gray_shift) & mask;
2555 *bp++ = (png_byte)b;
2556 }
2557 break;
2558 }
2559
2560 case 8:
2561 /* Single byte components, G, GA, RGB, RGBA */
2562 {
2563 png_bytep bp = row;
2564 png_bytep bp_end = bp + row_info->rowbytes;
2565 int channel = 0;
2566
2567 while (bp < bp_end)
2568 {
2569 int b = *bp >> shift[channel];
2570 if (++channel >= channels)
2571 channel = 0;
2572 *bp++ = (png_byte)b;
2573 }
2574 break;
2575 }
2576
2577#ifdef PNG_READ_16BIT_SUPPORTED
2578 case 16:
2579 /* Double byte components, G, GA, RGB, RGBA */
2580 {
2581 png_bytep bp = row;
2582 png_bytep bp_end = bp + row_info->rowbytes;
2583 int channel = 0;
2584
2585 while (bp < bp_end)
2586 {
2587 int value = (bp[0] << 8) + bp[1];
2588
2589 value >>= shift[channel];
2590 if (++channel >= channels)
2591 channel = 0;
2592 *bp++ = (png_byte)(value >> 8);
2593 *bp++ = (png_byte)(value & 0xff);
2594 }
2595 break;
2596 }
2597#endif
2598 }
2599 }
2600}
2601#endif
2602
2603#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
2604/* Scale rows of bit depth 16 down to 8 accurately */
2605void /* PRIVATE */
2606png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
2607{
2608 png_debug(1, "in png_do_scale_16_to_8");
2609
2610 if (row_info->bit_depth == 16)
2611 {
2612 png_bytep sp = row; /* source */
2613 png_bytep dp = row; /* destination */
2614 png_bytep ep = sp + row_info->rowbytes; /* end+1 */
2615
2616 while (sp < ep)
2617 {
2618 /* The input is an array of 16 bit components, these must be scaled to
2619 * 8 bits each. For a 16 bit value V the required value (from the PNG
2620 * specification) is:
2621 *
2622 * (V * 255) / 65535
2623 *
2624 * This reduces to round(V / 257), or floor((V + 128.5)/257)
2625 *
2626 * Represent V as the two byte value vhi.vlo. Make a guess that the
2627 * result is the top byte of V, vhi, then the correction to this value
2628 * is:
2629 *
2630 * error = floor(((V-vhi.vhi) + 128.5) / 257)
2631 * = floor(((vlo-vhi) + 128.5) / 257)
2632 *
2633 * This can be approximated using integer arithmetic (and a signed
2634 * shift):
2635 *
2636 * error = (vlo-vhi+128) >> 8;
2637 *
2638 * The approximate differs from the exact answer only when (vlo-vhi) is
2639 * 128; it then gives a correction of +1 when the exact correction is
2640 * 0. This gives 128 errors. The exact answer (correct for all 16 bit
2641 * input values) is:
2642 *
2643 * error = (vlo-vhi+128)*65535 >> 24;
2644 *
2645 * An alternative arithmetic calculation which also gives no errors is:
2646 *
2647 * (V * 255 + 32895) >> 16
2648 */
2649
2650 png_int_32 tmp = *sp++; /* must be signed! */
2651 tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
2652 *dp++ = (png_byte)tmp;
2653 }
2654
2655 row_info->bit_depth = 8;
2656 row_info->pixel_depth = (png_byte)(8 * row_info->channels);
2657 row_info->rowbytes = row_info->width * row_info->channels;
2658 }
2659}
2660#endif
2661
2662#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
2663void /* PRIVATE */
2664/* Simply discard the low byte. This was the default behavior prior
2665 * to libpng-1.5.4.
2666 */
2667png_do_chop(png_row_infop row_info, png_bytep row)
2668{
2669 png_debug(1, "in png_do_chop");
2670
2671 if (row_info->bit_depth == 16)
2672 {
2673 png_bytep sp = row; /* source */
2674 png_bytep dp = row; /* destination */
2675 png_bytep ep = sp + row_info->rowbytes; /* end+1 */
2676
2677 while (sp < ep)
2678 {
2679 *dp++ = *sp;
2680 sp += 2; /* skip low byte */
2681 }
2682
2683 row_info->bit_depth = 8;
2684 row_info->pixel_depth = (png_byte)(8 * row_info->channels);
2685 row_info->rowbytes = row_info->width * row_info->channels;
2686 }
2687}
2688#endif
2689
2690#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
2691void /* PRIVATE */
2692png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
2693{
2694 png_debug(1, "in png_do_read_swap_alpha");
2695
2696 {
2697 png_uint_32 row_width = row_info->width;
2698 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2699 {
2700 /* This converts from RGBA to ARGB */
2701 if (row_info->bit_depth == 8)
2702 {
2703 png_bytep sp = row + row_info->rowbytes;
2704 png_bytep dp = sp;
2705 png_byte save;
2706 png_uint_32 i;
2707
2708 for (i = 0; i < row_width; i++)
2709 {
2710 save = *(--sp);
2711 *(--dp) = *(--sp);
2712 *(--dp) = *(--sp);
2713 *(--dp) = *(--sp);
2714 *(--dp) = save;
2715 }
2716 }
2717
2718#ifdef PNG_READ_16BIT_SUPPORTED
2719 /* This converts from RRGGBBAA to AARRGGBB */
2720 else
2721 {
2722 png_bytep sp = row + row_info->rowbytes;
2723 png_bytep dp = sp;
2724 png_byte save[2];
2725 png_uint_32 i;
2726
2727 for (i = 0; i < row_width; i++)
2728 {
2729 save[0] = *(--sp);
2730 save[1] = *(--sp);
2731 *(--dp) = *(--sp);
2732 *(--dp) = *(--sp);
2733 *(--dp) = *(--sp);
2734 *(--dp) = *(--sp);
2735 *(--dp) = *(--sp);
2736 *(--dp) = *(--sp);
2737 *(--dp) = save[0];
2738 *(--dp) = save[1];
2739 }
2740 }
2741#endif
2742 }
2743
2744 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2745 {
2746 /* This converts from GA to AG */
2747 if (row_info->bit_depth == 8)
2748 {
2749 png_bytep sp = row + row_info->rowbytes;
2750 png_bytep dp = sp;
2751 png_byte save;
2752 png_uint_32 i;
2753
2754 for (i = 0; i < row_width; i++)
2755 {
2756 save = *(--sp);
2757 *(--dp) = *(--sp);
2758 *(--dp) = save;
2759 }
2760 }
2761
2762#ifdef PNG_READ_16BIT_SUPPORTED
2763 /* This converts from GGAA to AAGG */
2764 else
2765 {
2766 png_bytep sp = row + row_info->rowbytes;
2767 png_bytep dp = sp;
2768 png_byte save[2];
2769 png_uint_32 i;
2770
2771 for (i = 0; i < row_width; i++)
2772 {
2773 save[0] = *(--sp);
2774 save[1] = *(--sp);
2775 *(--dp) = *(--sp);
2776 *(--dp) = *(--sp);
2777 *(--dp) = save[0];
2778 *(--dp) = save[1];
2779 }
2780 }
2781#endif
2782 }
2783 }
2784}
2785#endif
2786
2787#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
2788void /* PRIVATE */
2789png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
2790{
2791 png_uint_32 row_width;
2792 png_debug(1, "in png_do_read_invert_alpha");
2793
2794 row_width = row_info->width;
2795 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2796 {
2797 if (row_info->bit_depth == 8)
2798 {
2799 /* This inverts the alpha channel in RGBA */
2800 png_bytep sp = row + row_info->rowbytes;
2801 png_bytep dp = sp;
2802 png_uint_32 i;
2803
2804 for (i = 0; i < row_width; i++)
2805 {
2806 *(--dp) = (png_byte)(255 - *(--sp));
2807
2808/* This does nothing:
2809 *(--dp) = *(--sp);
2810 *(--dp) = *(--sp);
2811 *(--dp) = *(--sp);
2812 We can replace it with:
2813*/
2814 sp-=3;
2815 dp=sp;
2816 }
2817 }
2818
2819#ifdef PNG_READ_16BIT_SUPPORTED
2820 /* This inverts the alpha channel in RRGGBBAA */
2821 else
2822 {
2823 png_bytep sp = row + row_info->rowbytes;
2824 png_bytep dp = sp;
2825 png_uint_32 i;
2826
2827 for (i = 0; i < row_width; i++)
2828 {
2829 *(--dp) = (png_byte)(255 - *(--sp));
2830 *(--dp) = (png_byte)(255 - *(--sp));
2831
2832/* This does nothing:
2833 *(--dp) = *(--sp);
2834 *(--dp) = *(--sp);
2835 *(--dp) = *(--sp);
2836 *(--dp) = *(--sp);
2837 *(--dp) = *(--sp);
2838 *(--dp) = *(--sp);
2839 We can replace it with:
2840*/
2841 sp-=6;
2842 dp=sp;
2843 }
2844 }
2845#endif
2846 }
2847 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
2848 {
2849 if (row_info->bit_depth == 8)
2850 {
2851 /* This inverts the alpha channel in GA */
2852 png_bytep sp = row + row_info->rowbytes;
2853 png_bytep dp = sp;
2854 png_uint_32 i;
2855
2856 for (i = 0; i < row_width; i++)
2857 {
2858 *(--dp) = (png_byte)(255 - *(--sp));
2859 *(--dp) = *(--sp);
2860 }
2861 }
2862
2863#ifdef PNG_READ_16BIT_SUPPORTED
2864 else
2865 {
2866 /* This inverts the alpha channel in GGAA */
2867 png_bytep sp = row + row_info->rowbytes;
2868 png_bytep dp = sp;
2869 png_uint_32 i;
2870
2871 for (i = 0; i < row_width; i++)
2872 {
2873 *(--dp) = (png_byte)(255 - *(--sp));
2874 *(--dp) = (png_byte)(255 - *(--sp));
2875/*
2876 *(--dp) = *(--sp);
2877 *(--dp) = *(--sp);
2878*/
2879 sp-=2;
2880 dp=sp;
2881 }
2882 }
2883#endif
2884 }
2885}
2886#endif
2887
2888#ifdef PNG_READ_FILLER_SUPPORTED
2889/* Add filler channel if we have RGB color */
2890void /* PRIVATE */
2891png_do_read_filler(png_row_infop row_info, png_bytep row,
2892 png_uint_32 filler, png_uint_32 flags)
2893{
2894 png_uint_32 i;
2895 png_uint_32 row_width = row_info->width;
2896
2897#ifdef PNG_READ_16BIT_SUPPORTED
2898 png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
2899#endif
2900 png_byte lo_filler = (png_byte)(filler & 0xff);
2901
2902 png_debug(1, "in png_do_read_filler");
2903
2904 if (
2905 row_info->color_type == PNG_COLOR_TYPE_GRAY)
2906 {
2907 if (row_info->bit_depth == 8)
2908 {
2909 if (flags & PNG_FLAG_FILLER_AFTER)
2910 {
2911 /* This changes the data from G to GX */
2912 png_bytep sp = row + (png_size_t)row_width;
2913 png_bytep dp = sp + (png_size_t)row_width;
2914 for (i = 1; i < row_width; i++)
2915 {
2916 *(--dp) = lo_filler;
2917 *(--dp) = *(--sp);
2918 }
2919 *(--dp) = lo_filler;
2920 row_info->channels = 2;
2921 row_info->pixel_depth = 16;
2922 row_info->rowbytes = row_width * 2;
2923 }
2924
2925 else
2926 {
2927 /* This changes the data from G to XG */
2928 png_bytep sp = row + (png_size_t)row_width;
2929 png_bytep dp = sp + (png_size_t)row_width;
2930 for (i = 0; i < row_width; i++)
2931 {
2932 *(--dp) = *(--sp);
2933 *(--dp) = lo_filler;
2934 }
2935 row_info->channels = 2;
2936 row_info->pixel_depth = 16;
2937 row_info->rowbytes = row_width * 2;
2938 }
2939 }
2940
2941#ifdef PNG_READ_16BIT_SUPPORTED
2942 else if (row_info->bit_depth == 16)
2943 {
2944 if (flags & PNG_FLAG_FILLER_AFTER)
2945 {
2946 /* This changes the data from GG to GGXX */
2947 png_bytep sp = row + (png_size_t)row_width * 2;
2948 png_bytep dp = sp + (png_size_t)row_width * 2;
2949 for (i = 1; i < row_width; i++)
2950 {
2951 *(--dp) = hi_filler;
2952 *(--dp) = lo_filler;
2953 *(--dp) = *(--sp);
2954 *(--dp) = *(--sp);
2955 }
2956 *(--dp) = hi_filler;
2957 *(--dp) = lo_filler;
2958 row_info->channels = 2;
2959 row_info->pixel_depth = 32;
2960 row_info->rowbytes = row_width * 4;
2961 }
2962
2963 else
2964 {
2965 /* This changes the data from GG to XXGG */
2966 png_bytep sp = row + (png_size_t)row_width * 2;
2967 png_bytep dp = sp + (png_size_t)row_width * 2;
2968 for (i = 0; i < row_width; i++)
2969 {
2970 *(--dp) = *(--sp);
2971 *(--dp) = *(--sp);
2972 *(--dp) = hi_filler;
2973 *(--dp) = lo_filler;
2974 }
2975 row_info->channels = 2;
2976 row_info->pixel_depth = 32;
2977 row_info->rowbytes = row_width * 4;
2978 }
2979 }
2980#endif
2981 } /* COLOR_TYPE == GRAY */
2982 else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
2983 {
2984 if (row_info->bit_depth == 8)
2985 {
2986 if (flags & PNG_FLAG_FILLER_AFTER)
2987 {
2988 /* This changes the data from RGB to RGBX */
2989 png_bytep sp = row + (png_size_t)row_width * 3;
2990 png_bytep dp = sp + (png_size_t)row_width;
2991 for (i = 1; i < row_width; i++)
2992 {
2993 *(--dp) = lo_filler;
2994 *(--dp) = *(--sp);
2995 *(--dp) = *(--sp);
2996 *(--dp) = *(--sp);
2997 }
2998 *(--dp) = lo_filler;
2999 row_info->channels = 4;
3000 row_info->pixel_depth = 32;
3001 row_info->rowbytes = row_width * 4;
3002 }
3003
3004 else
3005 {
3006 /* This changes the data from RGB to XRGB */
3007 png_bytep sp = row + (png_size_t)row_width * 3;
3008 png_bytep dp = sp + (png_size_t)row_width;
3009 for (i = 0; i < row_width; i++)
3010 {
3011 *(--dp) = *(--sp);
3012 *(--dp) = *(--sp);
3013 *(--dp) = *(--sp);
3014 *(--dp) = lo_filler;
3015 }
3016 row_info->channels = 4;
3017 row_info->pixel_depth = 32;
3018 row_info->rowbytes = row_width * 4;
3019 }
3020 }
3021
3022#ifdef PNG_READ_16BIT_SUPPORTED
3023 else if (row_info->bit_depth == 16)
3024 {
3025 if (flags & PNG_FLAG_FILLER_AFTER)
3026 {
3027 /* This changes the data from RRGGBB to RRGGBBXX */
3028 png_bytep sp = row + (png_size_t)row_width * 6;
3029 png_bytep dp = sp + (png_size_t)row_width * 2;
3030 for (i = 1; i < row_width; i++)
3031 {
3032 *(--dp) = hi_filler;
3033 *(--dp) = lo_filler;
3034 *(--dp) = *(--sp);
3035 *(--dp) = *(--sp);
3036 *(--dp) = *(--sp);
3037 *(--dp) = *(--sp);
3038 *(--dp) = *(--sp);
3039 *(--dp) = *(--sp);
3040 }
3041 *(--dp) = hi_filler;
3042 *(--dp) = lo_filler;
3043 row_info->channels = 4;
3044 row_info->pixel_depth = 64;
3045 row_info->rowbytes = row_width * 8;
3046 }
3047
3048 else
3049 {
3050 /* This changes the data from RRGGBB to XXRRGGBB */
3051 png_bytep sp = row + (png_size_t)row_width * 6;
3052 png_bytep dp = sp + (png_size_t)row_width * 2;
3053 for (i = 0; i < row_width; i++)
3054 {
3055 *(--dp) = *(--sp);
3056 *(--dp) = *(--sp);
3057 *(--dp) = *(--sp);
3058 *(--dp) = *(--sp);
3059 *(--dp) = *(--sp);
3060 *(--dp) = *(--sp);
3061 *(--dp) = hi_filler;
3062 *(--dp) = lo_filler;
3063 }
3064
3065 row_info->channels = 4;
3066 row_info->pixel_depth = 64;
3067 row_info->rowbytes = row_width * 8;
3068 }
3069 }
3070#endif
3071 } /* COLOR_TYPE == RGB */
3072}
3073#endif
3074
3075#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
3076/* Expand grayscale files to RGB, with or without alpha */
3077void /* PRIVATE */
3078png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
3079{
3080 png_uint_32 i;
3081 png_uint_32 row_width = row_info->width;
3082
3083 png_debug(1, "in png_do_gray_to_rgb");
3084
3085 if (row_info->bit_depth >= 8 &&
3086 !(row_info->color_type & PNG_COLOR_MASK_COLOR))
3087 {
3088 if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
3089 {
3090 if (row_info->bit_depth == 8)
3091 {
3092 /* This changes G to RGB */
3093 png_bytep sp = row + (png_size_t)row_width - 1;
3094 png_bytep dp = sp + (png_size_t)row_width * 2;
3095 for (i = 0; i < row_width; i++)
3096 {
3097 *(dp--) = *sp;
3098 *(dp--) = *sp;
3099 *(dp--) = *(sp--);
3100 }
3101 }
3102
3103 else
3104 {
3105 /* This changes GG to RRGGBB */
3106 png_bytep sp = row + (png_size_t)row_width * 2 - 1;
3107 png_bytep dp = sp + (png_size_t)row_width * 4;
3108 for (i = 0; i < row_width; i++)
3109 {
3110 *(dp--) = *sp;
3111 *(dp--) = *(sp - 1);
3112 *(dp--) = *sp;
3113 *(dp--) = *(sp - 1);
3114 *(dp--) = *(sp--);
3115 *(dp--) = *(sp--);
3116 }
3117 }
3118 }
3119
3120 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
3121 {
3122 if (row_info->bit_depth == 8)
3123 {
3124 /* This changes GA to RGBA */
3125 png_bytep sp = row + (png_size_t)row_width * 2 - 1;
3126 png_bytep dp = sp + (png_size_t)row_width * 2;
3127 for (i = 0; i < row_width; i++)
3128 {
3129 *(dp--) = *(sp--);
3130 *(dp--) = *sp;
3131 *(dp--) = *sp;
3132 *(dp--) = *(sp--);
3133 }
3134 }
3135
3136 else
3137 {
3138 /* This changes GGAA to RRGGBBAA */
3139 png_bytep sp = row + (png_size_t)row_width * 4 - 1;
3140 png_bytep dp = sp + (png_size_t)row_width * 4;
3141 for (i = 0; i < row_width; i++)
3142 {
3143 *(dp--) = *(sp--);
3144 *(dp--) = *(sp--);
3145 *(dp--) = *sp;
3146 *(dp--) = *(sp - 1);
3147 *(dp--) = *sp;
3148 *(dp--) = *(sp - 1);
3149 *(dp--) = *(sp--);
3150 *(dp--) = *(sp--);
3151 }
3152 }
3153 }
3154 row_info->channels = (png_byte)(row_info->channels + 2);
3155 row_info->color_type |= PNG_COLOR_MASK_COLOR;
3156 row_info->pixel_depth = (png_byte)(row_info->channels *
3157 row_info->bit_depth);
3158 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3159 }
3160}
3161#endif
3162
3163#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
3164/* Reduce RGB files to grayscale, with or without alpha
3165 * using the equation given in Poynton's ColorFAQ of 1998-01-04 at
3166 * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008 but
3167 * versions dated 1998 through November 2002 have been archived at
3168 * http://web.archive.org/web/20000816232553/http://www.inforamp.net/
3169 * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )
3170 * Charles Poynton poynton at poynton.com
3171 *
3172 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
3173 *
3174 * which can be expressed with integers as
3175 *
3176 * Y = (6969 * R + 23434 * G + 2365 * B)/32768
3177 *
3178 * Poynton's current link (as of January 2003 through July 2011):
3179 * <http://www.poynton.com/notes/colour_and_gamma/>
3180 * has changed the numbers slightly:
3181 *
3182 * Y = 0.2126*R + 0.7152*G + 0.0722*B
3183 *
3184 * which can be expressed with integers as
3185 *
3186 * Y = (6966 * R + 23436 * G + 2366 * B)/32768
3187 *
3188 * Historically, however, libpng uses numbers derived from the ITU-R Rec 709
3189 * end point chromaticities and the D65 white point. Depending on the
3190 * precision used for the D65 white point this produces a variety of different
3191 * numbers, however if the four decimal place value used in ITU-R Rec 709 is
3192 * used (0.3127,0.3290) the Y calculation would be:
3193 *
3194 * Y = (6968 * R + 23435 * G + 2366 * B)/32768
3195 *
3196 * While this is correct the rounding results in an overflow for white, because
3197 * the sum of the rounded coefficients is 32769, not 32768. Consequently
3198 * libpng uses, instead, the closest non-overflowing approximation:
3199 *
3200 * Y = (6968 * R + 23434 * G + 2366 * B)/32768
3201 *
3202 * Starting with libpng-1.5.5, if the image being converted has a cHRM chunk
3203 * (including an sRGB chunk) then the chromaticities are used to calculate the
3204 * coefficients. See the chunk handling in pngrutil.c for more information.
3205 *
3206 * In all cases the calculation is to be done in a linear colorspace. If no
3207 * gamma information is available to correct the encoding of the original RGB
3208 * values this results in an implicit assumption that the original PNG RGB
3209 * values were linear.
3210 *
3211 * Other integer coefficents can be used via png_set_rgb_to_gray(). Because
3212 * the API takes just red and green coefficients the blue coefficient is
3213 * calculated to make the sum 32768. This will result in different rounding
3214 * to that used above.
3215 */
3216int /* PRIVATE */
3217png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
3218
3219{
3220 int rgb_error = 0;
3221
3222 png_debug(1, "in png_do_rgb_to_gray");
3223
3224 if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) &&
3225 (row_info->color_type & PNG_COLOR_MASK_COLOR))
3226 {
3227 PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
3228 PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
3229 PNG_CONST png_uint_32 bc = 32768 - rc - gc;
3230 PNG_CONST png_uint_32 row_width = row_info->width;
3231 PNG_CONST int have_alpha =
3232 (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
3233
3234 if (row_info->bit_depth == 8)
3235 {
3236#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
3237 /* Notice that gamma to/from 1 are not necessarily inverses (if
3238 * there is an overall gamma correction). Prior to 1.5.5 this code
3239 * checked the linearized values for equality; this doesn't match
3240 * the documentation, the original values must be checked.
3241 */
3242 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
3243 {
3244 png_bytep sp = row;
3245 png_bytep dp = row;
3246 png_uint_32 i;
3247
3248 for (i = 0; i < row_width; i++)
3249 {
3250 png_byte red = *(sp++);
3251 png_byte green = *(sp++);
3252 png_byte blue = *(sp++);
3253
3254 if (red != green || red != blue)
3255 {
3256 red = png_ptr->gamma_to_1[red];
3257 green = png_ptr->gamma_to_1[green];
3258 blue = png_ptr->gamma_to_1[blue];
3259
3260 rgb_error |= 1;
3261 *(dp++) = png_ptr->gamma_from_1[
3262 (rc*red + gc*green + bc*blue + 16384)>>15];
3263 }
3264
3265 else
3266 {
3267 /* If there is no overall correction the table will not be
3268 * set.
3269 */
3270 if (png_ptr->gamma_table != NULL)
3271 red = png_ptr->gamma_table[red];
3272
3273 *(dp++) = red;
3274 }
3275
3276 if (have_alpha)
3277 *(dp++) = *(sp++);
3278 }
3279 }
3280 else
3281#endif
3282 {
3283 png_bytep sp = row;
3284 png_bytep dp = row;
3285 png_uint_32 i;
3286
3287 for (i = 0; i < row_width; i++)
3288 {
3289 png_byte red = *(sp++);
3290 png_byte green = *(sp++);
3291 png_byte blue = *(sp++);
3292
3293 if (red != green || red != blue)
3294 {
3295 rgb_error |= 1;
3296 /*NOTE: this is the historical approach which simply
3297 * truncates the results.
3298 */
3299 *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
3300 }
3301
3302 else
3303 *(dp++) = red;
3304
3305 if (have_alpha)
3306 *(dp++) = *(sp++);
3307 }
3308 }
3309 }
3310
3311 else /* RGB bit_depth == 16 */
3312 {
3313#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
3314 if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL)
3315 {
3316 png_bytep sp = row;
3317 png_bytep dp = row;
3318 png_uint_32 i;
3319
3320 for (i = 0; i < row_width; i++)
3321 {
3322 png_uint_16 red, green, blue, w;
3323
3324 red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3325 green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3326 blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3327
3328 if (red == green && red == blue)
3329 {
3330 if (png_ptr->gamma_16_table != NULL)
3331 w = png_ptr->gamma_16_table[(red&0xff)
3332 >> png_ptr->gamma_shift][red>>8];
3333
3334 else
3335 w = red;
3336 }
3337
3338 else
3339 {
3340 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff)
3341 >> png_ptr->gamma_shift][red>>8];
3342 png_uint_16 green_1 =
3343 png_ptr->gamma_16_to_1[(green&0xff) >>
3344 png_ptr->gamma_shift][green>>8];
3345 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff)
3346 >> png_ptr->gamma_shift][blue>>8];
3347 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
3348 + bc*blue_1 + 16384)>>15);
3349 w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
3350 png_ptr->gamma_shift][gray16 >> 8];
3351 rgb_error |= 1;
3352 }
3353
3354 *(dp++) = (png_byte)((w>>8) & 0xff);
3355 *(dp++) = (png_byte)(w & 0xff);
3356
3357 if (have_alpha)
3358 {
3359 *(dp++) = *(sp++);
3360 *(dp++) = *(sp++);
3361 }
3362 }
3363 }
3364 else
3365#endif
3366 {
3367 png_bytep sp = row;
3368 png_bytep dp = row;
3369 png_uint_32 i;
3370
3371 for (i = 0; i < row_width; i++)
3372 {
3373 png_uint_16 red, green, blue, gray16;
3374
3375 red = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3376 green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3377 blue = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
3378
3379 if (red != green || red != blue)
3380 rgb_error |= 1;
3381
3382 /* From 1.5.5 in the 16 bit case do the accurate conversion even
3383 * in the 'fast' case - this is because this is where the code
3384 * ends up when handling linear 16 bit data.
3385 */
3386 gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>
3387 15);
3388 *(dp++) = (png_byte)((gray16>>8) & 0xff);
3389 *(dp++) = (png_byte)(gray16 & 0xff);
3390
3391 if (have_alpha)
3392 {
3393 *(dp++) = *(sp++);
3394 *(dp++) = *(sp++);
3395 }
3396 }
3397 }
3398 }
3399
3400 row_info->channels = (png_byte)(row_info->channels - 2);
3401 row_info->color_type = (png_byte)(row_info->color_type &
3402 ~PNG_COLOR_MASK_COLOR);
3403 row_info->pixel_depth = (png_byte)(row_info->channels *
3404 row_info->bit_depth);
3405 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3406 }
3407 return rgb_error;
3408}
3409#endif
3410#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
3411
3412#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
3413/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
3414 * large of png_color. This lets grayscale images be treated as
3415 * paletted. Most useful for gamma correction and simplification
3416 * of code. This API is not used internally.
3417 */
3418void PNGAPI
3419png_build_grayscale_palette(int bit_depth, png_colorp palette)
3420{
3421 int num_palette;
3422 int color_inc;
3423 int i;
3424 int v;
3425
3426 png_debug(1, "in png_do_build_grayscale_palette");
3427
3428 if (palette == NULL)
3429 return;
3430
3431 switch (bit_depth)
3432 {
3433 case 1:
3434 num_palette = 2;
3435 color_inc = 0xff;
3436 break;
3437
3438 case 2:
3439 num_palette = 4;
3440 color_inc = 0x55;
3441 break;
3442
3443 case 4:
3444 num_palette = 16;
3445 color_inc = 0x11;
3446 break;
3447
3448 case 8:
3449 num_palette = 256;
3450 color_inc = 1;
3451 break;
3452
3453 default:
3454 num_palette = 0;
3455 color_inc = 0;
3456 break;
3457 }
3458
3459 for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
3460 {
3461 palette[i].red = (png_byte)v;
3462 palette[i].green = (png_byte)v;
3463 palette[i].blue = (png_byte)v;
3464 }
3465}
3466#endif
3467
3468
3469#ifdef PNG_READ_TRANSFORMS_SUPPORTED
3470#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
3471 (defined PNG_READ_ALPHA_MODE_SUPPORTED)
3472/* Replace any alpha or transparency with the supplied background color.
3473 * "background" is already in the screen gamma, while "background_1" is
3474 * at a gamma of 1.0. Paletted files have already been taken care of.
3475 */
3476void /* PRIVATE */
3477png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr)
3478{
3479#ifdef PNG_READ_GAMMA_SUPPORTED
3480 png_const_bytep gamma_table = png_ptr->gamma_table;
3481 png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;
3482 png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;
3483 png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;
3484 png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1;
3485 png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1;
3486 int gamma_shift = png_ptr->gamma_shift;
3487#endif
3488
3489 png_bytep sp;
3490 png_uint_32 i;
3491 png_uint_32 row_width = row_info->width;
3492 int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;
3493 int shift;
3494
3495 png_debug(1, "in png_do_compose");
3496
3497 {
3498 switch (row_info->color_type)
3499 {
3500 case PNG_COLOR_TYPE_GRAY:
3501 {
3502 switch (row_info->bit_depth)
3503 {
3504 case 1:
3505 {
3506 sp = row;
3507 shift = 7;
3508 for (i = 0; i < row_width; i++)
3509 {
3510 if ((png_uint_16)((*sp >> shift) & 0x01)
3511 == png_ptr->trans_color.gray)
3512 {
3513 *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
3514 *sp |= (png_byte)(png_ptr->background.gray << shift);
3515 }
3516
3517 if (!shift)
3518 {
3519 shift = 7;
3520 sp++;
3521 }
3522
3523 else
3524 shift--;
3525 }
3526 break;
3527 }
3528
3529 case 2:
3530 {
3531#ifdef PNG_READ_GAMMA_SUPPORTED
3532 if (gamma_table != NULL)
3533 {
3534 sp = row;
3535 shift = 6;
3536 for (i = 0; i < row_width; i++)
3537 {
3538 if ((png_uint_16)((*sp >> shift) & 0x03)
3539 == png_ptr->trans_color.gray)
3540 {
3541 *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
3542 *sp |= (png_byte)(png_ptr->background.gray << shift);
3543 }
3544
3545 else
3546 {
3547 png_byte p = (png_byte)((*sp >> shift) & 0x03);
3548 png_byte g = (png_byte)((gamma_table [p | (p << 2) |
3549 (p << 4) | (p << 6)] >> 6) & 0x03);
3550 *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
3551 *sp |= (png_byte)(g << shift);
3552 }
3553
3554 if (!shift)
3555 {
3556 shift = 6;
3557 sp++;
3558 }
3559
3560 else
3561 shift -= 2;
3562 }
3563 }
3564
3565 else
3566#endif
3567 {
3568 sp = row;
3569 shift = 6;
3570 for (i = 0; i < row_width; i++)
3571 {
3572 if ((png_uint_16)((*sp >> shift) & 0x03)
3573 == png_ptr->trans_color.gray)
3574 {
3575 *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
3576 *sp |= (png_byte)(png_ptr->background.gray << shift);
3577 }
3578
3579 if (!shift)
3580 {
3581 shift = 6;
3582 sp++;
3583 }
3584
3585 else
3586 shift -= 2;
3587 }
3588 }
3589 break;
3590 }
3591
3592 case 4:
3593 {
3594#ifdef PNG_READ_GAMMA_SUPPORTED
3595 if (gamma_table != NULL)
3596 {
3597 sp = row;
3598 shift = 4;
3599 for (i = 0; i < row_width; i++)
3600 {
3601 if ((png_uint_16)((*sp >> shift) & 0x0f)
3602 == png_ptr->trans_color.gray)
3603 {
3604 *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
3605 *sp |= (png_byte)(png_ptr->background.gray << shift);
3606 }
3607
3608 else
3609 {
3610 png_byte p = (png_byte)((*sp >> shift) & 0x0f);
3611 png_byte g = (png_byte)((gamma_table[p |
3612 (p << 4)] >> 4) & 0x0f);
3613 *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
3614 *sp |= (png_byte)(g << shift);
3615 }
3616
3617 if (!shift)
3618 {
3619 shift = 4;
3620 sp++;
3621 }
3622
3623 else
3624 shift -= 4;
3625 }
3626 }
3627
3628 else
3629#endif
3630 {
3631 sp = row;
3632 shift = 4;
3633 for (i = 0; i < row_width; i++)
3634 {
3635 if ((png_uint_16)((*sp >> shift) & 0x0f)
3636 == png_ptr->trans_color.gray)
3637 {
3638 *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
3639 *sp |= (png_byte)(png_ptr->background.gray << shift);
3640 }
3641
3642 if (!shift)
3643 {
3644 shift = 4;
3645 sp++;
3646 }
3647
3648 else
3649 shift -= 4;
3650 }
3651 }
3652 break;
3653 }
3654
3655 case 8:
3656 {
3657#ifdef PNG_READ_GAMMA_SUPPORTED
3658 if (gamma_table != NULL)
3659 {
3660 sp = row;
3661 for (i = 0; i < row_width; i++, sp++)
3662 {
3663 if (*sp == png_ptr->trans_color.gray)
3664 *sp = (png_byte)png_ptr->background.gray;
3665
3666 else
3667 *sp = gamma_table[*sp];
3668 }
3669 }
3670 else
3671#endif
3672 {
3673 sp = row;
3674 for (i = 0; i < row_width; i++, sp++)
3675 {
3676 if (*sp == png_ptr->trans_color.gray)
3677 *sp = (png_byte)png_ptr->background.gray;
3678 }
3679 }
3680 break;
3681 }
3682
3683 case 16:
3684 {
3685#ifdef PNG_READ_GAMMA_SUPPORTED
3686 if (gamma_16 != NULL)
3687 {
3688 sp = row;
3689 for (i = 0; i < row_width; i++, sp += 2)
3690 {
3691 png_uint_16 v;
3692
3693 v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
3694
3695 if (v == png_ptr->trans_color.gray)
3696 {
3697 /* Background is already in screen gamma */
3698 *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
3699 *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
3700 }
3701
3702 else
3703 {
3704 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3705 *sp = (png_byte)((v >> 8) & 0xff);
3706 *(sp + 1) = (png_byte)(v & 0xff);
3707 }
3708 }
3709 }
3710 else
3711#endif
3712 {
3713 sp = row;
3714 for (i = 0; i < row_width; i++, sp += 2)
3715 {
3716 png_uint_16 v;
3717
3718 v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
3719
3720 if (v == png_ptr->trans_color.gray)
3721 {
3722 *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
3723 *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
3724 }
3725 }
3726 }
3727 break;
3728 }
3729
3730 default:
3731 break;
3732 }
3733 break;
3734 }
3735
3736 case PNG_COLOR_TYPE_RGB:
3737 {
3738 if (row_info->bit_depth == 8)
3739 {
3740#ifdef PNG_READ_GAMMA_SUPPORTED
3741 if (gamma_table != NULL)
3742 {
3743 sp = row;
3744 for (i = 0; i < row_width; i++, sp += 3)
3745 {
3746 if (*sp == png_ptr->trans_color.red &&
3747 *(sp + 1) == png_ptr->trans_color.green &&
3748 *(sp + 2) == png_ptr->trans_color.blue)
3749 {
3750 *sp = (png_byte)png_ptr->background.red;
3751 *(sp + 1) = (png_byte)png_ptr->background.green;
3752 *(sp + 2) = (png_byte)png_ptr->background.blue;
3753 }
3754
3755 else
3756 {
3757 *sp = gamma_table[*sp];
3758 *(sp + 1) = gamma_table[*(sp + 1)];
3759 *(sp + 2) = gamma_table[*(sp + 2)];
3760 }
3761 }
3762 }
3763 else
3764#endif
3765 {
3766 sp = row;
3767 for (i = 0; i < row_width; i++, sp += 3)
3768 {
3769 if (*sp == png_ptr->trans_color.red &&
3770 *(sp + 1) == png_ptr->trans_color.green &&
3771 *(sp + 2) == png_ptr->trans_color.blue)
3772 {
3773 *sp = (png_byte)png_ptr->background.red;
3774 *(sp + 1) = (png_byte)png_ptr->background.green;
3775 *(sp + 2) = (png_byte)png_ptr->background.blue;
3776 }
3777 }
3778 }
3779 }
3780 else /* if (row_info->bit_depth == 16) */
3781 {
3782#ifdef PNG_READ_GAMMA_SUPPORTED
3783 if (gamma_16 != NULL)
3784 {
3785 sp = row;
3786 for (i = 0; i < row_width; i++, sp += 6)
3787 {
3788 png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
3789
3790 png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
3791 + *(sp + 3));
3792
3793 png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
3794 + *(sp + 5));
3795
3796 if (r == png_ptr->trans_color.red &&
3797 g == png_ptr->trans_color.green &&
3798 b == png_ptr->trans_color.blue)
3799 {
3800 /* Background is already in screen gamma */
3801 *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
3802 *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
3803 *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
3804 *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
3805 *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
3806 *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
3807 }
3808
3809 else
3810 {
3811 png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3812 *sp = (png_byte)((v >> 8) & 0xff);
3813 *(sp + 1) = (png_byte)(v & 0xff);
3814
3815 v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
3816 *(sp + 2) = (png_byte)((v >> 8) & 0xff);
3817 *(sp + 3) = (png_byte)(v & 0xff);
3818
3819 v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
3820 *(sp + 4) = (png_byte)((v >> 8) & 0xff);
3821 *(sp + 5) = (png_byte)(v & 0xff);
3822 }
3823 }
3824 }
3825
3826 else
3827#endif
3828 {
3829 sp = row;
3830 for (i = 0; i < row_width; i++, sp += 6)
3831 {
3832 png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
3833
3834 png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
3835 + *(sp + 3));
3836
3837 png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
3838 + *(sp + 5));
3839
3840 if (r == png_ptr->trans_color.red &&
3841 g == png_ptr->trans_color.green &&
3842 b == png_ptr->trans_color.blue)
3843 {
3844 *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
3845 *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
3846 *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
3847 *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
3848 *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
3849 *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
3850 }
3851 }
3852 }
3853 }
3854 break;
3855 }
3856
3857 case PNG_COLOR_TYPE_GRAY_ALPHA:
3858 {
3859 if (row_info->bit_depth == 8)
3860 {
3861#ifdef PNG_READ_GAMMA_SUPPORTED
3862 if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
3863 gamma_table != NULL)
3864 {
3865 sp = row;
3866 for (i = 0; i < row_width; i++, sp += 2)
3867 {
3868 png_uint_16 a = *(sp + 1);
3869
3870 if (a == 0xff)
3871 *sp = gamma_table[*sp];
3872
3873 else if (a == 0)
3874 {
3875 /* Background is already in screen gamma */
3876 *sp = (png_byte)png_ptr->background.gray;
3877 }
3878
3879 else
3880 {
3881 png_byte v, w;
3882
3883 v = gamma_to_1[*sp];
3884 png_composite(w, v, a, png_ptr->background_1.gray);
3885 if (!optimize)
3886 w = gamma_from_1[w];
3887 *sp = w;
3888 }
3889 }
3890 }
3891 else
3892#endif
3893 {
3894 sp = row;
3895 for (i = 0; i < row_width; i++, sp += 2)
3896 {
3897 png_byte a = *(sp + 1);
3898
3899 if (a == 0)
3900 *sp = (png_byte)png_ptr->background.gray;
3901
3902 else if (a < 0xff)
3903 png_composite(*sp, *sp, a, png_ptr->background_1.gray);
3904 }
3905 }
3906 }
3907 else /* if (png_ptr->bit_depth == 16) */
3908 {
3909#ifdef PNG_READ_GAMMA_SUPPORTED
3910 if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
3911 gamma_16_to_1 != NULL)
3912 {
3913 sp = row;
3914 for (i = 0; i < row_width; i++, sp += 4)
3915 {
3916 png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
3917 + *(sp + 3));
3918
3919 if (a == (png_uint_16)0xffff)
3920 {
3921 png_uint_16 v;
3922
3923 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3924 *sp = (png_byte)((v >> 8) & 0xff);
3925 *(sp + 1) = (png_byte)(v & 0xff);
3926 }
3927
3928 else if (a == 0)
3929 {
3930 /* Background is already in screen gamma */
3931 *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
3932 *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
3933 }
3934
3935 else
3936 {
3937 png_uint_16 g, v, w;
3938
3939 g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
3940 png_composite_16(v, g, a, png_ptr->background_1.gray);
3941 if (optimize)
3942 w = v;
3943 else
3944 w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
3945 *sp = (png_byte)((w >> 8) & 0xff);
3946 *(sp + 1) = (png_byte)(w & 0xff);
3947 }
3948 }
3949 }
3950 else
3951#endif
3952 {
3953 sp = row;
3954 for (i = 0; i < row_width; i++, sp += 4)
3955 {
3956 png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
3957 + *(sp + 3));
3958
3959 if (a == 0)
3960 {
3961 *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
3962 *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
3963 }
3964
3965 else if (a < 0xffff)
3966 {
3967 png_uint_16 g, v;
3968
3969 g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
3970 png_composite_16(v, g, a, png_ptr->background_1.gray);
3971 *sp = (png_byte)((v >> 8) & 0xff);
3972 *(sp + 1) = (png_byte)(v & 0xff);
3973 }
3974 }
3975 }
3976 }
3977 break;
3978 }
3979
3980 case PNG_COLOR_TYPE_RGB_ALPHA:
3981 {
3982 if (row_info->bit_depth == 8)
3983 {
3984#ifdef PNG_READ_GAMMA_SUPPORTED
3985 if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
3986 gamma_table != NULL)
3987 {
3988 sp = row;
3989 for (i = 0; i < row_width; i++, sp += 4)
3990 {
3991 png_byte a = *(sp + 3);
3992
3993 if (a == 0xff)
3994 {
3995 *sp = gamma_table[*sp];
3996 *(sp + 1) = gamma_table[*(sp + 1)];
3997 *(sp + 2) = gamma_table[*(sp + 2)];
3998 }
3999
4000 else if (a == 0)
4001 {
4002 /* Background is already in screen gamma */
4003 *sp = (png_byte)png_ptr->background.red;
4004 *(sp + 1) = (png_byte)png_ptr->background.green;
4005 *(sp + 2) = (png_byte)png_ptr->background.blue;
4006 }
4007
4008 else
4009 {
4010 png_byte v, w;
4011
4012 v = gamma_to_1[*sp];
4013 png_composite(w, v, a, png_ptr->background_1.red);
4014 if (!optimize) w = gamma_from_1[w];
4015 *sp = w;
4016
4017 v = gamma_to_1[*(sp + 1)];
4018 png_composite(w, v, a, png_ptr->background_1.green);
4019 if (!optimize) w = gamma_from_1[w];
4020 *(sp + 1) = w;
4021
4022 v = gamma_to_1[*(sp + 2)];
4023 png_composite(w, v, a, png_ptr->background_1.blue);
4024 if (!optimize) w = gamma_from_1[w];
4025 *(sp + 2) = w;
4026 }
4027 }
4028 }
4029 else
4030#endif
4031 {
4032 sp = row;
4033 for (i = 0; i < row_width; i++, sp += 4)
4034 {
4035 png_byte a = *(sp + 3);
4036
4037 if (a == 0)
4038 {
4039 *sp = (png_byte)png_ptr->background.red;
4040 *(sp + 1) = (png_byte)png_ptr->background.green;
4041 *(sp + 2) = (png_byte)png_ptr->background.blue;
4042 }
4043
4044 else if (a < 0xff)
4045 {
4046 png_composite(*sp, *sp, a, png_ptr->background.red);
4047
4048 png_composite(*(sp + 1), *(sp + 1), a,
4049 png_ptr->background.green);
4050
4051 png_composite(*(sp + 2), *(sp + 2), a,
4052 png_ptr->background.blue);
4053 }
4054 }
4055 }
4056 }
4057 else /* if (row_info->bit_depth == 16) */
4058 {
4059#ifdef PNG_READ_GAMMA_SUPPORTED
4060 if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
4061 gamma_16_to_1 != NULL)
4062 {
4063 sp = row;
4064 for (i = 0; i < row_width; i++, sp += 8)
4065 {
4066 png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
4067 << 8) + (png_uint_16)(*(sp + 7)));
4068
4069 if (a == (png_uint_16)0xffff)
4070 {
4071 png_uint_16 v;
4072
4073 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
4074 *sp = (png_byte)((v >> 8) & 0xff);
4075 *(sp + 1) = (png_byte)(v & 0xff);
4076
4077 v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
4078 *(sp + 2) = (png_byte)((v >> 8) & 0xff);
4079 *(sp + 3) = (png_byte)(v & 0xff);
4080
4081 v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
4082 *(sp + 4) = (png_byte)((v >> 8) & 0xff);
4083 *(sp + 5) = (png_byte)(v & 0xff);
4084 }
4085
4086 else if (a == 0)
4087 {
4088 /* Background is already in screen gamma */
4089 *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
4090 *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
4091 *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
4092 *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
4093 *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
4094 *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
4095 }
4096
4097 else
4098 {
4099 png_uint_16 v, w;
4100
4101 v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
4102 png_composite_16(w, v, a, png_ptr->background_1.red);
4103 if (!optimize)
4104 w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
4105 *sp = (png_byte)((w >> 8) & 0xff);
4106 *(sp + 1) = (png_byte)(w & 0xff);
4107
4108 v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
4109 png_composite_16(w, v, a, png_ptr->background_1.green);
4110 if (!optimize)
4111 w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
4112
4113 *(sp + 2) = (png_byte)((w >> 8) & 0xff);
4114 *(sp + 3) = (png_byte)(w & 0xff);
4115
4116 v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
4117 png_composite_16(w, v, a, png_ptr->background_1.blue);
4118 if (!optimize)
4119 w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
4120
4121 *(sp + 4) = (png_byte)((w >> 8) & 0xff);
4122 *(sp + 5) = (png_byte)(w & 0xff);
4123 }
4124 }
4125 }
4126
4127 else
4128#endif
4129 {
4130 sp = row;
4131 for (i = 0; i < row_width; i++, sp += 8)
4132 {
4133 png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
4134 << 8) + (png_uint_16)(*(sp + 7)));
4135
4136 if (a == 0)
4137 {
4138 *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
4139 *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
4140 *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
4141 *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
4142 *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
4143 *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
4144 }
4145
4146 else if (a < 0xffff)
4147 {
4148 png_uint_16 v;
4149
4150 png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
4151 png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
4152 + *(sp + 3));
4153 png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
4154 + *(sp + 5));
4155
4156 png_composite_16(v, r, a, png_ptr->background.red);
4157 *sp = (png_byte)((v >> 8) & 0xff);
4158 *(sp + 1) = (png_byte)(v & 0xff);
4159
4160 png_composite_16(v, g, a, png_ptr->background.green);
4161 *(sp + 2) = (png_byte)((v >> 8) & 0xff);
4162 *(sp + 3) = (png_byte)(v & 0xff);
4163
4164 png_composite_16(v, b, a, png_ptr->background.blue);
4165 *(sp + 4) = (png_byte)((v >> 8) & 0xff);
4166 *(sp + 5) = (png_byte)(v & 0xff);
4167 }
4168 }
4169 }
4170 }
4171 break;
4172 }
4173
4174 default:
4175 break;
4176 }
4177 }
4178}
4179#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_READ_ALPHA_MODE_SUPPORTED */
4180
4181#ifdef PNG_READ_GAMMA_SUPPORTED
4182/* Gamma correct the image, avoiding the alpha channel. Make sure
4183 * you do this after you deal with the transparency issue on grayscale
4184 * or RGB images. If your bit depth is 8, use gamma_table, if it
4185 * is 16, use gamma_16_table and gamma_shift. Build these with
4186 * build_gamma_table().
4187 */
4188void /* PRIVATE */
4189png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr)
4190{
4191 png_const_bytep gamma_table = png_ptr->gamma_table;
4192 png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;
4193 int gamma_shift = png_ptr->gamma_shift;
4194
4195 png_bytep sp;
4196 png_uint_32 i;
4197 png_uint_32 row_width=row_info->width;
4198
4199 png_debug(1, "in png_do_gamma");
4200
4201 if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||
4202 (row_info->bit_depth == 16 && gamma_16_table != NULL)))
4203 {
4204 switch (row_info->color_type)
4205 {
4206 case PNG_COLOR_TYPE_RGB:
4207 {
4208 if (row_info->bit_depth == 8)
4209 {
4210 sp = row;
4211 for (i = 0; i < row_width; i++)
4212 {
4213 *sp = gamma_table[*sp];
4214 sp++;
4215 *sp = gamma_table[*sp];
4216 sp++;
4217 *sp = gamma_table[*sp];
4218 sp++;
4219 }
4220 }
4221
4222 else /* if (row_info->bit_depth == 16) */
4223 {
4224 sp = row;
4225 for (i = 0; i < row_width; i++)
4226 {
4227 png_uint_16 v;
4228
4229 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4230 *sp = (png_byte)((v >> 8) & 0xff);
4231 *(sp + 1) = (png_byte)(v & 0xff);
4232 sp += 2;
4233
4234 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4235 *sp = (png_byte)((v >> 8) & 0xff);
4236 *(sp + 1) = (png_byte)(v & 0xff);
4237 sp += 2;
4238
4239 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4240 *sp = (png_byte)((v >> 8) & 0xff);
4241 *(sp + 1) = (png_byte)(v & 0xff);
4242 sp += 2;
4243 }
4244 }
4245 break;
4246 }
4247
4248 case PNG_COLOR_TYPE_RGB_ALPHA:
4249 {
4250 if (row_info->bit_depth == 8)
4251 {
4252 sp = row;
4253 for (i = 0; i < row_width; i++)
4254 {
4255 *sp = gamma_table[*sp];
4256 sp++;
4257
4258 *sp = gamma_table[*sp];
4259 sp++;
4260
4261 *sp = gamma_table[*sp];
4262 sp++;
4263
4264 sp++;
4265 }
4266 }
4267
4268 else /* if (row_info->bit_depth == 16) */
4269 {
4270 sp = row;
4271 for (i = 0; i < row_width; i++)
4272 {
4273 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4274 *sp = (png_byte)((v >> 8) & 0xff);
4275 *(sp + 1) = (png_byte)(v & 0xff);
4276 sp += 2;
4277
4278 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4279 *sp = (png_byte)((v >> 8) & 0xff);
4280 *(sp + 1) = (png_byte)(v & 0xff);
4281 sp += 2;
4282
4283 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4284 *sp = (png_byte)((v >> 8) & 0xff);
4285 *(sp + 1) = (png_byte)(v & 0xff);
4286 sp += 4;
4287 }
4288 }
4289 break;
4290 }
4291
4292 case PNG_COLOR_TYPE_GRAY_ALPHA:
4293 {
4294 if (row_info->bit_depth == 8)
4295 {
4296 sp = row;
4297 for (i = 0; i < row_width; i++)
4298 {
4299 *sp = gamma_table[*sp];
4300 sp += 2;
4301 }
4302 }
4303
4304 else /* if (row_info->bit_depth == 16) */
4305 {
4306 sp = row;
4307 for (i = 0; i < row_width; i++)
4308 {
4309 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4310 *sp = (png_byte)((v >> 8) & 0xff);
4311 *(sp + 1) = (png_byte)(v & 0xff);
4312 sp += 4;
4313 }
4314 }
4315 break;
4316 }
4317
4318 case PNG_COLOR_TYPE_GRAY:
4319 {
4320 if (row_info->bit_depth == 2)
4321 {
4322 sp = row;
4323 for (i = 0; i < row_width; i += 4)
4324 {
4325 int a = *sp & 0xc0;
4326 int b = *sp & 0x30;
4327 int c = *sp & 0x0c;
4328 int d = *sp & 0x03;
4329
4330 *sp = (png_byte)(
4331 ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
4332 ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
4333 ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
4334 ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
4335 sp++;
4336 }
4337 }
4338
4339 if (row_info->bit_depth == 4)
4340 {
4341 sp = row;
4342 for (i = 0; i < row_width; i += 2)
4343 {
4344 int msb = *sp & 0xf0;
4345 int lsb = *sp & 0x0f;
4346
4347 *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
4348 | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
4349 sp++;
4350 }
4351 }
4352
4353 else if (row_info->bit_depth == 8)
4354 {
4355 sp = row;
4356 for (i = 0; i < row_width; i++)
4357 {
4358 *sp = gamma_table[*sp];
4359 sp++;
4360 }
4361 }
4362
4363 else if (row_info->bit_depth == 16)
4364 {
4365 sp = row;
4366 for (i = 0; i < row_width; i++)
4367 {
4368 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
4369 *sp = (png_byte)((v >> 8) & 0xff);
4370 *(sp + 1) = (png_byte)(v & 0xff);
4371 sp += 2;
4372 }
4373 }
4374 break;
4375 }
4376
4377 default:
4378 break;
4379 }
4380 }
4381}
4382#endif
4383
4384#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
4385/* Encode the alpha channel to the output gamma (the input channel is always
4386 * linear.) Called only with color types that have an alpha channel. Needs the
4387 * from_1 tables.
4388 */
4389void /* PRIVATE */
4390png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr)
4391{
4392 png_uint_32 row_width = row_info->width;
4393
4394 png_debug(1, "in png_do_encode_alpha");
4395
4396 if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
4397 {
4398 if (row_info->bit_depth == 8)
4399 {
4400 PNG_CONST png_bytep table = png_ptr->gamma_from_1;
4401
4402 if (table != NULL)
4403 {
4404 PNG_CONST int step =
4405 (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
4406
4407 /* The alpha channel is the last component: */
4408 row += step - 1;
4409
4410 for (; row_width > 0; --row_width, row += step)
4411 *row = table[*row];
4412
4413 return;
4414 }
4415 }
4416
4417 else if (row_info->bit_depth == 16)
4418 {
4419 PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
4420 PNG_CONST int gamma_shift = png_ptr->gamma_shift;
4421
4422 if (table != NULL)
4423 {
4424 PNG_CONST int step =
4425 (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
4426
4427 /* The alpha channel is the last component: */
4428 row += step - 2;
4429
4430 for (; row_width > 0; --row_width, row += step)
4431 {
4432 png_uint_16 v;
4433
4434 v = table[*(row + 1) >> gamma_shift][*row];
4435 *row = (png_byte)((v >> 8) & 0xff);
4436 *(row + 1) = (png_byte)(v & 0xff);
4437 }
4438
4439 return;
4440 }
4441 }
4442 }
4443
4444 /* Only get to here if called with a weird row_info; no harm has been done,
4445 * so just issue a warning.
4446 */
4447 png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
4448}
4449#endif
4450
4451#ifdef PNG_READ_EXPAND_SUPPORTED
4452/* Expands a palette row to an RGB or RGBA row depending
4453 * upon whether you supply trans and num_trans.
4454 */
4455void /* PRIVATE */
4456png_do_expand_palette(png_row_infop row_info, png_bytep row,
4457 png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
4458{
4459 int shift, value;
4460 png_bytep sp, dp;
4461 png_uint_32 i;
4462 png_uint_32 row_width=row_info->width;
4463
4464 png_debug(1, "in png_do_expand_palette");
4465
4466 if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
4467 {
4468 if (row_info->bit_depth < 8)
4469 {
4470 switch (row_info->bit_depth)
4471 {
4472 case 1:
4473 {
4474 sp = row + (png_size_t)((row_width - 1) >> 3);
4475 dp = row + (png_size_t)row_width - 1;
4476 shift = 7 - (int)((row_width + 7) & 0x07);
4477 for (i = 0; i < row_width; i++)
4478 {
4479 if ((*sp >> shift) & 0x01)
4480 *dp = 1;
4481
4482 else
4483 *dp = 0;
4484
4485 if (shift == 7)
4486 {
4487 shift = 0;
4488 sp--;
4489 }
4490
4491 else
4492 shift++;
4493
4494 dp--;
4495 }
4496 break;
4497 }
4498
4499 case 2:
4500 {
4501 sp = row + (png_size_t)((row_width - 1) >> 2);
4502 dp = row + (png_size_t)row_width - 1;
4503 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
4504 for (i = 0; i < row_width; i++)
4505 {
4506 value = (*sp >> shift) & 0x03;
4507 *dp = (png_byte)value;
4508 if (shift == 6)
4509 {
4510 shift = 0;
4511 sp--;
4512 }
4513
4514 else
4515 shift += 2;
4516
4517 dp--;
4518 }
4519 break;
4520 }
4521
4522 case 4:
4523 {
4524 sp = row + (png_size_t)((row_width - 1) >> 1);
4525 dp = row + (png_size_t)row_width - 1;
4526 shift = (int)((row_width & 0x01) << 2);
4527 for (i = 0; i < row_width; i++)
4528 {
4529 value = (*sp >> shift) & 0x0f;
4530 *dp = (png_byte)value;
4531 if (shift == 4)
4532 {
4533 shift = 0;
4534 sp--;
4535 }
4536
4537 else
4538 shift += 4;
4539
4540 dp--;
4541 }
4542 break;
4543 }
4544
4545 default:
4546 break;
4547 }
4548 row_info->bit_depth = 8;
4549 row_info->pixel_depth = 8;
4550 row_info->rowbytes = row_width;
4551 }
4552
4553 if (row_info->bit_depth == 8)
4554 {
4555 {
4556 if (num_trans > 0)
4557 {
4558 sp = row + (png_size_t)row_width - 1;
4559 dp = row + (png_size_t)(row_width << 2) - 1;
4560
4561 for (i = 0; i < row_width; i++)
4562 {
4563 if ((int)(*sp) >= num_trans)
4564 *dp-- = 0xff;
4565
4566 else
4567 *dp-- = trans_alpha[*sp];
4568
4569 *dp-- = palette[*sp].blue;
4570 *dp-- = palette[*sp].green;
4571 *dp-- = palette[*sp].red;
4572 sp--;
4573 }
4574 row_info->bit_depth = 8;
4575 row_info->pixel_depth = 32;
4576 row_info->rowbytes = row_width * 4;
4577 row_info->color_type = 6;
4578 row_info->channels = 4;
4579 }
4580
4581 else
4582 {
4583 sp = row + (png_size_t)row_width - 1;
4584 dp = row + (png_size_t)(row_width * 3) - 1;
4585
4586 for (i = 0; i < row_width; i++)
4587 {
4588 *dp-- = palette[*sp].blue;
4589 *dp-- = palette[*sp].green;
4590 *dp-- = palette[*sp].red;
4591 sp--;
4592 }
4593
4594 row_info->bit_depth = 8;
4595 row_info->pixel_depth = 24;
4596 row_info->rowbytes = row_width * 3;
4597 row_info->color_type = 2;
4598 row_info->channels = 3;
4599 }
4600 }
4601 }
4602 }
4603}
4604
4605/* If the bit depth < 8, it is expanded to 8. Also, if the already
4606 * expanded transparency value is supplied, an alpha channel is built.
4607 */
4608void /* PRIVATE */
4609png_do_expand(png_row_infop row_info, png_bytep row,
4610 png_const_color_16p trans_color)
4611{
4612 int shift, value;
4613 png_bytep sp, dp;
4614 png_uint_32 i;
4615 png_uint_32 row_width=row_info->width;
4616
4617 png_debug(1, "in png_do_expand");
4618
4619 {
4620 if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
4621 {
4622 png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0);
4623
4624 if (row_info->bit_depth < 8)
4625 {
4626 switch (row_info->bit_depth)
4627 {
4628 case 1:
4629 {
4630 gray = (png_uint_16)((gray & 0x01) * 0xff);
4631 sp = row + (png_size_t)((row_width - 1) >> 3);
4632 dp = row + (png_size_t)row_width - 1;
4633 shift = 7 - (int)((row_width + 7) & 0x07);
4634 for (i = 0; i < row_width; i++)
4635 {
4636 if ((*sp >> shift) & 0x01)
4637 *dp = 0xff;
4638
4639 else
4640 *dp = 0;
4641
4642 if (shift == 7)
4643 {
4644 shift = 0;
4645 sp--;
4646 }
4647
4648 else
4649 shift++;
4650
4651 dp--;
4652 }
4653 break;
4654 }
4655
4656 case 2:
4657 {
4658 gray = (png_uint_16)((gray & 0x03) * 0x55);
4659 sp = row + (png_size_t)((row_width - 1) >> 2);
4660 dp = row + (png_size_t)row_width - 1;
4661 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
4662 for (i = 0; i < row_width; i++)
4663 {
4664 value = (*sp >> shift) & 0x03;
4665 *dp = (png_byte)(value | (value << 2) | (value << 4) |
4666 (value << 6));
4667 if (shift == 6)
4668 {
4669 shift = 0;
4670 sp--;
4671 }
4672
4673 else
4674 shift += 2;
4675
4676 dp--;
4677 }
4678 break;
4679 }
4680
4681 case 4:
4682 {
4683 gray = (png_uint_16)((gray & 0x0f) * 0x11);
4684 sp = row + (png_size_t)((row_width - 1) >> 1);
4685 dp = row + (png_size_t)row_width - 1;
4686 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
4687 for (i = 0; i < row_width; i++)
4688 {
4689 value = (*sp >> shift) & 0x0f;
4690 *dp = (png_byte)(value | (value << 4));
4691 if (shift == 4)
4692 {
4693 shift = 0;
4694 sp--;
4695 }
4696
4697 else
4698 shift = 4;
4699
4700 dp--;
4701 }
4702 break;
4703 }
4704
4705 default:
4706 break;
4707 }
4708
4709 row_info->bit_depth = 8;
4710 row_info->pixel_depth = 8;
4711 row_info->rowbytes = row_width;
4712 }
4713
4714 if (trans_color != NULL)
4715 {
4716 if (row_info->bit_depth == 8)
4717 {
4718 gray = gray & 0xff;
4719 sp = row + (png_size_t)row_width - 1;
4720 dp = row + (png_size_t)(row_width << 1) - 1;
4721
4722 for (i = 0; i < row_width; i++)
4723 {
4724 if (*sp == gray)
4725 *dp-- = 0;
4726
4727 else
4728 *dp-- = 0xff;
4729
4730 *dp-- = *sp--;
4731 }
4732 }
4733
4734 else if (row_info->bit_depth == 16)
4735 {
4736 png_byte gray_high = (png_byte)((gray >> 8) & 0xff);
4737 png_byte gray_low = (png_byte)(gray & 0xff);
4738 sp = row + row_info->rowbytes - 1;
4739 dp = row + (row_info->rowbytes << 1) - 1;
4740 for (i = 0; i < row_width; i++)
4741 {
4742 if (*(sp - 1) == gray_high && *(sp) == gray_low)
4743 {
4744 *dp-- = 0;
4745 *dp-- = 0;
4746 }
4747
4748 else
4749 {
4750 *dp-- = 0xff;
4751 *dp-- = 0xff;
4752 }
4753
4754 *dp-- = *sp--;
4755 *dp-- = *sp--;
4756 }
4757 }
4758
4759 row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
4760 row_info->channels = 2;
4761 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
4762 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
4763 row_width);
4764 }
4765 }
4766 else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color)
4767 {
4768 if (row_info->bit_depth == 8)
4769 {
4770 png_byte red = (png_byte)(trans_color->red & 0xff);
4771 png_byte green = (png_byte)(trans_color->green & 0xff);
4772 png_byte blue = (png_byte)(trans_color->blue & 0xff);
4773 sp = row + (png_size_t)row_info->rowbytes - 1;
4774 dp = row + (png_size_t)(row_width << 2) - 1;
4775 for (i = 0; i < row_width; i++)
4776 {
4777 if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
4778 *dp-- = 0;
4779
4780 else
4781 *dp-- = 0xff;
4782
4783 *dp-- = *sp--;
4784 *dp-- = *sp--;
4785 *dp-- = *sp--;
4786 }
4787 }
4788 else if (row_info->bit_depth == 16)
4789 {
4790 png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
4791 png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
4792 png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
4793 png_byte red_low = (png_byte)(trans_color->red & 0xff);
4794 png_byte green_low = (png_byte)(trans_color->green & 0xff);
4795 png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
4796 sp = row + row_info->rowbytes - 1;
4797 dp = row + (png_size_t)(row_width << 3) - 1;
4798 for (i = 0; i < row_width; i++)
4799 {
4800 if (*(sp - 5) == red_high &&
4801 *(sp - 4) == red_low &&
4802 *(sp - 3) == green_high &&
4803 *(sp - 2) == green_low &&
4804 *(sp - 1) == blue_high &&
4805 *(sp ) == blue_low)
4806 {
4807 *dp-- = 0;
4808 *dp-- = 0;
4809 }
4810
4811 else
4812 {
4813 *dp-- = 0xff;
4814 *dp-- = 0xff;
4815 }
4816
4817 *dp-- = *sp--;
4818 *dp-- = *sp--;
4819 *dp-- = *sp--;
4820 *dp-- = *sp--;
4821 *dp-- = *sp--;
4822 *dp-- = *sp--;
4823 }
4824 }
4825 row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
4826 row_info->channels = 4;
4827 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
4828 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
4829 }
4830 }
4831}
4832#endif
4833
4834#ifdef PNG_READ_EXPAND_16_SUPPORTED
4835/* If the bit depth is 8 and the color type is not a palette type expand the
4836 * whole row to 16 bits. Has no effect otherwise.
4837 */
4838void /* PRIVATE */
4839png_do_expand_16(png_row_infop row_info, png_bytep row)
4840{
4841 if (row_info->bit_depth == 8 &&
4842 row_info->color_type != PNG_COLOR_TYPE_PALETTE)
4843 {
4844 /* The row have a sequence of bytes containing [0..255] and we need
4845 * to turn it into another row containing [0..65535], to do this we
4846 * calculate:
4847 *
4848 * (input / 255) * 65535
4849 *
4850 * Which happens to be exactly input * 257 and this can be achieved
4851 * simply by byte replication in place (copying backwards).
4852 */
4853 png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
4854 png_byte *dp = sp + row_info->rowbytes; /* destination, end + 1 */
4855 while (dp > sp)
4856 dp[-2] = dp[-1] = *--sp, dp -= 2;
4857
4858 row_info->rowbytes *= 2;
4859 row_info->bit_depth = 16;
4860 row_info->pixel_depth = (png_byte)(row_info->channels * 16);
4861 }
4862}
4863#endif
4864
4865#ifdef PNG_READ_QUANTIZE_SUPPORTED
4866void /* PRIVATE */
4867png_do_quantize(png_row_infop row_info, png_bytep row,
4868 png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
4869{
4870 png_bytep sp, dp;
4871 png_uint_32 i;
4872 png_uint_32 row_width=row_info->width;
4873
4874 png_debug(1, "in png_do_quantize");
4875
4876 if (row_info->bit_depth == 8)
4877 {
4878 if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)
4879 {
4880 int r, g, b, p;
4881 sp = row;
4882 dp = row;
4883 for (i = 0; i < row_width; i++)
4884 {
4885 r = *sp++;
4886 g = *sp++;
4887 b = *sp++;
4888
4889 /* This looks real messy, but the compiler will reduce
4890 * it down to a reasonable formula. For example, with
4891 * 5 bits per color, we get:
4892 * p = (((r >> 3) & 0x1f) << 10) |
4893 * (((g >> 3) & 0x1f) << 5) |
4894 * ((b >> 3) & 0x1f);
4895 */
4896 p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
4897 ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
4898 (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
4899 (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
4900 ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
4901 (PNG_QUANTIZE_BLUE_BITS)) |
4902 ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
4903 ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
4904
4905 *dp++ = palette_lookup[p];
4906 }
4907
4908 row_info->color_type = PNG_COLOR_TYPE_PALETTE;
4909 row_info->channels = 1;
4910 row_info->pixel_depth = row_info->bit_depth;
4911 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
4912 }
4913
4914 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
4915 palette_lookup != NULL)
4916 {
4917 int r, g, b, p;
4918 sp = row;
4919 dp = row;
4920 for (i = 0; i < row_width; i++)
4921 {
4922 r = *sp++;
4923 g = *sp++;
4924 b = *sp++;
4925 sp++;
4926
4927 p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
4928 ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
4929 (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
4930 (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
4931 ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
4932 (PNG_QUANTIZE_BLUE_BITS)) |
4933 ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
4934 ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
4935
4936 *dp++ = palette_lookup[p];
4937 }
4938
4939 row_info->color_type = PNG_COLOR_TYPE_PALETTE;
4940 row_info->channels = 1;
4941 row_info->pixel_depth = row_info->bit_depth;
4942 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
4943 }
4944
4945 else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
4946 quantize_lookup)
4947 {
4948 sp = row;
4949
4950 for (i = 0; i < row_width; i++, sp++)
4951 {
4952 *sp = quantize_lookup[*sp];
4953 }
4954 }
4955 }
4956}
4957#endif /* PNG_READ_QUANTIZE_SUPPORTED */
4958#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
4959
4960#ifdef PNG_MNG_FEATURES_SUPPORTED
4961/* Undoes intrapixel differencing */
4962void /* PRIVATE */
4963png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
4964{
4965 png_debug(1, "in png_do_read_intrapixel");
4966
4967 if (
4968 (row_info->color_type & PNG_COLOR_MASK_COLOR))
4969 {
4970 int bytes_per_pixel;
4971 png_uint_32 row_width = row_info->width;
4972
4973 if (row_info->bit_depth == 8)
4974 {
4975 png_bytep rp;
4976 png_uint_32 i;
4977
4978 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
4979 bytes_per_pixel = 3;
4980
4981 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4982 bytes_per_pixel = 4;
4983
4984 else
4985 return;
4986
4987 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
4988 {
4989 *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
4990 *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
4991 }
4992 }
4993 else if (row_info->bit_depth == 16)
4994 {
4995 png_bytep rp;
4996 png_uint_32 i;
4997
4998 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
4999 bytes_per_pixel = 6;
5000
5001 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
5002 bytes_per_pixel = 8;
5003
5004 else
5005 return;
5006
5007 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
5008 {
5009 png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
5010 png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
5011 png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
5012 png_uint_32 red = (s0 + s1 + 65536) & 0xffff;
5013 png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;
5014 *(rp ) = (png_byte)((red >> 8) & 0xff);
5015 *(rp + 1) = (png_byte)(red & 0xff);
5016 *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
5017 *(rp + 5) = (png_byte)(blue & 0xff);
5018 }
5019 }
5020 }
5021}
5022#endif /* PNG_MNG_FEATURES_SUPPORTED */
5023#endif /* PNG_READ_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrutil.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrutil.c
new file mode 100644
index 0000000..7b4557f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngrutil.c
@@ -0,0 +1,4158 @@
1
2/* pngrutil.c - utilities to read a PNG file
3 *
4 * Last changed in libpng 1.5.9 [February 18, 2012]
5 * Copyright (c) 1998-2012 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file contains routines that are only called from within
14 * libpng itself during the course of reading an image.
15 */
16
17#include "pngpriv.h"
18
19#ifdef PNG_READ_SUPPORTED
20
21#define png_strtod(p,a,b) strtod(a,b)
22
23png_uint_32 PNGAPI
24png_get_uint_31(png_structp png_ptr, png_const_bytep buf)
25{
26 png_uint_32 uval = png_get_uint_32(buf);
27
28 if (uval > PNG_UINT_31_MAX)
29 png_error(png_ptr, "PNG unsigned integer out of range");
30
31 return (uval);
32}
33
34#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
35/* The following is a variation on the above for use with the fixed
36 * point values used for gAMA and cHRM. Instead of png_error it
37 * issues a warning and returns (-1) - an invalid value because both
38 * gAMA and cHRM use *unsigned* integers for fixed point values.
39 */
40#define PNG_FIXED_ERROR (-1)
41
42static png_fixed_point /* PRIVATE */
43png_get_fixed_point(png_structp png_ptr, png_const_bytep buf)
44{
45 png_uint_32 uval = png_get_uint_32(buf);
46
47 if (uval <= PNG_UINT_31_MAX)
48 return (png_fixed_point)uval; /* known to be in range */
49
50 /* The caller can turn off the warning by passing NULL. */
51 if (png_ptr != NULL)
52 png_warning(png_ptr, "PNG fixed point integer out of range");
53
54 return PNG_FIXED_ERROR;
55}
56#endif
57
58#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
59/* NOTE: the read macros will obscure these definitions, so that if
60 * PNG_USE_READ_MACROS is set the library will not use them internally,
61 * but the APIs will still be available externally.
62 *
63 * The parentheses around "PNGAPI function_name" in the following three
64 * functions are necessary because they allow the macros to co-exist with
65 * these (unused but exported) functions.
66 */
67
68/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
69png_uint_32 (PNGAPI
70png_get_uint_32)(png_const_bytep buf)
71{
72 png_uint_32 uval =
73 ((png_uint_32)(*(buf )) << 24) +
74 ((png_uint_32)(*(buf + 1)) << 16) +
75 ((png_uint_32)(*(buf + 2)) << 8) +
76 ((png_uint_32)(*(buf + 3)) ) ;
77
78 return uval;
79}
80
81/* Grab a signed 32-bit integer from a buffer in big-endian format. The
82 * data is stored in the PNG file in two's complement format and there
83 * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
84 * the following code does a two's complement to native conversion.
85 */
86png_int_32 (PNGAPI
87png_get_int_32)(png_const_bytep buf)
88{
89 png_uint_32 uval = png_get_uint_32(buf);
90 if ((uval & 0x80000000) == 0) /* non-negative */
91 return uval;
92
93 uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
94 return -(png_int_32)uval;
95}
96
97/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
98png_uint_16 (PNGAPI
99png_get_uint_16)(png_const_bytep buf)
100{
101 /* ANSI-C requires an int value to accomodate at least 16 bits so this
102 * works and allows the compiler not to worry about possible narrowing
103 * on 32 bit systems. (Pre-ANSI systems did not make integers smaller
104 * than 16 bits either.)
105 */
106 unsigned int val =
107 ((unsigned int)(*buf) << 8) +
108 ((unsigned int)(*(buf + 1)));
109
110 return (png_uint_16)val;
111}
112
113#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */
114
115/* Read and check the PNG file signature */
116void /* PRIVATE */
117png_read_sig(png_structp png_ptr, png_infop info_ptr)
118{
119 png_size_t num_checked, num_to_check;
120
121 /* Exit if the user application does not expect a signature. */
122 if (png_ptr->sig_bytes >= 8)
123 return;
124
125 num_checked = png_ptr->sig_bytes;
126 num_to_check = 8 - num_checked;
127
128#ifdef PNG_IO_STATE_SUPPORTED
129 png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
130#endif
131
132 /* The signature must be serialized in a single I/O call. */
133 png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
134 png_ptr->sig_bytes = 8;
135
136 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
137 {
138 if (num_checked < 4 &&
139 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
140 png_error(png_ptr, "Not a PNG file");
141 else
142 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
143 }
144 if (num_checked < 3)
145 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
146}
147
148/* Read the chunk header (length + type name).
149 * Put the type name into png_ptr->chunk_name, and return the length.
150 */
151png_uint_32 /* PRIVATE */
152png_read_chunk_header(png_structp png_ptr)
153{
154 png_byte buf[8];
155 png_uint_32 length;
156
157#ifdef PNG_IO_STATE_SUPPORTED
158 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
159#endif
160
161 /* Read the length and the chunk name.
162 * This must be performed in a single I/O call.
163 */
164 png_read_data(png_ptr, buf, 8);
165 length = png_get_uint_31(png_ptr, buf);
166
167 /* Put the chunk name into png_ptr->chunk_name. */
168 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4);
169
170 png_debug2(0, "Reading %lx chunk, length = %lu",
171 (unsigned long)png_ptr->chunk_name, (unsigned long)length);
172
173 /* Reset the crc and run it over the chunk name. */
174 png_reset_crc(png_ptr);
175 png_calculate_crc(png_ptr, buf + 4, 4);
176
177 /* Check to see if chunk name is valid. */
178 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
179
180#ifdef PNG_IO_STATE_SUPPORTED
181 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
182#endif
183
184 return length;
185}
186
187/* Read data, and (optionally) run it through the CRC. */
188void /* PRIVATE */
189png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
190{
191 if (png_ptr == NULL)
192 return;
193
194 png_read_data(png_ptr, buf, length);
195 png_calculate_crc(png_ptr, buf, length);
196}
197
198/* Optionally skip data and then check the CRC. Depending on whether we
199 * are reading a ancillary or critical chunk, and how the program has set
200 * things up, we may calculate the CRC on the data and print a message.
201 * Returns '1' if there was a CRC error, '0' otherwise.
202 */
203int /* PRIVATE */
204png_crc_finish(png_structp png_ptr, png_uint_32 skip)
205{
206 png_size_t i;
207 png_size_t istop = png_ptr->zbuf_size;
208
209 for (i = (png_size_t)skip; i > istop; i -= istop)
210 {
211 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
212 }
213
214 if (i)
215 {
216 png_crc_read(png_ptr, png_ptr->zbuf, i);
217 }
218
219 if (png_crc_error(png_ptr))
220 {
221 if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name) ?
222 !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) :
223 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
224 {
225 png_chunk_warning(png_ptr, "CRC error");
226 }
227
228 else
229 {
230 png_chunk_benign_error(png_ptr, "CRC error");
231 return (0);
232 }
233
234 return (1);
235 }
236
237 return (0);
238}
239
240/* Compare the CRC stored in the PNG file with that calculated by libpng from
241 * the data it has read thus far.
242 */
243int /* PRIVATE */
244png_crc_error(png_structp png_ptr)
245{
246 png_byte crc_bytes[4];
247 png_uint_32 crc;
248 int need_crc = 1;
249
250 if (PNG_CHUNK_ANCILLIARY(png_ptr->chunk_name))
251 {
252 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
253 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
254 need_crc = 0;
255 }
256
257 else /* critical */
258 {
259 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
260 need_crc = 0;
261 }
262
263#ifdef PNG_IO_STATE_SUPPORTED
264 png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
265#endif
266
267 /* The chunk CRC must be serialized in a single I/O call. */
268 png_read_data(png_ptr, crc_bytes, 4);
269
270 if (need_crc)
271 {
272 crc = png_get_uint_32(crc_bytes);
273 return ((int)(crc != png_ptr->crc));
274 }
275
276 else
277 return (0);
278}
279
280#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
281static png_size_t
282png_inflate(png_structp png_ptr, png_bytep data, png_size_t size,
283 png_bytep output, png_size_t output_size)
284{
285 png_size_t count = 0;
286
287 /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't
288 * even necessarily handle 65536 bytes) because the type uInt is "16 bits or
289 * more". Consequently it is necessary to chunk the input to zlib. This
290 * code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the maximum value
291 * that can be stored in a uInt.) It is possible to set ZLIB_IO_MAX to a
292 * lower value in pngpriv.h and this may sometimes have a performance
293 * advantage, because it forces access of the input data to be separated from
294 * at least some of the use by some period of time.
295 */
296 png_ptr->zstream.next_in = data;
297 /* avail_in is set below from 'size' */
298 png_ptr->zstream.avail_in = 0;
299
300 while (1)
301 {
302 int ret, avail;
303
304 /* The setting of 'avail_in' used to be outside the loop; by setting it
305 * inside it is possible to chunk the input to zlib and simply rely on
306 * zlib to advance the 'next_in' pointer. This allows arbitrary amounts o
307 * data to be passed through zlib at the unavoidable cost of requiring a
308 * window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX
309 * input bytes.
310 */
311 if (png_ptr->zstream.avail_in == 0 && size > 0)
312 {
313 if (size <= ZLIB_IO_MAX)
314 {
315 /* The value is less than ZLIB_IO_MAX so the cast is safe: */
316 png_ptr->zstream.avail_in = (uInt)size;
317 size = 0;
318 }
319
320 else
321 {
322 png_ptr->zstream.avail_in = ZLIB_IO_MAX;
323 size -= ZLIB_IO_MAX;
324 }
325 }
326
327 /* Reset the output buffer each time round - we empty it
328 * after every inflate call.
329 */
330 png_ptr->zstream.next_out = png_ptr->zbuf;
331 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
332
333 ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
334 avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out;
335
336 /* First copy/count any new output - but only if we didn't
337 * get an error code.
338 */
339 if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0)
340 {
341 png_size_t space = avail; /* > 0, see above */
342
343 if (output != 0 && output_size > count)
344 {
345 png_size_t copy = output_size - count;
346
347 if (space < copy)
348 copy = space;
349
350 png_memcpy(output + count, png_ptr->zbuf, copy);
351 }
352 count += space;
353 }
354
355 if (ret == Z_OK)
356 continue;
357
358 /* Termination conditions - always reset the zstream, it
359 * must be left in inflateInit state.
360 */
361 png_ptr->zstream.avail_in = 0;
362 inflateReset(&png_ptr->zstream);
363
364 if (ret == Z_STREAM_END)
365 return count; /* NOTE: may be zero. */
366
367 /* Now handle the error codes - the API always returns 0
368 * and the error message is dumped into the uncompressed
369 * buffer if available.
370 */
371# ifdef PNG_WARNINGS_SUPPORTED
372 {
373 png_const_charp msg;
374
375 if (png_ptr->zstream.msg != 0)
376 msg = png_ptr->zstream.msg;
377
378 else switch (ret)
379 {
380 case Z_BUF_ERROR:
381 msg = "Buffer error in compressed datastream";
382 break;
383
384 case Z_DATA_ERROR:
385 msg = "Data error in compressed datastream";
386 break;
387
388 default:
389 msg = "Incomplete compressed datastream";
390 break;
391 }
392
393 png_chunk_warning(png_ptr, msg);
394 }
395# endif
396
397 /* 0 means an error - notice that this code simply ignores
398 * zero length compressed chunks as a result.
399 */
400 return 0;
401 }
402}
403
404/*
405 * Decompress trailing data in a chunk. The assumption is that chunkdata
406 * points at an allocated area holding the contents of a chunk with a
407 * trailing compressed part. What we get back is an allocated area
408 * holding the original prefix part and an uncompressed version of the
409 * trailing part (the malloc area passed in is freed).
410 */
411void /* PRIVATE */
412png_decompress_chunk(png_structp png_ptr, int comp_type,
413 png_size_t chunklength,
414 png_size_t prefix_size, png_size_t *newlength)
415{
416 /* The caller should guarantee this */
417 if (prefix_size > chunklength)
418 {
419 /* The recovery is to delete the chunk. */
420 png_warning(png_ptr, "invalid chunklength");
421 prefix_size = 0; /* To delete everything */
422 }
423
424 else if (comp_type == PNG_COMPRESSION_TYPE_BASE)
425 {
426 png_size_t expanded_size = png_inflate(png_ptr,
427 (png_bytep)(png_ptr->chunkdata + prefix_size),
428 chunklength - prefix_size,
429 0, /* output */
430 0); /* output size */
431
432 /* Now check the limits on this chunk - if the limit fails the
433 * compressed data will be removed, the prefix will remain.
434 */
435 if (prefix_size >= (~(png_size_t)0) - 1 ||
436 expanded_size >= (~(png_size_t)0) - 1 - prefix_size
437#ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
438 || (png_ptr->user_chunk_malloc_max &&
439 (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1))
440#else
441# ifdef PNG_USER_CHUNK_MALLOC_MAX
442 || ((PNG_USER_CHUNK_MALLOC_MAX > 0) &&
443 prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1)
444# endif
445#endif
446 )
447 png_warning(png_ptr, "Exceeded size limit while expanding chunk");
448
449 /* If the size is zero either there was an error and a message
450 * has already been output (warning) or the size really is zero
451 * and we have nothing to do - the code will exit through the
452 * error case below.
453 */
454 else if (expanded_size > 0)
455 {
456 /* Success (maybe) - really uncompress the chunk. */
457 png_size_t new_size = 0;
458 png_charp text = (png_charp)png_malloc_warn(png_ptr,
459 prefix_size + expanded_size + 1);
460
461 if (text != NULL)
462 {
463 png_memcpy(text, png_ptr->chunkdata, prefix_size);
464 new_size = png_inflate(png_ptr,
465 (png_bytep)(png_ptr->chunkdata + prefix_size),
466 chunklength - prefix_size,
467 (png_bytep)(text + prefix_size), expanded_size);
468 text[prefix_size + expanded_size] = 0; /* just in case */
469
470 if (new_size == expanded_size)
471 {
472 png_free(png_ptr, png_ptr->chunkdata);
473 png_ptr->chunkdata = text;
474 *newlength = prefix_size + expanded_size;
475 return; /* The success return! */
476 }
477
478 png_warning(png_ptr, "png_inflate logic error");
479 png_free(png_ptr, text);
480 }
481
482 else
483 png_warning(png_ptr, "Not enough memory to decompress chunk");
484 }
485 }
486
487 else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
488 {
489 PNG_WARNING_PARAMETERS(p)
490 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type);
491 png_formatted_warning(png_ptr, p, "Unknown compression type @1");
492
493 /* The recovery is to simply drop the data. */
494 }
495
496 /* Generic error return - leave the prefix, delete the compressed
497 * data, reallocate the chunkdata to remove the potentially large
498 * amount of compressed data.
499 */
500 {
501 png_charp text = (png_charp)png_malloc_warn(png_ptr, prefix_size + 1);
502
503 if (text != NULL)
504 {
505 if (prefix_size > 0)
506 png_memcpy(text, png_ptr->chunkdata, prefix_size);
507
508 png_free(png_ptr, png_ptr->chunkdata);
509 png_ptr->chunkdata = text;
510
511 /* This is an extra zero in the 'uncompressed' part. */
512 *(png_ptr->chunkdata + prefix_size) = 0x00;
513 }
514 /* Ignore a malloc error here - it is safe. */
515 }
516
517 *newlength = prefix_size;
518}
519#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */
520
521/* Read and check the IDHR chunk */
522void /* PRIVATE */
523png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
524{
525 png_byte buf[13];
526 png_uint_32 width, height;
527 int bit_depth, color_type, compression_type, filter_type;
528 int interlace_type;
529
530 png_debug(1, "in png_handle_IHDR");
531
532 if (png_ptr->mode & PNG_HAVE_IHDR)
533 png_error(png_ptr, "Out of place IHDR");
534
535 /* Check the length */
536 if (length != 13)
537 png_error(png_ptr, "Invalid IHDR chunk");
538
539 png_ptr->mode |= PNG_HAVE_IHDR;
540
541 png_crc_read(png_ptr, buf, 13);
542 png_crc_finish(png_ptr, 0);
543
544 width = png_get_uint_31(png_ptr, buf);
545 height = png_get_uint_31(png_ptr, buf + 4);
546 bit_depth = buf[8];
547 color_type = buf[9];
548 compression_type = buf[10];
549 filter_type = buf[11];
550 interlace_type = buf[12];
551
552 /* Set internal variables */
553 png_ptr->width = width;
554 png_ptr->height = height;
555 png_ptr->bit_depth = (png_byte)bit_depth;
556 png_ptr->interlaced = (png_byte)interlace_type;
557 png_ptr->color_type = (png_byte)color_type;
558#ifdef PNG_MNG_FEATURES_SUPPORTED
559 png_ptr->filter_type = (png_byte)filter_type;
560#endif
561 png_ptr->compression_type = (png_byte)compression_type;
562
563 /* Find number of channels */
564 switch (png_ptr->color_type)
565 {
566 default: /* invalid, png_set_IHDR calls png_error */
567 case PNG_COLOR_TYPE_GRAY:
568 case PNG_COLOR_TYPE_PALETTE:
569 png_ptr->channels = 1;
570 break;
571
572 case PNG_COLOR_TYPE_RGB:
573 png_ptr->channels = 3;
574 break;
575
576 case PNG_COLOR_TYPE_GRAY_ALPHA:
577 png_ptr->channels = 2;
578 break;
579
580 case PNG_COLOR_TYPE_RGB_ALPHA:
581 png_ptr->channels = 4;
582 break;
583 }
584
585 /* Set up other useful info */
586 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
587 png_ptr->channels);
588 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
589 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
590 png_debug1(3, "channels = %d", png_ptr->channels);
591 png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes);
592 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
593 color_type, interlace_type, compression_type, filter_type);
594}
595
596/* Read and check the palette */
597void /* PRIVATE */
598png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
599{
600 png_color palette[PNG_MAX_PALETTE_LENGTH];
601 int num, i;
602#ifdef PNG_POINTER_INDEXING_SUPPORTED
603 png_colorp pal_ptr;
604#endif
605
606 png_debug(1, "in png_handle_PLTE");
607
608 if (!(png_ptr->mode & PNG_HAVE_IHDR))
609 png_error(png_ptr, "Missing IHDR before PLTE");
610
611 else if (png_ptr->mode & PNG_HAVE_IDAT)
612 {
613 png_warning(png_ptr, "Invalid PLTE after IDAT");
614 png_crc_finish(png_ptr, length);
615 return;
616 }
617
618 else if (png_ptr->mode & PNG_HAVE_PLTE)
619 png_error(png_ptr, "Duplicate PLTE chunk");
620
621 png_ptr->mode |= PNG_HAVE_PLTE;
622
623 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
624 {
625 png_warning(png_ptr,
626 "Ignoring PLTE chunk in grayscale PNG");
627 png_crc_finish(png_ptr, length);
628 return;
629 }
630
631#ifndef PNG_READ_OPT_PLTE_SUPPORTED
632 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
633 {
634 png_crc_finish(png_ptr, length);
635 return;
636 }
637#endif
638
639 if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
640 {
641 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
642 {
643 png_warning(png_ptr, "Invalid palette chunk");
644 png_crc_finish(png_ptr, length);
645 return;
646 }
647
648 else
649 {
650 png_error(png_ptr, "Invalid palette chunk");
651 }
652 }
653
654 num = (int)length / 3;
655
656#ifdef PNG_POINTER_INDEXING_SUPPORTED
657 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
658 {
659 png_byte buf[3];
660
661 png_crc_read(png_ptr, buf, 3);
662 pal_ptr->red = buf[0];
663 pal_ptr->green = buf[1];
664 pal_ptr->blue = buf[2];
665 }
666#else
667 for (i = 0; i < num; i++)
668 {
669 png_byte buf[3];
670
671 png_crc_read(png_ptr, buf, 3);
672 /* Don't depend upon png_color being any order */
673 palette[i].red = buf[0];
674 palette[i].green = buf[1];
675 palette[i].blue = buf[2];
676 }
677#endif
678
679 /* If we actually need the PLTE chunk (ie for a paletted image), we do
680 * whatever the normal CRC configuration tells us. However, if we
681 * have an RGB image, the PLTE can be considered ancillary, so
682 * we will act as though it is.
683 */
684#ifndef PNG_READ_OPT_PLTE_SUPPORTED
685 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
686#endif
687 {
688 png_crc_finish(png_ptr, 0);
689 }
690
691#ifndef PNG_READ_OPT_PLTE_SUPPORTED
692 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
693 {
694 /* If we don't want to use the data from an ancillary chunk,
695 * we have two options: an error abort, or a warning and we
696 * ignore the data in this chunk (which should be OK, since
697 * it's considered ancillary for a RGB or RGBA image).
698 */
699 if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
700 {
701 if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
702 {
703 png_chunk_benign_error(png_ptr, "CRC error");
704 }
705
706 else
707 {
708 png_chunk_warning(png_ptr, "CRC error");
709 return;
710 }
711 }
712
713 /* Otherwise, we (optionally) emit a warning and use the chunk. */
714 else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
715 {
716 png_chunk_warning(png_ptr, "CRC error");
717 }
718 }
719#endif
720
721 png_set_PLTE(png_ptr, info_ptr, palette, num);
722
723#ifdef PNG_READ_tRNS_SUPPORTED
724 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
725 {
726 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
727 {
728 if (png_ptr->num_trans > (png_uint_16)num)
729 {
730 png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
731 png_ptr->num_trans = (png_uint_16)num;
732 }
733
734 if (info_ptr->num_trans > (png_uint_16)num)
735 {
736 png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
737 info_ptr->num_trans = (png_uint_16)num;
738 }
739 }
740 }
741#endif
742
743}
744
745void /* PRIVATE */
746png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
747{
748 png_debug(1, "in png_handle_IEND");
749
750 if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
751 {
752 png_error(png_ptr, "No image in file");
753 }
754
755 png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
756
757 if (length != 0)
758 {
759 png_warning(png_ptr, "Incorrect IEND chunk length");
760 }
761
762 png_crc_finish(png_ptr, length);
763
764 PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */
765}
766
767#ifdef PNG_READ_gAMA_SUPPORTED
768void /* PRIVATE */
769png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
770{
771 png_fixed_point igamma;
772 png_byte buf[4];
773
774 png_debug(1, "in png_handle_gAMA");
775
776 if (!(png_ptr->mode & PNG_HAVE_IHDR))
777 png_error(png_ptr, "Missing IHDR before gAMA");
778
779 else if (png_ptr->mode & PNG_HAVE_IDAT)
780 {
781 png_warning(png_ptr, "Invalid gAMA after IDAT");
782 png_crc_finish(png_ptr, length);
783 return;
784 }
785
786 else if (png_ptr->mode & PNG_HAVE_PLTE)
787 /* Should be an error, but we can cope with it */
788 png_warning(png_ptr, "Out of place gAMA chunk");
789
790 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
791#ifdef PNG_READ_sRGB_SUPPORTED
792 && !(info_ptr->valid & PNG_INFO_sRGB)
793#endif
794 )
795 {
796 png_warning(png_ptr, "Duplicate gAMA chunk");
797 png_crc_finish(png_ptr, length);
798 return;
799 }
800
801 if (length != 4)
802 {
803 png_warning(png_ptr, "Incorrect gAMA chunk length");
804 png_crc_finish(png_ptr, length);
805 return;
806 }
807
808 png_crc_read(png_ptr, buf, 4);
809
810 if (png_crc_finish(png_ptr, 0))
811 return;
812
813 igamma = png_get_fixed_point(NULL, buf);
814
815 /* Check for zero gamma or an error. */
816 if (igamma <= 0)
817 {
818 png_warning(png_ptr,
819 "Ignoring gAMA chunk with out of range gamma");
820
821 return;
822 }
823
824# ifdef PNG_READ_sRGB_SUPPORTED
825 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
826 {
827 if (PNG_OUT_OF_RANGE(igamma, 45500, 500))
828 {
829 PNG_WARNING_PARAMETERS(p)
830 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, igamma);
831 png_formatted_warning(png_ptr, p,
832 "Ignoring incorrect gAMA value @1 when sRGB is also present");
833 return;
834 }
835 }
836# endif /* PNG_READ_sRGB_SUPPORTED */
837
838# ifdef PNG_READ_GAMMA_SUPPORTED
839 /* Gamma correction on read is supported. */
840 png_ptr->gamma = igamma;
841# endif
842 /* And set the 'info' structure members. */
843 png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
844}
845#endif
846
847#ifdef PNG_READ_sBIT_SUPPORTED
848void /* PRIVATE */
849png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
850{
851 png_size_t truelen;
852 png_byte buf[4];
853
854 png_debug(1, "in png_handle_sBIT");
855
856 buf[0] = buf[1] = buf[2] = buf[3] = 0;
857
858 if (!(png_ptr->mode & PNG_HAVE_IHDR))
859 png_error(png_ptr, "Missing IHDR before sBIT");
860
861 else if (png_ptr->mode & PNG_HAVE_IDAT)
862 {
863 png_warning(png_ptr, "Invalid sBIT after IDAT");
864 png_crc_finish(png_ptr, length);
865 return;
866 }
867
868 else if (png_ptr->mode & PNG_HAVE_PLTE)
869 {
870 /* Should be an error, but we can cope with it */
871 png_warning(png_ptr, "Out of place sBIT chunk");
872 }
873
874 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
875 {
876 png_warning(png_ptr, "Duplicate sBIT chunk");
877 png_crc_finish(png_ptr, length);
878 return;
879 }
880
881 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
882 truelen = 3;
883
884 else
885 truelen = (png_size_t)png_ptr->channels;
886
887 if (length != truelen || length > 4)
888 {
889 png_warning(png_ptr, "Incorrect sBIT chunk length");
890 png_crc_finish(png_ptr, length);
891 return;
892 }
893
894 png_crc_read(png_ptr, buf, truelen);
895
896 if (png_crc_finish(png_ptr, 0))
897 return;
898
899 if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
900 {
901 png_ptr->sig_bit.red = buf[0];
902 png_ptr->sig_bit.green = buf[1];
903 png_ptr->sig_bit.blue = buf[2];
904 png_ptr->sig_bit.alpha = buf[3];
905 }
906
907 else
908 {
909 png_ptr->sig_bit.gray = buf[0];
910 png_ptr->sig_bit.red = buf[0];
911 png_ptr->sig_bit.green = buf[0];
912 png_ptr->sig_bit.blue = buf[0];
913 png_ptr->sig_bit.alpha = buf[1];
914 }
915
916 png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
917}
918#endif
919
920#ifdef PNG_READ_cHRM_SUPPORTED
921void /* PRIVATE */
922png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
923{
924 png_byte buf[32];
925 png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue,
926 y_blue;
927
928 png_debug(1, "in png_handle_cHRM");
929
930 if (!(png_ptr->mode & PNG_HAVE_IHDR))
931 png_error(png_ptr, "Missing IHDR before cHRM");
932
933 else if (png_ptr->mode & PNG_HAVE_IDAT)
934 {
935 png_warning(png_ptr, "Invalid cHRM after IDAT");
936 png_crc_finish(png_ptr, length);
937 return;
938 }
939
940 else if (png_ptr->mode & PNG_HAVE_PLTE)
941 /* Should be an error, but we can cope with it */
942 png_warning(png_ptr, "Out of place cHRM chunk");
943
944 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
945# ifdef PNG_READ_sRGB_SUPPORTED
946 && !(info_ptr->valid & PNG_INFO_sRGB)
947# endif
948 )
949 {
950 png_warning(png_ptr, "Duplicate cHRM chunk");
951 png_crc_finish(png_ptr, length);
952 return;
953 }
954
955 if (length != 32)
956 {
957 png_warning(png_ptr, "Incorrect cHRM chunk length");
958 png_crc_finish(png_ptr, length);
959 return;
960 }
961
962 png_crc_read(png_ptr, buf, 32);
963
964 if (png_crc_finish(png_ptr, 0))
965 return;
966
967 x_white = png_get_fixed_point(NULL, buf);
968 y_white = png_get_fixed_point(NULL, buf + 4);
969 x_red = png_get_fixed_point(NULL, buf + 8);
970 y_red = png_get_fixed_point(NULL, buf + 12);
971 x_green = png_get_fixed_point(NULL, buf + 16);
972 y_green = png_get_fixed_point(NULL, buf + 20);
973 x_blue = png_get_fixed_point(NULL, buf + 24);
974 y_blue = png_get_fixed_point(NULL, buf + 28);
975
976 if (x_white == PNG_FIXED_ERROR ||
977 y_white == PNG_FIXED_ERROR ||
978 x_red == PNG_FIXED_ERROR ||
979 y_red == PNG_FIXED_ERROR ||
980 x_green == PNG_FIXED_ERROR ||
981 y_green == PNG_FIXED_ERROR ||
982 x_blue == PNG_FIXED_ERROR ||
983 y_blue == PNG_FIXED_ERROR)
984 {
985 png_warning(png_ptr, "Ignoring cHRM chunk with negative chromaticities");
986 return;
987 }
988
989#ifdef PNG_READ_sRGB_SUPPORTED
990 if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
991 {
992 if (PNG_OUT_OF_RANGE(x_white, 31270, 1000) ||
993 PNG_OUT_OF_RANGE(y_white, 32900, 1000) ||
994 PNG_OUT_OF_RANGE(x_red, 64000, 1000) ||
995 PNG_OUT_OF_RANGE(y_red, 33000, 1000) ||
996 PNG_OUT_OF_RANGE(x_green, 30000, 1000) ||
997 PNG_OUT_OF_RANGE(y_green, 60000, 1000) ||
998 PNG_OUT_OF_RANGE(x_blue, 15000, 1000) ||
999 PNG_OUT_OF_RANGE(y_blue, 6000, 1000))
1000 {
1001 PNG_WARNING_PARAMETERS(p)
1002
1003 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, x_white);
1004 png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_fixed, y_white);
1005 png_warning_parameter_signed(p, 3, PNG_NUMBER_FORMAT_fixed, x_red);
1006 png_warning_parameter_signed(p, 4, PNG_NUMBER_FORMAT_fixed, y_red);
1007 png_warning_parameter_signed(p, 5, PNG_NUMBER_FORMAT_fixed, x_green);
1008 png_warning_parameter_signed(p, 6, PNG_NUMBER_FORMAT_fixed, y_green);
1009 png_warning_parameter_signed(p, 7, PNG_NUMBER_FORMAT_fixed, x_blue);
1010 png_warning_parameter_signed(p, 8, PNG_NUMBER_FORMAT_fixed, y_blue);
1011
1012 png_formatted_warning(png_ptr, p,
1013 "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) "
1014 "when sRGB is also present");
1015 }
1016 return;
1017 }
1018#endif /* PNG_READ_sRGB_SUPPORTED */
1019
1020#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1021 /* Store the _white values as default coefficients for the rgb to gray
1022 * operation if it is supported. Check if the transform is already set to
1023 * avoid destroying the transform values.
1024 */
1025 if (!png_ptr->rgb_to_gray_coefficients_set)
1026 {
1027 /* png_set_background has not been called and we haven't seen an sRGB
1028 * chunk yet. Find the XYZ of the three end points.
1029 */
1030 png_XYZ XYZ;
1031 png_xy xy;
1032
1033 xy.redx = x_red;
1034 xy.redy = y_red;
1035 xy.greenx = x_green;
1036 xy.greeny = y_green;
1037 xy.bluex = x_blue;
1038 xy.bluey = y_blue;
1039 xy.whitex = x_white;
1040 xy.whitey = y_white;
1041
1042 if (png_XYZ_from_xy_checked(png_ptr, &XYZ, xy))
1043 {
1044 /* The success case, because XYZ_from_xy normalises to a reference
1045 * white Y of 1.0 we just need to scale the numbers. This should
1046 * always work just fine. It is an internal error if this overflows.
1047 */
1048 {
1049 png_fixed_point r, g, b;
1050 if (png_muldiv(&r, XYZ.redY, 32768, PNG_FP_1) &&
1051 r >= 0 && r <= 32768 &&
1052 png_muldiv(&g, XYZ.greenY, 32768, PNG_FP_1) &&
1053 g >= 0 && g <= 32768 &&
1054 png_muldiv(&b, XYZ.blueY, 32768, PNG_FP_1) &&
1055 b >= 0 && b <= 32768 &&
1056 r+g+b <= 32769)
1057 {
1058 /* We allow 0 coefficients here. r+g+b may be 32769 if two or
1059 * all of the coefficients were rounded up. Handle this by
1060 * reducing the *largest* coefficient by 1; this matches the
1061 * approach used for the default coefficients in pngrtran.c
1062 */
1063 int add = 0;
1064
1065 if (r+g+b > 32768)
1066 add = -1;
1067 else if (r+g+b < 32768)
1068 add = 1;
1069
1070 if (add != 0)
1071 {
1072 if (g >= r && g >= b)
1073 g += add;
1074 else if (r >= g && r >= b)
1075 r += add;
1076 else
1077 b += add;
1078 }
1079
1080 /* Check for an internal error. */
1081 if (r+g+b != 32768)
1082 png_error(png_ptr,
1083 "internal error handling cHRM coefficients");
1084
1085 png_ptr->rgb_to_gray_red_coeff = (png_uint_16)r;
1086 png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g;
1087 }
1088
1089 /* This is a png_error at present even though it could be ignored -
1090 * it should never happen, but it is important that if it does, the
1091 * bug is fixed.
1092 */
1093 else
1094 png_error(png_ptr, "internal error handling cHRM->XYZ");
1095 }
1096 }
1097 }
1098#endif
1099
1100 png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red,
1101 x_green, y_green, x_blue, y_blue);
1102}
1103#endif
1104
1105#ifdef PNG_READ_sRGB_SUPPORTED
1106void /* PRIVATE */
1107png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1108{
1109 int intent;
1110 png_byte buf[1];
1111
1112 png_debug(1, "in png_handle_sRGB");
1113
1114 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1115 png_error(png_ptr, "Missing IHDR before sRGB");
1116
1117 else if (png_ptr->mode & PNG_HAVE_IDAT)
1118 {
1119 png_warning(png_ptr, "Invalid sRGB after IDAT");
1120 png_crc_finish(png_ptr, length);
1121 return;
1122 }
1123
1124 else if (png_ptr->mode & PNG_HAVE_PLTE)
1125 /* Should be an error, but we can cope with it */
1126 png_warning(png_ptr, "Out of place sRGB chunk");
1127
1128 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
1129 {
1130 png_warning(png_ptr, "Duplicate sRGB chunk");
1131 png_crc_finish(png_ptr, length);
1132 return;
1133 }
1134
1135 if (length != 1)
1136 {
1137 png_warning(png_ptr, "Incorrect sRGB chunk length");
1138 png_crc_finish(png_ptr, length);
1139 return;
1140 }
1141
1142 png_crc_read(png_ptr, buf, 1);
1143
1144 if (png_crc_finish(png_ptr, 0))
1145 return;
1146
1147 intent = buf[0];
1148
1149 /* Check for bad intent */
1150 if (intent >= PNG_sRGB_INTENT_LAST)
1151 {
1152 png_warning(png_ptr, "Unknown sRGB intent");
1153 return;
1154 }
1155
1156#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
1157 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
1158 {
1159 if (PNG_OUT_OF_RANGE(info_ptr->gamma, 45500, 500))
1160 {
1161 PNG_WARNING_PARAMETERS(p)
1162
1163 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed,
1164 info_ptr->gamma);
1165
1166 png_formatted_warning(png_ptr, p,
1167 "Ignoring incorrect gAMA value @1 when sRGB is also present");
1168 }
1169 }
1170#endif /* PNG_READ_gAMA_SUPPORTED */
1171
1172#ifdef PNG_READ_cHRM_SUPPORTED
1173 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
1174 if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270, 1000) ||
1175 PNG_OUT_OF_RANGE(info_ptr->y_white, 32900, 1000) ||
1176 PNG_OUT_OF_RANGE(info_ptr->x_red, 64000, 1000) ||
1177 PNG_OUT_OF_RANGE(info_ptr->y_red, 33000, 1000) ||
1178 PNG_OUT_OF_RANGE(info_ptr->x_green, 30000, 1000) ||
1179 PNG_OUT_OF_RANGE(info_ptr->y_green, 60000, 1000) ||
1180 PNG_OUT_OF_RANGE(info_ptr->x_blue, 15000, 1000) ||
1181 PNG_OUT_OF_RANGE(info_ptr->y_blue, 6000, 1000))
1182 {
1183 png_warning(png_ptr,
1184 "Ignoring incorrect cHRM value when sRGB is also present");
1185 }
1186#endif /* PNG_READ_cHRM_SUPPORTED */
1187
1188 /* This is recorded for use when handling the cHRM chunk above. An sRGB
1189 * chunk unconditionally overwrites the coefficients for grayscale conversion
1190 * too.
1191 */
1192 png_ptr->is_sRGB = 1;
1193
1194# ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1195 /* Don't overwrite user supplied values: */
1196 if (!png_ptr->rgb_to_gray_coefficients_set)
1197 {
1198 /* These numbers come from the sRGB specification (or, since one has to
1199 * pay much money to get a copy, the wikipedia sRGB page) the
1200 * chromaticity values quoted have been inverted to get the reverse
1201 * transformation from RGB to XYZ and the 'Y' coefficients scaled by
1202 * 32768 (then rounded).
1203 *
1204 * sRGB and ITU Rec-709 both truncate the values for the D65 white
1205 * point to four digits and, even though it actually stores five
1206 * digits, the PNG spec gives the truncated value.
1207 *
1208 * This means that when the chromaticities are converted back to XYZ
1209 * end points we end up with (6968,23435,2366), which, as described in
1210 * pngrtran.c, would overflow. If the five digit precision and up is
1211 * used we get, instead:
1212 *
1213 * 6968*R + 23435*G + 2365*B
1214 *
1215 * (Notice that this rounds the blue coefficient down, rather than the
1216 * choice used in pngrtran.c which is to round the green one down.)
1217 */
1218 png_ptr->rgb_to_gray_red_coeff = 6968; /* 0.212639005871510 */
1219 png_ptr->rgb_to_gray_green_coeff = 23434; /* 0.715168678767756 */
1220 /* png_ptr->rgb_to_gray_blue_coeff = 2366; 0.072192315360734 */
1221
1222 /* The following keeps the cHRM chunk from destroying the
1223 * coefficients again in the event that it follows the sRGB chunk.
1224 */
1225 png_ptr->rgb_to_gray_coefficients_set = 1;
1226 }
1227# endif
1228
1229 png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
1230}
1231#endif /* PNG_READ_sRGB_SUPPORTED */
1232
1233#ifdef PNG_READ_iCCP_SUPPORTED
1234void /* PRIVATE */
1235png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1236/* Note: this does not properly handle chunks that are > 64K under DOS */
1237{
1238 png_byte compression_type;
1239 png_bytep pC;
1240 png_charp profile;
1241 png_uint_32 skip = 0;
1242 png_uint_32 profile_size;
1243 png_alloc_size_t profile_length;
1244 png_size_t slength, prefix_length, data_length;
1245
1246 png_debug(1, "in png_handle_iCCP");
1247
1248 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1249 png_error(png_ptr, "Missing IHDR before iCCP");
1250
1251 else if (png_ptr->mode & PNG_HAVE_IDAT)
1252 {
1253 png_warning(png_ptr, "Invalid iCCP after IDAT");
1254 png_crc_finish(png_ptr, length);
1255 return;
1256 }
1257
1258 else if (png_ptr->mode & PNG_HAVE_PLTE)
1259 /* Should be an error, but we can cope with it */
1260 png_warning(png_ptr, "Out of place iCCP chunk");
1261
1262 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
1263 {
1264 png_warning(png_ptr, "Duplicate iCCP chunk");
1265 png_crc_finish(png_ptr, length);
1266 return;
1267 }
1268
1269#ifdef PNG_MAX_MALLOC_64K
1270 if (length > (png_uint_32)65535L)
1271 {
1272 png_warning(png_ptr, "iCCP chunk too large to fit in memory");
1273 skip = length - (png_uint_32)65535L;
1274 length = (png_uint_32)65535L;
1275 }
1276#endif
1277
1278 png_free(png_ptr, png_ptr->chunkdata);
1279 png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
1280 slength = length;
1281 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
1282
1283 if (png_crc_finish(png_ptr, skip))
1284 {
1285 png_free(png_ptr, png_ptr->chunkdata);
1286 png_ptr->chunkdata = NULL;
1287 return;
1288 }
1289
1290 png_ptr->chunkdata[slength] = 0x00;
1291
1292 for (profile = png_ptr->chunkdata; *profile; profile++)
1293 /* Empty loop to find end of name */ ;
1294
1295 ++profile;
1296
1297 /* There should be at least one zero (the compression type byte)
1298 * following the separator, and we should be on it
1299 */
1300 if (profile >= png_ptr->chunkdata + slength - 1)
1301 {
1302 png_free(png_ptr, png_ptr->chunkdata);
1303 png_ptr->chunkdata = NULL;
1304 png_warning(png_ptr, "Malformed iCCP chunk");
1305 return;
1306 }
1307
1308 /* Compression_type should always be zero */
1309 compression_type = *profile++;
1310
1311 if (compression_type)
1312 {
1313 png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
1314 compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
1315 wrote nonzero) */
1316 }
1317
1318 prefix_length = profile - png_ptr->chunkdata;
1319 png_decompress_chunk(png_ptr, compression_type,
1320 slength, prefix_length, &data_length);
1321
1322 profile_length = data_length - prefix_length;
1323
1324 if (prefix_length > data_length || profile_length < 4)
1325 {
1326 png_free(png_ptr, png_ptr->chunkdata);
1327 png_ptr->chunkdata = NULL;
1328 png_warning(png_ptr, "Profile size field missing from iCCP chunk");
1329 return;
1330 }
1331
1332 /* Check the profile_size recorded in the first 32 bits of the ICC profile */
1333 pC = (png_bytep)(png_ptr->chunkdata + prefix_length);
1334 profile_size = ((*(pC )) << 24) |
1335 ((*(pC + 1)) << 16) |
1336 ((*(pC + 2)) << 8) |
1337 ((*(pC + 3)) );
1338
1339 /* NOTE: the following guarantees that 'profile_length' fits into 32 bits,
1340 * because profile_size is a 32 bit value.
1341 */
1342 if (profile_size < profile_length)
1343 profile_length = profile_size;
1344
1345 /* And the following guarantees that profile_size == profile_length. */
1346 if (profile_size > profile_length)
1347 {
1348 PNG_WARNING_PARAMETERS(p)
1349
1350 png_free(png_ptr, png_ptr->chunkdata);
1351 png_ptr->chunkdata = NULL;
1352
1353 png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_u, profile_size);
1354 png_warning_parameter_unsigned(p, 2, PNG_NUMBER_FORMAT_u, profile_length);
1355 png_formatted_warning(png_ptr, p,
1356 "Ignoring iCCP chunk with declared size = @1 and actual length = @2");
1357 return;
1358 }
1359
1360 png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata,
1361 compression_type, (png_bytep)png_ptr->chunkdata + prefix_length,
1362 profile_size);
1363 png_free(png_ptr, png_ptr->chunkdata);
1364 png_ptr->chunkdata = NULL;
1365}
1366#endif /* PNG_READ_iCCP_SUPPORTED */
1367
1368#ifdef PNG_READ_sPLT_SUPPORTED
1369void /* PRIVATE */
1370png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1371/* Note: this does not properly handle chunks that are > 64K under DOS */
1372{
1373 png_bytep entry_start;
1374 png_sPLT_t new_palette;
1375 png_sPLT_entryp pp;
1376 png_uint_32 data_length;
1377 int entry_size, i;
1378 png_uint_32 skip = 0;
1379 png_size_t slength;
1380 png_uint_32 dl;
1381 png_size_t max_dl;
1382
1383 png_debug(1, "in png_handle_sPLT");
1384
1385#ifdef PNG_USER_LIMITS_SUPPORTED
1386
1387 if (png_ptr->user_chunk_cache_max != 0)
1388 {
1389 if (png_ptr->user_chunk_cache_max == 1)
1390 {
1391 png_crc_finish(png_ptr, length);
1392 return;
1393 }
1394
1395 if (--png_ptr->user_chunk_cache_max == 1)
1396 {
1397 png_warning(png_ptr, "No space in chunk cache for sPLT");
1398 png_crc_finish(png_ptr, length);
1399 return;
1400 }
1401 }
1402#endif
1403
1404 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1405 png_error(png_ptr, "Missing IHDR before sPLT");
1406
1407 else if (png_ptr->mode & PNG_HAVE_IDAT)
1408 {
1409 png_warning(png_ptr, "Invalid sPLT after IDAT");
1410 png_crc_finish(png_ptr, length);
1411 return;
1412 }
1413
1414#ifdef PNG_MAX_MALLOC_64K
1415 if (length > (png_uint_32)65535L)
1416 {
1417 png_warning(png_ptr, "sPLT chunk too large to fit in memory");
1418 skip = length - (png_uint_32)65535L;
1419 length = (png_uint_32)65535L;
1420 }
1421#endif
1422
1423 png_free(png_ptr, png_ptr->chunkdata);
1424 png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
1425
1426 /* WARNING: this may break if size_t is less than 32 bits; it is assumed
1427 * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
1428 * potential breakage point if the types in pngconf.h aren't exactly right.
1429 */
1430 slength = length;
1431 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
1432
1433 if (png_crc_finish(png_ptr, skip))
1434 {
1435 png_free(png_ptr, png_ptr->chunkdata);
1436 png_ptr->chunkdata = NULL;
1437 return;
1438 }
1439
1440 png_ptr->chunkdata[slength] = 0x00;
1441
1442 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start;
1443 entry_start++)
1444 /* Empty loop to find end of name */ ;
1445
1446 ++entry_start;
1447
1448 /* A sample depth should follow the separator, and we should be on it */
1449 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2)
1450 {
1451 png_free(png_ptr, png_ptr->chunkdata);
1452 png_ptr->chunkdata = NULL;
1453 png_warning(png_ptr, "malformed sPLT chunk");
1454 return;
1455 }
1456
1457 new_palette.depth = *entry_start++;
1458 entry_size = (new_palette.depth == 8 ? 6 : 10);
1459 /* This must fit in a png_uint_32 because it is derived from the original
1460 * chunk data length (and use 'length', not 'slength' here for clarity -
1461 * they are guaranteed to be the same, see the tests above.)
1462 */
1463 data_length = length - (png_uint_32)(entry_start -
1464 (png_bytep)png_ptr->chunkdata);
1465
1466 /* Integrity-check the data length */
1467 if (data_length % entry_size)
1468 {
1469 png_free(png_ptr, png_ptr->chunkdata);
1470 png_ptr->chunkdata = NULL;
1471 png_warning(png_ptr, "sPLT chunk has bad length");
1472 return;
1473 }
1474
1475 dl = (png_int_32)(data_length / entry_size);
1476 max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry);
1477
1478 if (dl > max_dl)
1479 {
1480 png_warning(png_ptr, "sPLT chunk too long");
1481 return;
1482 }
1483
1484 new_palette.nentries = (png_int_32)(data_length / entry_size);
1485
1486 new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
1487 png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
1488
1489 if (new_palette.entries == NULL)
1490 {
1491 png_warning(png_ptr, "sPLT chunk requires too much memory");
1492 return;
1493 }
1494
1495#ifdef PNG_POINTER_INDEXING_SUPPORTED
1496 for (i = 0; i < new_palette.nentries; i++)
1497 {
1498 pp = new_palette.entries + i;
1499
1500 if (new_palette.depth == 8)
1501 {
1502 pp->red = *entry_start++;
1503 pp->green = *entry_start++;
1504 pp->blue = *entry_start++;
1505 pp->alpha = *entry_start++;
1506 }
1507
1508 else
1509 {
1510 pp->red = png_get_uint_16(entry_start); entry_start += 2;
1511 pp->green = png_get_uint_16(entry_start); entry_start += 2;
1512 pp->blue = png_get_uint_16(entry_start); entry_start += 2;
1513 pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
1514 }
1515
1516 pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
1517 }
1518#else
1519 pp = new_palette.entries;
1520
1521 for (i = 0; i < new_palette.nentries; i++)
1522 {
1523
1524 if (new_palette.depth == 8)
1525 {
1526 pp[i].red = *entry_start++;
1527 pp[i].green = *entry_start++;
1528 pp[i].blue = *entry_start++;
1529 pp[i].alpha = *entry_start++;
1530 }
1531
1532 else
1533 {
1534 pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
1535 pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
1536 pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
1537 pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
1538 }
1539
1540 pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;
1541 }
1542#endif
1543
1544 /* Discard all chunk data except the name and stash that */
1545 new_palette.name = png_ptr->chunkdata;
1546
1547 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1548
1549 png_free(png_ptr, png_ptr->chunkdata);
1550 png_ptr->chunkdata = NULL;
1551 png_free(png_ptr, new_palette.entries);
1552}
1553#endif /* PNG_READ_sPLT_SUPPORTED */
1554
1555#ifdef PNG_READ_tRNS_SUPPORTED
1556void /* PRIVATE */
1557png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1558{
1559 png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
1560
1561 png_debug(1, "in png_handle_tRNS");
1562
1563 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1564 png_error(png_ptr, "Missing IHDR before tRNS");
1565
1566 else if (png_ptr->mode & PNG_HAVE_IDAT)
1567 {
1568 png_warning(png_ptr, "Invalid tRNS after IDAT");
1569 png_crc_finish(png_ptr, length);
1570 return;
1571 }
1572
1573 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
1574 {
1575 png_warning(png_ptr, "Duplicate tRNS chunk");
1576 png_crc_finish(png_ptr, length);
1577 return;
1578 }
1579
1580 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
1581 {
1582 png_byte buf[2];
1583
1584 if (length != 2)
1585 {
1586 png_warning(png_ptr, "Incorrect tRNS chunk length");
1587 png_crc_finish(png_ptr, length);
1588 return;
1589 }
1590
1591 png_crc_read(png_ptr, buf, 2);
1592 png_ptr->num_trans = 1;
1593 png_ptr->trans_color.gray = png_get_uint_16(buf);
1594 }
1595
1596 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
1597 {
1598 png_byte buf[6];
1599
1600 if (length != 6)
1601 {
1602 png_warning(png_ptr, "Incorrect tRNS chunk length");
1603 png_crc_finish(png_ptr, length);
1604 return;
1605 }
1606
1607 png_crc_read(png_ptr, buf, (png_size_t)length);
1608 png_ptr->num_trans = 1;
1609 png_ptr->trans_color.red = png_get_uint_16(buf);
1610 png_ptr->trans_color.green = png_get_uint_16(buf + 2);
1611 png_ptr->trans_color.blue = png_get_uint_16(buf + 4);
1612 }
1613
1614 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1615 {
1616 if (!(png_ptr->mode & PNG_HAVE_PLTE))
1617 {
1618 /* Should be an error, but we can cope with it. */
1619 png_warning(png_ptr, "Missing PLTE before tRNS");
1620 }
1621
1622 if (length > (png_uint_32)png_ptr->num_palette ||
1623 length > PNG_MAX_PALETTE_LENGTH)
1624 {
1625 png_warning(png_ptr, "Incorrect tRNS chunk length");
1626 png_crc_finish(png_ptr, length);
1627 return;
1628 }
1629
1630 if (length == 0)
1631 {
1632 png_warning(png_ptr, "Zero length tRNS chunk");
1633 png_crc_finish(png_ptr, length);
1634 return;
1635 }
1636
1637 png_crc_read(png_ptr, readbuf, (png_size_t)length);
1638 png_ptr->num_trans = (png_uint_16)length;
1639 }
1640
1641 else
1642 {
1643 png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
1644 png_crc_finish(png_ptr, length);
1645 return;
1646 }
1647
1648 if (png_crc_finish(png_ptr, 0))
1649 {
1650 png_ptr->num_trans = 0;
1651 return;
1652 }
1653
1654 png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
1655 &(png_ptr->trans_color));
1656}
1657#endif
1658
1659#ifdef PNG_READ_bKGD_SUPPORTED
1660void /* PRIVATE */
1661png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1662{
1663 png_size_t truelen;
1664 png_byte buf[6];
1665 png_color_16 background;
1666
1667 png_debug(1, "in png_handle_bKGD");
1668
1669 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1670 png_error(png_ptr, "Missing IHDR before bKGD");
1671
1672 else if (png_ptr->mode & PNG_HAVE_IDAT)
1673 {
1674 png_warning(png_ptr, "Invalid bKGD after IDAT");
1675 png_crc_finish(png_ptr, length);
1676 return;
1677 }
1678
1679 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
1680 !(png_ptr->mode & PNG_HAVE_PLTE))
1681 {
1682 png_warning(png_ptr, "Missing PLTE before bKGD");
1683 png_crc_finish(png_ptr, length);
1684 return;
1685 }
1686
1687 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
1688 {
1689 png_warning(png_ptr, "Duplicate bKGD chunk");
1690 png_crc_finish(png_ptr, length);
1691 return;
1692 }
1693
1694 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1695 truelen = 1;
1696
1697 else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
1698 truelen = 6;
1699
1700 else
1701 truelen = 2;
1702
1703 if (length != truelen)
1704 {
1705 png_warning(png_ptr, "Incorrect bKGD chunk length");
1706 png_crc_finish(png_ptr, length);
1707 return;
1708 }
1709
1710 png_crc_read(png_ptr, buf, truelen);
1711
1712 if (png_crc_finish(png_ptr, 0))
1713 return;
1714
1715 /* We convert the index value into RGB components so that we can allow
1716 * arbitrary RGB values for background when we have transparency, and
1717 * so it is easy to determine the RGB values of the background color
1718 * from the info_ptr struct.
1719 */
1720 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
1721 {
1722 background.index = buf[0];
1723
1724 if (info_ptr && info_ptr->num_palette)
1725 {
1726 if (buf[0] >= info_ptr->num_palette)
1727 {
1728 png_warning(png_ptr, "Incorrect bKGD chunk index value");
1729 return;
1730 }
1731
1732 background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
1733 background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
1734 background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
1735 }
1736
1737 else
1738 background.red = background.green = background.blue = 0;
1739
1740 background.gray = 0;
1741 }
1742
1743 else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
1744 {
1745 background.index = 0;
1746 background.red =
1747 background.green =
1748 background.blue =
1749 background.gray = png_get_uint_16(buf);
1750 }
1751
1752 else
1753 {
1754 background.index = 0;
1755 background.red = png_get_uint_16(buf);
1756 background.green = png_get_uint_16(buf + 2);
1757 background.blue = png_get_uint_16(buf + 4);
1758 background.gray = 0;
1759 }
1760
1761 png_set_bKGD(png_ptr, info_ptr, &background);
1762}
1763#endif
1764
1765#ifdef PNG_READ_hIST_SUPPORTED
1766void /* PRIVATE */
1767png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1768{
1769 unsigned int num, i;
1770 png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
1771
1772 png_debug(1, "in png_handle_hIST");
1773
1774 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1775 png_error(png_ptr, "Missing IHDR before hIST");
1776
1777 else if (png_ptr->mode & PNG_HAVE_IDAT)
1778 {
1779 png_warning(png_ptr, "Invalid hIST after IDAT");
1780 png_crc_finish(png_ptr, length);
1781 return;
1782 }
1783
1784 else if (!(png_ptr->mode & PNG_HAVE_PLTE))
1785 {
1786 png_warning(png_ptr, "Missing PLTE before hIST");
1787 png_crc_finish(png_ptr, length);
1788 return;
1789 }
1790
1791 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
1792 {
1793 png_warning(png_ptr, "Duplicate hIST chunk");
1794 png_crc_finish(png_ptr, length);
1795 return;
1796 }
1797
1798 num = length / 2 ;
1799
1800 if (num != (unsigned int)png_ptr->num_palette || num >
1801 (unsigned int)PNG_MAX_PALETTE_LENGTH)
1802 {
1803 png_warning(png_ptr, "Incorrect hIST chunk length");
1804 png_crc_finish(png_ptr, length);
1805 return;
1806 }
1807
1808 for (i = 0; i < num; i++)
1809 {
1810 png_byte buf[2];
1811
1812 png_crc_read(png_ptr, buf, 2);
1813 readbuf[i] = png_get_uint_16(buf);
1814 }
1815
1816 if (png_crc_finish(png_ptr, 0))
1817 return;
1818
1819 png_set_hIST(png_ptr, info_ptr, readbuf);
1820}
1821#endif
1822
1823#ifdef PNG_READ_pHYs_SUPPORTED
1824void /* PRIVATE */
1825png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1826{
1827 png_byte buf[9];
1828 png_uint_32 res_x, res_y;
1829 int unit_type;
1830
1831 png_debug(1, "in png_handle_pHYs");
1832
1833 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1834 png_error(png_ptr, "Missing IHDR before pHYs");
1835
1836 else if (png_ptr->mode & PNG_HAVE_IDAT)
1837 {
1838 png_warning(png_ptr, "Invalid pHYs after IDAT");
1839 png_crc_finish(png_ptr, length);
1840 return;
1841 }
1842
1843 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
1844 {
1845 png_warning(png_ptr, "Duplicate pHYs chunk");
1846 png_crc_finish(png_ptr, length);
1847 return;
1848 }
1849
1850 if (length != 9)
1851 {
1852 png_warning(png_ptr, "Incorrect pHYs chunk length");
1853 png_crc_finish(png_ptr, length);
1854 return;
1855 }
1856
1857 png_crc_read(png_ptr, buf, 9);
1858
1859 if (png_crc_finish(png_ptr, 0))
1860 return;
1861
1862 res_x = png_get_uint_32(buf);
1863 res_y = png_get_uint_32(buf + 4);
1864 unit_type = buf[8];
1865 png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
1866}
1867#endif
1868
1869#ifdef PNG_READ_oFFs_SUPPORTED
1870void /* PRIVATE */
1871png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1872{
1873 png_byte buf[9];
1874 png_int_32 offset_x, offset_y;
1875 int unit_type;
1876
1877 png_debug(1, "in png_handle_oFFs");
1878
1879 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1880 png_error(png_ptr, "Missing IHDR before oFFs");
1881
1882 else if (png_ptr->mode & PNG_HAVE_IDAT)
1883 {
1884 png_warning(png_ptr, "Invalid oFFs after IDAT");
1885 png_crc_finish(png_ptr, length);
1886 return;
1887 }
1888
1889 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
1890 {
1891 png_warning(png_ptr, "Duplicate oFFs chunk");
1892 png_crc_finish(png_ptr, length);
1893 return;
1894 }
1895
1896 if (length != 9)
1897 {
1898 png_warning(png_ptr, "Incorrect oFFs chunk length");
1899 png_crc_finish(png_ptr, length);
1900 return;
1901 }
1902
1903 png_crc_read(png_ptr, buf, 9);
1904
1905 if (png_crc_finish(png_ptr, 0))
1906 return;
1907
1908 offset_x = png_get_int_32(buf);
1909 offset_y = png_get_int_32(buf + 4);
1910 unit_type = buf[8];
1911 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
1912}
1913#endif
1914
1915#ifdef PNG_READ_pCAL_SUPPORTED
1916/* Read the pCAL chunk (described in the PNG Extensions document) */
1917void /* PRIVATE */
1918png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1919{
1920 png_int_32 X0, X1;
1921 png_byte type, nparams;
1922 png_charp buf, units, endptr;
1923 png_charpp params;
1924 png_size_t slength;
1925 int i;
1926
1927 png_debug(1, "in png_handle_pCAL");
1928
1929 if (!(png_ptr->mode & PNG_HAVE_IHDR))
1930 png_error(png_ptr, "Missing IHDR before pCAL");
1931
1932 else if (png_ptr->mode & PNG_HAVE_IDAT)
1933 {
1934 png_warning(png_ptr, "Invalid pCAL after IDAT");
1935 png_crc_finish(png_ptr, length);
1936 return;
1937 }
1938
1939 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
1940 {
1941 png_warning(png_ptr, "Duplicate pCAL chunk");
1942 png_crc_finish(png_ptr, length);
1943 return;
1944 }
1945
1946 png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",
1947 length + 1);
1948 png_free(png_ptr, png_ptr->chunkdata);
1949 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
1950
1951 if (png_ptr->chunkdata == NULL)
1952 {
1953 png_warning(png_ptr, "No memory for pCAL purpose");
1954 return;
1955 }
1956
1957 slength = length;
1958 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
1959
1960 if (png_crc_finish(png_ptr, 0))
1961 {
1962 png_free(png_ptr, png_ptr->chunkdata);
1963 png_ptr->chunkdata = NULL;
1964 return;
1965 }
1966
1967 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
1968
1969 png_debug(3, "Finding end of pCAL purpose string");
1970 for (buf = png_ptr->chunkdata; *buf; buf++)
1971 /* Empty loop */ ;
1972
1973 endptr = png_ptr->chunkdata + slength;
1974
1975 /* We need to have at least 12 bytes after the purpose string
1976 * in order to get the parameter information.
1977 */
1978 if (endptr <= buf + 12)
1979 {
1980 png_warning(png_ptr, "Invalid pCAL data");
1981 png_free(png_ptr, png_ptr->chunkdata);
1982 png_ptr->chunkdata = NULL;
1983 return;
1984 }
1985
1986 png_debug(3, "Reading pCAL X0, X1, type, nparams, and units");
1987 X0 = png_get_int_32((png_bytep)buf+1);
1988 X1 = png_get_int_32((png_bytep)buf+5);
1989 type = buf[9];
1990 nparams = buf[10];
1991 units = buf + 11;
1992
1993 png_debug(3, "Checking pCAL equation type and number of parameters");
1994 /* Check that we have the right number of parameters for known
1995 * equation types.
1996 */
1997 if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
1998 (type == PNG_EQUATION_BASE_E && nparams != 3) ||
1999 (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
2000 (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
2001 {
2002 png_warning(png_ptr, "Invalid pCAL parameters for equation type");
2003 png_free(png_ptr, png_ptr->chunkdata);
2004 png_ptr->chunkdata = NULL;
2005 return;
2006 }
2007
2008 else if (type >= PNG_EQUATION_LAST)
2009 {
2010 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
2011 }
2012
2013 for (buf = units; *buf; buf++)
2014 /* Empty loop to move past the units string. */ ;
2015
2016 png_debug(3, "Allocating pCAL parameters array");
2017
2018 params = (png_charpp)png_malloc_warn(png_ptr,
2019 (png_size_t)(nparams * png_sizeof(png_charp)));
2020
2021 if (params == NULL)
2022 {
2023 png_free(png_ptr, png_ptr->chunkdata);
2024 png_ptr->chunkdata = NULL;
2025 png_warning(png_ptr, "No memory for pCAL params");
2026 return;
2027 }
2028
2029 /* Get pointers to the start of each parameter string. */
2030 for (i = 0; i < (int)nparams; i++)
2031 {
2032 buf++; /* Skip the null string terminator from previous parameter. */
2033
2034 png_debug1(3, "Reading pCAL parameter %d", i);
2035
2036 for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
2037 /* Empty loop to move past each parameter string */ ;
2038
2039 /* Make sure we haven't run out of data yet */
2040 if (buf > endptr)
2041 {
2042 png_warning(png_ptr, "Invalid pCAL data");
2043 png_free(png_ptr, png_ptr->chunkdata);
2044 png_ptr->chunkdata = NULL;
2045 png_free(png_ptr, params);
2046 return;
2047 }
2048 }
2049
2050 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
2051 units, params);
2052
2053 png_free(png_ptr, png_ptr->chunkdata);
2054 png_ptr->chunkdata = NULL;
2055 png_free(png_ptr, params);
2056}
2057#endif
2058
2059#ifdef PNG_READ_sCAL_SUPPORTED
2060/* Read the sCAL chunk */
2061void /* PRIVATE */
2062png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2063{
2064 png_size_t slength, i;
2065 int state;
2066
2067 png_debug(1, "in png_handle_sCAL");
2068
2069 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2070 png_error(png_ptr, "Missing IHDR before sCAL");
2071
2072 else if (png_ptr->mode & PNG_HAVE_IDAT)
2073 {
2074 png_warning(png_ptr, "Invalid sCAL after IDAT");
2075 png_crc_finish(png_ptr, length);
2076 return;
2077 }
2078
2079 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
2080 {
2081 png_warning(png_ptr, "Duplicate sCAL chunk");
2082 png_crc_finish(png_ptr, length);
2083 return;
2084 }
2085
2086 /* Need unit type, width, \0, height: minimum 4 bytes */
2087 else if (length < 4)
2088 {
2089 png_warning(png_ptr, "sCAL chunk too short");
2090 png_crc_finish(png_ptr, length);
2091 return;
2092 }
2093
2094 png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
2095 length + 1);
2096
2097 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
2098
2099 if (png_ptr->chunkdata == NULL)
2100 {
2101 png_warning(png_ptr, "Out of memory while processing sCAL chunk");
2102 png_crc_finish(png_ptr, length);
2103 return;
2104 }
2105
2106 slength = length;
2107 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
2108 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
2109
2110 if (png_crc_finish(png_ptr, 0))
2111 {
2112 png_free(png_ptr, png_ptr->chunkdata);
2113 png_ptr->chunkdata = NULL;
2114 return;
2115 }
2116
2117 /* Validate the unit. */
2118 if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2)
2119 {
2120 png_warning(png_ptr, "Invalid sCAL ignored: invalid unit");
2121 png_free(png_ptr, png_ptr->chunkdata);
2122 png_ptr->chunkdata = NULL;
2123 return;
2124 }
2125
2126 /* Validate the ASCII numbers, need two ASCII numbers separated by
2127 * a '\0' and they need to fit exactly in the chunk data.
2128 */
2129 i = 1;
2130 state = 0;
2131
2132 if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
2133 i >= slength || png_ptr->chunkdata[i++] != 0)
2134 png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format");
2135
2136 else if (!PNG_FP_IS_POSITIVE(state))
2137 png_warning(png_ptr, "Invalid sCAL chunk ignored: non-positive width");
2138
2139 else
2140 {
2141 png_size_t heighti = i;
2142
2143 state = 0;
2144 if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
2145 i != slength)
2146 png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format");
2147
2148 else if (!PNG_FP_IS_POSITIVE(state))
2149 png_warning(png_ptr,
2150 "Invalid sCAL chunk ignored: non-positive height");
2151
2152 else
2153 /* This is the (only) success case. */
2154 png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0],
2155 png_ptr->chunkdata+1, png_ptr->chunkdata+heighti);
2156 }
2157
2158 /* Clean up - just free the temporarily allocated buffer. */
2159 png_free(png_ptr, png_ptr->chunkdata);
2160 png_ptr->chunkdata = NULL;
2161}
2162#endif
2163
2164#ifdef PNG_READ_tIME_SUPPORTED
2165void /* PRIVATE */
2166png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2167{
2168 png_byte buf[7];
2169 png_time mod_time;
2170
2171 png_debug(1, "in png_handle_tIME");
2172
2173 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2174 png_error(png_ptr, "Out of place tIME chunk");
2175
2176 else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
2177 {
2178 png_warning(png_ptr, "Duplicate tIME chunk");
2179 png_crc_finish(png_ptr, length);
2180 return;
2181 }
2182
2183 if (png_ptr->mode & PNG_HAVE_IDAT)
2184 png_ptr->mode |= PNG_AFTER_IDAT;
2185
2186 if (length != 7)
2187 {
2188 png_warning(png_ptr, "Incorrect tIME chunk length");
2189 png_crc_finish(png_ptr, length);
2190 return;
2191 }
2192
2193 png_crc_read(png_ptr, buf, 7);
2194
2195 if (png_crc_finish(png_ptr, 0))
2196 return;
2197
2198 mod_time.second = buf[6];
2199 mod_time.minute = buf[5];
2200 mod_time.hour = buf[4];
2201 mod_time.day = buf[3];
2202 mod_time.month = buf[2];
2203 mod_time.year = png_get_uint_16(buf);
2204
2205 png_set_tIME(png_ptr, info_ptr, &mod_time);
2206}
2207#endif
2208
2209#ifdef PNG_READ_tEXt_SUPPORTED
2210/* Note: this does not properly handle chunks that are > 64K under DOS */
2211void /* PRIVATE */
2212png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2213{
2214 png_textp text_ptr;
2215 png_charp key;
2216 png_charp text;
2217 png_uint_32 skip = 0;
2218 png_size_t slength;
2219 int ret;
2220
2221 png_debug(1, "in png_handle_tEXt");
2222
2223#ifdef PNG_USER_LIMITS_SUPPORTED
2224 if (png_ptr->user_chunk_cache_max != 0)
2225 {
2226 if (png_ptr->user_chunk_cache_max == 1)
2227 {
2228 png_crc_finish(png_ptr, length);
2229 return;
2230 }
2231
2232 if (--png_ptr->user_chunk_cache_max == 1)
2233 {
2234 png_warning(png_ptr, "No space in chunk cache for tEXt");
2235 png_crc_finish(png_ptr, length);
2236 return;
2237 }
2238 }
2239#endif
2240
2241 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2242 png_error(png_ptr, "Missing IHDR before tEXt");
2243
2244 if (png_ptr->mode & PNG_HAVE_IDAT)
2245 png_ptr->mode |= PNG_AFTER_IDAT;
2246
2247#ifdef PNG_MAX_MALLOC_64K
2248 if (length > (png_uint_32)65535L)
2249 {
2250 png_warning(png_ptr, "tEXt chunk too large to fit in memory");
2251 skip = length - (png_uint_32)65535L;
2252 length = (png_uint_32)65535L;
2253 }
2254#endif
2255
2256 png_free(png_ptr, png_ptr->chunkdata);
2257
2258 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
2259
2260 if (png_ptr->chunkdata == NULL)
2261 {
2262 png_warning(png_ptr, "No memory to process text chunk");
2263 return;
2264 }
2265
2266 slength = length;
2267 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
2268
2269 if (png_crc_finish(png_ptr, skip))
2270 {
2271 png_free(png_ptr, png_ptr->chunkdata);
2272 png_ptr->chunkdata = NULL;
2273 return;
2274 }
2275
2276 key = png_ptr->chunkdata;
2277
2278 key[slength] = 0x00;
2279
2280 for (text = key; *text; text++)
2281 /* Empty loop to find end of key */ ;
2282
2283 if (text != key + slength)
2284 text++;
2285
2286 text_ptr = (png_textp)png_malloc_warn(png_ptr,
2287 png_sizeof(png_text));
2288
2289 if (text_ptr == NULL)
2290 {
2291 png_warning(png_ptr, "Not enough memory to process text chunk");
2292 png_free(png_ptr, png_ptr->chunkdata);
2293 png_ptr->chunkdata = NULL;
2294 return;
2295 }
2296
2297 text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
2298 text_ptr->key = key;
2299 text_ptr->lang = NULL;
2300 text_ptr->lang_key = NULL;
2301 text_ptr->itxt_length = 0;
2302 text_ptr->text = text;
2303 text_ptr->text_length = png_strlen(text);
2304
2305 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
2306
2307 png_free(png_ptr, png_ptr->chunkdata);
2308 png_ptr->chunkdata = NULL;
2309 png_free(png_ptr, text_ptr);
2310
2311 if (ret)
2312 png_warning(png_ptr, "Insufficient memory to process text chunk");
2313}
2314#endif
2315
2316#ifdef PNG_READ_zTXt_SUPPORTED
2317/* Note: this does not correctly handle chunks that are > 64K under DOS */
2318void /* PRIVATE */
2319png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2320{
2321 png_textp text_ptr;
2322 png_charp text;
2323 int comp_type;
2324 int ret;
2325 png_size_t slength, prefix_len, data_len;
2326
2327 png_debug(1, "in png_handle_zTXt");
2328
2329#ifdef PNG_USER_LIMITS_SUPPORTED
2330 if (png_ptr->user_chunk_cache_max != 0)
2331 {
2332 if (png_ptr->user_chunk_cache_max == 1)
2333 {
2334 png_crc_finish(png_ptr, length);
2335 return;
2336 }
2337
2338 if (--png_ptr->user_chunk_cache_max == 1)
2339 {
2340 png_warning(png_ptr, "No space in chunk cache for zTXt");
2341 png_crc_finish(png_ptr, length);
2342 return;
2343 }
2344 }
2345#endif
2346
2347 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2348 png_error(png_ptr, "Missing IHDR before zTXt");
2349
2350 if (png_ptr->mode & PNG_HAVE_IDAT)
2351 png_ptr->mode |= PNG_AFTER_IDAT;
2352
2353#ifdef PNG_MAX_MALLOC_64K
2354 /* We will no doubt have problems with chunks even half this size, but
2355 * there is no hard and fast rule to tell us where to stop.
2356 */
2357 if (length > (png_uint_32)65535L)
2358 {
2359 png_warning(png_ptr, "zTXt chunk too large to fit in memory");
2360 png_crc_finish(png_ptr, length);
2361 return;
2362 }
2363#endif
2364
2365 png_free(png_ptr, png_ptr->chunkdata);
2366 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
2367
2368 if (png_ptr->chunkdata == NULL)
2369 {
2370 png_warning(png_ptr, "Out of memory processing zTXt chunk");
2371 return;
2372 }
2373
2374 slength = length;
2375 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
2376
2377 if (png_crc_finish(png_ptr, 0))
2378 {
2379 png_free(png_ptr, png_ptr->chunkdata);
2380 png_ptr->chunkdata = NULL;
2381 return;
2382 }
2383
2384 png_ptr->chunkdata[slength] = 0x00;
2385
2386 for (text = png_ptr->chunkdata; *text; text++)
2387 /* Empty loop */ ;
2388
2389 /* zTXt must have some text after the chunkdataword */
2390 if (text >= png_ptr->chunkdata + slength - 2)
2391 {
2392 png_warning(png_ptr, "Truncated zTXt chunk");
2393 png_free(png_ptr, png_ptr->chunkdata);
2394 png_ptr->chunkdata = NULL;
2395 return;
2396 }
2397
2398 else
2399 {
2400 comp_type = *(++text);
2401
2402 if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
2403 {
2404 png_warning(png_ptr, "Unknown compression type in zTXt chunk");
2405 comp_type = PNG_TEXT_COMPRESSION_zTXt;
2406 }
2407
2408 text++; /* Skip the compression_method byte */
2409 }
2410
2411 prefix_len = text - png_ptr->chunkdata;
2412
2413 png_decompress_chunk(png_ptr, comp_type,
2414 (png_size_t)length, prefix_len, &data_len);
2415
2416 text_ptr = (png_textp)png_malloc_warn(png_ptr,
2417 png_sizeof(png_text));
2418
2419 if (text_ptr == NULL)
2420 {
2421 png_warning(png_ptr, "Not enough memory to process zTXt chunk");
2422 png_free(png_ptr, png_ptr->chunkdata);
2423 png_ptr->chunkdata = NULL;
2424 return;
2425 }
2426
2427 text_ptr->compression = comp_type;
2428 text_ptr->key = png_ptr->chunkdata;
2429 text_ptr->lang = NULL;
2430 text_ptr->lang_key = NULL;
2431 text_ptr->itxt_length = 0;
2432 text_ptr->text = png_ptr->chunkdata + prefix_len;
2433 text_ptr->text_length = data_len;
2434
2435 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
2436
2437 png_free(png_ptr, text_ptr);
2438 png_free(png_ptr, png_ptr->chunkdata);
2439 png_ptr->chunkdata = NULL;
2440
2441 if (ret)
2442 png_error(png_ptr, "Insufficient memory to store zTXt chunk");
2443}
2444#endif
2445
2446#ifdef PNG_READ_iTXt_SUPPORTED
2447/* Note: this does not correctly handle chunks that are > 64K under DOS */
2448void /* PRIVATE */
2449png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2450{
2451 png_textp text_ptr;
2452 png_charp key, lang, text, lang_key;
2453 int comp_flag;
2454 int comp_type = 0;
2455 int ret;
2456 png_size_t slength, prefix_len, data_len;
2457
2458 png_debug(1, "in png_handle_iTXt");
2459
2460#ifdef PNG_USER_LIMITS_SUPPORTED
2461 if (png_ptr->user_chunk_cache_max != 0)
2462 {
2463 if (png_ptr->user_chunk_cache_max == 1)
2464 {
2465 png_crc_finish(png_ptr, length);
2466 return;
2467 }
2468
2469 if (--png_ptr->user_chunk_cache_max == 1)
2470 {
2471 png_warning(png_ptr, "No space in chunk cache for iTXt");
2472 png_crc_finish(png_ptr, length);
2473 return;
2474 }
2475 }
2476#endif
2477
2478 if (!(png_ptr->mode & PNG_HAVE_IHDR))
2479 png_error(png_ptr, "Missing IHDR before iTXt");
2480
2481 if (png_ptr->mode & PNG_HAVE_IDAT)
2482 png_ptr->mode |= PNG_AFTER_IDAT;
2483
2484#ifdef PNG_MAX_MALLOC_64K
2485 /* We will no doubt have problems with chunks even half this size, but
2486 * there is no hard and fast rule to tell us where to stop.
2487 */
2488 if (length > (png_uint_32)65535L)
2489 {
2490 png_warning(png_ptr, "iTXt chunk too large to fit in memory");
2491 png_crc_finish(png_ptr, length);
2492 return;
2493 }
2494#endif
2495
2496 png_free(png_ptr, png_ptr->chunkdata);
2497 png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
2498
2499 if (png_ptr->chunkdata == NULL)
2500 {
2501 png_warning(png_ptr, "No memory to process iTXt chunk");
2502 return;
2503 }
2504
2505 slength = length;
2506 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
2507
2508 if (png_crc_finish(png_ptr, 0))
2509 {
2510 png_free(png_ptr, png_ptr->chunkdata);
2511 png_ptr->chunkdata = NULL;
2512 return;
2513 }
2514
2515 png_ptr->chunkdata[slength] = 0x00;
2516
2517 for (lang = png_ptr->chunkdata; *lang; lang++)
2518 /* Empty loop */ ;
2519
2520 lang++; /* Skip NUL separator */
2521
2522 /* iTXt must have a language tag (possibly empty), two compression bytes,
2523 * translated keyword (possibly empty), and possibly some text after the
2524 * keyword
2525 */
2526
2527 if (lang >= png_ptr->chunkdata + slength - 3)
2528 {
2529 png_warning(png_ptr, "Truncated iTXt chunk");
2530 png_free(png_ptr, png_ptr->chunkdata);
2531 png_ptr->chunkdata = NULL;
2532 return;
2533 }
2534
2535 else
2536 {
2537 comp_flag = *lang++;
2538 comp_type = *lang++;
2539 }
2540
2541 if (comp_type || (comp_flag && comp_flag != PNG_TEXT_COMPRESSION_zTXt))
2542 {
2543 png_warning(png_ptr, "Unknown iTXt compression type or method");
2544 png_free(png_ptr, png_ptr->chunkdata);
2545 png_ptr->chunkdata = NULL;
2546 return;
2547 }
2548
2549 for (lang_key = lang; *lang_key; lang_key++)
2550 /* Empty loop */ ;
2551
2552 lang_key++; /* Skip NUL separator */
2553
2554 if (lang_key >= png_ptr->chunkdata + slength)
2555 {
2556 png_warning(png_ptr, "Truncated iTXt chunk");
2557 png_free(png_ptr, png_ptr->chunkdata);
2558 png_ptr->chunkdata = NULL;
2559 return;
2560 }
2561
2562 for (text = lang_key; *text; text++)
2563 /* Empty loop */ ;
2564
2565 text++; /* Skip NUL separator */
2566
2567 if (text >= png_ptr->chunkdata + slength)
2568 {
2569 png_warning(png_ptr, "Malformed iTXt chunk");
2570 png_free(png_ptr, png_ptr->chunkdata);
2571 png_ptr->chunkdata = NULL;
2572 return;
2573 }
2574
2575 prefix_len = text - png_ptr->chunkdata;
2576
2577 key=png_ptr->chunkdata;
2578
2579 if (comp_flag)
2580 png_decompress_chunk(png_ptr, comp_type,
2581 (size_t)length, prefix_len, &data_len);
2582
2583 else
2584 data_len = png_strlen(png_ptr->chunkdata + prefix_len);
2585
2586 text_ptr = (png_textp)png_malloc_warn(png_ptr,
2587 png_sizeof(png_text));
2588
2589 if (text_ptr == NULL)
2590 {
2591 png_warning(png_ptr, "Not enough memory to process iTXt chunk");
2592 png_free(png_ptr, png_ptr->chunkdata);
2593 png_ptr->chunkdata = NULL;
2594 return;
2595 }
2596
2597 text_ptr->compression = (int)comp_flag + 1;
2598 text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
2599 text_ptr->lang = png_ptr->chunkdata + (lang - key);
2600 text_ptr->itxt_length = data_len;
2601 text_ptr->text_length = 0;
2602 text_ptr->key = png_ptr->chunkdata;
2603 text_ptr->text = png_ptr->chunkdata + prefix_len;
2604
2605 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
2606
2607 png_free(png_ptr, text_ptr);
2608 png_free(png_ptr, png_ptr->chunkdata);
2609 png_ptr->chunkdata = NULL;
2610
2611 if (ret)
2612 png_error(png_ptr, "Insufficient memory to store iTXt chunk");
2613}
2614#endif
2615
2616/* This function is called when we haven't found a handler for a
2617 * chunk. If there isn't a problem with the chunk itself (ie bad
2618 * chunk name, CRC, or a critical chunk), the chunk is silently ignored
2619 * -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
2620 * case it will be saved away to be written out later.
2621 */
2622void /* PRIVATE */
2623png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2624{
2625 png_uint_32 skip = 0;
2626
2627 png_debug(1, "in png_handle_unknown");
2628
2629#ifdef PNG_USER_LIMITS_SUPPORTED
2630 if (png_ptr->user_chunk_cache_max != 0)
2631 {
2632 if (png_ptr->user_chunk_cache_max == 1)
2633 {
2634 png_crc_finish(png_ptr, length);
2635 return;
2636 }
2637
2638 if (--png_ptr->user_chunk_cache_max == 1)
2639 {
2640 png_warning(png_ptr, "No space in chunk cache for unknown chunk");
2641 png_crc_finish(png_ptr, length);
2642 return;
2643 }
2644 }
2645#endif
2646
2647 if (png_ptr->mode & PNG_HAVE_IDAT)
2648 {
2649 if (png_ptr->chunk_name != png_IDAT)
2650 png_ptr->mode |= PNG_AFTER_IDAT;
2651 }
2652
2653 if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
2654 {
2655#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2656 if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) !=
2657 PNG_HANDLE_CHUNK_ALWAYS
2658#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2659 && png_ptr->read_user_chunk_fn == NULL
2660#endif
2661 )
2662#endif
2663 png_chunk_error(png_ptr, "unknown critical chunk");
2664 }
2665
2666#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
2667 if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
2668#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2669 || (png_ptr->read_user_chunk_fn != NULL)
2670#endif
2671 )
2672 {
2673#ifdef PNG_MAX_MALLOC_64K
2674 if (length > 65535)
2675 {
2676 png_warning(png_ptr, "unknown chunk too large to fit in memory");
2677 skip = length - 65535;
2678 length = 65535;
2679 }
2680#endif
2681
2682 /* TODO: this code is very close to the unknown handling in pngpread.c,
2683 * maybe it can be put into a common utility routine?
2684 * png_struct::unknown_chunk is just used as a temporary variable, along
2685 * with the data into which the chunk is read. These can be eliminated.
2686 */
2687 PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
2688 png_ptr->unknown_chunk.size = (png_size_t)length;
2689
2690 if (length == 0)
2691 png_ptr->unknown_chunk.data = NULL;
2692
2693 else
2694 {
2695 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
2696 png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
2697 }
2698
2699#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
2700 if (png_ptr->read_user_chunk_fn != NULL)
2701 {
2702 /* Callback to user unknown chunk handler */
2703 int ret;
2704
2705 ret = (*(png_ptr->read_user_chunk_fn))
2706 (png_ptr, &png_ptr->unknown_chunk);
2707
2708 if (ret < 0)
2709 png_chunk_error(png_ptr, "error in user chunk");
2710
2711 if (ret == 0)
2712 {
2713 if (PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
2714 {
2715#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
2716 if (png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name) !=
2717 PNG_HANDLE_CHUNK_ALWAYS)
2718#endif
2719 png_chunk_error(png_ptr, "unknown critical chunk");
2720 }
2721
2722 png_set_unknown_chunks(png_ptr, info_ptr,
2723 &png_ptr->unknown_chunk, 1);
2724 }
2725 }
2726
2727 else
2728#endif
2729 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
2730
2731 png_free(png_ptr, png_ptr->unknown_chunk.data);
2732 png_ptr->unknown_chunk.data = NULL;
2733 }
2734
2735 else
2736#endif
2737 skip = length;
2738
2739 png_crc_finish(png_ptr, skip);
2740
2741#ifndef PNG_READ_USER_CHUNKS_SUPPORTED
2742 PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */
2743#endif
2744}
2745
2746/* This function is called to verify that a chunk name is valid.
2747 * This function can't have the "critical chunk check" incorporated
2748 * into it, since in the future we will need to be able to call user
2749 * functions to handle unknown critical chunks after we check that
2750 * the chunk name itself is valid.
2751 */
2752
2753/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is:
2754 *
2755 * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
2756 */
2757
2758void /* PRIVATE */
2759png_check_chunk_name(png_structp png_ptr, png_uint_32 chunk_name)
2760{
2761 int i;
2762
2763 png_debug(1, "in png_check_chunk_name");
2764
2765 for (i=1; i<=4; ++i)
2766 {
2767 int c = chunk_name & 0xff;
2768
2769 if (c < 65 || c > 122 || (c > 90 && c < 97))
2770 png_chunk_error(png_ptr, "invalid chunk type");
2771
2772 chunk_name >>= 8;
2773 }
2774}
2775
2776/* Combines the row recently read in with the existing pixels in the row. This
2777 * routine takes care of alpha and transparency if requested. This routine also
2778 * handles the two methods of progressive display of interlaced images,
2779 * depending on the 'display' value; if 'display' is true then the whole row
2780 * (dp) is filled from the start by replicating the available pixels. If
2781 * 'display' is false only those pixels present in the pass are filled in.
2782 */
2783void /* PRIVATE */
2784png_combine_row(png_structp png_ptr, png_bytep dp, int display)
2785{
2786 unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
2787 png_const_bytep sp = png_ptr->row_buf + 1;
2788 png_uint_32 row_width = png_ptr->width;
2789 unsigned int pass = png_ptr->pass;
2790 png_bytep end_ptr = 0;
2791 png_byte end_byte = 0;
2792 unsigned int end_mask;
2793
2794 png_debug(1, "in png_combine_row");
2795
2796 /* Added in 1.5.6: it should not be possible to enter this routine until at
2797 * least one row has been read from the PNG data and transformed.
2798 */
2799 if (pixel_depth == 0)
2800 png_error(png_ptr, "internal row logic error");
2801
2802 /* Added in 1.5.4: the pixel depth should match the information returned by
2803 * any call to png_read_update_info at this point. Do not continue if we got
2804 * this wrong.
2805 */
2806 if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
2807 PNG_ROWBYTES(pixel_depth, row_width))
2808 png_error(png_ptr, "internal row size calculation error");
2809
2810 /* Don't expect this to ever happen: */
2811 if (row_width == 0)
2812 png_error(png_ptr, "internal row width error");
2813
2814 /* Preserve the last byte in cases where only part of it will be overwritten,
2815 * the multiply below may overflow, we don't care because ANSI-C guarantees
2816 * we get the low bits.
2817 */
2818 end_mask = (pixel_depth * row_width) & 7;
2819 if (end_mask != 0)
2820 {
2821 /* end_ptr == NULL is a flag to say do nothing */
2822 end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1;
2823 end_byte = *end_ptr;
2824# ifdef PNG_READ_PACKSWAP_SUPPORTED
2825 if (png_ptr->transformations & PNG_PACKSWAP) /* little-endian byte */
2826 end_mask = 0xff << end_mask;
2827
2828 else /* big-endian byte */
2829# endif
2830 end_mask = 0xff >> end_mask;
2831 /* end_mask is now the bits to *keep* from the destination row */
2832 }
2833
2834 /* For non-interlaced images this reduces to a png_memcpy(). A png_memcpy()
2835 * will also happen if interlacing isn't supported or if the application
2836 * does not call png_set_interlace_handling(). In the latter cases the
2837 * caller just gets a sequence of the unexpanded rows from each interlace
2838 * pass.
2839 */
2840#ifdef PNG_READ_INTERLACING_SUPPORTED
2841 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE) &&
2842 pass < 6 && (display == 0 ||
2843 /* The following copies everything for 'display' on passes 0, 2 and 4. */
2844 (display == 1 && (pass & 1) != 0)))
2845 {
2846 /* Narrow images may have no bits in a pass; the caller should handle
2847 * this, but this test is cheap:
2848 */
2849 if (row_width <= PNG_PASS_START_COL(pass))
2850 return;
2851
2852 if (pixel_depth < 8)
2853 {
2854 /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
2855 * into 32 bits, then a single loop over the bytes using the four byte
2856 * values in the 32-bit mask can be used. For the 'display' option the
2857 * expanded mask may also not require any masking within a byte. To
2858 * make this work the PACKSWAP option must be taken into account - it
2859 * simply requires the pixels to be reversed in each byte.
2860 *
2861 * The 'regular' case requires a mask for each of the first 6 passes,
2862 * the 'display' case does a copy for the even passes in the range
2863 * 0..6. This has already been handled in the test above.
2864 *
2865 * The masks are arranged as four bytes with the first byte to use in
2866 * the lowest bits (little-endian) regardless of the order (PACKSWAP or
2867 * not) of the pixels in each byte.
2868 *
2869 * NOTE: the whole of this logic depends on the caller of this function
2870 * only calling it on rows appropriate to the pass. This function only
2871 * understands the 'x' logic; the 'y' logic is handled by the caller.
2872 *
2873 * The following defines allow generation of compile time constant bit
2874 * masks for each pixel depth and each possibility of swapped or not
2875 * swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index,
2876 * is in the range 0..7; and the result is 1 if the pixel is to be
2877 * copied in the pass, 0 if not. 'S' is for the sparkle method, 'B'
2878 * for the block method.
2879 *
2880 * With some compilers a compile time expression of the general form:
2881 *
2882 * (shift >= 32) ? (a >> (shift-32)) : (b >> shift)
2883 *
2884 * Produces warnings with values of 'shift' in the range 33 to 63
2885 * because the right hand side of the ?: expression is evaluated by
2886 * the compiler even though it isn't used. Microsoft Visual C (various
2887 * versions) and the Intel C compiler are known to do this. To avoid
2888 * this the following macros are used in 1.5.6. This is a temporary
2889 * solution to avoid destabilizing the code during the release process.
2890 */
2891# if PNG_USE_COMPILE_TIME_MASKS
2892# define PNG_LSR(x,s) ((x)>>((s) & 0x1f))
2893# define PNG_LSL(x,s) ((x)<<((s) & 0x1f))
2894# else
2895# define PNG_LSR(x,s) ((x)>>(s))
2896# define PNG_LSL(x,s) ((x)<<(s))
2897# endif
2898# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\
2899 PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1)
2900# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\
2901 PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1)
2902
2903 /* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is
2904 * little endian - the first pixel is at bit 0 - however the extra
2905 * parameter 's' can be set to cause the mask position to be swapped
2906 * within each byte, to match the PNG format. This is done by XOR of
2907 * the shift with 7, 6 or 4 for bit depths 1, 2 and 4.
2908 */
2909# define PIXEL_MASK(p,x,d,s) \
2910 (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0))))
2911
2912 /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.
2913 */
2914# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
2915# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
2916
2917 /* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp
2918 * cases the result needs replicating, for the 4-bpp case the above
2919 * generates a full 32 bits.
2920 */
2921# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
2922
2923# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\
2924 S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\
2925 S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)
2926
2927# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\
2928 B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\
2929 B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)
2930
2931#if PNG_USE_COMPILE_TIME_MASKS
2932 /* Utility macros to construct all the masks for a depth/swap
2933 * combination. The 's' parameter says whether the format is PNG
2934 * (big endian bytes) or not. Only the three odd-numbered passes are
2935 * required for the display/block algorithm.
2936 */
2937# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
2938 S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }
2939
2940# define B_MASKS(d,s) { B_MASK(1,d,s), S_MASK(3,d,s), S_MASK(5,d,s) }
2941
2942# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))
2943
2944 /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
2945 * then pass:
2946 */
2947 static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
2948 {
2949 /* Little-endian byte masks for PACKSWAP */
2950 { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
2951 /* Normal (big-endian byte) masks - PNG format */
2952 { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) }
2953 };
2954
2955 /* display_mask has only three entries for the odd passes, so index by
2956 * pass>>1.
2957 */
2958 static PNG_CONST png_uint_32 display_mask[2][3][3] =
2959 {
2960 /* Little-endian byte masks for PACKSWAP */
2961 { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
2962 /* Normal (big-endian byte) masks - PNG format */
2963 { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) }
2964 };
2965
2966# define MASK(pass,depth,display,png)\
2967 ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\
2968 row_mask[png][DEPTH_INDEX(depth)][pass])
2969
2970#else /* !PNG_USE_COMPILE_TIME_MASKS */
2971 /* This is the runtime alternative: it seems unlikely that this will
2972 * ever be either smaller or faster than the compile time approach.
2973 */
2974# define MASK(pass,depth,display,png)\
2975 ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))
2976#endif /* !PNG_USE_COMPILE_TIME_MASKS */
2977
2978 /* Use the appropriate mask to copy the required bits. In some cases
2979 * the byte mask will be 0 or 0xff, optimize these cases. row_width is
2980 * the number of pixels, but the code copies bytes, so it is necessary
2981 * to special case the end.
2982 */
2983 png_uint_32 pixels_per_byte = 8 / pixel_depth;
2984 png_uint_32 mask;
2985
2986# ifdef PNG_READ_PACKSWAP_SUPPORTED
2987 if (png_ptr->transformations & PNG_PACKSWAP)
2988 mask = MASK(pass, pixel_depth, display, 0);
2989
2990 else
2991# endif
2992 mask = MASK(pass, pixel_depth, display, 1);
2993
2994 for (;;)
2995 {
2996 png_uint_32 m;
2997
2998 /* It doesn't matter in the following if png_uint_32 has more than
2999 * 32 bits because the high bits always match those in m<<24; it is,
3000 * however, essential to use OR here, not +, because of this.
3001 */
3002 m = mask;
3003 mask = (m >> 8) | (m << 24); /* rotate right to good compilers */
3004 m &= 0xff;
3005
3006 if (m != 0) /* something to copy */
3007 {
3008 if (m != 0xff)
3009 *dp = (png_byte)((*dp & ~m) | (*sp & m));
3010 else
3011 *dp = *sp;
3012 }
3013
3014 /* NOTE: this may overwrite the last byte with garbage if the image
3015 * is not an exact number of bytes wide; libpng has always done
3016 * this.
3017 */
3018 if (row_width <= pixels_per_byte)
3019 break; /* May need to restore part of the last byte */
3020
3021 row_width -= pixels_per_byte;
3022 ++dp;
3023 ++sp;
3024 }
3025 }
3026
3027 else /* pixel_depth >= 8 */
3028 {
3029 unsigned int bytes_to_copy, bytes_to_jump;
3030
3031 /* Validate the depth - it must be a multiple of 8 */
3032 if (pixel_depth & 7)
3033 png_error(png_ptr, "invalid user transform pixel depth");
3034
3035 pixel_depth >>= 3; /* now in bytes */
3036 row_width *= pixel_depth;
3037
3038 /* Regardless of pass number the Adam 7 interlace always results in a
3039 * fixed number of pixels to copy then to skip. There may be a
3040 * different number of pixels to skip at the start though.
3041 */
3042 {
3043 unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth;
3044
3045 row_width -= offset;
3046 dp += offset;
3047 sp += offset;
3048 }
3049
3050 /* Work out the bytes to copy. */
3051 if (display)
3052 {
3053 /* When doing the 'block' algorithm the pixel in the pass gets
3054 * replicated to adjacent pixels. This is why the even (0,2,4,6)
3055 * passes are skipped above - the entire expanded row is copied.
3056 */
3057 bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
3058
3059 /* But don't allow this number to exceed the actual row width. */
3060 if (bytes_to_copy > row_width)
3061 bytes_to_copy = row_width;
3062 }
3063
3064 else /* normal row; Adam7 only ever gives us one pixel to copy. */
3065 bytes_to_copy = pixel_depth;
3066
3067 /* In Adam7 there is a constant offset between where the pixels go. */
3068 bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth;
3069
3070 /* And simply copy these bytes. Some optimization is possible here,
3071 * depending on the value of 'bytes_to_copy'. Special case the low
3072 * byte counts, which we know to be frequent.
3073 *
3074 * Notice that these cases all 'return' rather than 'break' - this
3075 * avoids an unnecessary test on whether to restore the last byte
3076 * below.
3077 */
3078 switch (bytes_to_copy)
3079 {
3080 case 1:
3081 for (;;)
3082 {
3083 *dp = *sp;
3084
3085 if (row_width <= bytes_to_jump)
3086 return;
3087
3088 dp += bytes_to_jump;
3089 sp += bytes_to_jump;
3090 row_width -= bytes_to_jump;
3091 }
3092
3093 case 2:
3094 /* There is a possibility of a partial copy at the end here; this
3095 * slows the code down somewhat.
3096 */
3097 do
3098 {
3099 dp[0] = sp[0], dp[1] = sp[1];
3100
3101 if (row_width <= bytes_to_jump)
3102 return;
3103
3104 sp += bytes_to_jump;
3105 dp += bytes_to_jump;
3106 row_width -= bytes_to_jump;
3107 }
3108 while (row_width > 1);
3109
3110 /* And there can only be one byte left at this point: */
3111 *dp = *sp;
3112 return;
3113
3114 case 3:
3115 /* This can only be the RGB case, so each copy is exactly one
3116 * pixel and it is not necessary to check for a partial copy.
3117 */
3118 for(;;)
3119 {
3120 dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
3121
3122 if (row_width <= bytes_to_jump)
3123 return;
3124
3125 sp += bytes_to_jump;
3126 dp += bytes_to_jump;
3127 row_width -= bytes_to_jump;
3128 }
3129
3130 default:
3131#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE
3132 /* Check for double byte alignment and, if possible, use a
3133 * 16-bit copy. Don't attempt this for narrow images - ones that
3134 * are less than an interlace panel wide. Don't attempt it for
3135 * wide bytes_to_copy either - use the png_memcpy there.
3136 */
3137 if (bytes_to_copy < 16 /*else use png_memcpy*/ &&
3138 png_isaligned(dp, png_uint_16) &&
3139 png_isaligned(sp, png_uint_16) &&
3140 bytes_to_copy % sizeof (png_uint_16) == 0 &&
3141 bytes_to_jump % sizeof (png_uint_16) == 0)
3142 {
3143 /* Everything is aligned for png_uint_16 copies, but try for
3144 * png_uint_32 first.
3145 */
3146 if (png_isaligned(dp, png_uint_32) &&
3147 png_isaligned(sp, png_uint_32) &&
3148 bytes_to_copy % sizeof (png_uint_32) == 0 &&
3149 bytes_to_jump % sizeof (png_uint_32) == 0)
3150 {
3151 png_uint_32p dp32 = (png_uint_32p)dp;
3152 png_const_uint_32p sp32 = (png_const_uint_32p)sp;
3153 unsigned int skip = (bytes_to_jump-bytes_to_copy) /
3154 sizeof (png_uint_32);
3155
3156 do
3157 {
3158 size_t c = bytes_to_copy;
3159 do
3160 {
3161 *dp32++ = *sp32++;
3162 c -= sizeof (png_uint_32);
3163 }
3164 while (c > 0);
3165
3166 if (row_width <= bytes_to_jump)
3167 return;
3168
3169 dp32 += skip;
3170 sp32 += skip;
3171 row_width -= bytes_to_jump;
3172 }
3173 while (bytes_to_copy <= row_width);
3174
3175 /* Get to here when the row_width truncates the final copy.
3176 * There will be 1-3 bytes left to copy, so don't try the
3177 * 16-bit loop below.
3178 */
3179 dp = (png_bytep)dp32;
3180 sp = (png_const_bytep)sp32;
3181 do
3182 *dp++ = *sp++;
3183 while (--row_width > 0);
3184 return;
3185 }
3186
3187 /* Else do it in 16-bit quantities, but only if the size is
3188 * not too large.
3189 */
3190 else
3191 {
3192 png_uint_16p dp16 = (png_uint_16p)dp;
3193 png_const_uint_16p sp16 = (png_const_uint_16p)sp;
3194 unsigned int skip = (bytes_to_jump-bytes_to_copy) /
3195 sizeof (png_uint_16);
3196
3197 do
3198 {
3199 size_t c = bytes_to_copy;
3200 do
3201 {
3202 *dp16++ = *sp16++;
3203 c -= sizeof (png_uint_16);
3204 }
3205 while (c > 0);
3206
3207 if (row_width <= bytes_to_jump)
3208 return;
3209
3210 dp16 += skip;
3211 sp16 += skip;
3212 row_width -= bytes_to_jump;
3213 }
3214 while (bytes_to_copy <= row_width);
3215
3216 /* End of row - 1 byte left, bytes_to_copy > row_width: */
3217 dp = (png_bytep)dp16;
3218 sp = (png_const_bytep)sp16;
3219 do
3220 *dp++ = *sp++;
3221 while (--row_width > 0);
3222 return;
3223 }
3224 }
3225#endif /* PNG_ALIGN_ code */
3226
3227 /* The true default - use a png_memcpy: */
3228 for (;;)
3229 {
3230 png_memcpy(dp, sp, bytes_to_copy);
3231
3232 if (row_width <= bytes_to_jump)
3233 return;
3234
3235 sp += bytes_to_jump;
3236 dp += bytes_to_jump;
3237 row_width -= bytes_to_jump;
3238 if (bytes_to_copy > row_width)
3239 bytes_to_copy = row_width;
3240 }
3241 }
3242
3243 /* NOT REACHED*/
3244 } /* pixel_depth >= 8 */
3245
3246 /* Here if pixel_depth < 8 to check 'end_ptr' below. */
3247 }
3248 else
3249#endif
3250
3251 /* If here then the switch above wasn't used so just png_memcpy the whole row
3252 * from the temporary row buffer (notice that this overwrites the end of the
3253 * destination row if it is a partial byte.)
3254 */
3255 png_memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));
3256
3257 /* Restore the overwritten bits from the last byte if necessary. */
3258 if (end_ptr != NULL)
3259 *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
3260}
3261
3262#ifdef PNG_READ_INTERLACING_SUPPORTED
3263void /* PRIVATE */
3264png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
3265 png_uint_32 transformations /* Because these may affect the byte layout */)
3266{
3267 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3268 /* Offset to next interlace block */
3269 static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3270
3271 png_debug(1, "in png_do_read_interlace");
3272 if (row != NULL && row_info != NULL)
3273 {
3274 png_uint_32 final_width;
3275
3276 final_width = row_info->width * png_pass_inc[pass];
3277
3278 switch (row_info->pixel_depth)
3279 {
3280 case 1:
3281 {
3282 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
3283 png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
3284 int sshift, dshift;
3285 int s_start, s_end, s_inc;
3286 int jstop = png_pass_inc[pass];
3287 png_byte v;
3288 png_uint_32 i;
3289 int j;
3290
3291#ifdef PNG_READ_PACKSWAP_SUPPORTED
3292 if (transformations & PNG_PACKSWAP)
3293 {
3294 sshift = (int)((row_info->width + 7) & 0x07);
3295 dshift = (int)((final_width + 7) & 0x07);
3296 s_start = 7;
3297 s_end = 0;
3298 s_inc = -1;
3299 }
3300
3301 else
3302#endif
3303 {
3304 sshift = 7 - (int)((row_info->width + 7) & 0x07);
3305 dshift = 7 - (int)((final_width + 7) & 0x07);
3306 s_start = 0;
3307 s_end = 7;
3308 s_inc = 1;
3309 }
3310
3311 for (i = 0; i < row_info->width; i++)
3312 {
3313 v = (png_byte)((*sp >> sshift) & 0x01);
3314 for (j = 0; j < jstop; j++)
3315 {
3316 *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
3317 *dp |= (png_byte)(v << dshift);
3318
3319 if (dshift == s_end)
3320 {
3321 dshift = s_start;
3322 dp--;
3323 }
3324
3325 else
3326 dshift += s_inc;
3327 }
3328
3329 if (sshift == s_end)
3330 {
3331 sshift = s_start;
3332 sp--;
3333 }
3334
3335 else
3336 sshift += s_inc;
3337 }
3338 break;
3339 }
3340
3341 case 2:
3342 {
3343 png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
3344 png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
3345 int sshift, dshift;
3346 int s_start, s_end, s_inc;
3347 int jstop = png_pass_inc[pass];
3348 png_uint_32 i;
3349
3350#ifdef PNG_READ_PACKSWAP_SUPPORTED
3351 if (transformations & PNG_PACKSWAP)
3352 {
3353 sshift = (int)(((row_info->width + 3) & 0x03) << 1);
3354 dshift = (int)(((final_width + 3) & 0x03) << 1);
3355 s_start = 6;
3356 s_end = 0;
3357 s_inc = -2;
3358 }
3359
3360 else
3361#endif
3362 {
3363 sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
3364 dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
3365 s_start = 0;
3366 s_end = 6;
3367 s_inc = 2;
3368 }
3369
3370 for (i = 0; i < row_info->width; i++)
3371 {
3372 png_byte v;
3373 int j;
3374
3375 v = (png_byte)((*sp >> sshift) & 0x03);
3376 for (j = 0; j < jstop; j++)
3377 {
3378 *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
3379 *dp |= (png_byte)(v << dshift);
3380
3381 if (dshift == s_end)
3382 {
3383 dshift = s_start;
3384 dp--;
3385 }
3386
3387 else
3388 dshift += s_inc;
3389 }
3390
3391 if (sshift == s_end)
3392 {
3393 sshift = s_start;
3394 sp--;
3395 }
3396
3397 else
3398 sshift += s_inc;
3399 }
3400 break;
3401 }
3402
3403 case 4:
3404 {
3405 png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
3406 png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
3407 int sshift, dshift;
3408 int s_start, s_end, s_inc;
3409 png_uint_32 i;
3410 int jstop = png_pass_inc[pass];
3411
3412#ifdef PNG_READ_PACKSWAP_SUPPORTED
3413 if (transformations & PNG_PACKSWAP)
3414 {
3415 sshift = (int)(((row_info->width + 1) & 0x01) << 2);
3416 dshift = (int)(((final_width + 1) & 0x01) << 2);
3417 s_start = 4;
3418 s_end = 0;
3419 s_inc = -4;
3420 }
3421
3422 else
3423#endif
3424 {
3425 sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
3426 dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
3427 s_start = 0;
3428 s_end = 4;
3429 s_inc = 4;
3430 }
3431
3432 for (i = 0; i < row_info->width; i++)
3433 {
3434 png_byte v = (png_byte)((*sp >> sshift) & 0x0f);
3435 int j;
3436
3437 for (j = 0; j < jstop; j++)
3438 {
3439 *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
3440 *dp |= (png_byte)(v << dshift);
3441
3442 if (dshift == s_end)
3443 {
3444 dshift = s_start;
3445 dp--;
3446 }
3447
3448 else
3449 dshift += s_inc;
3450 }
3451
3452 if (sshift == s_end)
3453 {
3454 sshift = s_start;
3455 sp--;
3456 }
3457
3458 else
3459 sshift += s_inc;
3460 }
3461 break;
3462 }
3463
3464 default:
3465 {
3466 png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
3467
3468 png_bytep sp = row + (png_size_t)(row_info->width - 1)
3469 * pixel_bytes;
3470
3471 png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
3472
3473 int jstop = png_pass_inc[pass];
3474 png_uint_32 i;
3475
3476 for (i = 0; i < row_info->width; i++)
3477 {
3478 png_byte v[8];
3479 int j;
3480
3481 png_memcpy(v, sp, pixel_bytes);
3482
3483 for (j = 0; j < jstop; j++)
3484 {
3485 png_memcpy(dp, v, pixel_bytes);
3486 dp -= pixel_bytes;
3487 }
3488
3489 sp -= pixel_bytes;
3490 }
3491 break;
3492 }
3493 }
3494
3495 row_info->width = final_width;
3496 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
3497 }
3498#ifndef PNG_READ_PACKSWAP_SUPPORTED
3499 PNG_UNUSED(transformations) /* Silence compiler warning */
3500#endif
3501}
3502#endif /* PNG_READ_INTERLACING_SUPPORTED */
3503
3504static void
3505png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
3506 png_const_bytep prev_row)
3507{
3508 png_size_t i;
3509 png_size_t istop = row_info->rowbytes;
3510 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3511 png_bytep rp = row + bpp;
3512
3513 PNG_UNUSED(prev_row)
3514
3515 for (i = bpp; i < istop; i++)
3516 {
3517 *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
3518 rp++;
3519 }
3520}
3521
3522static void
3523png_read_filter_row_up(png_row_infop row_info, png_bytep row,
3524 png_const_bytep prev_row)
3525{
3526 png_size_t i;
3527 png_size_t istop = row_info->rowbytes;
3528 png_bytep rp = row;
3529 png_const_bytep pp = prev_row;
3530
3531 for (i = 0; i < istop; i++)
3532 {
3533 *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
3534 rp++;
3535 }
3536}
3537
3538static void
3539png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
3540 png_const_bytep prev_row)
3541{
3542 png_size_t i;
3543 png_bytep rp = row;
3544 png_const_bytep pp = prev_row;
3545 unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
3546 png_size_t istop = row_info->rowbytes - bpp;
3547
3548 for (i = 0; i < bpp; i++)
3549 {
3550 *rp = (png_byte)(((int)(*rp) +
3551 ((int)(*pp++) / 2 )) & 0xff);
3552
3553 rp++;
3554 }
3555
3556 for (i = 0; i < istop; i++)
3557 {
3558 *rp = (png_byte)(((int)(*rp) +
3559 (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
3560
3561 rp++;
3562 }
3563}
3564
3565static void
3566png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
3567 png_const_bytep prev_row)
3568{
3569 png_bytep rp_end = row + row_info->rowbytes;
3570 int a, c;
3571
3572 /* First pixel/byte */
3573 c = *prev_row++;
3574 a = *row + c;
3575 *row++ = (png_byte)a;
3576
3577 /* Remainder */
3578 while (row < rp_end)
3579 {
3580 int b, pa, pb, pc, p;
3581
3582 a &= 0xff; /* From previous iteration or start */
3583 b = *prev_row++;
3584
3585 p = b - c;
3586 pc = a - c;
3587
3588# ifdef PNG_USE_ABS
3589 pa = abs(p);
3590 pb = abs(pc);
3591 pc = abs(p + pc);
3592# else
3593 pa = p < 0 ? -p : p;
3594 pb = pc < 0 ? -pc : pc;
3595 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3596# endif
3597
3598 /* Find the best predictor, the least of pa, pb, pc favoring the earlier
3599 * ones in the case of a tie.
3600 */
3601 if (pb < pa) pa = pb, a = b;
3602 if (pc < pa) a = c;
3603
3604 /* Calculate the current pixel in a, and move the previous row pixel to c
3605 * for the next time round the loop
3606 */
3607 c = b;
3608 a += *row;
3609 *row++ = (png_byte)a;
3610 }
3611}
3612
3613static void
3614png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
3615 png_const_bytep prev_row)
3616{
3617 int bpp = (row_info->pixel_depth + 7) >> 3;
3618 png_bytep rp_end = row + bpp;
3619
3620 /* Process the first pixel in the row completely (this is the same as 'up'
3621 * because there is only one candidate predictor for the first row).
3622 */
3623 while (row < rp_end)
3624 {
3625 int a = *row + *prev_row++;
3626 *row++ = (png_byte)a;
3627 }
3628
3629 /* Remainder */
3630 rp_end += row_info->rowbytes - bpp;
3631
3632 while (row < rp_end)
3633 {
3634 int a, b, c, pa, pb, pc, p;
3635
3636 c = *(prev_row - bpp);
3637 a = *(row - bpp);
3638 b = *prev_row++;
3639
3640 p = b - c;
3641 pc = a - c;
3642
3643# ifdef PNG_USE_ABS
3644 pa = abs(p);
3645 pb = abs(pc);
3646 pc = abs(p + pc);
3647# else
3648 pa = p < 0 ? -p : p;
3649 pb = pc < 0 ? -pc : pc;
3650 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3651# endif
3652
3653 if (pb < pa) pa = pb, a = b;
3654 if (pc < pa) a = c;
3655
3656 c = b;
3657 a += *row;
3658 *row++ = (png_byte)a;
3659 }
3660}
3661
3662#ifdef PNG_ARM_NEON
3663
3664#ifdef __linux__
3665#include <stdio.h>
3666#include <elf.h>
3667#include <asm/hwcap.h>
3668
3669static int png_have_hwcap(unsigned cap)
3670{
3671 FILE *f = fopen("/proc/self/auxv", "r");
3672 Elf32_auxv_t aux;
3673 int have_cap = 0;
3674
3675 if (!f)
3676 return 0;
3677
3678 while (fread(&aux, sizeof(aux), 1, f) > 0)
3679 {
3680 if (aux.a_type == AT_HWCAP &&
3681 aux.a_un.a_val & cap)
3682 {
3683 have_cap = 1;
3684 break;
3685 }
3686 }
3687
3688 fclose(f);
3689
3690 return have_cap;
3691}
3692#endif /* __linux__ */
3693
3694static void
3695png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
3696{
3697#ifdef __linux__
3698 if (!png_have_hwcap(HWCAP_NEON))
3699 return;
3700#endif
3701
3702 pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
3703
3704 if (bpp == 3)
3705 {
3706 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
3707 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
3708 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
3709 png_read_filter_row_paeth3_neon;
3710 }
3711
3712 else if (bpp == 4)
3713 {
3714 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
3715 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
3716 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
3717 png_read_filter_row_paeth4_neon;
3718 }
3719}
3720#endif /* PNG_ARM_NEON */
3721
3722static void
3723png_init_filter_functions(png_structp pp)
3724{
3725 unsigned int bpp = (pp->pixel_depth + 7) >> 3;
3726
3727 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub;
3728 pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up;
3729 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg;
3730 if (bpp == 1)
3731 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
3732 png_read_filter_row_paeth_1byte_pixel;
3733 else
3734 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
3735 png_read_filter_row_paeth_multibyte_pixel;
3736
3737#ifdef PNG_ARM_NEON
3738 png_init_filter_functions_neon(pp, bpp);
3739#endif
3740}
3741
3742void /* PRIVATE */
3743png_read_filter_row(png_structp pp, png_row_infop row_info, png_bytep row,
3744 png_const_bytep prev_row, int filter)
3745{
3746 if (pp->read_filter[0] == NULL)
3747 png_init_filter_functions(pp);
3748 if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
3749 pp->read_filter[filter-1](row_info, row, prev_row);
3750}
3751
3752#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
3753void /* PRIVATE */
3754png_read_finish_row(png_structp png_ptr)
3755{
3756#ifdef PNG_READ_INTERLACING_SUPPORTED
3757 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3758
3759 /* Start of interlace block */
3760 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
3761
3762 /* Offset to next interlace block */
3763 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3764
3765 /* Start of interlace block in the y direction */
3766 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
3767
3768 /* Offset to next interlace block in the y direction */
3769 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
3770#endif /* PNG_READ_INTERLACING_SUPPORTED */
3771
3772 png_debug(1, "in png_read_finish_row");
3773 png_ptr->row_number++;
3774 if (png_ptr->row_number < png_ptr->num_rows)
3775 return;
3776
3777#ifdef PNG_READ_INTERLACING_SUPPORTED
3778 if (png_ptr->interlaced)
3779 {
3780 png_ptr->row_number = 0;
3781
3782 /* TO DO: don't do this if prev_row isn't needed (requires
3783 * read-ahead of the next row's filter byte.
3784 */
3785 png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
3786
3787 do
3788 {
3789 png_ptr->pass++;
3790
3791 if (png_ptr->pass >= 7)
3792 break;
3793
3794 png_ptr->iwidth = (png_ptr->width +
3795 png_pass_inc[png_ptr->pass] - 1 -
3796 png_pass_start[png_ptr->pass]) /
3797 png_pass_inc[png_ptr->pass];
3798
3799 if (!(png_ptr->transformations & PNG_INTERLACE))
3800 {
3801 png_ptr->num_rows = (png_ptr->height +
3802 png_pass_yinc[png_ptr->pass] - 1 -
3803 png_pass_ystart[png_ptr->pass]) /
3804 png_pass_yinc[png_ptr->pass];
3805 }
3806
3807 else /* if (png_ptr->transformations & PNG_INTERLACE) */
3808 break; /* libpng deinterlacing sees every row */
3809
3810 } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
3811
3812 if (png_ptr->pass < 7)
3813 return;
3814 }
3815#endif /* PNG_READ_INTERLACING_SUPPORTED */
3816
3817 if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
3818 {
3819 char extra;
3820 int ret;
3821
3822 png_ptr->zstream.next_out = (Byte *)&extra;
3823 png_ptr->zstream.avail_out = (uInt)1;
3824
3825 for (;;)
3826 {
3827 if (!(png_ptr->zstream.avail_in))
3828 {
3829 while (!png_ptr->idat_size)
3830 {
3831 png_crc_finish(png_ptr, 0);
3832 png_ptr->idat_size = png_read_chunk_header(png_ptr);
3833 if (png_ptr->chunk_name != png_IDAT)
3834 png_error(png_ptr, "Not enough image data");
3835 }
3836
3837 png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
3838 png_ptr->zstream.next_in = png_ptr->zbuf;
3839
3840 if (png_ptr->zbuf_size > png_ptr->idat_size)
3841 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
3842
3843 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
3844 png_ptr->idat_size -= png_ptr->zstream.avail_in;
3845 }
3846
3847 ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
3848
3849 if (ret == Z_STREAM_END)
3850 {
3851 if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
3852 png_ptr->idat_size)
3853 png_warning(png_ptr, "Extra compressed data");
3854
3855 png_ptr->mode |= PNG_AFTER_IDAT;
3856 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3857 break;
3858 }
3859
3860 if (ret != Z_OK)
3861 png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
3862 "Decompression Error");
3863
3864 if (!(png_ptr->zstream.avail_out))
3865 {
3866 png_warning(png_ptr, "Extra compressed data");
3867 png_ptr->mode |= PNG_AFTER_IDAT;
3868 png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
3869 break;
3870 }
3871
3872 }
3873 png_ptr->zstream.avail_out = 0;
3874 }
3875
3876 if (png_ptr->idat_size || png_ptr->zstream.avail_in)
3877 png_warning(png_ptr, "Extra compression data");
3878
3879 inflateReset(&png_ptr->zstream);
3880
3881 png_ptr->mode |= PNG_AFTER_IDAT;
3882}
3883#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
3884
3885void /* PRIVATE */
3886png_read_start_row(png_structp png_ptr)
3887{
3888#ifdef PNG_READ_INTERLACING_SUPPORTED
3889 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3890
3891 /* Start of interlace block */
3892 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
3893
3894 /* Offset to next interlace block */
3895 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3896
3897 /* Start of interlace block in the y direction */
3898 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
3899
3900 /* Offset to next interlace block in the y direction */
3901 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
3902#endif
3903
3904 int max_pixel_depth;
3905 png_size_t row_bytes;
3906
3907 png_debug(1, "in png_read_start_row");
3908 png_ptr->zstream.avail_in = 0;
3909#ifdef PNG_READ_TRANSFORMS_SUPPORTED
3910 png_init_read_transformations(png_ptr);
3911#endif
3912#ifdef PNG_READ_INTERLACING_SUPPORTED
3913 if (png_ptr->interlaced)
3914 {
3915 if (!(png_ptr->transformations & PNG_INTERLACE))
3916 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
3917 png_pass_ystart[0]) / png_pass_yinc[0];
3918
3919 else
3920 png_ptr->num_rows = png_ptr->height;
3921
3922 png_ptr->iwidth = (png_ptr->width +
3923 png_pass_inc[png_ptr->pass] - 1 -
3924 png_pass_start[png_ptr->pass]) /
3925 png_pass_inc[png_ptr->pass];
3926 }
3927
3928 else
3929#endif /* PNG_READ_INTERLACING_SUPPORTED */
3930 {
3931 png_ptr->num_rows = png_ptr->height;
3932 png_ptr->iwidth = png_ptr->width;
3933 }
3934
3935 max_pixel_depth = png_ptr->pixel_depth;
3936
3937 /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpliar set of
3938 * calculations to calculate the final pixel depth, then
3939 * png_do_read_transforms actually does the transforms. This means that the
3940 * code which effectively calculates this value is actually repeated in three
3941 * separate places. They must all match. Innocent changes to the order of
3942 * transformations can and will break libpng in a way that causes memory
3943 * overwrites.
3944 *
3945 * TODO: fix this.
3946 */
3947#ifdef PNG_READ_PACK_SUPPORTED
3948 if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
3949 max_pixel_depth = 8;
3950#endif
3951
3952#ifdef PNG_READ_EXPAND_SUPPORTED
3953 if (png_ptr->transformations & PNG_EXPAND)
3954 {
3955 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
3956 {
3957 if (png_ptr->num_trans)
3958 max_pixel_depth = 32;
3959
3960 else
3961 max_pixel_depth = 24;
3962 }
3963
3964 else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
3965 {
3966 if (max_pixel_depth < 8)
3967 max_pixel_depth = 8;
3968
3969 if (png_ptr->num_trans)
3970 max_pixel_depth *= 2;
3971 }
3972
3973 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
3974 {
3975 if (png_ptr->num_trans)
3976 {
3977 max_pixel_depth *= 4;
3978 max_pixel_depth /= 3;
3979 }
3980 }
3981 }
3982#endif
3983
3984#ifdef PNG_READ_EXPAND_16_SUPPORTED
3985 if (png_ptr->transformations & PNG_EXPAND_16)
3986 {
3987# ifdef PNG_READ_EXPAND_SUPPORTED
3988 /* In fact it is an error if it isn't supported, but checking is
3989 * the safe way.
3990 */
3991 if (png_ptr->transformations & PNG_EXPAND)
3992 {
3993 if (png_ptr->bit_depth < 16)
3994 max_pixel_depth *= 2;
3995 }
3996 else
3997# endif
3998 png_ptr->transformations &= ~PNG_EXPAND_16;
3999 }
4000#endif
4001
4002#ifdef PNG_READ_FILLER_SUPPORTED
4003 if (png_ptr->transformations & (PNG_FILLER))
4004 {
4005 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
4006 {
4007 if (max_pixel_depth <= 8)
4008 max_pixel_depth = 16;
4009
4010 else
4011 max_pixel_depth = 32;
4012 }
4013
4014 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB ||
4015 png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
4016 {
4017 if (max_pixel_depth <= 32)
4018 max_pixel_depth = 32;
4019
4020 else
4021 max_pixel_depth = 64;
4022 }
4023 }
4024#endif
4025
4026#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
4027 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
4028 {
4029 if (
4030#ifdef PNG_READ_EXPAND_SUPPORTED
4031 (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
4032#endif
4033#ifdef PNG_READ_FILLER_SUPPORTED
4034 (png_ptr->transformations & (PNG_FILLER)) ||
4035#endif
4036 png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
4037 {
4038 if (max_pixel_depth <= 16)
4039 max_pixel_depth = 32;
4040
4041 else
4042 max_pixel_depth = 64;
4043 }
4044
4045 else
4046 {
4047 if (max_pixel_depth <= 8)
4048 {
4049 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4050 max_pixel_depth = 32;
4051
4052 else
4053 max_pixel_depth = 24;
4054 }
4055
4056 else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4057 max_pixel_depth = 64;
4058
4059 else
4060 max_pixel_depth = 48;
4061 }
4062 }
4063#endif
4064
4065#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
4066defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
4067 if (png_ptr->transformations & PNG_USER_TRANSFORM)
4068 {
4069 int user_pixel_depth = png_ptr->user_transform_depth *
4070 png_ptr->user_transform_channels;
4071
4072 if (user_pixel_depth > max_pixel_depth)
4073 max_pixel_depth = user_pixel_depth;
4074 }
4075#endif
4076
4077 /* This value is stored in png_struct and double checked in the row read
4078 * code.
4079 */
4080 png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;
4081 png_ptr->transformed_pixel_depth = 0; /* calculated on demand */
4082
4083 /* Align the width on the next larger 8 pixels. Mainly used
4084 * for interlacing
4085 */
4086 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
4087 /* Calculate the maximum bytes needed, adding a byte and a pixel
4088 * for safety's sake
4089 */
4090 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
4091 1 + ((max_pixel_depth + 7) >> 3);
4092
4093#ifdef PNG_MAX_MALLOC_64K
4094 if (row_bytes > (png_uint_32)65536L)
4095 png_error(png_ptr, "This image requires a row greater than 64KB");
4096#endif
4097
4098 if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
4099 {
4100 png_free(png_ptr, png_ptr->big_row_buf);
4101 png_free(png_ptr, png_ptr->big_prev_row);
4102
4103 if (png_ptr->interlaced)
4104 png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
4105 row_bytes + 48);
4106
4107 else
4108 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
4109
4110 png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
4111
4112#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
4113 /* Use 16-byte aligned memory for row_buf with at least 16 bytes
4114 * of padding before and after row_buf; treat prev_row similarly.
4115 * NOTE: the alignment is to the start of the pixels, one beyond the start
4116 * of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
4117 * was incorrect; the filter byte was aligned, which had the exact
4118 * opposite effect of that intended.
4119 */
4120 {
4121 png_bytep temp = png_ptr->big_row_buf + 32;
4122 int extra = (int)((temp - (png_bytep)0) & 0x0f);
4123 png_ptr->row_buf = temp - extra - 1/*filter byte*/;
4124
4125 temp = png_ptr->big_prev_row + 32;
4126 extra = (int)((temp - (png_bytep)0) & 0x0f);
4127 png_ptr->prev_row = temp - extra - 1/*filter byte*/;
4128 }
4129
4130#else
4131 /* Use 31 bytes of padding before and 17 bytes after row_buf. */
4132 png_ptr->row_buf = png_ptr->big_row_buf + 31;
4133 png_ptr->prev_row = png_ptr->big_prev_row + 31;
4134#endif
4135 png_ptr->old_big_row_buf_size = row_bytes + 48;
4136 }
4137
4138#ifdef PNG_MAX_MALLOC_64K
4139 if (png_ptr->rowbytes > 65535)
4140 png_error(png_ptr, "This image requires a row greater than 64KB");
4141
4142#endif
4143 if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))
4144 png_error(png_ptr, "Row has too many bytes to allocate in memory");
4145
4146 png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
4147
4148 png_debug1(3, "width = %u,", png_ptr->width);
4149 png_debug1(3, "height = %u,", png_ptr->height);
4150 png_debug1(3, "iwidth = %u,", png_ptr->iwidth);
4151 png_debug1(3, "num_rows = %u,", png_ptr->num_rows);
4152 png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes);
4153 png_debug1(3, "irowbytes = %lu",
4154 (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
4155
4156 png_ptr->flags |= PNG_FLAG_ROW_INIT;
4157}
4158#endif /* PNG_READ_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngset.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngset.c
new file mode 100644
index 0000000..e753ca8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngset.c
@@ -0,0 +1,1284 @@
1
2/* pngset.c - storage of image information into info struct
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * The functions here are used during reads to store data from the file
14 * into the info struct, and during writes to store application data
15 * into the info struct for writing into the file. This abstracts the
16 * info struct and allows us to change the structure in the future.
17 */
18
19#include "pngpriv.h"
20
21#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
22
23#ifdef PNG_bKGD_SUPPORTED
24void PNGAPI
25png_set_bKGD(png_structp png_ptr, png_infop info_ptr,
26 png_const_color_16p background)
27{
28 png_debug1(1, "in %s storage function", "bKGD");
29
30 if (png_ptr == NULL || info_ptr == NULL)
31 return;
32
33 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
34 info_ptr->valid |= PNG_INFO_bKGD;
35}
36#endif
37
38#ifdef PNG_cHRM_SUPPORTED
39void PNGFAPI
40png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
41 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
42 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
43 png_fixed_point blue_x, png_fixed_point blue_y)
44{
45 png_debug1(1, "in %s storage function", "cHRM fixed");
46
47 if (png_ptr == NULL || info_ptr == NULL)
48 return;
49
50# ifdef PNG_CHECK_cHRM_SUPPORTED
51 if (png_check_cHRM_fixed(png_ptr,
52 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
53# endif
54 {
55 info_ptr->x_white = white_x;
56 info_ptr->y_white = white_y;
57 info_ptr->x_red = red_x;
58 info_ptr->y_red = red_y;
59 info_ptr->x_green = green_x;
60 info_ptr->y_green = green_y;
61 info_ptr->x_blue = blue_x;
62 info_ptr->y_blue = blue_y;
63 info_ptr->valid |= PNG_INFO_cHRM;
64 }
65}
66
67void PNGFAPI
68png_set_cHRM_XYZ_fixed(png_structp png_ptr, png_infop info_ptr,
69 png_fixed_point int_red_X, png_fixed_point int_red_Y,
70 png_fixed_point int_red_Z, png_fixed_point int_green_X,
71 png_fixed_point int_green_Y, png_fixed_point int_green_Z,
72 png_fixed_point int_blue_X, png_fixed_point int_blue_Y,
73 png_fixed_point int_blue_Z)
74{
75 png_XYZ XYZ;
76 png_xy xy;
77
78 png_debug1(1, "in %s storage function", "cHRM XYZ fixed");
79
80 if (png_ptr == NULL || info_ptr == NULL)
81 return;
82
83 XYZ.redX = int_red_X;
84 XYZ.redY = int_red_Y;
85 XYZ.redZ = int_red_Z;
86 XYZ.greenX = int_green_X;
87 XYZ.greenY = int_green_Y;
88 XYZ.greenZ = int_green_Z;
89 XYZ.blueX = int_blue_X;
90 XYZ.blueY = int_blue_Y;
91 XYZ.blueZ = int_blue_Z;
92
93 if (png_xy_from_XYZ(&xy, XYZ))
94 png_error(png_ptr, "XYZ values out of representable range");
95
96 png_set_cHRM_fixed(png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy,
97 xy.greenx, xy.greeny, xy.bluex, xy.bluey);
98}
99
100# ifdef PNG_FLOATING_POINT_SUPPORTED
101void PNGAPI
102png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
103 double white_x, double white_y, double red_x, double red_y,
104 double green_x, double green_y, double blue_x, double blue_y)
105{
106 png_set_cHRM_fixed(png_ptr, info_ptr,
107 png_fixed(png_ptr, white_x, "cHRM White X"),
108 png_fixed(png_ptr, white_y, "cHRM White Y"),
109 png_fixed(png_ptr, red_x, "cHRM Red X"),
110 png_fixed(png_ptr, red_y, "cHRM Red Y"),
111 png_fixed(png_ptr, green_x, "cHRM Green X"),
112 png_fixed(png_ptr, green_y, "cHRM Green Y"),
113 png_fixed(png_ptr, blue_x, "cHRM Blue X"),
114 png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
115}
116
117void PNGAPI
118png_set_cHRM_XYZ(png_structp png_ptr, png_infop info_ptr, double red_X,
119 double red_Y, double red_Z, double green_X, double green_Y, double green_Z,
120 double blue_X, double blue_Y, double blue_Z)
121{
122 png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,
123 png_fixed(png_ptr, red_X, "cHRM Red X"),
124 png_fixed(png_ptr, red_Y, "cHRM Red Y"),
125 png_fixed(png_ptr, red_Z, "cHRM Red Z"),
126 png_fixed(png_ptr, green_X, "cHRM Red X"),
127 png_fixed(png_ptr, green_Y, "cHRM Red Y"),
128 png_fixed(png_ptr, green_Z, "cHRM Red Z"),
129 png_fixed(png_ptr, blue_X, "cHRM Red X"),
130 png_fixed(png_ptr, blue_Y, "cHRM Red Y"),
131 png_fixed(png_ptr, blue_Z, "cHRM Red Z"));
132}
133# endif /* PNG_FLOATING_POINT_SUPPORTED */
134
135#endif /* PNG_cHRM_SUPPORTED */
136
137#ifdef PNG_gAMA_SUPPORTED
138void PNGFAPI
139png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
140 file_gamma)
141{
142 png_debug1(1, "in %s storage function", "gAMA");
143
144 if (png_ptr == NULL || info_ptr == NULL)
145 return;
146
147 /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
148 * occur. Since the fixed point representation is assymetrical it is
149 * possible for 1/gamma to overflow the limit of 21474 and this means the
150 * gamma value must be at least 5/100000 and hence at most 20000.0. For
151 * safety the limits here are a little narrower. The values are 0.00016 to
152 * 6250.0, which are truly ridiculous gammma values (and will produce
153 * displays that are all black or all white.)
154 */
155 if (file_gamma < 16 || file_gamma > 625000000)
156 png_warning(png_ptr, "Out of range gamma value ignored");
157
158 else
159 {
160 info_ptr->gamma = file_gamma;
161 info_ptr->valid |= PNG_INFO_gAMA;
162 }
163}
164
165# ifdef PNG_FLOATING_POINT_SUPPORTED
166void PNGAPI
167png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
168{
169 png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,
170 "png_set_gAMA"));
171}
172# endif
173#endif
174
175#ifdef PNG_hIST_SUPPORTED
176void PNGAPI
177png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist)
178{
179 int i;
180
181 png_debug1(1, "in %s storage function", "hIST");
182
183 if (png_ptr == NULL || info_ptr == NULL)
184 return;
185
186 if (info_ptr->num_palette == 0 || info_ptr->num_palette
187 > PNG_MAX_PALETTE_LENGTH)
188 {
189 png_warning(png_ptr,
190 "Invalid palette size, hIST allocation skipped");
191
192 return;
193 }
194
195 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
196
197 /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
198 * version 1.2.1
199 */
200 png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
201 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
202
203 if (png_ptr->hist == NULL)
204 {
205 png_warning(png_ptr, "Insufficient memory for hIST chunk data");
206 return;
207 }
208
209 for (i = 0; i < info_ptr->num_palette; i++)
210 png_ptr->hist[i] = hist[i];
211
212 info_ptr->hist = png_ptr->hist;
213 info_ptr->valid |= PNG_INFO_hIST;
214 info_ptr->free_me |= PNG_FREE_HIST;
215}
216#endif
217
218void PNGAPI
219png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
220 png_uint_32 width, png_uint_32 height, int bit_depth,
221 int color_type, int interlace_type, int compression_type,
222 int filter_type)
223{
224 png_debug1(1, "in %s storage function", "IHDR");
225
226 if (png_ptr == NULL || info_ptr == NULL)
227 return;
228
229 info_ptr->width = width;
230 info_ptr->height = height;
231 info_ptr->bit_depth = (png_byte)bit_depth;
232 info_ptr->color_type = (png_byte)color_type;
233 info_ptr->compression_type = (png_byte)compression_type;
234 info_ptr->filter_type = (png_byte)filter_type;
235 info_ptr->interlace_type = (png_byte)interlace_type;
236
237 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
238 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
239 info_ptr->compression_type, info_ptr->filter_type);
240
241 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
242 info_ptr->channels = 1;
243
244 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
245 info_ptr->channels = 3;
246
247 else
248 info_ptr->channels = 1;
249
250 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
251 info_ptr->channels++;
252
253 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
254
255 /* Check for potential overflow */
256 if (width >
257 (PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */
258 - 48 /* bigrowbuf hack */
259 - 1 /* filter byte */
260 - 7*8 /* rounding of width to multiple of 8 pixels */
261 - 8) /* extra max_pixel_depth pad */
262 info_ptr->rowbytes = 0;
263 else
264 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
265}
266
267#ifdef PNG_oFFs_SUPPORTED
268void PNGAPI
269png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
270 png_int_32 offset_x, png_int_32 offset_y, int unit_type)
271{
272 png_debug1(1, "in %s storage function", "oFFs");
273
274 if (png_ptr == NULL || info_ptr == NULL)
275 return;
276
277 info_ptr->x_offset = offset_x;
278 info_ptr->y_offset = offset_y;
279 info_ptr->offset_unit_type = (png_byte)unit_type;
280 info_ptr->valid |= PNG_INFO_oFFs;
281}
282#endif
283
284#ifdef PNG_pCAL_SUPPORTED
285void PNGAPI
286png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
287 png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
288 int nparams, png_const_charp units, png_charpp params)
289{
290 png_size_t length;
291 int i;
292
293 png_debug1(1, "in %s storage function", "pCAL");
294
295 if (png_ptr == NULL || info_ptr == NULL)
296 return;
297
298 length = png_strlen(purpose) + 1;
299 png_debug1(3, "allocating purpose for info (%lu bytes)",
300 (unsigned long)length);
301
302 /* TODO: validate format of calibration name and unit name */
303
304 /* Check that the type matches the specification. */
305 if (type < 0 || type > 3)
306 png_error(png_ptr, "Invalid pCAL equation type");
307
308 /* Validate params[nparams] */
309 for (i=0; i<nparams; ++i)
310 if (!png_check_fp_string(params[i], png_strlen(params[i])))
311 png_error(png_ptr, "Invalid format for pCAL parameter");
312
313 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
314
315 if (info_ptr->pcal_purpose == NULL)
316 {
317 png_warning(png_ptr, "Insufficient memory for pCAL purpose");
318 return;
319 }
320
321 png_memcpy(info_ptr->pcal_purpose, purpose, length);
322
323 png_debug(3, "storing X0, X1, type, and nparams in info");
324 info_ptr->pcal_X0 = X0;
325 info_ptr->pcal_X1 = X1;
326 info_ptr->pcal_type = (png_byte)type;
327 info_ptr->pcal_nparams = (png_byte)nparams;
328
329 length = png_strlen(units) + 1;
330 png_debug1(3, "allocating units for info (%lu bytes)",
331 (unsigned long)length);
332
333 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
334
335 if (info_ptr->pcal_units == NULL)
336 {
337 png_warning(png_ptr, "Insufficient memory for pCAL units");
338 return;
339 }
340
341 png_memcpy(info_ptr->pcal_units, units, length);
342
343 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
344 (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
345
346 if (info_ptr->pcal_params == NULL)
347 {
348 png_warning(png_ptr, "Insufficient memory for pCAL params");
349 return;
350 }
351
352 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
353
354 for (i = 0; i < nparams; i++)
355 {
356 length = png_strlen(params[i]) + 1;
357 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
358 (unsigned long)length);
359
360 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
361
362 if (info_ptr->pcal_params[i] == NULL)
363 {
364 png_warning(png_ptr, "Insufficient memory for pCAL parameter");
365 return;
366 }
367
368 png_memcpy(info_ptr->pcal_params[i], params[i], length);
369 }
370
371 info_ptr->valid |= PNG_INFO_pCAL;
372 info_ptr->free_me |= PNG_FREE_PCAL;
373}
374#endif
375
376#ifdef PNG_sCAL_SUPPORTED
377void PNGAPI
378png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
379 int unit, png_const_charp swidth, png_const_charp sheight)
380{
381 png_size_t lengthw = 0, lengthh = 0;
382
383 png_debug1(1, "in %s storage function", "sCAL");
384
385 if (png_ptr == NULL || info_ptr == NULL)
386 return;
387
388 /* Double check the unit (should never get here with an invalid
389 * unit unless this is an API call.)
390 */
391 if (unit != 1 && unit != 2)
392 png_error(png_ptr, "Invalid sCAL unit");
393
394 if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 ||
395 swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))
396 png_error(png_ptr, "Invalid sCAL width");
397
398 if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 ||
399 sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))
400 png_error(png_ptr, "Invalid sCAL height");
401
402 info_ptr->scal_unit = (png_byte)unit;
403
404 ++lengthw;
405
406 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
407
408 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw);
409
410 if (info_ptr->scal_s_width == NULL)
411 {
412 png_warning(png_ptr, "Memory allocation failed while processing sCAL");
413 return;
414 }
415
416 png_memcpy(info_ptr->scal_s_width, swidth, lengthw);
417
418 ++lengthh;
419
420 png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
421
422 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh);
423
424 if (info_ptr->scal_s_height == NULL)
425 {
426 png_free (png_ptr, info_ptr->scal_s_width);
427 info_ptr->scal_s_width = NULL;
428
429 png_warning(png_ptr, "Memory allocation failed while processing sCAL");
430 return;
431 }
432
433 png_memcpy(info_ptr->scal_s_height, sheight, lengthh);
434
435 info_ptr->valid |= PNG_INFO_sCAL;
436 info_ptr->free_me |= PNG_FREE_SCAL;
437}
438
439# ifdef PNG_FLOATING_POINT_SUPPORTED
440void PNGAPI
441png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width,
442 double height)
443{
444 png_debug1(1, "in %s storage function", "sCAL");
445
446 /* Check the arguments. */
447 if (width <= 0)
448 png_warning(png_ptr, "Invalid sCAL width ignored");
449
450 else if (height <= 0)
451 png_warning(png_ptr, "Invalid sCAL height ignored");
452
453 else
454 {
455 /* Convert 'width' and 'height' to ASCII. */
456 char swidth[PNG_sCAL_MAX_DIGITS+1];
457 char sheight[PNG_sCAL_MAX_DIGITS+1];
458
459 png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width,
460 PNG_sCAL_PRECISION);
461 png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height,
462 PNG_sCAL_PRECISION);
463
464 png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
465 }
466}
467# endif
468
469# ifdef PNG_FIXED_POINT_SUPPORTED
470void PNGAPI
471png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit,
472 png_fixed_point width, png_fixed_point height)
473{
474 png_debug1(1, "in %s storage function", "sCAL");
475
476 /* Check the arguments. */
477 if (width <= 0)
478 png_warning(png_ptr, "Invalid sCAL width ignored");
479
480 else if (height <= 0)
481 png_warning(png_ptr, "Invalid sCAL height ignored");
482
483 else
484 {
485 /* Convert 'width' and 'height' to ASCII. */
486 char swidth[PNG_sCAL_MAX_DIGITS+1];
487 char sheight[PNG_sCAL_MAX_DIGITS+1];
488
489 png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width);
490 png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height);
491
492 png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
493 }
494}
495# endif
496#endif
497
498#ifdef PNG_pHYs_SUPPORTED
499void PNGAPI
500png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
501 png_uint_32 res_x, png_uint_32 res_y, int unit_type)
502{
503 png_debug1(1, "in %s storage function", "pHYs");
504
505 if (png_ptr == NULL || info_ptr == NULL)
506 return;
507
508 info_ptr->x_pixels_per_unit = res_x;
509 info_ptr->y_pixels_per_unit = res_y;
510 info_ptr->phys_unit_type = (png_byte)unit_type;
511 info_ptr->valid |= PNG_INFO_pHYs;
512}
513#endif
514
515void PNGAPI
516png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
517 png_const_colorp palette, int num_palette)
518{
519
520 png_debug1(1, "in %s storage function", "PLTE");
521
522 if (png_ptr == NULL || info_ptr == NULL)
523 return;
524
525 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
526 {
527 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
528 png_error(png_ptr, "Invalid palette length");
529
530 else
531 {
532 png_warning(png_ptr, "Invalid palette length");
533 return;
534 }
535 }
536
537 /* It may not actually be necessary to set png_ptr->palette here;
538 * we do it for backward compatibility with the way the png_handle_tRNS
539 * function used to do the allocation.
540 */
541 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
542
543 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
544 * of num_palette entries, in case of an invalid PNG file that has
545 * too-large sample values.
546 */
547 png_ptr->palette = (png_colorp)png_calloc(png_ptr,
548 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
549
550 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
551 info_ptr->palette = png_ptr->palette;
552 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
553
554 info_ptr->free_me |= PNG_FREE_PLTE;
555
556 info_ptr->valid |= PNG_INFO_PLTE;
557}
558
559#ifdef PNG_sBIT_SUPPORTED
560void PNGAPI
561png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
562 png_const_color_8p sig_bit)
563{
564 png_debug1(1, "in %s storage function", "sBIT");
565
566 if (png_ptr == NULL || info_ptr == NULL)
567 return;
568
569 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
570 info_ptr->valid |= PNG_INFO_sBIT;
571}
572#endif
573
574#ifdef PNG_sRGB_SUPPORTED
575void PNGAPI
576png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent)
577{
578 png_debug1(1, "in %s storage function", "sRGB");
579
580 if (png_ptr == NULL || info_ptr == NULL)
581 return;
582
583 info_ptr->srgb_intent = (png_byte)srgb_intent;
584 info_ptr->valid |= PNG_INFO_sRGB;
585}
586
587void PNGAPI
588png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
589 int srgb_intent)
590{
591 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
592
593 if (png_ptr == NULL || info_ptr == NULL)
594 return;
595
596 png_set_sRGB(png_ptr, info_ptr, srgb_intent);
597
598# ifdef PNG_gAMA_SUPPORTED
599 png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
600# endif
601
602# ifdef PNG_cHRM_SUPPORTED
603 png_set_cHRM_fixed(png_ptr, info_ptr,
604 /* color x y */
605 /* white */ 31270, 32900,
606 /* red */ 64000, 33000,
607 /* green */ 30000, 60000,
608 /* blue */ 15000, 6000
609 );
610# endif /* cHRM */
611}
612#endif /* sRGB */
613
614
615#ifdef PNG_iCCP_SUPPORTED
616void PNGAPI
617png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
618 png_const_charp name, int compression_type,
619 png_const_bytep profile, png_uint_32 proflen)
620{
621 png_charp new_iccp_name;
622 png_bytep new_iccp_profile;
623 png_size_t length;
624
625 png_debug1(1, "in %s storage function", "iCCP");
626
627 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
628 return;
629
630 length = png_strlen(name)+1;
631 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
632
633 if (new_iccp_name == NULL)
634 {
635 png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
636 return;
637 }
638
639 png_memcpy(new_iccp_name, name, length);
640 new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen);
641
642 if (new_iccp_profile == NULL)
643 {
644 png_free (png_ptr, new_iccp_name);
645 png_warning(png_ptr,
646 "Insufficient memory to process iCCP profile");
647 return;
648 }
649
650 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
651
652 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
653
654 info_ptr->iccp_proflen = proflen;
655 info_ptr->iccp_name = new_iccp_name;
656 info_ptr->iccp_profile = new_iccp_profile;
657 /* Compression is always zero but is here so the API and info structure
658 * does not have to change if we introduce multiple compression types
659 */
660 info_ptr->iccp_compression = (png_byte)compression_type;
661 info_ptr->free_me |= PNG_FREE_ICCP;
662 info_ptr->valid |= PNG_INFO_iCCP;
663}
664#endif
665
666#ifdef PNG_TEXT_SUPPORTED
667void PNGAPI
668png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr,
669 int num_text)
670{
671 int ret;
672 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
673
674 if (ret)
675 png_error(png_ptr, "Insufficient memory to store text");
676}
677
678int /* PRIVATE */
679png_set_text_2(png_structp png_ptr, png_infop info_ptr,
680 png_const_textp text_ptr, int num_text)
681{
682 int i;
683
684 png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" :
685 (unsigned long)png_ptr->chunk_name);
686
687 if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
688 return(0);
689
690 /* Make sure we have enough space in the "text" array in info_struct
691 * to hold all of the incoming text_ptr objects.
692 */
693 if (info_ptr->num_text + num_text > info_ptr->max_text)
694 {
695 if (info_ptr->text != NULL)
696 {
697 png_textp old_text;
698 int old_max;
699
700 old_max = info_ptr->max_text;
701 info_ptr->max_text = info_ptr->num_text + num_text + 8;
702 old_text = info_ptr->text;
703 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
704 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
705
706 if (info_ptr->text == NULL)
707 {
708 png_free(png_ptr, old_text);
709 return(1);
710 }
711
712 png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
713 png_sizeof(png_text)));
714 png_free(png_ptr, old_text);
715 }
716
717 else
718 {
719 info_ptr->max_text = num_text + 8;
720 info_ptr->num_text = 0;
721 info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
722 (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
723 if (info_ptr->text == NULL)
724 return(1);
725 info_ptr->free_me |= PNG_FREE_TEXT;
726 }
727
728 png_debug1(3, "allocated %d entries for info_ptr->text",
729 info_ptr->max_text);
730 }
731 for (i = 0; i < num_text; i++)
732 {
733 png_size_t text_length, key_len;
734 png_size_t lang_len, lang_key_len;
735 png_textp textp = &(info_ptr->text[info_ptr->num_text]);
736
737 if (text_ptr[i].key == NULL)
738 continue;
739
740 if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
741 text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
742 {
743 png_warning(png_ptr, "text compression mode is out of range");
744 continue;
745 }
746
747 key_len = png_strlen(text_ptr[i].key);
748
749 if (text_ptr[i].compression <= 0)
750 {
751 lang_len = 0;
752 lang_key_len = 0;
753 }
754
755 else
756# ifdef PNG_iTXt_SUPPORTED
757 {
758 /* Set iTXt data */
759
760 if (text_ptr[i].lang != NULL)
761 lang_len = png_strlen(text_ptr[i].lang);
762
763 else
764 lang_len = 0;
765
766 if (text_ptr[i].lang_key != NULL)
767 lang_key_len = png_strlen(text_ptr[i].lang_key);
768
769 else
770 lang_key_len = 0;
771 }
772# else /* PNG_iTXt_SUPPORTED */
773 {
774 png_warning(png_ptr, "iTXt chunk not supported");
775 continue;
776 }
777# endif
778
779 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
780 {
781 text_length = 0;
782# ifdef PNG_iTXt_SUPPORTED
783 if (text_ptr[i].compression > 0)
784 textp->compression = PNG_ITXT_COMPRESSION_NONE;
785
786 else
787# endif
788 textp->compression = PNG_TEXT_COMPRESSION_NONE;
789 }
790
791 else
792 {
793 text_length = png_strlen(text_ptr[i].text);
794 textp->compression = text_ptr[i].compression;
795 }
796
797 textp->key = (png_charp)png_malloc_warn(png_ptr,
798 (png_size_t)
799 (key_len + text_length + lang_len + lang_key_len + 4));
800
801 if (textp->key == NULL)
802 return(1);
803
804 png_debug2(2, "Allocated %lu bytes at %p in png_set_text",
805 (unsigned long)(png_uint_32)
806 (key_len + lang_len + lang_key_len + text_length + 4),
807 textp->key);
808
809 png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
810 *(textp->key + key_len) = '\0';
811
812 if (text_ptr[i].compression > 0)
813 {
814 textp->lang = textp->key + key_len + 1;
815 png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
816 *(textp->lang + lang_len) = '\0';
817 textp->lang_key = textp->lang + lang_len + 1;
818 png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
819 *(textp->lang_key + lang_key_len) = '\0';
820 textp->text = textp->lang_key + lang_key_len + 1;
821 }
822
823 else
824 {
825 textp->lang=NULL;
826 textp->lang_key=NULL;
827 textp->text = textp->key + key_len + 1;
828 }
829
830 if (text_length)
831 png_memcpy(textp->text, text_ptr[i].text,
832 (png_size_t)(text_length));
833
834 *(textp->text + text_length) = '\0';
835
836# ifdef PNG_iTXt_SUPPORTED
837 if (textp->compression > 0)
838 {
839 textp->text_length = 0;
840 textp->itxt_length = text_length;
841 }
842
843 else
844# endif
845 {
846 textp->text_length = text_length;
847 textp->itxt_length = 0;
848 }
849
850 info_ptr->num_text++;
851 png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
852 }
853 return(0);
854}
855#endif
856
857#ifdef PNG_tIME_SUPPORTED
858void PNGAPI
859png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)
860{
861 png_debug1(1, "in %s storage function", "tIME");
862
863 if (png_ptr == NULL || info_ptr == NULL ||
864 (png_ptr->mode & PNG_WROTE_tIME))
865 return;
866
867 if (mod_time->month == 0 || mod_time->month > 12 ||
868 mod_time->day == 0 || mod_time->day > 31 ||
869 mod_time->hour > 23 || mod_time->minute > 59 ||
870 mod_time->second > 60)
871 {
872 png_warning(png_ptr, "Ignoring invalid time value");
873 return;
874 }
875
876 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
877 info_ptr->valid |= PNG_INFO_tIME;
878}
879#endif
880
881#ifdef PNG_tRNS_SUPPORTED
882void PNGAPI
883png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
884 png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
885{
886 png_debug1(1, "in %s storage function", "tRNS");
887
888 if (png_ptr == NULL || info_ptr == NULL)
889 return;
890
891 if (trans_alpha != NULL)
892 {
893 /* It may not actually be necessary to set png_ptr->trans_alpha here;
894 * we do it for backward compatibility with the way the png_handle_tRNS
895 * function used to do the allocation.
896 */
897
898 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
899
900 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
901 png_ptr->trans_alpha = info_ptr->trans_alpha =
902 (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH);
903
904 if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
905 png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
906 }
907
908 if (trans_color != NULL)
909 {
910 int sample_max = (1 << info_ptr->bit_depth);
911
912 if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
913 (int)trans_color->gray > sample_max) ||
914 (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
915 ((int)trans_color->red > sample_max ||
916 (int)trans_color->green > sample_max ||
917 (int)trans_color->blue > sample_max)))
918 png_warning(png_ptr,
919 "tRNS chunk has out-of-range samples for bit_depth");
920
921 png_memcpy(&(info_ptr->trans_color), trans_color,
922 png_sizeof(png_color_16));
923
924 if (num_trans == 0)
925 num_trans = 1;
926 }
927
928 info_ptr->num_trans = (png_uint_16)num_trans;
929
930 if (num_trans != 0)
931 {
932 info_ptr->valid |= PNG_INFO_tRNS;
933 info_ptr->free_me |= PNG_FREE_TRNS;
934 }
935}
936#endif
937
938#ifdef PNG_sPLT_SUPPORTED
939void PNGAPI
940png_set_sPLT(png_structp png_ptr,
941 png_infop info_ptr, png_const_sPLT_tp entries, int nentries)
942/*
943 * entries - array of png_sPLT_t structures
944 * to be added to the list of palettes
945 * in the info structure.
946 *
947 * nentries - number of palette structures to be
948 * added.
949 */
950{
951 png_sPLT_tp np;
952 int i;
953
954 if (png_ptr == NULL || info_ptr == NULL)
955 return;
956
957 np = (png_sPLT_tp)png_malloc_warn(png_ptr,
958 (info_ptr->splt_palettes_num + nentries) *
959 (png_size_t)png_sizeof(png_sPLT_t));
960
961 if (np == NULL)
962 {
963 png_warning(png_ptr, "No memory for sPLT palettes");
964 return;
965 }
966
967 png_memcpy(np, info_ptr->splt_palettes,
968 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
969
970 png_free(png_ptr, info_ptr->splt_palettes);
971 info_ptr->splt_palettes=NULL;
972
973 for (i = 0; i < nentries; i++)
974 {
975 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
976 png_const_sPLT_tp from = entries + i;
977 png_size_t length;
978
979 length = png_strlen(from->name) + 1;
980 to->name = (png_charp)png_malloc_warn(png_ptr, length);
981
982 if (to->name == NULL)
983 {
984 png_warning(png_ptr,
985 "Out of memory while processing sPLT chunk");
986 continue;
987 }
988
989 png_memcpy(to->name, from->name, length);
990 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
991 from->nentries * png_sizeof(png_sPLT_entry));
992
993 if (to->entries == NULL)
994 {
995 png_warning(png_ptr,
996 "Out of memory while processing sPLT chunk");
997 png_free(png_ptr, to->name);
998 to->name = NULL;
999 continue;
1000 }
1001
1002 png_memcpy(to->entries, from->entries,
1003 from->nentries * png_sizeof(png_sPLT_entry));
1004
1005 to->nentries = from->nentries;
1006 to->depth = from->depth;
1007 }
1008
1009 info_ptr->splt_palettes = np;
1010 info_ptr->splt_palettes_num += nentries;
1011 info_ptr->valid |= PNG_INFO_sPLT;
1012 info_ptr->free_me |= PNG_FREE_SPLT;
1013}
1014#endif /* PNG_sPLT_SUPPORTED */
1015
1016#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1017void PNGAPI
1018png_set_unknown_chunks(png_structp png_ptr,
1019 png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
1020{
1021 png_unknown_chunkp np;
1022 int i;
1023
1024 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
1025 return;
1026
1027 np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
1028 (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
1029 png_sizeof(png_unknown_chunk));
1030
1031 if (np == NULL)
1032 {
1033 png_warning(png_ptr,
1034 "Out of memory while processing unknown chunk");
1035 return;
1036 }
1037
1038 png_memcpy(np, info_ptr->unknown_chunks,
1039 (png_size_t)info_ptr->unknown_chunks_num *
1040 png_sizeof(png_unknown_chunk));
1041
1042 png_free(png_ptr, info_ptr->unknown_chunks);
1043 info_ptr->unknown_chunks = NULL;
1044
1045 for (i = 0; i < num_unknowns; i++)
1046 {
1047 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
1048 png_const_unknown_chunkp from = unknowns + i;
1049
1050 png_memcpy(to->name, from->name, png_sizeof(from->name));
1051 to->name[png_sizeof(to->name)-1] = '\0';
1052 to->size = from->size;
1053
1054 /* Note our location in the read or write sequence */
1055 to->location = (png_byte)(png_ptr->mode & 0xff);
1056
1057 if (from->size == 0)
1058 to->data=NULL;
1059
1060 else
1061 {
1062 to->data = (png_bytep)png_malloc_warn(png_ptr,
1063 (png_size_t)from->size);
1064
1065 if (to->data == NULL)
1066 {
1067 png_warning(png_ptr,
1068 "Out of memory while processing unknown chunk");
1069 to->size = 0;
1070 }
1071
1072 else
1073 png_memcpy(to->data, from->data, from->size);
1074 }
1075 }
1076
1077 info_ptr->unknown_chunks = np;
1078 info_ptr->unknown_chunks_num += num_unknowns;
1079 info_ptr->free_me |= PNG_FREE_UNKN;
1080}
1081
1082void PNGAPI
1083png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
1084 int chunk, int location)
1085{
1086 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
1087 info_ptr->unknown_chunks_num)
1088 info_ptr->unknown_chunks[chunk].location = (png_byte)location;
1089}
1090#endif
1091
1092
1093#ifdef PNG_MNG_FEATURES_SUPPORTED
1094png_uint_32 PNGAPI
1095png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
1096{
1097 png_debug(1, "in png_permit_mng_features");
1098
1099 if (png_ptr == NULL)
1100 return (png_uint_32)0;
1101
1102 png_ptr->mng_features_permitted =
1103 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
1104
1105 return (png_uint_32)png_ptr->mng_features_permitted;
1106}
1107#endif
1108
1109#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1110void PNGAPI
1111png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep
1112 chunk_list, int num_chunks)
1113{
1114 png_bytep new_list, p;
1115 int i, old_num_chunks;
1116 if (png_ptr == NULL)
1117 return;
1118
1119 if (num_chunks == 0)
1120 {
1121 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
1122 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1123
1124 else
1125 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
1126
1127 if (keep == PNG_HANDLE_CHUNK_ALWAYS)
1128 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1129
1130 else
1131 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
1132
1133 return;
1134 }
1135
1136 if (chunk_list == NULL)
1137 return;
1138
1139 old_num_chunks = png_ptr->num_chunk_list;
1140 new_list=(png_bytep)png_malloc(png_ptr,
1141 (png_size_t)(5*(num_chunks + old_num_chunks)));
1142
1143 if (png_ptr->chunk_list != NULL)
1144 {
1145 png_memcpy(new_list, png_ptr->chunk_list,
1146 (png_size_t)(5*old_num_chunks));
1147 png_free(png_ptr, png_ptr->chunk_list);
1148 png_ptr->chunk_list=NULL;
1149 }
1150
1151 png_memcpy(new_list + 5*old_num_chunks, chunk_list,
1152 (png_size_t)(5*num_chunks));
1153
1154 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
1155 *p=(png_byte)keep;
1156
1157 png_ptr->num_chunk_list = old_num_chunks + num_chunks;
1158 png_ptr->chunk_list = new_list;
1159 png_ptr->free_me |= PNG_FREE_LIST;
1160}
1161#endif
1162
1163#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
1164void PNGAPI
1165png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
1166 png_user_chunk_ptr read_user_chunk_fn)
1167{
1168 png_debug(1, "in png_set_read_user_chunk_fn");
1169
1170 if (png_ptr == NULL)
1171 return;
1172
1173 png_ptr->read_user_chunk_fn = read_user_chunk_fn;
1174 png_ptr->user_chunk_ptr = user_chunk_ptr;
1175}
1176#endif
1177
1178#ifdef PNG_INFO_IMAGE_SUPPORTED
1179void PNGAPI
1180png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
1181{
1182 png_debug1(1, "in %s storage function", "rows");
1183
1184 if (png_ptr == NULL || info_ptr == NULL)
1185 return;
1186
1187 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
1188 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
1189
1190 info_ptr->row_pointers = row_pointers;
1191
1192 if (row_pointers)
1193 info_ptr->valid |= PNG_INFO_IDAT;
1194}
1195#endif
1196
1197void PNGAPI
1198png_set_compression_buffer_size(png_structp png_ptr, png_size_t size)
1199{
1200 if (png_ptr == NULL)
1201 return;
1202
1203 png_free(png_ptr, png_ptr->zbuf);
1204
1205 if (size > ZLIB_IO_MAX)
1206 {
1207 png_warning(png_ptr, "Attempt to set buffer size beyond max ignored");
1208 png_ptr->zbuf_size = ZLIB_IO_MAX;
1209 size = ZLIB_IO_MAX; /* must fit */
1210 }
1211
1212 else
1213 png_ptr->zbuf_size = (uInt)size;
1214
1215 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
1216
1217 /* The following ensures a relatively safe failure if this gets called while
1218 * the buffer is actually in use.
1219 */
1220 png_ptr->zstream.next_out = png_ptr->zbuf;
1221 png_ptr->zstream.avail_out = 0;
1222 png_ptr->zstream.avail_in = 0;
1223}
1224
1225void PNGAPI
1226png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
1227{
1228 if (png_ptr && info_ptr)
1229 info_ptr->valid &= ~mask;
1230}
1231
1232
1233
1234#ifdef PNG_SET_USER_LIMITS_SUPPORTED
1235/* This function was added to libpng 1.2.6 */
1236void PNGAPI
1237png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
1238 png_uint_32 user_height_max)
1239{
1240 /* Images with dimensions larger than these limits will be
1241 * rejected by png_set_IHDR(). To accept any PNG datastream
1242 * regardless of dimensions, set both limits to 0x7ffffffL.
1243 */
1244 if (png_ptr == NULL)
1245 return;
1246
1247 png_ptr->user_width_max = user_width_max;
1248 png_ptr->user_height_max = user_height_max;
1249}
1250
1251/* This function was added to libpng 1.4.0 */
1252void PNGAPI
1253png_set_chunk_cache_max (png_structp png_ptr,
1254 png_uint_32 user_chunk_cache_max)
1255{
1256 if (png_ptr)
1257 png_ptr->user_chunk_cache_max = user_chunk_cache_max;
1258}
1259
1260/* This function was added to libpng 1.4.1 */
1261void PNGAPI
1262png_set_chunk_malloc_max (png_structp png_ptr,
1263 png_alloc_size_t user_chunk_malloc_max)
1264{
1265 if (png_ptr)
1266 png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
1267}
1268#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
1269
1270
1271#ifdef PNG_BENIGN_ERRORS_SUPPORTED
1272void PNGAPI
1273png_set_benign_errors(png_structp png_ptr, int allowed)
1274{
1275 png_debug(1, "in png_set_benign_errors");
1276
1277 if (allowed)
1278 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
1279
1280 else
1281 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
1282}
1283#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
1284#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngstruct.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngstruct.h
new file mode 100644
index 0000000..1824c49
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngstruct.h
@@ -0,0 +1,358 @@
1
2/* pngstruct.h - header file for PNG reference library
3 *
4 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
7 *
8 * Last changed in libpng 1.5.9 [February 18, 2012]
9 *
10 * This code is released under the libpng license.
11 * For conditions of distribution and use, see the disclaimer
12 * and license in png.h
13 */
14
15/* The structure that holds the information to read and write PNG files.
16 * The only people who need to care about what is inside of this are the
17 * people who will be modifying the library for their own special needs.
18 * It should NOT be accessed directly by an application.
19 */
20
21#ifndef PNGSTRUCT_H
22#define PNGSTRUCT_H
23/* zlib.h defines the structure z_stream, an instance of which is included
24 * in this structure and is required for decompressing the LZ compressed
25 * data in PNG files.
26 */
27#include "zlib.h"
28
29struct png_struct_def
30{
31#ifdef PNG_SETJMP_SUPPORTED
32 jmp_buf longjmp_buffer; /* used in png_error */
33 png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
34#endif
35 png_error_ptr error_fn; /* function for printing errors and aborting */
36#ifdef PNG_WARNINGS_SUPPORTED
37 png_error_ptr warning_fn; /* function for printing warnings */
38#endif
39 png_voidp error_ptr; /* user supplied struct for error functions */
40 png_rw_ptr write_data_fn; /* function for writing output data */
41 png_rw_ptr read_data_fn; /* function for reading input data */
42 png_voidp io_ptr; /* ptr to application struct for I/O functions */
43
44#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
45 png_user_transform_ptr read_user_transform_fn; /* user read transform */
46#endif
47
48#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
49 png_user_transform_ptr write_user_transform_fn; /* user write transform */
50#endif
51
52/* These were added in libpng-1.0.2 */
53#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
54#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
55 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
56 png_voidp user_transform_ptr; /* user supplied struct for user transform */
57 png_byte user_transform_depth; /* bit depth of user transformed pixels */
58 png_byte user_transform_channels; /* channels in user transformed pixels */
59#endif
60#endif
61
62 png_uint_32 mode; /* tells us where we are in the PNG file */
63 png_uint_32 flags; /* flags indicating various things to libpng */
64 png_uint_32 transformations; /* which transformations to perform */
65
66 z_stream zstream; /* pointer to decompression structure (below) */
67 png_bytep zbuf; /* buffer for zlib */
68 uInt zbuf_size; /* size of zbuf (typically 65536) */
69#ifdef PNG_WRITE_SUPPORTED
70
71/* Added in 1.5.4: state to keep track of whether the zstream has been
72 * initialized and if so whether it is for IDAT or some other chunk.
73 */
74#define PNG_ZLIB_UNINITIALIZED 0
75#define PNG_ZLIB_FOR_IDAT 1
76#define PNG_ZLIB_FOR_TEXT 2 /* anything other than IDAT */
77#define PNG_ZLIB_USE_MASK 3 /* bottom two bits */
78#define PNG_ZLIB_IN_USE 4 /* a flag value */
79
80 png_uint_32 zlib_state; /* State of zlib initialization */
81/* End of material added at libpng 1.5.4 */
82
83 int zlib_level; /* holds zlib compression level */
84 int zlib_method; /* holds zlib compression method */
85 int zlib_window_bits; /* holds zlib compression window bits */
86 int zlib_mem_level; /* holds zlib compression memory level */
87 int zlib_strategy; /* holds zlib compression strategy */
88#endif
89/* Added at libpng 1.5.4 */
90#if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \
91 defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED)
92 int zlib_text_level; /* holds zlib compression level */
93 int zlib_text_method; /* holds zlib compression method */
94 int zlib_text_window_bits; /* holds zlib compression window bits */
95 int zlib_text_mem_level; /* holds zlib compression memory level */
96 int zlib_text_strategy; /* holds zlib compression strategy */
97#endif
98/* End of material added at libpng 1.5.4 */
99
100 png_uint_32 width; /* width of image in pixels */
101 png_uint_32 height; /* height of image in pixels */
102 png_uint_32 num_rows; /* number of rows in current pass */
103 png_uint_32 usr_width; /* width of row at start of write */
104 png_size_t rowbytes; /* size of row in bytes */
105 png_uint_32 iwidth; /* width of current interlaced row in pixels */
106 png_uint_32 row_number; /* current row in interlace pass */
107 png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
108 png_bytep prev_row; /* buffer to save previous (unfiltered) row.
109 * This is a pointer into big_prev_row
110 */
111 png_bytep row_buf; /* buffer to save current (unfiltered) row.
112 * This is a pointer into big_row_buf
113 */
114 png_bytep sub_row; /* buffer to save "sub" row when filtering */
115 png_bytep up_row; /* buffer to save "up" row when filtering */
116 png_bytep avg_row; /* buffer to save "avg" row when filtering */
117 png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
118 png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
119
120 png_uint_32 idat_size; /* current IDAT size for read */
121 png_uint_32 crc; /* current chunk CRC value */
122 png_colorp palette; /* palette from the input file */
123 png_uint_16 num_palette; /* number of color entries in palette */
124 png_uint_16 num_trans; /* number of transparency values */
125 png_byte compression; /* file compression type (always 0) */
126 png_byte filter; /* file filter type (always 0) */
127 png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
128 png_byte pass; /* current interlace pass (0 - 6) */
129 png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
130 png_byte color_type; /* color type of file */
131 png_byte bit_depth; /* bit depth of file */
132 png_byte usr_bit_depth; /* bit depth of users row: write only */
133 png_byte pixel_depth; /* number of bits per pixel */
134 png_byte channels; /* number of channels in file */
135 png_byte usr_channels; /* channels at start of write: write only */
136 png_byte sig_bytes; /* magic bytes read/written from start of file */
137 png_byte maximum_pixel_depth;
138 /* pixel depth used for the row buffers */
139 png_byte transformed_pixel_depth;
140 /* pixel depth after read/write transforms */
141 png_byte io_chunk_string[5];
142 /* string name of chunk */
143
144#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
145 png_uint_16 filler; /* filler bytes for pixel expansion */
146#endif
147
148#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
149 defined(PNG_READ_ALPHA_MODE_SUPPORTED)
150 png_byte background_gamma_type;
151 png_fixed_point background_gamma;
152 png_color_16 background; /* background color in screen gamma space */
153#ifdef PNG_READ_GAMMA_SUPPORTED
154 png_color_16 background_1; /* background normalized to gamma 1.0 */
155#endif
156#endif /* PNG_bKGD_SUPPORTED */
157
158#ifdef PNG_WRITE_FLUSH_SUPPORTED
159 png_flush_ptr output_flush_fn; /* Function for flushing output */
160 png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
161 png_uint_32 flush_rows; /* number of rows written since last flush */
162#endif
163
164#ifdef PNG_READ_GAMMA_SUPPORTED
165 int gamma_shift; /* number of "insignificant" bits in 16-bit gamma */
166 png_fixed_point gamma; /* file gamma value */
167 png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
168
169 png_bytep gamma_table; /* gamma table for 8-bit depth files */
170 png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
171#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
172 defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
173 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
174 png_bytep gamma_from_1; /* converts from 1.0 to screen */
175 png_bytep gamma_to_1; /* converts from file to 1.0 */
176 png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
177 png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
178#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
179#endif
180
181#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
182 png_color_8 sig_bit; /* significant bits in each available channel */
183#endif
184
185#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
186 png_color_8 shift; /* shift for significant bit tranformation */
187#endif
188
189#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
190 || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
191 png_bytep trans_alpha; /* alpha values for paletted files */
192 png_color_16 trans_color; /* transparent color for non-paletted files */
193#endif
194
195 png_read_status_ptr read_row_fn; /* called after each row is decoded */
196 png_write_status_ptr write_row_fn; /* called after each row is encoded */
197#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
198 png_progressive_info_ptr info_fn; /* called after header data fully read */
199 png_progressive_row_ptr row_fn; /* called after a prog. row is decoded */
200 png_progressive_end_ptr end_fn; /* called after image is complete */
201 png_bytep save_buffer_ptr; /* current location in save_buffer */
202 png_bytep save_buffer; /* buffer for previously read data */
203 png_bytep current_buffer_ptr; /* current location in current_buffer */
204 png_bytep current_buffer; /* buffer for recently used data */
205 png_uint_32 push_length; /* size of current input chunk */
206 png_uint_32 skip_length; /* bytes to skip in input data */
207 png_size_t save_buffer_size; /* amount of data now in save_buffer */
208 png_size_t save_buffer_max; /* total size of save_buffer */
209 png_size_t buffer_size; /* total amount of available input data */
210 png_size_t current_buffer_size; /* amount of data now in current_buffer */
211 int process_mode; /* what push library is currently doing */
212 int cur_palette; /* current push library palette index */
213
214# ifdef PNG_TEXT_SUPPORTED
215 png_size_t current_text_size; /* current size of text input data */
216 png_size_t current_text_left; /* how much text left to read in input */
217 png_charp current_text; /* current text chunk buffer */
218 png_charp current_text_ptr; /* current location in current_text */
219# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
220
221#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
222
223#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
224/* For the Borland special 64K segment handler */
225 png_bytepp offset_table_ptr;
226 png_bytep offset_table;
227 png_uint_16 offset_table_number;
228 png_uint_16 offset_table_count;
229 png_uint_16 offset_table_count_free;
230#endif
231
232#ifdef PNG_READ_QUANTIZE_SUPPORTED
233 png_bytep palette_lookup; /* lookup table for quantizing */
234 png_bytep quantize_index; /* index translation for palette files */
235#endif
236
237#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
238 png_uint_16p hist; /* histogram */
239#endif
240
241#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
242 png_byte heuristic_method; /* heuristic for row filter selection */
243 png_byte num_prev_filters; /* number of weights for previous rows */
244 png_bytep prev_filters; /* filter type(s) of previous row(s) */
245 png_uint_16p filter_weights; /* weight(s) for previous line(s) */
246 png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
247 png_uint_16p filter_costs; /* relative filter calculation cost */
248 png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
249#endif
250
251#ifdef PNG_TIME_RFC1123_SUPPORTED
252 char time_buffer[29]; /* String to hold RFC 1123 time text */
253#endif
254
255/* New members added in libpng-1.0.6 */
256
257 png_uint_32 free_me; /* flags items libpng is responsible for freeing */
258
259#ifdef PNG_USER_CHUNKS_SUPPORTED
260 png_voidp user_chunk_ptr;
261 png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
262#endif
263
264#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
265 int num_chunk_list;
266 png_bytep chunk_list;
267#endif
268
269#ifdef PNG_READ_sRGB_SUPPORTED
270 /* Added in 1.5.5 to record an sRGB chunk in the png. */
271 png_byte is_sRGB;
272#endif
273
274/* New members added in libpng-1.0.3 */
275#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
276 png_byte rgb_to_gray_status;
277 /* Added in libpng 1.5.5 to record setting of coefficients: */
278 png_byte rgb_to_gray_coefficients_set;
279 /* These were changed from png_byte in libpng-1.0.6 */
280 png_uint_16 rgb_to_gray_red_coeff;
281 png_uint_16 rgb_to_gray_green_coeff;
282 /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
283#endif
284
285/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
286#if defined(PNG_MNG_FEATURES_SUPPORTED)
287/* Changed from png_byte to png_uint_32 at version 1.2.0 */
288 png_uint_32 mng_features_permitted;
289#endif
290
291/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
292#ifdef PNG_MNG_FEATURES_SUPPORTED
293 png_byte filter_type;
294#endif
295
296/* New members added in libpng-1.2.0 */
297
298/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
299#ifdef PNG_USER_MEM_SUPPORTED
300 png_voidp mem_ptr; /* user supplied struct for mem functions */
301 png_malloc_ptr malloc_fn; /* function for allocating memory */
302 png_free_ptr free_fn; /* function for freeing memory */
303#endif
304
305/* New member added in libpng-1.0.13 and 1.2.0 */
306 png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
307
308#ifdef PNG_READ_QUANTIZE_SUPPORTED
309/* The following three members were added at version 1.0.14 and 1.2.4 */
310 png_bytep quantize_sort; /* working sort array */
311 png_bytep index_to_palette; /* where the original index currently is
312 in the palette */
313 png_bytep palette_to_index; /* which original index points to this
314 palette color */
315#endif
316
317/* New members added in libpng-1.0.16 and 1.2.6 */
318 png_byte compression_type;
319
320#ifdef PNG_USER_LIMITS_SUPPORTED
321 png_uint_32 user_width_max;
322 png_uint_32 user_height_max;
323
324 /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
325 * chunks that can be stored (0 means unlimited).
326 */
327 png_uint_32 user_chunk_cache_max;
328
329 /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
330 * can occupy when decompressed. 0 means unlimited.
331 */
332 png_alloc_size_t user_chunk_malloc_max;
333#endif
334
335/* New member added in libpng-1.0.25 and 1.2.17 */
336#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
337 /* Storage for unknown chunk that the library doesn't recognize. */
338 png_unknown_chunk unknown_chunk;
339#endif
340
341/* New member added in libpng-1.2.26 */
342 png_size_t old_big_row_buf_size;
343
344/* New member added in libpng-1.2.30 */
345 png_charp chunkdata; /* buffer for reading chunk data */
346
347#ifdef PNG_IO_STATE_SUPPORTED
348/* New member added in libpng-1.4.0 */
349 png_uint_32 io_state;
350#endif
351
352/* New member added in libpng-1.5.6 */
353 png_bytep big_prev_row;
354
355 void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,
356 png_bytep row, png_const_bytep prev_row);
357};
358#endif /* PNGSTRUCT_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.c
new file mode 100644
index 0000000..8405174
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.c
@@ -0,0 +1,1820 @@
1
2/* pngtest.c - a simple test program to test libpng
3 *
4 * Last changed in libpng 1.5.6 [November 3, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This program reads in a PNG image, writes it out again, and then
14 * compares the two files. If the files are identical, this shows that
15 * the basic chunk handling, filtering, and (de)compression code is working
16 * properly. It does not currently test all of the transforms, although
17 * it probably should.
18 *
19 * The program will report "FAIL" in certain legitimate cases:
20 * 1) when the compression level or filter selection method is changed.
21 * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
22 * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks
23 * exist in the input file.
24 * 4) others not listed here...
25 * In these cases, it is best to check with another tool such as "pngcheck"
26 * to see what the differences between the two files are.
27 *
28 * If a filename is given on the command-line, then this file is used
29 * for the input, rather than the default "pngtest.png". This allows
30 * testing a wide variety of files easily. You can also test a number
31 * of files at once by typing "pngtest -m file1.png file2.png ..."
32 */
33
34#define _POSIX_SOURCE 1
35
36#include "zlib.h"
37#include "png.h"
38/* Copied from pngpriv.h but only used in error messages below. */
39#ifndef PNG_ZBUF_SIZE
40# define PNG_ZBUF_SIZE 8192
41#endif
42# include <stdio.h>
43# include <stdlib.h>
44# include <string.h>
45# define FCLOSE(file) fclose(file)
46
47#ifndef PNG_STDIO_SUPPORTED
48typedef FILE * png_FILE_p;
49#endif
50
51/* Makes pngtest verbose so we can find problems. */
52#ifndef PNG_DEBUG
53# define PNG_DEBUG 0
54#endif
55
56#if PNG_DEBUG > 1
57# define pngtest_debug(m) ((void)fprintf(stderr, m "\n"))
58# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1))
59# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
60#else
61# define pngtest_debug(m) ((void)0)
62# define pngtest_debug1(m,p1) ((void)0)
63# define pngtest_debug2(m,p1,p2) ((void)0)
64#endif
65
66#if !PNG_DEBUG
67# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
68#endif
69
70/* The code uses memcmp and memcpy on large objects (typically row pointers) so
71 * it is necessary to do soemthing special on certain architectures, note that
72 * the actual support for this was effectively removed in 1.4, so only the
73 * memory remains in this program:
74 */
75#define CVT_PTR(ptr) (ptr)
76#define CVT_PTR_NOCHECK(ptr) (ptr)
77#define png_memcmp memcmp
78#define png_memcpy memcpy
79#define png_memset memset
80
81/* Turn on CPU timing
82#define PNGTEST_TIMING
83*/
84
85#ifndef PNG_FLOATING_POINT_SUPPORTED
86#undef PNGTEST_TIMING
87#endif
88
89#ifdef PNGTEST_TIMING
90static float t_start, t_stop, t_decode, t_encode, t_misc;
91#include <time.h>
92#endif
93
94#ifdef PNG_TIME_RFC1123_SUPPORTED
95#define PNG_tIME_STRING_LENGTH 29
96static int tIME_chunk_present = 0;
97static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
98#endif
99
100static int verbose = 0;
101static int strict = 0;
102
103int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
104
105#ifdef __TURBOC__
106#include <mem.h>
107#endif
108
109/* Defined so I can write to a file on gui/windowing platforms */
110/* #define STDERR stderr */
111#define STDERR stdout /* For DOS */
112
113/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
114#ifndef png_jmpbuf
115# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
116#endif
117
118/* Example of using row callbacks to make a simple progress meter */
119static int status_pass = 1;
120static int status_dots_requested = 0;
121static int status_dots = 1;
122
123void PNGCBAPI
124read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
125void PNGCBAPI
126read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
127{
128 if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)
129 return;
130
131 if (status_pass != pass)
132 {
133 fprintf(stdout, "\n Pass %d: ", pass);
134 status_pass = pass;
135 status_dots = 31;
136 }
137
138 status_dots--;
139
140 if (status_dots == 0)
141 {
142 fprintf(stdout, "\n ");
143 status_dots=30;
144 }
145
146 fprintf(stdout, "r");
147}
148
149void PNGCBAPI
150write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
151void PNGCBAPI
152write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
153{
154 if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)
155 return;
156
157 fprintf(stdout, "w");
158}
159
160
161#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
162/* Example of using user transform callback (we don't transform anything,
163 * but merely examine the row filters. We set this to 256 rather than
164 * 5 in case illegal filter values are present.)
165 */
166static png_uint_32 filters_used[256];
167void PNGCBAPI
168count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);
169void PNGCBAPI
170count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
171{
172 if (png_ptr != NULL && row_info != NULL)
173 ++filters_used[*(data - 1)];
174}
175#endif
176
177#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
178/* Example of using user transform callback (we don't transform anything,
179 * but merely count the zero samples)
180 */
181
182static png_uint_32 zero_samples;
183
184void PNGCBAPI
185count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data);
186void PNGCBAPI
187count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
188{
189 png_bytep dp = data;
190 if (png_ptr == NULL)
191 return;
192
193 /* Contents of row_info:
194 * png_uint_32 width width of row
195 * png_uint_32 rowbytes number of bytes in row
196 * png_byte color_type color type of pixels
197 * png_byte bit_depth bit depth of samples
198 * png_byte channels number of channels (1-4)
199 * png_byte pixel_depth bits per pixel (depth*channels)
200 */
201
202 /* Counts the number of zero samples (or zero pixels if color_type is 3 */
203
204 if (row_info->color_type == 0 || row_info->color_type == 3)
205 {
206 int pos = 0;
207 png_uint_32 n, nstop;
208
209 for (n = 0, nstop=row_info->width; n<nstop; n++)
210 {
211 if (row_info->bit_depth == 1)
212 {
213 if (((*dp << pos++ ) & 0x80) == 0)
214 zero_samples++;
215
216 if (pos == 8)
217 {
218 pos = 0;
219 dp++;
220 }
221 }
222
223 if (row_info->bit_depth == 2)
224 {
225 if (((*dp << (pos+=2)) & 0xc0) == 0)
226 zero_samples++;
227
228 if (pos == 8)
229 {
230 pos = 0;
231 dp++;
232 }
233 }
234
235 if (row_info->bit_depth == 4)
236 {
237 if (((*dp << (pos+=4)) & 0xf0) == 0)
238 zero_samples++;
239
240 if (pos == 8)
241 {
242 pos = 0;
243 dp++;
244 }
245 }
246
247 if (row_info->bit_depth == 8)
248 if (*dp++ == 0)
249 zero_samples++;
250
251 if (row_info->bit_depth == 16)
252 {
253 if ((*dp | *(dp+1)) == 0)
254 zero_samples++;
255 dp+=2;
256 }
257 }
258 }
259 else /* Other color types */
260 {
261 png_uint_32 n, nstop;
262 int channel;
263 int color_channels = row_info->channels;
264 if (row_info->color_type > 3)color_channels--;
265
266 for (n = 0, nstop=row_info->width; n<nstop; n++)
267 {
268 for (channel = 0; channel < color_channels; channel++)
269 {
270 if (row_info->bit_depth == 8)
271 if (*dp++ == 0)
272 zero_samples++;
273
274 if (row_info->bit_depth == 16)
275 {
276 if ((*dp | *(dp+1)) == 0)
277 zero_samples++;
278
279 dp+=2;
280 }
281 }
282 if (row_info->color_type > 3)
283 {
284 dp++;
285 if (row_info->bit_depth == 16)
286 dp++;
287 }
288 }
289 }
290}
291#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
292
293static int wrote_question = 0;
294
295#ifndef PNG_STDIO_SUPPORTED
296/* START of code to validate stdio-free compilation */
297/* These copies of the default read/write functions come from pngrio.c and
298 * pngwio.c. They allow "don't include stdio" testing of the library.
299 * This is the function that does the actual reading of data. If you are
300 * not reading from a standard C stream, you should create a replacement
301 * read_data function and use it at run time with png_set_read_fn(), rather
302 * than changing the library.
303 */
304
305#ifdef PNG_IO_STATE_SUPPORTED
306void
307pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
308 png_uint_32 io_op);
309void
310pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
311 png_uint_32 io_op)
312{
313 png_uint_32 io_state = png_get_io_state(png_ptr);
314 int err = 0;
315
316 /* Check if the current operation (reading / writing) is as expected. */
317 if ((io_state & PNG_IO_MASK_OP) != io_op)
318 png_error(png_ptr, "Incorrect operation in I/O state");
319
320 /* Check if the buffer size specific to the current location
321 * (file signature / header / data / crc) is as expected.
322 */
323 switch (io_state & PNG_IO_MASK_LOC)
324 {
325 case PNG_IO_SIGNATURE:
326 if (data_length > 8)
327 err = 1;
328 break;
329 case PNG_IO_CHUNK_HDR:
330 if (data_length != 8)
331 err = 1;
332 break;
333 case PNG_IO_CHUNK_DATA:
334 break; /* no restrictions here */
335 case PNG_IO_CHUNK_CRC:
336 if (data_length != 4)
337 err = 1;
338 break;
339 default:
340 err = 1; /* uninitialized */
341 }
342 if (err)
343 png_error(png_ptr, "Bad I/O state or buffer size");
344}
345#endif
346
347#ifndef USE_FAR_KEYWORD
348static void PNGCBAPI
349pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
350{
351 png_size_t check = 0;
352 png_voidp io_ptr;
353
354 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
355 * instead of an int, which is what fread() actually returns.
356 */
357 io_ptr = png_get_io_ptr(png_ptr);
358 if (io_ptr != NULL)
359 {
360 check = fread(data, 1, length, (png_FILE_p)io_ptr);
361 }
362
363 if (check != length)
364 {
365 png_error(png_ptr, "Read Error");
366 }
367
368#ifdef PNG_IO_STATE_SUPPORTED
369 pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
370#endif
371}
372#else
373/* This is the model-independent version. Since the standard I/O library
374 can't handle far buffers in the medium and small models, we have to copy
375 the data.
376*/
377
378#define NEAR_BUF_SIZE 1024
379#define MIN(a,b) (a <= b ? a : b)
380
381static void PNGCBAPI
382pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
383{
384 png_size_t check;
385 png_byte *n_data;
386 png_FILE_p io_ptr;
387
388 /* Check if data really is near. If so, use usual code. */
389 n_data = (png_byte *)CVT_PTR_NOCHECK(data);
390 io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
391 if ((png_bytep)n_data == data)
392 {
393 check = fread(n_data, 1, length, io_ptr);
394 }
395 else
396 {
397 png_byte buf[NEAR_BUF_SIZE];
398 png_size_t read, remaining, err;
399 check = 0;
400 remaining = length;
401
402 do
403 {
404 read = MIN(NEAR_BUF_SIZE, remaining);
405 err = fread(buf, 1, 1, io_ptr);
406 png_memcpy(data, buf, read); /* Copy far buffer to near buffer */
407 if (err != read)
408 break;
409 else
410 check += err;
411 data += read;
412 remaining -= read;
413 }
414 while (remaining != 0);
415 }
416
417 if (check != length)
418 png_error(png_ptr, "Read Error");
419
420#ifdef PNG_IO_STATE_SUPPORTED
421 pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
422#endif
423}
424#endif /* USE_FAR_KEYWORD */
425
426#ifdef PNG_WRITE_FLUSH_SUPPORTED
427static void PNGCBAPI
428pngtest_flush(png_structp png_ptr)
429{
430 /* Do nothing; fflush() is said to be just a waste of energy. */
431 PNG_UNUSED(png_ptr) /* Stifle compiler warning */
432}
433#endif
434
435/* This is the function that does the actual writing of data. If you are
436 * not writing to a standard C stream, you should create a replacement
437 * write_data function and use it at run time with png_set_write_fn(), rather
438 * than changing the library.
439 */
440#ifndef USE_FAR_KEYWORD
441static void PNGCBAPI
442pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
443{
444 png_size_t check;
445
446 check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));
447
448 if (check != length)
449 {
450 png_error(png_ptr, "Write Error");
451 }
452
453#ifdef PNG_IO_STATE_SUPPORTED
454 pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
455#endif
456}
457#else
458/* This is the model-independent version. Since the standard I/O library
459 can't handle far buffers in the medium and small models, we have to copy
460 the data.
461*/
462
463#define NEAR_BUF_SIZE 1024
464#define MIN(a,b) (a <= b ? a : b)
465
466static void PNGCBAPI
467pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
468{
469 png_size_t check;
470 png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
471 png_FILE_p io_ptr;
472
473 /* Check if data really is near. If so, use usual code. */
474 near_data = (png_byte *)CVT_PTR_NOCHECK(data);
475 io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
476
477 if ((png_bytep)near_data == data)
478 {
479 check = fwrite(near_data, 1, length, io_ptr);
480 }
481
482 else
483 {
484 png_byte buf[NEAR_BUF_SIZE];
485 png_size_t written, remaining, err;
486 check = 0;
487 remaining = length;
488
489 do
490 {
491 written = MIN(NEAR_BUF_SIZE, remaining);
492 png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
493 err = fwrite(buf, 1, written, io_ptr);
494 if (err != written)
495 break;
496 else
497 check += err;
498 data += written;
499 remaining -= written;
500 }
501 while (remaining != 0);
502 }
503
504 if (check != length)
505 {
506 png_error(png_ptr, "Write Error");
507 }
508
509#ifdef PNG_IO_STATE_SUPPORTED
510 pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
511#endif
512}
513#endif /* USE_FAR_KEYWORD */
514
515/* This function is called when there is a warning, but the library thinks
516 * it can continue anyway. Replacement functions don't have to do anything
517 * here if you don't want to. In the default configuration, png_ptr is
518 * not used, but it is passed in case it may be useful.
519 */
520static void PNGCBAPI
521pngtest_warning(png_structp png_ptr, png_const_charp message)
522{
523 PNG_CONST char *name = "UNKNOWN (ERROR!)";
524 char *test;
525 test = png_get_error_ptr(png_ptr);
526
527 if (test == NULL)
528 fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
529
530 else
531 fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
532}
533
534/* This is the default error handling function. Note that replacements for
535 * this function MUST NOT RETURN, or the program will likely crash. This
536 * function is used by default, or if the program supplies NULL for the
537 * error function pointer in png_set_error_fn().
538 */
539static void PNGCBAPI
540pngtest_error(png_structp png_ptr, png_const_charp message)
541{
542 pngtest_warning(png_ptr, message);
543 /* We can return because png_error calls the default handler, which is
544 * actually OK in this case.
545 */
546}
547#endif /* !PNG_STDIO_SUPPORTED */
548/* END of code to validate stdio-free compilation */
549
550/* START of code to validate memory allocation and deallocation */
551#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
552
553/* Allocate memory. For reasonable files, size should never exceed
554 * 64K. However, zlib may allocate more then 64K if you don't tell
555 * it not to. See zconf.h and png.h for more information. zlib does
556 * need to allocate exactly 64K, so whatever you call here must
557 * have the ability to do that.
558 *
559 * This piece of code can be compiled to validate max 64K allocations
560 * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
561 */
562typedef struct memory_information
563{
564 png_alloc_size_t size;
565 png_voidp pointer;
566 struct memory_information FAR *next;
567} memory_information;
568typedef memory_information FAR *memory_infop;
569
570static memory_infop pinformation = NULL;
571static int current_allocation = 0;
572static int maximum_allocation = 0;
573static int total_allocation = 0;
574static int num_allocations = 0;
575
576png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
577 png_alloc_size_t size));
578void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
579
580png_voidp
581PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
582{
583
584 /* png_malloc has already tested for NULL; png_create_struct calls
585 * png_debug_malloc directly, with png_ptr == NULL which is OK
586 */
587
588 if (size == 0)
589 return (NULL);
590
591 /* This calls the library allocator twice, once to get the requested
592 buffer and once to get a new free list entry. */
593 {
594 /* Disable malloc_fn and free_fn */
595 memory_infop pinfo;
596 png_set_mem_fn(png_ptr, NULL, NULL, NULL);
597 pinfo = (memory_infop)png_malloc(png_ptr,
598 png_sizeof(*pinfo));
599 pinfo->size = size;
600 current_allocation += size;
601 total_allocation += size;
602 num_allocations ++;
603
604 if (current_allocation > maximum_allocation)
605 maximum_allocation = current_allocation;
606
607 pinfo->pointer = png_malloc(png_ptr, size);
608 /* Restore malloc_fn and free_fn */
609
610 png_set_mem_fn(png_ptr,
611 NULL, png_debug_malloc, png_debug_free);
612
613 if (size != 0 && pinfo->pointer == NULL)
614 {
615 current_allocation -= size;
616 total_allocation -= size;
617 png_error(png_ptr,
618 "out of memory in pngtest->png_debug_malloc");
619 }
620
621 pinfo->next = pinformation;
622 pinformation = pinfo;
623 /* Make sure the caller isn't assuming zeroed memory. */
624 png_memset(pinfo->pointer, 0xdd, pinfo->size);
625
626 if (verbose)
627 printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
628 pinfo->pointer);
629
630 return (png_voidp)(pinfo->pointer);
631 }
632}
633
634/* Free a pointer. It is removed from the list at the same time. */
635void PNGCBAPI
636png_debug_free(png_structp png_ptr, png_voidp ptr)
637{
638 if (png_ptr == NULL)
639 fprintf(STDERR, "NULL pointer to png_debug_free.\n");
640
641 if (ptr == 0)
642 {
643#if 0 /* This happens all the time. */
644 fprintf(STDERR, "WARNING: freeing NULL pointer\n");
645#endif
646 return;
647 }
648
649 /* Unlink the element from the list. */
650 {
651 memory_infop FAR *ppinfo = &pinformation;
652
653 for (;;)
654 {
655 memory_infop pinfo = *ppinfo;
656
657 if (pinfo->pointer == ptr)
658 {
659 *ppinfo = pinfo->next;
660 current_allocation -= pinfo->size;
661 if (current_allocation < 0)
662 fprintf(STDERR, "Duplicate free of memory\n");
663 /* We must free the list element too, but first kill
664 the memory that is to be freed. */
665 png_memset(ptr, 0x55, pinfo->size);
666 png_free_default(png_ptr, pinfo);
667 pinfo = NULL;
668 break;
669 }
670
671 if (pinfo->next == NULL)
672 {
673 fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);
674 break;
675 }
676
677 ppinfo = &pinfo->next;
678 }
679 }
680
681 /* Finally free the data. */
682 if (verbose)
683 printf("Freeing %p\n", ptr);
684
685 png_free_default(png_ptr, ptr);
686 ptr = NULL;
687}
688#endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
689/* END of code to test memory allocation/deallocation */
690
691
692/* Demonstration of user chunk support of the sTER and vpAg chunks */
693#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
694
695/* (sTER is a public chunk not yet known by libpng. vpAg is a private
696chunk used in ImageMagick to store "virtual page" size). */
697
698static png_uint_32 user_chunk_data[4];
699
700 /* 0: sTER mode + 1
701 * 1: vpAg width
702 * 2: vpAg height
703 * 3: vpAg units
704 */
705
706static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
707 png_unknown_chunkp chunk)
708{
709 png_uint_32
710 *my_user_chunk_data;
711
712 /* Return one of the following:
713 * return (-n); chunk had an error
714 * return (0); did not recognize
715 * return (n); success
716 *
717 * The unknown chunk structure contains the chunk data:
718 * png_byte name[5];
719 * png_byte *data;
720 * png_size_t size;
721 *
722 * Note that libpng has already taken care of the CRC handling.
723 */
724
725 if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */
726 chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */
727 {
728 /* Found sTER chunk */
729 if (chunk->size != 1)
730 return (-1); /* Error return */
731
732 if (chunk->data[0] != 0 && chunk->data[0] != 1)
733 return (-1); /* Invalid mode */
734
735 my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
736 my_user_chunk_data[0]=chunk->data[0]+1;
737 return (1);
738 }
739
740 if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
741 chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */
742 return (0); /* Did not recognize */
743
744 /* Found ImageMagick vpAg chunk */
745
746 if (chunk->size != 9)
747 return (-1); /* Error return */
748
749 my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
750
751 my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
752 my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
753 my_user_chunk_data[3]=(png_uint_32)chunk->data[8];
754
755 return (1);
756
757}
758#endif
759/* END of code to demonstrate user chunk support */
760
761/* Test one file */
762int
763test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
764{
765 static png_FILE_p fpin;
766 static png_FILE_p fpout; /* "static" prevents setjmp corruption */
767 png_structp read_ptr;
768 png_infop read_info_ptr, end_info_ptr;
769#ifdef PNG_WRITE_SUPPORTED
770 png_structp write_ptr;
771 png_infop write_info_ptr;
772 png_infop write_end_info_ptr;
773#else
774 png_structp write_ptr = NULL;
775 png_infop write_info_ptr = NULL;
776 png_infop write_end_info_ptr = NULL;
777#endif
778 png_bytep row_buf;
779 png_uint_32 y;
780 png_uint_32 width, height;
781 int num_pass, pass;
782 int bit_depth, color_type;
783#ifdef PNG_SETJMP_SUPPORTED
784#ifdef USE_FAR_KEYWORD
785 jmp_buf tmp_jmpbuf;
786#endif
787#endif
788
789 char inbuf[256], outbuf[256];
790
791 row_buf = NULL;
792
793 if ((fpin = fopen(inname, "rb")) == NULL)
794 {
795 fprintf(STDERR, "Could not find input file %s\n", inname);
796 return (1);
797 }
798
799 if ((fpout = fopen(outname, "wb")) == NULL)
800 {
801 fprintf(STDERR, "Could not open output file %s\n", outname);
802 FCLOSE(fpin);
803 return (1);
804 }
805
806 pngtest_debug("Allocating read and write structures");
807#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
808 read_ptr =
809 png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
810 NULL, NULL, NULL, png_debug_malloc, png_debug_free);
811#else
812 read_ptr =
813 png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
814#endif
815#ifndef PNG_STDIO_SUPPORTED
816 png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
817 pngtest_warning);
818#endif
819
820#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
821 user_chunk_data[0] = 0;
822 user_chunk_data[1] = 0;
823 user_chunk_data[2] = 0;
824 user_chunk_data[3] = 0;
825 png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
826 read_user_chunk_callback);
827
828#endif
829#ifdef PNG_WRITE_SUPPORTED
830#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
831 write_ptr =
832 png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
833 NULL, NULL, NULL, png_debug_malloc, png_debug_free);
834#else
835 write_ptr =
836 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
837#endif
838#ifndef PNG_STDIO_SUPPORTED
839 png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
840 pngtest_warning);
841#endif
842#endif
843 pngtest_debug("Allocating read_info, write_info and end_info structures");
844 read_info_ptr = png_create_info_struct(read_ptr);
845 end_info_ptr = png_create_info_struct(read_ptr);
846#ifdef PNG_WRITE_SUPPORTED
847 write_info_ptr = png_create_info_struct(write_ptr);
848 write_end_info_ptr = png_create_info_struct(write_ptr);
849#endif
850
851#ifdef PNG_SETJMP_SUPPORTED
852 pngtest_debug("Setting jmpbuf for read struct");
853#ifdef USE_FAR_KEYWORD
854 if (setjmp(tmp_jmpbuf))
855#else
856 if (setjmp(png_jmpbuf(read_ptr)))
857#endif
858 {
859 fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
860 png_free(read_ptr, row_buf);
861 row_buf = NULL;
862 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
863#ifdef PNG_WRITE_SUPPORTED
864 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
865 png_destroy_write_struct(&write_ptr, &write_info_ptr);
866#endif
867 FCLOSE(fpin);
868 FCLOSE(fpout);
869 return (1);
870 }
871#ifdef USE_FAR_KEYWORD
872 png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
873#endif
874
875#ifdef PNG_WRITE_SUPPORTED
876 pngtest_debug("Setting jmpbuf for write struct");
877#ifdef USE_FAR_KEYWORD
878
879 if (setjmp(tmp_jmpbuf))
880#else
881 if (setjmp(png_jmpbuf(write_ptr)))
882#endif
883 {
884 fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
885 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
886 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
887#ifdef PNG_WRITE_SUPPORTED
888 png_destroy_write_struct(&write_ptr, &write_info_ptr);
889#endif
890 FCLOSE(fpin);
891 FCLOSE(fpout);
892 return (1);
893 }
894
895#ifdef USE_FAR_KEYWORD
896 png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
897#endif
898#endif
899#endif
900
901 pngtest_debug("Initializing input and output streams");
902#ifdef PNG_STDIO_SUPPORTED
903 png_init_io(read_ptr, fpin);
904# ifdef PNG_WRITE_SUPPORTED
905 png_init_io(write_ptr, fpout);
906# endif
907#else
908 png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
909# ifdef PNG_WRITE_SUPPORTED
910 png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
911# ifdef PNG_WRITE_FLUSH_SUPPORTED
912 pngtest_flush);
913# else
914 NULL);
915# endif
916# endif
917#endif
918
919#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
920 /* Normally one would use Z_DEFAULT_STRATEGY for text compression.
921 * This is here just to make pngtest replicate the results from libpng
922 * versions prior to 1.5.4, and to test this new API.
923 */
924 png_set_text_compression_strategy(write_ptr, Z_FILTERED);
925#endif
926
927 if (status_dots_requested == 1)
928 {
929#ifdef PNG_WRITE_SUPPORTED
930 png_set_write_status_fn(write_ptr, write_row_callback);
931#endif
932 png_set_read_status_fn(read_ptr, read_row_callback);
933 }
934
935 else
936 {
937#ifdef PNG_WRITE_SUPPORTED
938 png_set_write_status_fn(write_ptr, NULL);
939#endif
940 png_set_read_status_fn(read_ptr, NULL);
941 }
942
943#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
944 {
945 int i;
946
947 for (i = 0; i<256; i++)
948 filters_used[i] = 0;
949
950 png_set_read_user_transform_fn(read_ptr, count_filters);
951 }
952#endif
953#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
954 zero_samples = 0;
955 png_set_write_user_transform_fn(write_ptr, count_zero_samples);
956#endif
957
958#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
959# ifndef PNG_HANDLE_CHUNK_ALWAYS
960# define PNG_HANDLE_CHUNK_ALWAYS 3
961# endif
962 png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
963 NULL, 0);
964#endif
965#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
966# ifndef PNG_HANDLE_CHUNK_IF_SAFE
967# define PNG_HANDLE_CHUNK_IF_SAFE 2
968# endif
969 png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
970 NULL, 0);
971#endif
972
973 pngtest_debug("Reading info struct");
974 png_read_info(read_ptr, read_info_ptr);
975
976 pngtest_debug("Transferring info struct");
977 {
978 int interlace_type, compression_type, filter_type;
979
980 if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
981 &color_type, &interlace_type, &compression_type, &filter_type))
982 {
983 png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
984#ifdef PNG_WRITE_INTERLACING_SUPPORTED
985 color_type, interlace_type, compression_type, filter_type);
986#else
987 color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
988#endif
989 }
990 }
991#ifdef PNG_FIXED_POINT_SUPPORTED
992#ifdef PNG_cHRM_SUPPORTED
993 {
994 png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
995 blue_y;
996
997 if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
998 &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
999 {
1000 png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
1001 red_y, green_x, green_y, blue_x, blue_y);
1002 }
1003 }
1004#endif
1005#ifdef PNG_gAMA_SUPPORTED
1006 {
1007 png_fixed_point gamma;
1008
1009 if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
1010 png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
1011 }
1012#endif
1013#else /* Use floating point versions */
1014#ifdef PNG_FLOATING_POINT_SUPPORTED
1015#ifdef PNG_cHRM_SUPPORTED
1016 {
1017 double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
1018 blue_y;
1019
1020 if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
1021 &red_y, &green_x, &green_y, &blue_x, &blue_y))
1022 {
1023 png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
1024 red_y, green_x, green_y, blue_x, blue_y);
1025 }
1026 }
1027#endif
1028#ifdef PNG_gAMA_SUPPORTED
1029 {
1030 double gamma;
1031
1032 if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
1033 png_set_gAMA(write_ptr, write_info_ptr, gamma);
1034 }
1035#endif
1036#endif /* Floating point */
1037#endif /* Fixed point */
1038#ifdef PNG_iCCP_SUPPORTED
1039 {
1040 png_charp name;
1041 png_bytep profile;
1042 png_uint_32 proflen;
1043 int compression_type;
1044
1045 if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
1046 &profile, &proflen))
1047 {
1048 png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
1049 profile, proflen);
1050 }
1051 }
1052#endif
1053#ifdef PNG_sRGB_SUPPORTED
1054 {
1055 int intent;
1056
1057 if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
1058 png_set_sRGB(write_ptr, write_info_ptr, intent);
1059 }
1060#endif
1061 {
1062 png_colorp palette;
1063 int num_palette;
1064
1065 if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
1066 png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
1067 }
1068#ifdef PNG_bKGD_SUPPORTED
1069 {
1070 png_color_16p background;
1071
1072 if (png_get_bKGD(read_ptr, read_info_ptr, &background))
1073 {
1074 png_set_bKGD(write_ptr, write_info_ptr, background);
1075 }
1076 }
1077#endif
1078#ifdef PNG_hIST_SUPPORTED
1079 {
1080 png_uint_16p hist;
1081
1082 if (png_get_hIST(read_ptr, read_info_ptr, &hist))
1083 png_set_hIST(write_ptr, write_info_ptr, hist);
1084 }
1085#endif
1086#ifdef PNG_oFFs_SUPPORTED
1087 {
1088 png_int_32 offset_x, offset_y;
1089 int unit_type;
1090
1091 if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
1092 &unit_type))
1093 {
1094 png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
1095 }
1096 }
1097#endif
1098#ifdef PNG_pCAL_SUPPORTED
1099 {
1100 png_charp purpose, units;
1101 png_charpp params;
1102 png_int_32 X0, X1;
1103 int type, nparams;
1104
1105 if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
1106 &nparams, &units, &params))
1107 {
1108 png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
1109 nparams, units, params);
1110 }
1111 }
1112#endif
1113#ifdef PNG_pHYs_SUPPORTED
1114 {
1115 png_uint_32 res_x, res_y;
1116 int unit_type;
1117
1118 if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
1119 png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
1120 }
1121#endif
1122#ifdef PNG_sBIT_SUPPORTED
1123 {
1124 png_color_8p sig_bit;
1125
1126 if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
1127 png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
1128 }
1129#endif
1130#ifdef PNG_sCAL_SUPPORTED
1131#ifdef PNG_FLOATING_POINT_SUPPORTED
1132 {
1133 int unit;
1134 double scal_width, scal_height;
1135
1136 if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
1137 &scal_height))
1138 {
1139 png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
1140 }
1141 }
1142#else
1143#ifdef PNG_FIXED_POINT_SUPPORTED
1144 {
1145 int unit;
1146 png_charp scal_width, scal_height;
1147
1148 if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
1149 &scal_height))
1150 {
1151 png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
1152 scal_height);
1153 }
1154 }
1155#endif
1156#endif
1157#endif
1158#ifdef PNG_TEXT_SUPPORTED
1159 {
1160 png_textp text_ptr;
1161 int num_text;
1162
1163 if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
1164 {
1165 pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
1166
1167 if (verbose)
1168 printf("\n Text compression=%d\n", text_ptr->compression);
1169
1170 png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
1171 }
1172 }
1173#endif
1174#ifdef PNG_tIME_SUPPORTED
1175 {
1176 png_timep mod_time;
1177
1178 if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
1179 {
1180 png_set_tIME(write_ptr, write_info_ptr, mod_time);
1181#ifdef PNG_TIME_RFC1123_SUPPORTED
1182 /* We have to use png_memcpy instead of "=" because the string
1183 * pointed to by png_convert_to_rfc1123() gets free'ed before
1184 * we use it.
1185 */
1186 png_memcpy(tIME_string,
1187 png_convert_to_rfc1123(read_ptr, mod_time),
1188 png_sizeof(tIME_string));
1189
1190 tIME_string[png_sizeof(tIME_string) - 1] = '\0';
1191 tIME_chunk_present++;
1192#endif /* PNG_TIME_RFC1123_SUPPORTED */
1193 }
1194 }
1195#endif
1196#ifdef PNG_tRNS_SUPPORTED
1197 {
1198 png_bytep trans_alpha;
1199 int num_trans;
1200 png_color_16p trans_color;
1201
1202 if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
1203 &trans_color))
1204 {
1205 int sample_max = (1 << bit_depth);
1206 /* libpng doesn't reject a tRNS chunk with out-of-range samples */
1207 if (!((color_type == PNG_COLOR_TYPE_GRAY &&
1208 (int)trans_color->gray > sample_max) ||
1209 (color_type == PNG_COLOR_TYPE_RGB &&
1210 ((int)trans_color->red > sample_max ||
1211 (int)trans_color->green > sample_max ||
1212 (int)trans_color->blue > sample_max))))
1213 png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,
1214 trans_color);
1215 }
1216 }
1217#endif
1218#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1219 {
1220 png_unknown_chunkp unknowns;
1221 int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
1222 &unknowns);
1223
1224 if (num_unknowns)
1225 {
1226 int i;
1227 png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
1228 num_unknowns);
1229 /* Copy the locations from the read_info_ptr. The automatically
1230 * generated locations in write_info_ptr are wrong because we
1231 * haven't written anything yet.
1232 */
1233 for (i = 0; i < num_unknowns; i++)
1234 png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
1235 unknowns[i].location);
1236 }
1237 }
1238#endif
1239
1240#ifdef PNG_WRITE_SUPPORTED
1241 pngtest_debug("Writing info struct");
1242
1243/* If we wanted, we could write info in two steps:
1244 * png_write_info_before_PLTE(write_ptr, write_info_ptr);
1245 */
1246 png_write_info(write_ptr, write_info_ptr);
1247
1248#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1249 if (user_chunk_data[0] != 0)
1250 {
1251 png_byte png_sTER[5] = {115, 84, 69, 82, '\0'};
1252
1253 unsigned char
1254 ster_chunk_data[1];
1255
1256 if (verbose)
1257 fprintf(STDERR, "\n stereo mode = %lu\n",
1258 (unsigned long)(user_chunk_data[0] - 1));
1259
1260 ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
1261 png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
1262 }
1263
1264 if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
1265 {
1266 png_byte png_vpAg[5] = {118, 112, 65, 103, '\0'};
1267
1268 unsigned char
1269 vpag_chunk_data[9];
1270
1271 if (verbose)
1272 fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",
1273 (unsigned long)user_chunk_data[1],
1274 (unsigned long)user_chunk_data[2],
1275 (unsigned long)user_chunk_data[3]);
1276
1277 png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
1278 png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
1279 vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
1280 png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
1281 }
1282
1283#endif
1284#endif
1285
1286#ifdef SINGLE_ROWBUF_ALLOC
1287 pngtest_debug("Allocating row buffer...");
1288 row_buf = (png_bytep)png_malloc(read_ptr,
1289 png_get_rowbytes(read_ptr, read_info_ptr));
1290
1291 pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
1292#endif /* SINGLE_ROWBUF_ALLOC */
1293 pngtest_debug("Writing row data");
1294
1295#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
1296 defined(PNG_WRITE_INTERLACING_SUPPORTED)
1297 num_pass = png_set_interlace_handling(read_ptr);
1298# ifdef PNG_WRITE_SUPPORTED
1299 png_set_interlace_handling(write_ptr);
1300# endif
1301#else
1302 num_pass = 1;
1303#endif
1304
1305#ifdef PNGTEST_TIMING
1306 t_stop = (float)clock();
1307 t_misc += (t_stop - t_start);
1308 t_start = t_stop;
1309#endif
1310 for (pass = 0; pass < num_pass; pass++)
1311 {
1312 pngtest_debug1("Writing row data for pass %d", pass);
1313 for (y = 0; y < height; y++)
1314 {
1315#ifndef SINGLE_ROWBUF_ALLOC
1316 pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
1317 row_buf = (png_bytep)png_malloc(read_ptr,
1318 png_get_rowbytes(read_ptr, read_info_ptr));
1319
1320 pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,
1321 png_get_rowbytes(read_ptr, read_info_ptr));
1322
1323#endif /* !SINGLE_ROWBUF_ALLOC */
1324 png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
1325
1326#ifdef PNG_WRITE_SUPPORTED
1327#ifdef PNGTEST_TIMING
1328 t_stop = (float)clock();
1329 t_decode += (t_stop - t_start);
1330 t_start = t_stop;
1331#endif
1332 png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
1333#ifdef PNGTEST_TIMING
1334 t_stop = (float)clock();
1335 t_encode += (t_stop - t_start);
1336 t_start = t_stop;
1337#endif
1338#endif /* PNG_WRITE_SUPPORTED */
1339
1340#ifndef SINGLE_ROWBUF_ALLOC
1341 pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
1342 png_free(read_ptr, row_buf);
1343 row_buf = NULL;
1344#endif /* !SINGLE_ROWBUF_ALLOC */
1345 }
1346 }
1347
1348#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1349 png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
1350#endif
1351#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1352 png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
1353#endif
1354
1355 pngtest_debug("Reading and writing end_info data");
1356
1357 png_read_end(read_ptr, end_info_ptr);
1358#ifdef PNG_TEXT_SUPPORTED
1359 {
1360 png_textp text_ptr;
1361 int num_text;
1362
1363 if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
1364 {
1365 pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
1366 png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
1367 }
1368 }
1369#endif
1370#ifdef PNG_tIME_SUPPORTED
1371 {
1372 png_timep mod_time;
1373
1374 if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
1375 {
1376 png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
1377#ifdef PNG_TIME_RFC1123_SUPPORTED
1378 /* We have to use png_memcpy instead of "=" because the string
1379 pointed to by png_convert_to_rfc1123() gets free'ed before
1380 we use it */
1381 png_memcpy(tIME_string,
1382 png_convert_to_rfc1123(read_ptr, mod_time),
1383 png_sizeof(tIME_string));
1384
1385 tIME_string[png_sizeof(tIME_string) - 1] = '\0';
1386 tIME_chunk_present++;
1387#endif /* PNG_TIME_RFC1123_SUPPORTED */
1388 }
1389 }
1390#endif
1391#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1392 {
1393 png_unknown_chunkp unknowns;
1394 int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
1395 &unknowns);
1396
1397 if (num_unknowns)
1398 {
1399 int i;
1400 png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
1401 num_unknowns);
1402 /* Copy the locations from the read_info_ptr. The automatically
1403 * generated locations in write_end_info_ptr are wrong because we
1404 * haven't written the end_info yet.
1405 */
1406 for (i = 0; i < num_unknowns; i++)
1407 png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
1408 unknowns[i].location);
1409 }
1410 }
1411#endif
1412#ifdef PNG_WRITE_SUPPORTED
1413 png_write_end(write_ptr, write_end_info_ptr);
1414#endif
1415
1416#ifdef PNG_EASY_ACCESS_SUPPORTED
1417 if (verbose)
1418 {
1419 png_uint_32 iwidth, iheight;
1420 iwidth = png_get_image_width(write_ptr, write_info_ptr);
1421 iheight = png_get_image_height(write_ptr, write_info_ptr);
1422 fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
1423 (unsigned long)iwidth, (unsigned long)iheight);
1424 }
1425#endif
1426
1427 pngtest_debug("Destroying data structs");
1428#ifdef SINGLE_ROWBUF_ALLOC
1429 pngtest_debug("destroying row_buf for read_ptr");
1430 png_free(read_ptr, row_buf);
1431 row_buf = NULL;
1432#endif /* SINGLE_ROWBUF_ALLOC */
1433 pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
1434 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
1435#ifdef PNG_WRITE_SUPPORTED
1436 pngtest_debug("destroying write_end_info_ptr");
1437 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
1438 pngtest_debug("destroying write_ptr, write_info_ptr");
1439 png_destroy_write_struct(&write_ptr, &write_info_ptr);
1440#endif
1441 pngtest_debug("Destruction complete.");
1442
1443 FCLOSE(fpin);
1444 FCLOSE(fpout);
1445
1446 pngtest_debug("Opening files for comparison");
1447 if ((fpin = fopen(inname, "rb")) == NULL)
1448 {
1449 fprintf(STDERR, "Could not find file %s\n", inname);
1450 return (1);
1451 }
1452
1453 if ((fpout = fopen(outname, "rb")) == NULL)
1454 {
1455 fprintf(STDERR, "Could not find file %s\n", outname);
1456 FCLOSE(fpin);
1457 return (1);
1458 }
1459
1460 for (;;)
1461 {
1462 png_size_t num_in, num_out;
1463
1464 num_in = fread(inbuf, 1, 1, fpin);
1465 num_out = fread(outbuf, 1, 1, fpout);
1466
1467 if (num_in != num_out)
1468 {
1469 fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
1470 inname, outname);
1471
1472 if (wrote_question == 0)
1473 {
1474 fprintf(STDERR,
1475 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1476 inname, PNG_ZBUF_SIZE);
1477 fprintf(STDERR,
1478 "\n filtering heuristic (libpng default), compression");
1479 fprintf(STDERR,
1480 " level (zlib default),\n and zlib version (%s)?\n\n",
1481 ZLIB_VERSION);
1482 wrote_question = 1;
1483 }
1484
1485 FCLOSE(fpin);
1486 FCLOSE(fpout);
1487
1488 if (strict != 0)
1489 return (1);
1490
1491 else
1492 return (0);
1493 }
1494
1495 if (!num_in)
1496 break;
1497
1498 if (png_memcmp(inbuf, outbuf, num_in))
1499 {
1500 fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
1501
1502 if (wrote_question == 0)
1503 {
1504 fprintf(STDERR,
1505 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1506 inname, PNG_ZBUF_SIZE);
1507 fprintf(STDERR,
1508 "\n filtering heuristic (libpng default), compression");
1509 fprintf(STDERR,
1510 " level (zlib default),\n and zlib version (%s)?\n\n",
1511 ZLIB_VERSION);
1512 wrote_question = 1;
1513 }
1514
1515 FCLOSE(fpin);
1516 FCLOSE(fpout);
1517
1518 if (strict != 0)
1519 return (1);
1520
1521 else
1522 return (0);
1523 }
1524 }
1525
1526 FCLOSE(fpin);
1527 FCLOSE(fpout);
1528
1529 return (0);
1530}
1531
1532/* Input and output filenames */
1533#ifdef RISCOS
1534static PNG_CONST char *inname = "pngtest/png";
1535static PNG_CONST char *outname = "pngout/png";
1536#else
1537static PNG_CONST char *inname = "pngtest.png";
1538static PNG_CONST char *outname = "pngout.png";
1539#endif
1540
1541int
1542main(int argc, char *argv[])
1543{
1544 int multiple = 0;
1545 int ierror = 0;
1546
1547 fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
1548 fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
1549 fprintf(STDERR, "%s", png_get_copyright(NULL));
1550 /* Show the version of libpng used in building the library */
1551 fprintf(STDERR, " library (%lu):%s",
1552 (unsigned long)png_access_version_number(),
1553 png_get_header_version(NULL));
1554
1555 /* Show the version of libpng used in building the application */
1556 fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
1557 PNG_HEADER_VERSION_STRING);
1558
1559 /* Do some consistency checking on the memory allocation settings, I'm
1560 * not sure this matters, but it is nice to know, the first of these
1561 * tests should be impossible because of the way the macros are set
1562 * in pngconf.h
1563 */
1564#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
1565 fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
1566#endif
1567 /* I think the following can happen. */
1568#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
1569 fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
1570#endif
1571
1572 if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
1573 {
1574 fprintf(STDERR,
1575 "Warning: versions are different between png.h and png.c\n");
1576 fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
1577 fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
1578 ++ierror;
1579 }
1580
1581 if (argc > 1)
1582 {
1583 if (strcmp(argv[1], "-m") == 0)
1584 {
1585 multiple = 1;
1586 status_dots_requested = 0;
1587 }
1588
1589 else if (strcmp(argv[1], "-mv") == 0 ||
1590 strcmp(argv[1], "-vm") == 0 )
1591 {
1592 multiple = 1;
1593 verbose = 1;
1594 status_dots_requested = 1;
1595 }
1596
1597 else if (strcmp(argv[1], "-v") == 0)
1598 {
1599 verbose = 1;
1600 status_dots_requested = 1;
1601 inname = argv[2];
1602 }
1603
1604 else if (strcmp(argv[1], "--strict") == 0)
1605 {
1606 status_dots_requested = 0;
1607 verbose = 1;
1608 inname = argv[2];
1609 strict++;
1610 }
1611
1612 else
1613 {
1614 inname = argv[1];
1615 status_dots_requested = 0;
1616 }
1617 }
1618
1619 if (!multiple && argc == 3 + verbose)
1620 outname = argv[2 + verbose];
1621
1622 if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
1623 {
1624 fprintf(STDERR,
1625 "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
1626 argv[0], argv[0]);
1627 fprintf(STDERR,
1628 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1629 fprintf(STDERR,
1630 " with -m %s is used as a temporary file\n", outname);
1631 exit(1);
1632 }
1633
1634 if (multiple)
1635 {
1636 int i;
1637#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1638 int allocation_now = current_allocation;
1639#endif
1640 for (i=2; i<argc; ++i)
1641 {
1642 int kerror;
1643 fprintf(STDERR, "\n Testing %s:", argv[i]);
1644 kerror = test_one_file(argv[i], outname);
1645 if (kerror == 0)
1646 {
1647#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1648 int k;
1649#endif
1650#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1651 fprintf(STDERR, "\n PASS (%lu zero samples)\n",
1652 (unsigned long)zero_samples);
1653#else
1654 fprintf(STDERR, " PASS\n");
1655#endif
1656#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1657 for (k = 0; k<256; k++)
1658 if (filters_used[k])
1659 fprintf(STDERR, " Filter %d was used %lu times\n",
1660 k, (unsigned long)filters_used[k]);
1661#endif
1662#ifdef PNG_TIME_RFC1123_SUPPORTED
1663 if (tIME_chunk_present != 0)
1664 fprintf(STDERR, " tIME = %s\n", tIME_string);
1665
1666 tIME_chunk_present = 0;
1667#endif /* PNG_TIME_RFC1123_SUPPORTED */
1668 }
1669
1670 else
1671 {
1672 fprintf(STDERR, " FAIL\n");
1673 ierror += kerror;
1674 }
1675#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1676 if (allocation_now != current_allocation)
1677 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1678 current_allocation - allocation_now);
1679
1680 if (current_allocation != 0)
1681 {
1682 memory_infop pinfo = pinformation;
1683
1684 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1685 current_allocation);
1686
1687 while (pinfo != NULL)
1688 {
1689 fprintf(STDERR, " %lu bytes at %x\n",
1690 (unsigned long)pinfo->size,
1691 (unsigned int)pinfo->pointer);
1692 pinfo = pinfo->next;
1693 }
1694 }
1695#endif
1696 }
1697#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1698 fprintf(STDERR, " Current memory allocation: %10d bytes\n",
1699 current_allocation);
1700 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
1701 maximum_allocation);
1702 fprintf(STDERR, " Total memory allocation: %10d bytes\n",
1703 total_allocation);
1704 fprintf(STDERR, " Number of allocations: %10d\n",
1705 num_allocations);
1706#endif
1707 }
1708
1709 else
1710 {
1711 int i;
1712 for (i = 0; i<3; ++i)
1713 {
1714 int kerror;
1715#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1716 int allocation_now = current_allocation;
1717#endif
1718 if (i == 1)
1719 status_dots_requested = 1;
1720
1721 else if (verbose == 0)
1722 status_dots_requested = 0;
1723
1724 if (i == 0 || verbose == 1 || ierror != 0)
1725 fprintf(STDERR, "\n Testing %s:", inname);
1726
1727 kerror = test_one_file(inname, outname);
1728
1729 if (kerror == 0)
1730 {
1731 if (verbose == 1 || i == 2)
1732 {
1733#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1734 int k;
1735#endif
1736#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1737 fprintf(STDERR, "\n PASS (%lu zero samples)\n",
1738 (unsigned long)zero_samples);
1739#else
1740 fprintf(STDERR, " PASS\n");
1741#endif
1742#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1743 for (k = 0; k<256; k++)
1744 if (filters_used[k])
1745 fprintf(STDERR, " Filter %d was used %lu times\n",
1746 k, (unsigned long)filters_used[k]);
1747#endif
1748#ifdef PNG_TIME_RFC1123_SUPPORTED
1749 if (tIME_chunk_present != 0)
1750 fprintf(STDERR, " tIME = %s\n", tIME_string);
1751#endif /* PNG_TIME_RFC1123_SUPPORTED */
1752 }
1753 }
1754
1755 else
1756 {
1757 if (verbose == 0 && i != 2)
1758 fprintf(STDERR, "\n Testing %s:", inname);
1759
1760 fprintf(STDERR, " FAIL\n");
1761 ierror += kerror;
1762 }
1763#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1764 if (allocation_now != current_allocation)
1765 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1766 current_allocation - allocation_now);
1767
1768 if (current_allocation != 0)
1769 {
1770 memory_infop pinfo = pinformation;
1771
1772 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1773 current_allocation);
1774
1775 while (pinfo != NULL)
1776 {
1777 fprintf(STDERR, " %lu bytes at %x\n",
1778 (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
1779 pinfo = pinfo->next;
1780 }
1781 }
1782#endif
1783 }
1784#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1785 fprintf(STDERR, " Current memory allocation: %10d bytes\n",
1786 current_allocation);
1787 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
1788 maximum_allocation);
1789 fprintf(STDERR, " Total memory allocation: %10d bytes\n",
1790 total_allocation);
1791 fprintf(STDERR, " Number of allocations: %10d\n",
1792 num_allocations);
1793#endif
1794 }
1795
1796#ifdef PNGTEST_TIMING
1797 t_stop = (float)clock();
1798 t_misc += (t_stop - t_start);
1799 t_start = t_stop;
1800 fprintf(STDERR, " CPU time used = %.3f seconds",
1801 (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
1802 fprintf(STDERR, " (decoding %.3f,\n",
1803 t_decode/(float)CLOCKS_PER_SEC);
1804 fprintf(STDERR, " encoding %.3f ,",
1805 t_encode/(float)CLOCKS_PER_SEC);
1806 fprintf(STDERR, " other %.3f seconds)\n\n",
1807 t_misc/(float)CLOCKS_PER_SEC);
1808#endif
1809
1810 if (ierror == 0)
1811 fprintf(STDERR, " libpng passes test\n");
1812
1813 else
1814 fprintf(STDERR, " libpng FAILS test\n");
1815
1816 return (int)(ierror != 0);
1817}
1818
1819/* Generate a compiler error if there is an old png.h in the search path. */
1820typedef png_libpng_version_1_5_9 Your_png_h_is_not_version_1_5_9;
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.png
new file mode 100644
index 0000000..81f5f84
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtest.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtrans.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtrans.c
new file mode 100644
index 0000000..53d9a25
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngtrans.c
@@ -0,0 +1,678 @@
1
2/* pngtrans.c - transforms the data in a row (used by both readers and writers)
3 *
4 * Last changed in libpng 1.5.4 [July 7, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
17
18#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
19/* Turn on BGR-to-RGB mapping */
20void PNGAPI
21png_set_bgr(png_structp png_ptr)
22{
23 png_debug(1, "in png_set_bgr");
24
25 if (png_ptr == NULL)
26 return;
27
28 png_ptr->transformations |= PNG_BGR;
29}
30#endif
31
32#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
33/* Turn on 16 bit byte swapping */
34void PNGAPI
35png_set_swap(png_structp png_ptr)
36{
37 png_debug(1, "in png_set_swap");
38
39 if (png_ptr == NULL)
40 return;
41
42 if (png_ptr->bit_depth == 16)
43 png_ptr->transformations |= PNG_SWAP_BYTES;
44}
45#endif
46
47#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
48/* Turn on pixel packing */
49void PNGAPI
50png_set_packing(png_structp png_ptr)
51{
52 png_debug(1, "in png_set_packing");
53
54 if (png_ptr == NULL)
55 return;
56
57 if (png_ptr->bit_depth < 8)
58 {
59 png_ptr->transformations |= PNG_PACK;
60 png_ptr->usr_bit_depth = 8;
61 }
62}
63#endif
64
65#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
66/* Turn on packed pixel swapping */
67void PNGAPI
68png_set_packswap(png_structp png_ptr)
69{
70 png_debug(1, "in png_set_packswap");
71
72 if (png_ptr == NULL)
73 return;
74
75 if (png_ptr->bit_depth < 8)
76 png_ptr->transformations |= PNG_PACKSWAP;
77}
78#endif
79
80#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
81void PNGAPI
82png_set_shift(png_structp png_ptr, png_const_color_8p true_bits)
83{
84 png_debug(1, "in png_set_shift");
85
86 if (png_ptr == NULL)
87 return;
88
89 png_ptr->transformations |= PNG_SHIFT;
90 png_ptr->shift = *true_bits;
91}
92#endif
93
94#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
95 defined(PNG_WRITE_INTERLACING_SUPPORTED)
96int PNGAPI
97png_set_interlace_handling(png_structp png_ptr)
98{
99 png_debug(1, "in png_set_interlace handling");
100
101 if (png_ptr && png_ptr->interlaced)
102 {
103 png_ptr->transformations |= PNG_INTERLACE;
104 return (7);
105 }
106
107 return (1);
108}
109#endif
110
111#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
112/* Add a filler byte on read, or remove a filler or alpha byte on write.
113 * The filler type has changed in v0.95 to allow future 2-byte fillers
114 * for 48-bit input data, as well as to avoid problems with some compilers
115 * that don't like bytes as parameters.
116 */
117void PNGAPI
118png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
119{
120 png_debug(1, "in png_set_filler");
121
122 if (png_ptr == NULL)
123 return;
124
125 png_ptr->transformations |= PNG_FILLER;
126 png_ptr->filler = (png_uint_16)filler;
127
128 if (filler_loc == PNG_FILLER_AFTER)
129 png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
130
131 else
132 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
133
134 /* This should probably go in the "do_read_filler" routine.
135 * I attempted to do that in libpng-1.0.1a but that caused problems
136 * so I restored it in libpng-1.0.2a
137 */
138
139 if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
140 {
141 png_ptr->usr_channels = 4;
142 }
143
144 /* Also I added this in libpng-1.0.2a (what happens when we expand
145 * a less-than-8-bit grayscale to GA?) */
146
147 if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
148 {
149 png_ptr->usr_channels = 2;
150 }
151}
152
153/* Added to libpng-1.2.7 */
154void PNGAPI
155png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
156{
157 png_debug(1, "in png_set_add_alpha");
158
159 if (png_ptr == NULL)
160 return;
161
162 png_set_filler(png_ptr, filler, filler_loc);
163 png_ptr->transformations |= PNG_ADD_ALPHA;
164}
165
166#endif
167
168#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
169 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
170void PNGAPI
171png_set_swap_alpha(png_structp png_ptr)
172{
173 png_debug(1, "in png_set_swap_alpha");
174
175 if (png_ptr == NULL)
176 return;
177
178 png_ptr->transformations |= PNG_SWAP_ALPHA;
179}
180#endif
181
182#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
183 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
184void PNGAPI
185png_set_invert_alpha(png_structp png_ptr)
186{
187 png_debug(1, "in png_set_invert_alpha");
188
189 if (png_ptr == NULL)
190 return;
191
192 png_ptr->transformations |= PNG_INVERT_ALPHA;
193}
194#endif
195
196#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
197void PNGAPI
198png_set_invert_mono(png_structp png_ptr)
199{
200 png_debug(1, "in png_set_invert_mono");
201
202 if (png_ptr == NULL)
203 return;
204
205 png_ptr->transformations |= PNG_INVERT_MONO;
206}
207
208/* Invert monochrome grayscale data */
209void /* PRIVATE */
210png_do_invert(png_row_infop row_info, png_bytep row)
211{
212 png_debug(1, "in png_do_invert");
213
214 /* This test removed from libpng version 1.0.13 and 1.2.0:
215 * if (row_info->bit_depth == 1 &&
216 */
217 if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
218 {
219 png_bytep rp = row;
220 png_size_t i;
221 png_size_t istop = row_info->rowbytes;
222
223 for (i = 0; i < istop; i++)
224 {
225 *rp = (png_byte)(~(*rp));
226 rp++;
227 }
228 }
229
230 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
231 row_info->bit_depth == 8)
232 {
233 png_bytep rp = row;
234 png_size_t i;
235 png_size_t istop = row_info->rowbytes;
236
237 for (i = 0; i < istop; i += 2)
238 {
239 *rp = (png_byte)(~(*rp));
240 rp += 2;
241 }
242 }
243
244#ifdef PNG_16BIT_SUPPORTED
245 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
246 row_info->bit_depth == 16)
247 {
248 png_bytep rp = row;
249 png_size_t i;
250 png_size_t istop = row_info->rowbytes;
251
252 for (i = 0; i < istop; i += 4)
253 {
254 *rp = (png_byte)(~(*rp));
255 *(rp + 1) = (png_byte)(~(*(rp + 1)));
256 rp += 4;
257 }
258 }
259#endif
260}
261#endif
262
263#ifdef PNG_16BIT_SUPPORTED
264#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
265/* Swaps byte order on 16 bit depth images */
266void /* PRIVATE */
267png_do_swap(png_row_infop row_info, png_bytep row)
268{
269 png_debug(1, "in png_do_swap");
270
271 if (row_info->bit_depth == 16)
272 {
273 png_bytep rp = row;
274 png_uint_32 i;
275 png_uint_32 istop= row_info->width * row_info->channels;
276
277 for (i = 0; i < istop; i++, rp += 2)
278 {
279 png_byte t = *rp;
280 *rp = *(rp + 1);
281 *(rp + 1) = t;
282 }
283 }
284}
285#endif
286#endif
287
288#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
289static PNG_CONST png_byte onebppswaptable[256] = {
290 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
291 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
292 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
293 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
294 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
295 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
296 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
297 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
298 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
299 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
300 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
301 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
302 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
303 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
304 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
305 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
306 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
307 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
308 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
309 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
310 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
311 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
312 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
313 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
314 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
315 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
316 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
317 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
318 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
319 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
320 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
321 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
322};
323
324static PNG_CONST png_byte twobppswaptable[256] = {
325 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
326 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
327 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
328 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
329 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
330 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
331 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
332 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
333 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
334 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
335 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
336 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
337 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
338 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
339 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
340 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
341 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
342 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
343 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
344 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
345 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
346 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
347 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
348 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
349 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
350 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
351 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
352 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
353 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
354 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
355 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
356 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
357};
358
359static PNG_CONST png_byte fourbppswaptable[256] = {
360 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
361 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
362 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
363 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
364 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
365 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
366 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
367 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
368 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
369 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
370 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
371 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
372 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
373 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
374 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
375 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
376 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
377 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
378 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
379 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
380 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
381 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
382 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
383 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
384 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
385 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
386 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
387 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
388 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
389 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
390 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
391 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
392};
393
394/* Swaps pixel packing order within bytes */
395void /* PRIVATE */
396png_do_packswap(png_row_infop row_info, png_bytep row)
397{
398 png_debug(1, "in png_do_packswap");
399
400 if (row_info->bit_depth < 8)
401 {
402 png_bytep rp;
403 png_const_bytep end, table;
404
405 end = row + row_info->rowbytes;
406
407 if (row_info->bit_depth == 1)
408 table = onebppswaptable;
409
410 else if (row_info->bit_depth == 2)
411 table = twobppswaptable;
412
413 else if (row_info->bit_depth == 4)
414 table = fourbppswaptable;
415
416 else
417 return;
418
419 for (rp = row; rp < end; rp++)
420 *rp = table[*rp];
421 }
422}
423#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
424
425#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
426 defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
427/* Remove a channel - this used to be 'png_do_strip_filler' but it used a
428 * somewhat weird combination of flags to determine what to do. All the calls
429 * to png_do_strip_filler are changed in 1.5.2 to call this instead with the
430 * correct arguments.
431 *
432 * The routine isn't general - the channel must be the channel at the start or
433 * end (not in the middle) of each pixel.
434 */
435void /* PRIVATE */
436png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
437{
438 png_bytep sp = row; /* source pointer */
439 png_bytep dp = row; /* destination pointer */
440 png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */
441
442 /* At the start sp will point to the first byte to copy and dp to where
443 * it is copied to. ep always points just beyond the end of the row, so
444 * the loop simply copies (channels-1) channels until sp reaches ep.
445 *
446 * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc.
447 * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
448 */
449
450 /* GA, GX, XG cases */
451 if (row_info->channels == 2)
452 {
453 if (row_info->bit_depth == 8)
454 {
455 if (at_start) /* Skip initial filler */
456 ++sp;
457 else /* Skip initial channel and, for sp, the filler */
458 sp += 2, ++dp;
459
460 /* For a 1 pixel wide image there is nothing to do */
461 while (sp < ep)
462 *dp++ = *sp, sp += 2;
463
464 row_info->pixel_depth = 8;
465 }
466
467 else if (row_info->bit_depth == 16)
468 {
469 if (at_start) /* Skip initial filler */
470 sp += 2;
471 else /* Skip initial channel and, for sp, the filler */
472 sp += 4, dp += 2;
473
474 while (sp < ep)
475 *dp++ = *sp++, *dp++ = *sp, sp += 3;
476
477 row_info->pixel_depth = 16;
478 }
479
480 else
481 return; /* bad bit depth */
482
483 row_info->channels = 1;
484
485 /* Finally fix the color type if it records an alpha channel */
486 if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
487 row_info->color_type = PNG_COLOR_TYPE_GRAY;
488 }
489
490 /* RGBA, RGBX, XRGB cases */
491 else if (row_info->channels == 4)
492 {
493 if (row_info->bit_depth == 8)
494 {
495 if (at_start) /* Skip initial filler */
496 ++sp;
497 else /* Skip initial channels and, for sp, the filler */
498 sp += 4, dp += 3;
499
500 /* Note that the loop adds 3 to dp and 4 to sp each time. */
501 while (sp < ep)
502 *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
503
504 row_info->pixel_depth = 24;
505 }
506
507 else if (row_info->bit_depth == 16)
508 {
509 if (at_start) /* Skip initial filler */
510 sp += 2;
511 else /* Skip initial channels and, for sp, the filler */
512 sp += 8, dp += 6;
513
514 while (sp < ep)
515 {
516 /* Copy 6 bytes, skip 2 */
517 *dp++ = *sp++, *dp++ = *sp++;
518 *dp++ = *sp++, *dp++ = *sp++;
519 *dp++ = *sp++, *dp++ = *sp, sp += 3;
520 }
521
522 row_info->pixel_depth = 48;
523 }
524
525 else
526 return; /* bad bit depth */
527
528 row_info->channels = 3;
529
530 /* Finally fix the color type if it records an alpha channel */
531 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
532 row_info->color_type = PNG_COLOR_TYPE_RGB;
533 }
534
535 else
536 return; /* The filler channel has gone already */
537
538 /* Fix the rowbytes value. */
539 row_info->rowbytes = dp-row;
540}
541#endif
542
543#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
544/* Swaps red and blue bytes within a pixel */
545void /* PRIVATE */
546png_do_bgr(png_row_infop row_info, png_bytep row)
547{
548 png_debug(1, "in png_do_bgr");
549
550 if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
551 {
552 png_uint_32 row_width = row_info->width;
553 if (row_info->bit_depth == 8)
554 {
555 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
556 {
557 png_bytep rp;
558 png_uint_32 i;
559
560 for (i = 0, rp = row; i < row_width; i++, rp += 3)
561 {
562 png_byte save = *rp;
563 *rp = *(rp + 2);
564 *(rp + 2) = save;
565 }
566 }
567
568 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
569 {
570 png_bytep rp;
571 png_uint_32 i;
572
573 for (i = 0, rp = row; i < row_width; i++, rp += 4)
574 {
575 png_byte save = *rp;
576 *rp = *(rp + 2);
577 *(rp + 2) = save;
578 }
579 }
580 }
581
582#ifdef PNG_16BIT_SUPPORTED
583 else if (row_info->bit_depth == 16)
584 {
585 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
586 {
587 png_bytep rp;
588 png_uint_32 i;
589
590 for (i = 0, rp = row; i < row_width; i++, rp += 6)
591 {
592 png_byte save = *rp;
593 *rp = *(rp + 4);
594 *(rp + 4) = save;
595 save = *(rp + 1);
596 *(rp + 1) = *(rp + 5);
597 *(rp + 5) = save;
598 }
599 }
600
601 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
602 {
603 png_bytep rp;
604 png_uint_32 i;
605
606 for (i = 0, rp = row; i < row_width; i++, rp += 8)
607 {
608 png_byte save = *rp;
609 *rp = *(rp + 4);
610 *(rp + 4) = save;
611 save = *(rp + 1);
612 *(rp + 1) = *(rp + 5);
613 *(rp + 5) = save;
614 }
615 }
616 }
617#endif
618 }
619}
620#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
621
622#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
623 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
624#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
625void PNGAPI
626png_set_user_transform_info(png_structp png_ptr, png_voidp
627 user_transform_ptr, int user_transform_depth, int user_transform_channels)
628{
629 png_debug(1, "in png_set_user_transform_info");
630
631 if (png_ptr == NULL)
632 return;
633 png_ptr->user_transform_ptr = user_transform_ptr;
634 png_ptr->user_transform_depth = (png_byte)user_transform_depth;
635 png_ptr->user_transform_channels = (png_byte)user_transform_channels;
636}
637#endif
638
639/* This function returns a pointer to the user_transform_ptr associated with
640 * the user transform functions. The application should free any memory
641 * associated with this pointer before png_write_destroy and png_read_destroy
642 * are called.
643 */
644#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
645png_voidp PNGAPI
646png_get_user_transform_ptr(png_const_structp png_ptr)
647{
648 if (png_ptr == NULL)
649 return (NULL);
650
651 return ((png_voidp)png_ptr->user_transform_ptr);
652}
653#endif
654
655#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
656png_uint_32 PNGAPI
657png_get_current_row_number(png_const_structp png_ptr)
658{
659 /* See the comments in png.h - this is the sub-image row when reading and
660 * interlaced image.
661 */
662 if (png_ptr != NULL)
663 return png_ptr->row_number;
664
665 return PNG_UINT_32_MAX; /* help the app not to fail silently */
666}
667
668png_byte PNGAPI
669png_get_current_pass_number(png_const_structp png_ptr)
670{
671 if (png_ptr != NULL)
672 return png_ptr->pass;
673 return 8; /* invalid */
674}
675#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
676#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
677 PNG_WRITE_USER_TRANSFORM_SUPPORTED */
678#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwio.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwio.c
new file mode 100644
index 0000000..8eacf9f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwio.c
@@ -0,0 +1,254 @@
1
2/* pngwio.c - functions for data output
3 *
4 * Last changed in libpng 1.5.0 [January 6, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 *
13 * This file provides a location for all output. Users who need
14 * special handling are expected to write functions that have the same
15 * arguments as these and perform similar functions, but that possibly
16 * use different output methods. Note that you shouldn't change these
17 * functions, but rather write replacement functions and then change
18 * them at run time with png_set_write_fn(...).
19 */
20
21#include "pngpriv.h"
22
23#ifdef PNG_WRITE_SUPPORTED
24
25/* Write the data to whatever output you are using. The default routine
26 * writes to a file pointer. Note that this routine sometimes gets called
27 * with very small lengths, so you should implement some kind of simple
28 * buffering if you are using unbuffered writes. This should never be asked
29 * to write more than 64K on a 16 bit machine.
30 */
31
32void /* PRIVATE */
33png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
34{
35 /* NOTE: write_data_fn must not change the buffer! */
36 if (png_ptr->write_data_fn != NULL )
37 (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length);
38
39 else
40 png_error(png_ptr, "Call to NULL write function");
41}
42
43#ifdef PNG_STDIO_SUPPORTED
44/* This is the function that does the actual writing of data. If you are
45 * not writing to a standard C stream, you should create a replacement
46 * write_data function and use it at run time with png_set_write_fn(), rather
47 * than changing the library.
48 */
49#ifndef USE_FAR_KEYWORD
50void PNGCBAPI
51png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
52{
53 png_size_t check;
54
55 if (png_ptr == NULL)
56 return;
57
58 check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
59
60 if (check != length)
61 png_error(png_ptr, "Write Error");
62}
63#else
64/* This is the model-independent version. Since the standard I/O library
65 * can't handle far buffers in the medium and small models, we have to copy
66 * the data.
67 */
68
69#define NEAR_BUF_SIZE 1024
70#define MIN(a,b) (a <= b ? a : b)
71
72void PNGCBAPI
73png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
74{
75 png_uint_32 check;
76 png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
77 png_FILE_p io_ptr;
78
79 if (png_ptr == NULL)
80 return;
81
82 /* Check if data really is near. If so, use usual code. */
83 near_data = (png_byte *)CVT_PTR_NOCHECK(data);
84 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
85
86 if ((png_bytep)near_data == data)
87 {
88 check = fwrite(near_data, 1, length, io_ptr);
89 }
90
91 else
92 {
93 png_byte buf[NEAR_BUF_SIZE];
94 png_size_t written, remaining, err;
95 check = 0;
96 remaining = length;
97
98 do
99 {
100 written = MIN(NEAR_BUF_SIZE, remaining);
101 png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
102 err = fwrite(buf, 1, written, io_ptr);
103
104 if (err != written)
105 break;
106
107 else
108 check += err;
109
110 data += written;
111 remaining -= written;
112 }
113 while (remaining != 0);
114 }
115
116 if (check != length)
117 png_error(png_ptr, "Write Error");
118}
119
120#endif
121#endif
122
123/* This function is called to output any data pending writing (normally
124 * to disk). After png_flush is called, there should be no data pending
125 * writing in any buffers.
126 */
127#ifdef PNG_WRITE_FLUSH_SUPPORTED
128void /* PRIVATE */
129png_flush(png_structp png_ptr)
130{
131 if (png_ptr->output_flush_fn != NULL)
132 (*(png_ptr->output_flush_fn))(png_ptr);
133}
134
135# ifdef PNG_STDIO_SUPPORTED
136void PNGCBAPI
137png_default_flush(png_structp png_ptr)
138{
139 png_FILE_p io_ptr;
140
141 if (png_ptr == NULL)
142 return;
143
144 io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
145 fflush(io_ptr);
146}
147# endif
148#endif
149
150/* This function allows the application to supply new output functions for
151 * libpng if standard C streams aren't being used.
152 *
153 * This function takes as its arguments:
154 * png_ptr - pointer to a png output data structure
155 * io_ptr - pointer to user supplied structure containing info about
156 * the output functions. May be NULL.
157 * write_data_fn - pointer to a new output function that takes as its
158 * arguments a pointer to a png_struct, a pointer to
159 * data to be written, and a 32-bit unsigned int that is
160 * the number of bytes to be written. The new write
161 * function should call png_error(png_ptr, "Error msg")
162 * to exit and output any fatal error messages. May be
163 * NULL, in which case libpng's default function will
164 * be used.
165 * flush_data_fn - pointer to a new flush function that takes as its
166 * arguments a pointer to a png_struct. After a call to
167 * the flush function, there should be no data in any buffers
168 * or pending transmission. If the output method doesn't do
169 * any buffering of output, a function prototype must still be
170 * supplied although it doesn't have to do anything. If
171 * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
172 * time, output_flush_fn will be ignored, although it must be
173 * supplied for compatibility. May be NULL, in which case
174 * libpng's default function will be used, if
175 * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not
176 * a good idea if io_ptr does not point to a standard
177 * *FILE structure.
178 */
179void PNGAPI
180png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
181 png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
182{
183 if (png_ptr == NULL)
184 return;
185
186 png_ptr->io_ptr = io_ptr;
187
188#ifdef PNG_STDIO_SUPPORTED
189 if (write_data_fn != NULL)
190 png_ptr->write_data_fn = write_data_fn;
191
192 else
193 png_ptr->write_data_fn = png_default_write_data;
194#else
195 png_ptr->write_data_fn = write_data_fn;
196#endif
197
198#ifdef PNG_WRITE_FLUSH_SUPPORTED
199# ifdef PNG_STDIO_SUPPORTED
200
201 if (output_flush_fn != NULL)
202 png_ptr->output_flush_fn = output_flush_fn;
203
204 else
205 png_ptr->output_flush_fn = png_default_flush;
206
207# else
208 png_ptr->output_flush_fn = output_flush_fn;
209# endif
210#endif /* PNG_WRITE_FLUSH_SUPPORTED */
211
212 /* It is an error to read while writing a png file */
213 if (png_ptr->read_data_fn != NULL)
214 {
215 png_ptr->read_data_fn = NULL;
216
217 png_warning(png_ptr,
218 "Can't set both read_data_fn and write_data_fn in the"
219 " same structure");
220 }
221}
222
223#ifdef USE_FAR_KEYWORD
224# ifdef _MSC_VER
225void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
226{
227 void *near_ptr;
228 void FAR *far_ptr;
229 FP_OFF(near_ptr) = FP_OFF(ptr);
230 far_ptr = (void FAR *)near_ptr;
231
232 if (check != 0)
233 if (FP_SEG(ptr) != FP_SEG(far_ptr))
234 png_error(png_ptr, "segment lost in conversion");
235
236 return(near_ptr);
237}
238# else
239void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
240{
241 void *near_ptr;
242 void FAR *far_ptr;
243 near_ptr = (void FAR *)ptr;
244 far_ptr = (void FAR *)near_ptr;
245
246 if (check != 0)
247 if (far_ptr != ptr)
248 png_error(png_ptr, "segment lost in conversion");
249
250 return(near_ptr);
251}
252# endif
253#endif
254#endif /* PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwrite.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwrite.c
new file mode 100644
index 0000000..dc12a20
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwrite.c
@@ -0,0 +1,1655 @@
1
2/* pngwrite.c - general routines to write a PNG file
3 *
4 * Last changed in libpng 1.5.7 [December 15, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16#ifdef PNG_WRITE_SUPPORTED
17
18/* Writes all the PNG information. This is the suggested way to use the
19 * library. If you have a new chunk to add, make a function to write it,
20 * and put it in the correct location here. If you want the chunk written
21 * after the image data, put it in png_write_end(). I strongly encourage
22 * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
23 * the chunk, as that will keep the code from breaking if you want to just
24 * write a plain PNG file. If you have long comments, I suggest writing
25 * them in png_write_end(), and compressing them.
26 */
27void PNGAPI
28png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
29{
30 png_debug(1, "in png_write_info_before_PLTE");
31
32 if (png_ptr == NULL || info_ptr == NULL)
33 return;
34
35 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
36 {
37 /* Write PNG signature */
38 png_write_sig(png_ptr);
39
40#ifdef PNG_MNG_FEATURES_SUPPORTED
41 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
42 (png_ptr->mng_features_permitted))
43 {
44 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
45 png_ptr->mng_features_permitted = 0;
46 }
47#endif
48
49 /* Write IHDR information. */
50 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
51 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
52 info_ptr->filter_type,
53#ifdef PNG_WRITE_INTERLACING_SUPPORTED
54 info_ptr->interlace_type);
55#else
56 0);
57#endif
58 /* The rest of these check to see if the valid field has the appropriate
59 * flag set, and if it does, writes the chunk.
60 */
61#ifdef PNG_WRITE_gAMA_SUPPORTED
62 if (info_ptr->valid & PNG_INFO_gAMA)
63 png_write_gAMA_fixed(png_ptr, info_ptr->gamma);
64#endif
65#ifdef PNG_WRITE_sRGB_SUPPORTED
66 if (info_ptr->valid & PNG_INFO_sRGB)
67 png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
68#endif
69
70#ifdef PNG_WRITE_iCCP_SUPPORTED
71 if (info_ptr->valid & PNG_INFO_iCCP)
72 png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
73 (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
74#endif
75#ifdef PNG_WRITE_sBIT_SUPPORTED
76 if (info_ptr->valid & PNG_INFO_sBIT)
77 png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
78#endif
79#ifdef PNG_WRITE_cHRM_SUPPORTED
80 if (info_ptr->valid & PNG_INFO_cHRM)
81 png_write_cHRM_fixed(png_ptr,
82 info_ptr->x_white, info_ptr->y_white,
83 info_ptr->x_red, info_ptr->y_red,
84 info_ptr->x_green, info_ptr->y_green,
85 info_ptr->x_blue, info_ptr->y_blue);
86#endif
87
88#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
89 if (info_ptr->unknown_chunks_num)
90 {
91 png_unknown_chunk *up;
92
93 png_debug(5, "writing extra chunks");
94
95 for (up = info_ptr->unknown_chunks;
96 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
97 up++)
98 {
99 int keep = png_handle_as_unknown(png_ptr, up->name);
100
101 if (keep != PNG_HANDLE_CHUNK_NEVER &&
102 up->location &&
103 !(up->location & PNG_HAVE_PLTE) &&
104 !(up->location & PNG_HAVE_IDAT) &&
105 !(up->location & PNG_AFTER_IDAT) &&
106 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
107 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
108 {
109 if (up->size == 0)
110 png_warning(png_ptr, "Writing zero-length unknown chunk");
111
112 png_write_chunk(png_ptr, up->name, up->data, up->size);
113 }
114 }
115 }
116#endif
117 png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
118 }
119}
120
121void PNGAPI
122png_write_info(png_structp png_ptr, png_infop info_ptr)
123{
124#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
125 int i;
126#endif
127
128 png_debug(1, "in png_write_info");
129
130 if (png_ptr == NULL || info_ptr == NULL)
131 return;
132
133 png_write_info_before_PLTE(png_ptr, info_ptr);
134
135 if (info_ptr->valid & PNG_INFO_PLTE)
136 png_write_PLTE(png_ptr, info_ptr->palette,
137 (png_uint_32)info_ptr->num_palette);
138
139 else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
140 png_error(png_ptr, "Valid palette required for paletted images");
141
142#ifdef PNG_WRITE_tRNS_SUPPORTED
143 if (info_ptr->valid & PNG_INFO_tRNS)
144 {
145#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
146 /* Invert the alpha channel (in tRNS) */
147 if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
148 info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
149 {
150 int j;
151 for (j = 0; j<(int)info_ptr->num_trans; j++)
152 info_ptr->trans_alpha[j] =
153 (png_byte)(255 - info_ptr->trans_alpha[j]);
154 }
155#endif
156 png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),
157 info_ptr->num_trans, info_ptr->color_type);
158 }
159#endif
160#ifdef PNG_WRITE_bKGD_SUPPORTED
161 if (info_ptr->valid & PNG_INFO_bKGD)
162 png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
163#endif
164
165#ifdef PNG_WRITE_hIST_SUPPORTED
166 if (info_ptr->valid & PNG_INFO_hIST)
167 png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
168#endif
169
170#ifdef PNG_WRITE_oFFs_SUPPORTED
171 if (info_ptr->valid & PNG_INFO_oFFs)
172 png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
173 info_ptr->offset_unit_type);
174#endif
175
176#ifdef PNG_WRITE_pCAL_SUPPORTED
177 if (info_ptr->valid & PNG_INFO_pCAL)
178 png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
179 info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
180 info_ptr->pcal_units, info_ptr->pcal_params);
181#endif
182
183#ifdef PNG_WRITE_sCAL_SUPPORTED
184 if (info_ptr->valid & PNG_INFO_sCAL)
185 png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
186 info_ptr->scal_s_width, info_ptr->scal_s_height);
187#endif /* sCAL */
188
189#ifdef PNG_WRITE_pHYs_SUPPORTED
190 if (info_ptr->valid & PNG_INFO_pHYs)
191 png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
192 info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
193#endif /* pHYs */
194
195#ifdef PNG_WRITE_tIME_SUPPORTED
196 if (info_ptr->valid & PNG_INFO_tIME)
197 {
198 png_write_tIME(png_ptr, &(info_ptr->mod_time));
199 png_ptr->mode |= PNG_WROTE_tIME;
200 }
201#endif /* tIME */
202
203#ifdef PNG_WRITE_sPLT_SUPPORTED
204 if (info_ptr->valid & PNG_INFO_sPLT)
205 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
206 png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
207#endif /* sPLT */
208
209#ifdef PNG_WRITE_TEXT_SUPPORTED
210 /* Check to see if we need to write text chunks */
211 for (i = 0; i < info_ptr->num_text; i++)
212 {
213 png_debug2(2, "Writing header text chunk %d, type %d", i,
214 info_ptr->text[i].compression);
215 /* An internationalized chunk? */
216 if (info_ptr->text[i].compression > 0)
217 {
218#ifdef PNG_WRITE_iTXt_SUPPORTED
219 /* Write international chunk */
220 png_write_iTXt(png_ptr,
221 info_ptr->text[i].compression,
222 info_ptr->text[i].key,
223 info_ptr->text[i].lang,
224 info_ptr->text[i].lang_key,
225 info_ptr->text[i].text);
226#else
227 png_warning(png_ptr, "Unable to write international text");
228#endif
229 /* Mark this chunk as written */
230 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
231 }
232
233 /* If we want a compressed text chunk */
234 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
235 {
236#ifdef PNG_WRITE_zTXt_SUPPORTED
237 /* Write compressed chunk */
238 png_write_zTXt(png_ptr, info_ptr->text[i].key,
239 info_ptr->text[i].text, 0,
240 info_ptr->text[i].compression);
241#else
242 png_warning(png_ptr, "Unable to write compressed text");
243#endif
244 /* Mark this chunk as written */
245 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
246 }
247
248 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
249 {
250#ifdef PNG_WRITE_tEXt_SUPPORTED
251 /* Write uncompressed chunk */
252 png_write_tEXt(png_ptr, info_ptr->text[i].key,
253 info_ptr->text[i].text,
254 0);
255 /* Mark this chunk as written */
256 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
257#else
258 /* Can't get here */
259 png_warning(png_ptr, "Unable to write uncompressed text");
260#endif
261 }
262 }
263#endif /* tEXt */
264
265#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
266 if (info_ptr->unknown_chunks_num)
267 {
268 png_unknown_chunk *up;
269
270 png_debug(5, "writing extra chunks");
271
272 for (up = info_ptr->unknown_chunks;
273 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
274 up++)
275 {
276 int keep = png_handle_as_unknown(png_ptr, up->name);
277 if (keep != PNG_HANDLE_CHUNK_NEVER &&
278 up->location &&
279 (up->location & PNG_HAVE_PLTE) &&
280 !(up->location & PNG_HAVE_IDAT) &&
281 !(up->location & PNG_AFTER_IDAT) &&
282 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
283 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
284 {
285 png_write_chunk(png_ptr, up->name, up->data, up->size);
286 }
287 }
288 }
289#endif
290}
291
292/* Writes the end of the PNG file. If you don't want to write comments or
293 * time information, you can pass NULL for info. If you already wrote these
294 * in png_write_info(), do not write them again here. If you have long
295 * comments, I suggest writing them here, and compressing them.
296 */
297void PNGAPI
298png_write_end(png_structp png_ptr, png_infop info_ptr)
299{
300 png_debug(1, "in png_write_end");
301
302 if (png_ptr == NULL)
303 return;
304
305 if (!(png_ptr->mode & PNG_HAVE_IDAT))
306 png_error(png_ptr, "No IDATs written into file");
307
308 /* See if user wants us to write information chunks */
309 if (info_ptr != NULL)
310 {
311#ifdef PNG_WRITE_TEXT_SUPPORTED
312 int i; /* local index variable */
313#endif
314#ifdef PNG_WRITE_tIME_SUPPORTED
315 /* Check to see if user has supplied a time chunk */
316 if ((info_ptr->valid & PNG_INFO_tIME) &&
317 !(png_ptr->mode & PNG_WROTE_tIME))
318 png_write_tIME(png_ptr, &(info_ptr->mod_time));
319
320#endif
321#ifdef PNG_WRITE_TEXT_SUPPORTED
322 /* Loop through comment chunks */
323 for (i = 0; i < info_ptr->num_text; i++)
324 {
325 png_debug2(2, "Writing trailer text chunk %d, type %d", i,
326 info_ptr->text[i].compression);
327 /* An internationalized chunk? */
328 if (info_ptr->text[i].compression > 0)
329 {
330#ifdef PNG_WRITE_iTXt_SUPPORTED
331 /* Write international chunk */
332 png_write_iTXt(png_ptr,
333 info_ptr->text[i].compression,
334 info_ptr->text[i].key,
335 info_ptr->text[i].lang,
336 info_ptr->text[i].lang_key,
337 info_ptr->text[i].text);
338#else
339 png_warning(png_ptr, "Unable to write international text");
340#endif
341 /* Mark this chunk as written */
342 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
343 }
344
345 else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
346 {
347#ifdef PNG_WRITE_zTXt_SUPPORTED
348 /* Write compressed chunk */
349 png_write_zTXt(png_ptr, info_ptr->text[i].key,
350 info_ptr->text[i].text, 0,
351 info_ptr->text[i].compression);
352#else
353 png_warning(png_ptr, "Unable to write compressed text");
354#endif
355 /* Mark this chunk as written */
356 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
357 }
358
359 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
360 {
361#ifdef PNG_WRITE_tEXt_SUPPORTED
362 /* Write uncompressed chunk */
363 png_write_tEXt(png_ptr, info_ptr->text[i].key,
364 info_ptr->text[i].text, 0);
365#else
366 png_warning(png_ptr, "Unable to write uncompressed text");
367#endif
368
369 /* Mark this chunk as written */
370 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
371 }
372 }
373#endif
374#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
375 if (info_ptr->unknown_chunks_num)
376 {
377 png_unknown_chunk *up;
378
379 png_debug(5, "writing extra chunks");
380
381 for (up = info_ptr->unknown_chunks;
382 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
383 up++)
384 {
385 int keep = png_handle_as_unknown(png_ptr, up->name);
386 if (keep != PNG_HANDLE_CHUNK_NEVER &&
387 up->location &&
388 (up->location & PNG_AFTER_IDAT) &&
389 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
390 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
391 {
392 png_write_chunk(png_ptr, up->name, up->data, up->size);
393 }
394 }
395 }
396#endif
397 }
398
399 png_ptr->mode |= PNG_AFTER_IDAT;
400
401 /* Write end of PNG file */
402 png_write_IEND(png_ptr);
403 /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
404 * and restored again in libpng-1.2.30, may cause some applications that
405 * do not set png_ptr->output_flush_fn to crash. If your application
406 * experiences a problem, please try building libpng with
407 * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
408 * png-mng-implement at lists.sf.net .
409 */
410#ifdef PNG_WRITE_FLUSH_SUPPORTED
411# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
412 png_flush(png_ptr);
413# endif
414#endif
415}
416
417#ifdef PNG_CONVERT_tIME_SUPPORTED
418/* "tm" structure is not supported on WindowsCE */
419void PNGAPI
420png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime)
421{
422 png_debug(1, "in png_convert_from_struct_tm");
423
424 ptime->year = (png_uint_16)(1900 + ttime->tm_year);
425 ptime->month = (png_byte)(ttime->tm_mon + 1);
426 ptime->day = (png_byte)ttime->tm_mday;
427 ptime->hour = (png_byte)ttime->tm_hour;
428 ptime->minute = (png_byte)ttime->tm_min;
429 ptime->second = (png_byte)ttime->tm_sec;
430}
431
432void PNGAPI
433png_convert_from_time_t(png_timep ptime, time_t ttime)
434{
435 struct tm *tbuf;
436
437 png_debug(1, "in png_convert_from_time_t");
438
439 tbuf = gmtime(&ttime);
440 png_convert_from_struct_tm(ptime, tbuf);
441}
442#endif
443
444/* Initialize png_ptr structure, and allocate any memory needed */
445PNG_FUNCTION(png_structp,PNGAPI
446png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
447 png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)
448{
449#ifdef PNG_USER_MEM_SUPPORTED
450 return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
451 warn_fn, NULL, NULL, NULL));
452}
453
454/* Alternate initialize png_ptr structure, and allocate any memory needed */
455static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */
456
457PNG_FUNCTION(png_structp,PNGAPI
458png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
459 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
460 png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
461{
462#endif /* PNG_USER_MEM_SUPPORTED */
463 volatile int png_cleanup_needed = 0;
464#ifdef PNG_SETJMP_SUPPORTED
465 volatile
466#endif
467 png_structp png_ptr;
468#ifdef PNG_SETJMP_SUPPORTED
469#ifdef USE_FAR_KEYWORD
470 jmp_buf tmp_jmpbuf;
471#endif
472#endif
473
474 png_debug(1, "in png_create_write_struct");
475
476#ifdef PNG_USER_MEM_SUPPORTED
477 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
478 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
479#else
480 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
481#endif /* PNG_USER_MEM_SUPPORTED */
482 if (png_ptr == NULL)
483 return (NULL);
484
485 /* Added at libpng-1.2.6 */
486#ifdef PNG_SET_USER_LIMITS_SUPPORTED
487 png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
488 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
489#endif
490
491#ifdef PNG_SETJMP_SUPPORTED
492/* Applications that neglect to set up their own setjmp() and then
493 * encounter a png_error() will longjmp here. Since the jmpbuf is
494 * then meaningless we abort instead of returning.
495 */
496#ifdef USE_FAR_KEYWORD
497 if (setjmp(tmp_jmpbuf))
498#else
499 if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */
500#endif
501#ifdef USE_FAR_KEYWORD
502 png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
503#endif
504 PNG_ABORT();
505#endif
506
507#ifdef PNG_USER_MEM_SUPPORTED
508 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
509#endif /* PNG_USER_MEM_SUPPORTED */
510 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
511
512 if (!png_user_version_check(png_ptr, user_png_ver))
513 png_cleanup_needed = 1;
514
515 /* Initialize zbuf - compression buffer */
516 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
517
518 if (!png_cleanup_needed)
519 {
520 png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
521 png_ptr->zbuf_size);
522 if (png_ptr->zbuf == NULL)
523 png_cleanup_needed = 1;
524 }
525
526 if (png_cleanup_needed)
527 {
528 /* Clean up PNG structure and deallocate any memory. */
529 png_free(png_ptr, png_ptr->zbuf);
530 png_ptr->zbuf = NULL;
531#ifdef PNG_USER_MEM_SUPPORTED
532 png_destroy_struct_2((png_voidp)png_ptr,
533 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
534#else
535 png_destroy_struct((png_voidp)png_ptr);
536#endif
537 return (NULL);
538 }
539
540 png_set_write_fn(png_ptr, NULL, NULL, NULL);
541
542#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
543 png_reset_filter_heuristics(png_ptr);
544#endif
545
546 return (png_ptr);
547}
548
549
550/* Write a few rows of image data. If the image is interlaced,
551 * either you will have to write the 7 sub images, or, if you
552 * have called png_set_interlace_handling(), you will have to
553 * "write" the image seven times.
554 */
555void PNGAPI
556png_write_rows(png_structp png_ptr, png_bytepp row,
557 png_uint_32 num_rows)
558{
559 png_uint_32 i; /* row counter */
560 png_bytepp rp; /* row pointer */
561
562 png_debug(1, "in png_write_rows");
563
564 if (png_ptr == NULL)
565 return;
566
567 /* Loop through the rows */
568 for (i = 0, rp = row; i < num_rows; i++, rp++)
569 {
570 png_write_row(png_ptr, *rp);
571 }
572}
573
574/* Write the image. You only need to call this function once, even
575 * if you are writing an interlaced image.
576 */
577void PNGAPI
578png_write_image(png_structp png_ptr, png_bytepp image)
579{
580 png_uint_32 i; /* row index */
581 int pass, num_pass; /* pass variables */
582 png_bytepp rp; /* points to current row */
583
584 if (png_ptr == NULL)
585 return;
586
587 png_debug(1, "in png_write_image");
588
589#ifdef PNG_WRITE_INTERLACING_SUPPORTED
590 /* Initialize interlace handling. If image is not interlaced,
591 * this will set pass to 1
592 */
593 num_pass = png_set_interlace_handling(png_ptr);
594#else
595 num_pass = 1;
596#endif
597 /* Loop through passes */
598 for (pass = 0; pass < num_pass; pass++)
599 {
600 /* Loop through image */
601 for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
602 {
603 png_write_row(png_ptr, *rp);
604 }
605 }
606}
607
608/* Called by user to write a row of image data */
609void PNGAPI
610png_write_row(png_structp png_ptr, png_const_bytep row)
611{
612 /* 1.5.6: moved from png_struct to be a local structure: */
613 png_row_info row_info;
614
615 if (png_ptr == NULL)
616 return;
617
618 png_debug2(1, "in png_write_row (row %u, pass %d)",
619 png_ptr->row_number, png_ptr->pass);
620
621 /* Initialize transformations and other stuff if first time */
622 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
623 {
624 /* Make sure we wrote the header info */
625 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
626 png_error(png_ptr,
627 "png_write_info was never called before png_write_row");
628
629 /* Check for transforms that have been set but were defined out */
630#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
631 if (png_ptr->transformations & PNG_INVERT_MONO)
632 png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
633#endif
634
635#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
636 if (png_ptr->transformations & PNG_FILLER)
637 png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
638#endif
639#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
640 defined(PNG_READ_PACKSWAP_SUPPORTED)
641 if (png_ptr->transformations & PNG_PACKSWAP)
642 png_warning(png_ptr,
643 "PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
644#endif
645
646#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
647 if (png_ptr->transformations & PNG_PACK)
648 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
649#endif
650
651#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
652 if (png_ptr->transformations & PNG_SHIFT)
653 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
654#endif
655
656#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
657 if (png_ptr->transformations & PNG_BGR)
658 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
659#endif
660
661#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
662 if (png_ptr->transformations & PNG_SWAP_BYTES)
663 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
664#endif
665
666 png_write_start_row(png_ptr);
667 }
668
669#ifdef PNG_WRITE_INTERLACING_SUPPORTED
670 /* If interlaced and not interested in row, return */
671 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
672 {
673 switch (png_ptr->pass)
674 {
675 case 0:
676 if (png_ptr->row_number & 0x07)
677 {
678 png_write_finish_row(png_ptr);
679 return;
680 }
681 break;
682
683 case 1:
684 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
685 {
686 png_write_finish_row(png_ptr);
687 return;
688 }
689 break;
690
691 case 2:
692 if ((png_ptr->row_number & 0x07) != 4)
693 {
694 png_write_finish_row(png_ptr);
695 return;
696 }
697 break;
698
699 case 3:
700 if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
701 {
702 png_write_finish_row(png_ptr);
703 return;
704 }
705 break;
706
707 case 4:
708 if ((png_ptr->row_number & 0x03) != 2)
709 {
710 png_write_finish_row(png_ptr);
711 return;
712 }
713 break;
714
715 case 5:
716 if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
717 {
718 png_write_finish_row(png_ptr);
719 return;
720 }
721 break;
722
723 case 6:
724 if (!(png_ptr->row_number & 0x01))
725 {
726 png_write_finish_row(png_ptr);
727 return;
728 }
729 break;
730
731 default: /* error: ignore it */
732 break;
733 }
734 }
735#endif
736
737 /* Set up row info for transformations */
738 row_info.color_type = png_ptr->color_type;
739 row_info.width = png_ptr->usr_width;
740 row_info.channels = png_ptr->usr_channels;
741 row_info.bit_depth = png_ptr->usr_bit_depth;
742 row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels);
743 row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
744
745 png_debug1(3, "row_info->color_type = %d", row_info.color_type);
746 png_debug1(3, "row_info->width = %u", row_info.width);
747 png_debug1(3, "row_info->channels = %d", row_info.channels);
748 png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth);
749 png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth);
750 png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes);
751
752 /* Copy user's row into buffer, leaving room for filter byte. */
753 png_memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes);
754
755#ifdef PNG_WRITE_INTERLACING_SUPPORTED
756 /* Handle interlacing */
757 if (png_ptr->interlaced && png_ptr->pass < 6 &&
758 (png_ptr->transformations & PNG_INTERLACE))
759 {
760 png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass);
761 /* This should always get caught above, but still ... */
762 if (!(row_info.width))
763 {
764 png_write_finish_row(png_ptr);
765 return;
766 }
767 }
768#endif
769
770#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
771 /* Handle other transformations */
772 if (png_ptr->transformations)
773 png_do_write_transformations(png_ptr, &row_info);
774#endif
775
776 /* At this point the row_info pixel depth must match the 'transformed' depth,
777 * which is also the output depth.
778 */
779 if (row_info.pixel_depth != png_ptr->pixel_depth ||
780 row_info.pixel_depth != png_ptr->transformed_pixel_depth)
781 png_error(png_ptr, "internal write transform logic error");
782
783#ifdef PNG_MNG_FEATURES_SUPPORTED
784 /* Write filter_method 64 (intrapixel differencing) only if
785 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
786 * 2. Libpng did not write a PNG signature (this filter_method is only
787 * used in PNG datastreams that are embedded in MNG datastreams) and
788 * 3. The application called png_permit_mng_features with a mask that
789 * included PNG_FLAG_MNG_FILTER_64 and
790 * 4. The filter_method is 64 and
791 * 5. The color_type is RGB or RGBA
792 */
793 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
794 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
795 {
796 /* Intrapixel differencing */
797 png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1);
798 }
799#endif
800
801 /* Find a filter if necessary, filter the row and write it out. */
802 png_write_find_filter(png_ptr, &row_info);
803
804 if (png_ptr->write_row_fn != NULL)
805 (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
806}
807
808#ifdef PNG_WRITE_FLUSH_SUPPORTED
809/* Set the automatic flush interval or 0 to turn flushing off */
810void PNGAPI
811png_set_flush(png_structp png_ptr, int nrows)
812{
813 png_debug(1, "in png_set_flush");
814
815 if (png_ptr == NULL)
816 return;
817
818 png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
819}
820
821/* Flush the current output buffers now */
822void PNGAPI
823png_write_flush(png_structp png_ptr)
824{
825 int wrote_IDAT;
826
827 png_debug(1, "in png_write_flush");
828
829 if (png_ptr == NULL)
830 return;
831
832 /* We have already written out all of the data */
833 if (png_ptr->row_number >= png_ptr->num_rows)
834 return;
835
836 do
837 {
838 int ret;
839
840 /* Compress the data */
841 ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
842 wrote_IDAT = 0;
843
844 /* Check for compression errors */
845 if (ret != Z_OK)
846 {
847 if (png_ptr->zstream.msg != NULL)
848 png_error(png_ptr, png_ptr->zstream.msg);
849
850 else
851 png_error(png_ptr, "zlib error");
852 }
853
854 if (!(png_ptr->zstream.avail_out))
855 {
856 /* Write the IDAT and reset the zlib output buffer */
857 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
858 wrote_IDAT = 1;
859 }
860 } while (wrote_IDAT == 1);
861
862 /* If there is any data left to be output, write it into a new IDAT */
863 if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
864 {
865 /* Write the IDAT and reset the zlib output buffer */
866 png_write_IDAT(png_ptr, png_ptr->zbuf,
867 png_ptr->zbuf_size - png_ptr->zstream.avail_out);
868 }
869 png_ptr->flush_rows = 0;
870 png_flush(png_ptr);
871}
872#endif /* PNG_WRITE_FLUSH_SUPPORTED */
873
874/* Free all memory used by the write */
875void PNGAPI
876png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
877{
878 png_structp png_ptr = NULL;
879 png_infop info_ptr = NULL;
880#ifdef PNG_USER_MEM_SUPPORTED
881 png_free_ptr free_fn = NULL;
882 png_voidp mem_ptr = NULL;
883#endif
884
885 png_debug(1, "in png_destroy_write_struct");
886
887 if (png_ptr_ptr != NULL)
888 png_ptr = *png_ptr_ptr;
889
890#ifdef PNG_USER_MEM_SUPPORTED
891 if (png_ptr != NULL)
892 {
893 free_fn = png_ptr->free_fn;
894 mem_ptr = png_ptr->mem_ptr;
895 }
896#endif
897
898 if (info_ptr_ptr != NULL)
899 info_ptr = *info_ptr_ptr;
900
901 if (info_ptr != NULL)
902 {
903 if (png_ptr != NULL)
904 {
905 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
906
907#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
908 if (png_ptr->num_chunk_list)
909 {
910 png_free(png_ptr, png_ptr->chunk_list);
911 png_ptr->num_chunk_list = 0;
912 }
913#endif
914 }
915
916#ifdef PNG_USER_MEM_SUPPORTED
917 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
918 (png_voidp)mem_ptr);
919#else
920 png_destroy_struct((png_voidp)info_ptr);
921#endif
922 *info_ptr_ptr = NULL;
923 }
924
925 if (png_ptr != NULL)
926 {
927 png_write_destroy(png_ptr);
928#ifdef PNG_USER_MEM_SUPPORTED
929 png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
930 (png_voidp)mem_ptr);
931#else
932 png_destroy_struct((png_voidp)png_ptr);
933#endif
934 *png_ptr_ptr = NULL;
935 }
936}
937
938
939/* Free any memory used in png_ptr struct (old method) */
940void /* PRIVATE */
941png_write_destroy(png_structp png_ptr)
942{
943#ifdef PNG_SETJMP_SUPPORTED
944 jmp_buf tmp_jmp; /* Save jump buffer */
945#endif
946 png_error_ptr error_fn;
947#ifdef PNG_WARNINGS_SUPPORTED
948 png_error_ptr warning_fn;
949#endif
950 png_voidp error_ptr;
951#ifdef PNG_USER_MEM_SUPPORTED
952 png_free_ptr free_fn;
953#endif
954
955 png_debug(1, "in png_write_destroy");
956
957 /* Free any memory zlib uses */
958 if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
959 deflateEnd(&png_ptr->zstream);
960
961 /* Free our memory. png_free checks NULL for us. */
962 png_free(png_ptr, png_ptr->zbuf);
963 png_free(png_ptr, png_ptr->row_buf);
964#ifdef PNG_WRITE_FILTER_SUPPORTED
965 png_free(png_ptr, png_ptr->prev_row);
966 png_free(png_ptr, png_ptr->sub_row);
967 png_free(png_ptr, png_ptr->up_row);
968 png_free(png_ptr, png_ptr->avg_row);
969 png_free(png_ptr, png_ptr->paeth_row);
970#endif
971
972#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
973 /* Use this to save a little code space, it doesn't free the filter_costs */
974 png_reset_filter_heuristics(png_ptr);
975 png_free(png_ptr, png_ptr->filter_costs);
976 png_free(png_ptr, png_ptr->inv_filter_costs);
977#endif
978
979#ifdef PNG_SETJMP_SUPPORTED
980 /* Reset structure */
981 png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
982#endif
983
984 error_fn = png_ptr->error_fn;
985#ifdef PNG_WARNINGS_SUPPORTED
986 warning_fn = png_ptr->warning_fn;
987#endif
988 error_ptr = png_ptr->error_ptr;
989#ifdef PNG_USER_MEM_SUPPORTED
990 free_fn = png_ptr->free_fn;
991#endif
992
993 png_memset(png_ptr, 0, png_sizeof(png_struct));
994
995 png_ptr->error_fn = error_fn;
996#ifdef PNG_WARNINGS_SUPPORTED
997 png_ptr->warning_fn = warning_fn;
998#endif
999 png_ptr->error_ptr = error_ptr;
1000#ifdef PNG_USER_MEM_SUPPORTED
1001 png_ptr->free_fn = free_fn;
1002#endif
1003
1004#ifdef PNG_SETJMP_SUPPORTED
1005 png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf));
1006#endif
1007}
1008
1009/* Allow the application to select one or more row filters to use. */
1010void PNGAPI
1011png_set_filter(png_structp png_ptr, int method, int filters)
1012{
1013 png_debug(1, "in png_set_filter");
1014
1015 if (png_ptr == NULL)
1016 return;
1017
1018#ifdef PNG_MNG_FEATURES_SUPPORTED
1019 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
1020 (method == PNG_INTRAPIXEL_DIFFERENCING))
1021 method = PNG_FILTER_TYPE_BASE;
1022
1023#endif
1024 if (method == PNG_FILTER_TYPE_BASE)
1025 {
1026 switch (filters & (PNG_ALL_FILTERS | 0x07))
1027 {
1028#ifdef PNG_WRITE_FILTER_SUPPORTED
1029 case 5:
1030 case 6:
1031 case 7: png_warning(png_ptr, "Unknown row filter for method 0");
1032#endif /* PNG_WRITE_FILTER_SUPPORTED */
1033 case PNG_FILTER_VALUE_NONE:
1034 png_ptr->do_filter = PNG_FILTER_NONE; break;
1035
1036#ifdef PNG_WRITE_FILTER_SUPPORTED
1037 case PNG_FILTER_VALUE_SUB:
1038 png_ptr->do_filter = PNG_FILTER_SUB; break;
1039
1040 case PNG_FILTER_VALUE_UP:
1041 png_ptr->do_filter = PNG_FILTER_UP; break;
1042
1043 case PNG_FILTER_VALUE_AVG:
1044 png_ptr->do_filter = PNG_FILTER_AVG; break;
1045
1046 case PNG_FILTER_VALUE_PAETH:
1047 png_ptr->do_filter = PNG_FILTER_PAETH; break;
1048
1049 default:
1050 png_ptr->do_filter = (png_byte)filters; break;
1051#else
1052 default:
1053 png_warning(png_ptr, "Unknown row filter for method 0");
1054#endif /* PNG_WRITE_FILTER_SUPPORTED */
1055 }
1056
1057 /* If we have allocated the row_buf, this means we have already started
1058 * with the image and we should have allocated all of the filter buffers
1059 * that have been selected. If prev_row isn't already allocated, then
1060 * it is too late to start using the filters that need it, since we
1061 * will be missing the data in the previous row. If an application
1062 * wants to start and stop using particular filters during compression,
1063 * it should start out with all of the filters, and then add and
1064 * remove them after the start of compression.
1065 */
1066 if (png_ptr->row_buf != NULL)
1067 {
1068#ifdef PNG_WRITE_FILTER_SUPPORTED
1069 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
1070 {
1071 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
1072 (png_ptr->rowbytes + 1));
1073 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
1074 }
1075
1076 if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
1077 {
1078 if (png_ptr->prev_row == NULL)
1079 {
1080 png_warning(png_ptr, "Can't add Up filter after starting");
1081 png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
1082 ~PNG_FILTER_UP);
1083 }
1084
1085 else
1086 {
1087 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
1088 (png_ptr->rowbytes + 1));
1089 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
1090 }
1091 }
1092
1093 if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
1094 {
1095 if (png_ptr->prev_row == NULL)
1096 {
1097 png_warning(png_ptr, "Can't add Average filter after starting");
1098 png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
1099 ~PNG_FILTER_AVG);
1100 }
1101
1102 else
1103 {
1104 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
1105 (png_ptr->rowbytes + 1));
1106 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
1107 }
1108 }
1109
1110 if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
1111 png_ptr->paeth_row == NULL)
1112 {
1113 if (png_ptr->prev_row == NULL)
1114 {
1115 png_warning(png_ptr, "Can't add Paeth filter after starting");
1116 png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
1117 }
1118
1119 else
1120 {
1121 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
1122 (png_ptr->rowbytes + 1));
1123 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
1124 }
1125 }
1126
1127 if (png_ptr->do_filter == PNG_NO_FILTERS)
1128#endif /* PNG_WRITE_FILTER_SUPPORTED */
1129 png_ptr->do_filter = PNG_FILTER_NONE;
1130 }
1131 }
1132 else
1133 png_error(png_ptr, "Unknown custom filter method");
1134}
1135
1136/* This allows us to influence the way in which libpng chooses the "best"
1137 * filter for the current scanline. While the "minimum-sum-of-absolute-
1138 * differences metric is relatively fast and effective, there is some
1139 * question as to whether it can be improved upon by trying to keep the
1140 * filtered data going to zlib more consistent, hopefully resulting in
1141 * better compression.
1142 */
1143#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */
1144/* Convenience reset API. */
1145static void
1146png_reset_filter_heuristics(png_structp png_ptr)
1147{
1148 /* Clear out any old values in the 'weights' - this must be done because if
1149 * the app calls set_filter_heuristics multiple times with different
1150 * 'num_weights' values we would otherwise potentially have wrong sized
1151 * arrays.
1152 */
1153 png_ptr->num_prev_filters = 0;
1154 png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
1155 if (png_ptr->prev_filters != NULL)
1156 {
1157 png_bytep old = png_ptr->prev_filters;
1158 png_ptr->prev_filters = NULL;
1159 png_free(png_ptr, old);
1160 }
1161 if (png_ptr->filter_weights != NULL)
1162 {
1163 png_uint_16p old = png_ptr->filter_weights;
1164 png_ptr->filter_weights = NULL;
1165 png_free(png_ptr, old);
1166 }
1167
1168 if (png_ptr->inv_filter_weights != NULL)
1169 {
1170 png_uint_16p old = png_ptr->inv_filter_weights;
1171 png_ptr->inv_filter_weights = NULL;
1172 png_free(png_ptr, old);
1173 }
1174
1175 /* Leave the filter_costs - this array is fixed size. */
1176}
1177
1178static int
1179png_init_filter_heuristics(png_structp png_ptr, int heuristic_method,
1180 int num_weights)
1181{
1182 if (png_ptr == NULL)
1183 return 0;
1184
1185 /* Clear out the arrays */
1186 png_reset_filter_heuristics(png_ptr);
1187
1188 /* Check arguments; the 'reset' function makes the correct settings for the
1189 * unweighted case, but we must handle the weight case by initializing the
1190 * arrays for the caller.
1191 */
1192 if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
1193 {
1194 int i;
1195
1196 if (num_weights > 0)
1197 {
1198 png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
1199 (png_uint_32)(png_sizeof(png_byte) * num_weights));
1200
1201 /* To make sure that the weighting starts out fairly */
1202 for (i = 0; i < num_weights; i++)
1203 {
1204 png_ptr->prev_filters[i] = 255;
1205 }
1206
1207 png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
1208 (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
1209
1210 png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
1211 (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
1212
1213 for (i = 0; i < num_weights; i++)
1214 {
1215 png_ptr->inv_filter_weights[i] =
1216 png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
1217 }
1218
1219 /* Safe to set this now */
1220 png_ptr->num_prev_filters = (png_byte)num_weights;
1221 }
1222
1223 /* If, in the future, there are other filter methods, this would
1224 * need to be based on png_ptr->filter.
1225 */
1226 if (png_ptr->filter_costs == NULL)
1227 {
1228 png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
1229 (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
1230
1231 png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
1232 (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
1233 }
1234
1235 for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
1236 {
1237 png_ptr->inv_filter_costs[i] =
1238 png_ptr->filter_costs[i] = PNG_COST_FACTOR;
1239 }
1240
1241 /* All the arrays are inited, safe to set this: */
1242 png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED;
1243
1244 /* Return the 'ok' code. */
1245 return 1;
1246 }
1247 else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT ||
1248 heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
1249 {
1250 return 1;
1251 }
1252 else
1253 {
1254 png_warning(png_ptr, "Unknown filter heuristic method");
1255 return 0;
1256 }
1257}
1258
1259/* Provide floating and fixed point APIs */
1260#ifdef PNG_FLOATING_POINT_SUPPORTED
1261void PNGAPI
1262png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
1263 int num_weights, png_const_doublep filter_weights,
1264 png_const_doublep filter_costs)
1265{
1266 png_debug(1, "in png_set_filter_heuristics");
1267
1268 /* The internal API allocates all the arrays and ensures that the elements of
1269 * those arrays are set to the default value.
1270 */
1271 if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
1272 return;
1273
1274 /* If using the weighted method copy in the weights. */
1275 if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
1276 {
1277 int i;
1278 for (i = 0; i < num_weights; i++)
1279 {
1280 if (filter_weights[i] <= 0.0)
1281 {
1282 png_ptr->inv_filter_weights[i] =
1283 png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
1284 }
1285
1286 else
1287 {
1288 png_ptr->inv_filter_weights[i] =
1289 (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
1290
1291 png_ptr->filter_weights[i] =
1292 (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
1293 }
1294 }
1295
1296 /* Here is where we set the relative costs of the different filters. We
1297 * should take the desired compression level into account when setting
1298 * the costs, so that Paeth, for instance, has a high relative cost at low
1299 * compression levels, while it has a lower relative cost at higher
1300 * compression settings. The filter types are in order of increasing
1301 * relative cost, so it would be possible to do this with an algorithm.
1302 */
1303 for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0)
1304 {
1305 png_ptr->inv_filter_costs[i] =
1306 (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5);
1307
1308 png_ptr->filter_costs[i] =
1309 (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5);
1310 }
1311 }
1312}
1313#endif /* FLOATING_POINT */
1314
1315#ifdef PNG_FIXED_POINT_SUPPORTED
1316void PNGAPI
1317png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method,
1318 int num_weights, png_const_fixed_point_p filter_weights,
1319 png_const_fixed_point_p filter_costs)
1320{
1321 png_debug(1, "in png_set_filter_heuristics_fixed");
1322
1323 /* The internal API allocates all the arrays and ensures that the elements of
1324 * those arrays are set to the default value.
1325 */
1326 if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
1327 return;
1328
1329 /* If using the weighted method copy in the weights. */
1330 if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
1331 {
1332 int i;
1333 for (i = 0; i < num_weights; i++)
1334 {
1335 if (filter_weights[i] <= 0)
1336 {
1337 png_ptr->inv_filter_weights[i] =
1338 png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
1339 }
1340
1341 else
1342 {
1343 png_ptr->inv_filter_weights[i] = (png_uint_16)
1344 ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
1345
1346 png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR*
1347 PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]);
1348 }
1349 }
1350
1351 /* Here is where we set the relative costs of the different filters. We
1352 * should take the desired compression level into account when setting
1353 * the costs, so that Paeth, for instance, has a high relative cost at low
1354 * compression levels, while it has a lower relative cost at higher
1355 * compression settings. The filter types are in order of increasing
1356 * relative cost, so it would be possible to do this with an algorithm.
1357 */
1358 for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
1359 if (filter_costs[i] >= PNG_FP_1)
1360 {
1361 png_uint_32 tmp;
1362
1363 /* Use a 32 bit unsigned temporary here because otherwise the
1364 * intermediate value will be a 32 bit *signed* integer (ANSI rules)
1365 * and this will get the wrong answer on division.
1366 */
1367 tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2);
1368 tmp /= filter_costs[i];
1369
1370 png_ptr->inv_filter_costs[i] = (png_uint_16)tmp;
1371
1372 tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF;
1373 tmp /= PNG_FP_1;
1374
1375 png_ptr->filter_costs[i] = (png_uint_16)tmp;
1376 }
1377 }
1378}
1379#endif /* FIXED_POINT */
1380#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
1381
1382void PNGAPI
1383png_set_compression_level(png_structp png_ptr, int level)
1384{
1385 png_debug(1, "in png_set_compression_level");
1386
1387 if (png_ptr == NULL)
1388 return;
1389
1390 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
1391 png_ptr->zlib_level = level;
1392}
1393
1394void PNGAPI
1395png_set_compression_mem_level(png_structp png_ptr, int mem_level)
1396{
1397 png_debug(1, "in png_set_compression_mem_level");
1398
1399 if (png_ptr == NULL)
1400 return;
1401
1402 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
1403 png_ptr->zlib_mem_level = mem_level;
1404}
1405
1406void PNGAPI
1407png_set_compression_strategy(png_structp png_ptr, int strategy)
1408{
1409 png_debug(1, "in png_set_compression_strategy");
1410
1411 if (png_ptr == NULL)
1412 return;
1413
1414 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
1415 png_ptr->zlib_strategy = strategy;
1416}
1417
1418/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
1419 * smaller value of window_bits if it can do so safely.
1420 */
1421void PNGAPI
1422png_set_compression_window_bits(png_structp png_ptr, int window_bits)
1423{
1424 if (png_ptr == NULL)
1425 return;
1426
1427 if (window_bits > 15)
1428 png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
1429
1430 else if (window_bits < 8)
1431 png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1432
1433#ifndef WBITS_8_OK
1434 /* Avoid libpng bug with 256-byte windows */
1435 if (window_bits == 8)
1436 {
1437 png_warning(png_ptr, "Compression window is being reset to 512");
1438 window_bits = 9;
1439 }
1440
1441#endif
1442 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
1443 png_ptr->zlib_window_bits = window_bits;
1444}
1445
1446void PNGAPI
1447png_set_compression_method(png_structp png_ptr, int method)
1448{
1449 png_debug(1, "in png_set_compression_method");
1450
1451 if (png_ptr == NULL)
1452 return;
1453
1454 if (method != 8)
1455 png_warning(png_ptr, "Only compression method 8 is supported by PNG");
1456
1457 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
1458 png_ptr->zlib_method = method;
1459}
1460
1461/* The following were added to libpng-1.5.4 */
1462#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
1463void PNGAPI
1464png_set_text_compression_level(png_structp png_ptr, int level)
1465{
1466 png_debug(1, "in png_set_text_compression_level");
1467
1468 if (png_ptr == NULL)
1469 return;
1470
1471 png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL;
1472 png_ptr->zlib_text_level = level;
1473}
1474
1475void PNGAPI
1476png_set_text_compression_mem_level(png_structp png_ptr, int mem_level)
1477{
1478 png_debug(1, "in png_set_text_compression_mem_level");
1479
1480 if (png_ptr == NULL)
1481 return;
1482
1483 png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL;
1484 png_ptr->zlib_text_mem_level = mem_level;
1485}
1486
1487void PNGAPI
1488png_set_text_compression_strategy(png_structp png_ptr, int strategy)
1489{
1490 png_debug(1, "in png_set_text_compression_strategy");
1491
1492 if (png_ptr == NULL)
1493 return;
1494
1495 png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY;
1496 png_ptr->zlib_text_strategy = strategy;
1497}
1498
1499/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
1500 * smaller value of window_bits if it can do so safely.
1501 */
1502void PNGAPI
1503png_set_text_compression_window_bits(png_structp png_ptr, int window_bits)
1504{
1505 if (png_ptr == NULL)
1506 return;
1507
1508 if (window_bits > 15)
1509 png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
1510
1511 else if (window_bits < 8)
1512 png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1513
1514#ifndef WBITS_8_OK
1515 /* Avoid libpng bug with 256-byte windows */
1516 if (window_bits == 8)
1517 {
1518 png_warning(png_ptr, "Text compression window is being reset to 512");
1519 window_bits = 9;
1520 }
1521
1522#endif
1523 png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS;
1524 png_ptr->zlib_text_window_bits = window_bits;
1525}
1526
1527void PNGAPI
1528png_set_text_compression_method(png_structp png_ptr, int method)
1529{
1530 png_debug(1, "in png_set_text_compression_method");
1531
1532 if (png_ptr == NULL)
1533 return;
1534
1535 if (method != 8)
1536 png_warning(png_ptr, "Only compression method 8 is supported by PNG");
1537
1538 png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD;
1539 png_ptr->zlib_text_method = method;
1540}
1541#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
1542/* end of API added to libpng-1.5.4 */
1543
1544void PNGAPI
1545png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
1546{
1547 if (png_ptr == NULL)
1548 return;
1549
1550 png_ptr->write_row_fn = write_row_fn;
1551}
1552
1553#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1554void PNGAPI
1555png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
1556 write_user_transform_fn)
1557{
1558 png_debug(1, "in png_set_write_user_transform_fn");
1559
1560 if (png_ptr == NULL)
1561 return;
1562
1563 png_ptr->transformations |= PNG_USER_TRANSFORM;
1564 png_ptr->write_user_transform_fn = write_user_transform_fn;
1565}
1566#endif
1567
1568
1569#ifdef PNG_INFO_IMAGE_SUPPORTED
1570void PNGAPI
1571png_write_png(png_structp png_ptr, png_infop info_ptr,
1572 int transforms, voidp params)
1573{
1574 if (png_ptr == NULL || info_ptr == NULL)
1575 return;
1576
1577 /* Write the file header information. */
1578 png_write_info(png_ptr, info_ptr);
1579
1580 /* ------ these transformations don't touch the info structure ------- */
1581
1582#ifdef PNG_WRITE_INVERT_SUPPORTED
1583 /* Invert monochrome pixels */
1584 if (transforms & PNG_TRANSFORM_INVERT_MONO)
1585 png_set_invert_mono(png_ptr);
1586#endif
1587
1588#ifdef PNG_WRITE_SHIFT_SUPPORTED
1589 /* Shift the pixels up to a legal bit depth and fill in
1590 * as appropriate to correctly scale the image.
1591 */
1592 if ((transforms & PNG_TRANSFORM_SHIFT)
1593 && (info_ptr->valid & PNG_INFO_sBIT))
1594 png_set_shift(png_ptr, &info_ptr->sig_bit);
1595#endif
1596
1597#ifdef PNG_WRITE_PACK_SUPPORTED
1598 /* Pack pixels into bytes */
1599 if (transforms & PNG_TRANSFORM_PACKING)
1600 png_set_packing(png_ptr);
1601#endif
1602
1603#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
1604 /* Swap location of alpha bytes from ARGB to RGBA */
1605 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1606 png_set_swap_alpha(png_ptr);
1607#endif
1608
1609#ifdef PNG_WRITE_FILLER_SUPPORTED
1610 /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
1611 if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
1612 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1613
1614 else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
1615 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
1616#endif
1617
1618#ifdef PNG_WRITE_BGR_SUPPORTED
1619 /* Flip BGR pixels to RGB */
1620 if (transforms & PNG_TRANSFORM_BGR)
1621 png_set_bgr(png_ptr);
1622#endif
1623
1624#ifdef PNG_WRITE_SWAP_SUPPORTED
1625 /* Swap bytes of 16-bit files to most significant byte first */
1626 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1627 png_set_swap(png_ptr);
1628#endif
1629
1630#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
1631 /* Swap bits of 1, 2, 4 bit packed pixel formats */
1632 if (transforms & PNG_TRANSFORM_PACKSWAP)
1633 png_set_packswap(png_ptr);
1634#endif
1635
1636#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
1637 /* Invert the alpha channel from opacity to transparency */
1638 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1639 png_set_invert_alpha(png_ptr);
1640#endif
1641
1642 /* ----------------------- end of transformations ------------------- */
1643
1644 /* Write the bits */
1645 if (info_ptr->valid & PNG_INFO_IDAT)
1646 png_write_image(png_ptr, info_ptr->row_pointers);
1647
1648 /* It is REQUIRED to call this to finish writing the rest of the file */
1649 png_write_end(png_ptr, info_ptr);
1650
1651 PNG_UNUSED(transforms) /* Quiet compiler warnings */
1652 PNG_UNUSED(params)
1653}
1654#endif
1655#endif /* PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c
new file mode 100644
index 0000000..b598149
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwtran.c
@@ -0,0 +1,633 @@
1
2/* pngwtran.c - transforms the data in a row for PNG writers
3 *
4 * Last changed in libpng 1.5.6 [November 3, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16#ifdef PNG_WRITE_SUPPORTED
17
18#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
19/* Transform the data according to the user's wishes. The order of
20 * transformations is significant.
21 */
22void /* PRIVATE */
23png_do_write_transformations(png_structp png_ptr, png_row_infop row_info)
24{
25 png_debug(1, "in png_do_write_transformations");
26
27 if (png_ptr == NULL)
28 return;
29
30#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
31 if (png_ptr->transformations & PNG_USER_TRANSFORM)
32 if (png_ptr->write_user_transform_fn != NULL)
33 (*(png_ptr->write_user_transform_fn)) /* User write transform
34 function */
35 (png_ptr, /* png_ptr */
36 row_info, /* row_info: */
37 /* png_uint_32 width; width of row */
38 /* png_size_t rowbytes; number of bytes in row */
39 /* png_byte color_type; color type of pixels */
40 /* png_byte bit_depth; bit depth of samples */
41 /* png_byte channels; number of channels (1-4) */
42 /* png_byte pixel_depth; bits per pixel (depth*channels) */
43 png_ptr->row_buf + 1); /* start of pixel data for row */
44#endif
45
46#ifdef PNG_WRITE_FILLER_SUPPORTED
47 if (png_ptr->transformations & PNG_FILLER)
48 png_do_strip_channel(row_info, png_ptr->row_buf + 1,
49 !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
50#endif
51
52#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
53 if (png_ptr->transformations & PNG_PACKSWAP)
54 png_do_packswap(row_info, png_ptr->row_buf + 1);
55#endif
56
57#ifdef PNG_WRITE_PACK_SUPPORTED
58 if (png_ptr->transformations & PNG_PACK)
59 png_do_pack(row_info, png_ptr->row_buf + 1,
60 (png_uint_32)png_ptr->bit_depth);
61#endif
62
63#ifdef PNG_WRITE_SWAP_SUPPORTED
64 if (png_ptr->transformations & PNG_SWAP_BYTES)
65 png_do_swap(row_info, png_ptr->row_buf + 1);
66#endif
67
68#ifdef PNG_WRITE_SHIFT_SUPPORTED
69 if (png_ptr->transformations & PNG_SHIFT)
70 png_do_shift(row_info, png_ptr->row_buf + 1,
71 &(png_ptr->shift));
72#endif
73
74#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
75 if (png_ptr->transformations & PNG_SWAP_ALPHA)
76 png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
77#endif
78
79#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
80 if (png_ptr->transformations & PNG_INVERT_ALPHA)
81 png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
82#endif
83
84#ifdef PNG_WRITE_BGR_SUPPORTED
85 if (png_ptr->transformations & PNG_BGR)
86 png_do_bgr(row_info, png_ptr->row_buf + 1);
87#endif
88
89#ifdef PNG_WRITE_INVERT_SUPPORTED
90 if (png_ptr->transformations & PNG_INVERT_MONO)
91 png_do_invert(row_info, png_ptr->row_buf + 1);
92#endif
93}
94
95#ifdef PNG_WRITE_PACK_SUPPORTED
96/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
97 * row_info bit depth should be 8 (one pixel per byte). The channels
98 * should be 1 (this only happens on grayscale and paletted images).
99 */
100void /* PRIVATE */
101png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
102{
103 png_debug(1, "in png_do_pack");
104
105 if (row_info->bit_depth == 8 &&
106 row_info->channels == 1)
107 {
108 switch ((int)bit_depth)
109 {
110 case 1:
111 {
112 png_bytep sp, dp;
113 int mask, v;
114 png_uint_32 i;
115 png_uint_32 row_width = row_info->width;
116
117 sp = row;
118 dp = row;
119 mask = 0x80;
120 v = 0;
121
122 for (i = 0; i < row_width; i++)
123 {
124 if (*sp != 0)
125 v |= mask;
126
127 sp++;
128
129 if (mask > 1)
130 mask >>= 1;
131
132 else
133 {
134 mask = 0x80;
135 *dp = (png_byte)v;
136 dp++;
137 v = 0;
138 }
139 }
140
141 if (mask != 0x80)
142 *dp = (png_byte)v;
143
144 break;
145 }
146
147 case 2:
148 {
149 png_bytep sp, dp;
150 int shift, v;
151 png_uint_32 i;
152 png_uint_32 row_width = row_info->width;
153
154 sp = row;
155 dp = row;
156 shift = 6;
157 v = 0;
158
159 for (i = 0; i < row_width; i++)
160 {
161 png_byte value;
162
163 value = (png_byte)(*sp & 0x03);
164 v |= (value << shift);
165
166 if (shift == 0)
167 {
168 shift = 6;
169 *dp = (png_byte)v;
170 dp++;
171 v = 0;
172 }
173
174 else
175 shift -= 2;
176
177 sp++;
178 }
179
180 if (shift != 6)
181 *dp = (png_byte)v;
182
183 break;
184 }
185
186 case 4:
187 {
188 png_bytep sp, dp;
189 int shift, v;
190 png_uint_32 i;
191 png_uint_32 row_width = row_info->width;
192
193 sp = row;
194 dp = row;
195 shift = 4;
196 v = 0;
197
198 for (i = 0; i < row_width; i++)
199 {
200 png_byte value;
201
202 value = (png_byte)(*sp & 0x0f);
203 v |= (value << shift);
204
205 if (shift == 0)
206 {
207 shift = 4;
208 *dp = (png_byte)v;
209 dp++;
210 v = 0;
211 }
212
213 else
214 shift -= 4;
215
216 sp++;
217 }
218
219 if (shift != 4)
220 *dp = (png_byte)v;
221
222 break;
223 }
224
225 default:
226 break;
227 }
228
229 row_info->bit_depth = (png_byte)bit_depth;
230 row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
231 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
232 row_info->width);
233 }
234}
235#endif
236
237#ifdef PNG_WRITE_SHIFT_SUPPORTED
238/* Shift pixel values to take advantage of whole range. Pass the
239 * true number of bits in bit_depth. The row should be packed
240 * according to row_info->bit_depth. Thus, if you had a row of
241 * bit depth 4, but the pixels only had values from 0 to 7, you
242 * would pass 3 as bit_depth, and this routine would translate the
243 * data to 0 to 15.
244 */
245void /* PRIVATE */
246png_do_shift(png_row_infop row_info, png_bytep row,
247 png_const_color_8p bit_depth)
248{
249 png_debug(1, "in png_do_shift");
250
251 if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
252 {
253 int shift_start[4], shift_dec[4];
254 int channels = 0;
255
256 if (row_info->color_type & PNG_COLOR_MASK_COLOR)
257 {
258 shift_start[channels] = row_info->bit_depth - bit_depth->red;
259 shift_dec[channels] = bit_depth->red;
260 channels++;
261
262 shift_start[channels] = row_info->bit_depth - bit_depth->green;
263 shift_dec[channels] = bit_depth->green;
264 channels++;
265
266 shift_start[channels] = row_info->bit_depth - bit_depth->blue;
267 shift_dec[channels] = bit_depth->blue;
268 channels++;
269 }
270
271 else
272 {
273 shift_start[channels] = row_info->bit_depth - bit_depth->gray;
274 shift_dec[channels] = bit_depth->gray;
275 channels++;
276 }
277
278 if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
279 {
280 shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
281 shift_dec[channels] = bit_depth->alpha;
282 channels++;
283 }
284
285 /* With low row depths, could only be grayscale, so one channel */
286 if (row_info->bit_depth < 8)
287 {
288 png_bytep bp = row;
289 png_size_t i;
290 png_byte mask;
291 png_size_t row_bytes = row_info->rowbytes;
292
293 if (bit_depth->gray == 1 && row_info->bit_depth == 2)
294 mask = 0x55;
295
296 else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
297 mask = 0x11;
298
299 else
300 mask = 0xff;
301
302 for (i = 0; i < row_bytes; i++, bp++)
303 {
304 png_uint_16 v;
305 int j;
306
307 v = *bp;
308 *bp = 0;
309
310 for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
311 {
312 if (j > 0)
313 *bp |= (png_byte)((v << j) & 0xff);
314
315 else
316 *bp |= (png_byte)((v >> (-j)) & mask);
317 }
318 }
319 }
320
321 else if (row_info->bit_depth == 8)
322 {
323 png_bytep bp = row;
324 png_uint_32 i;
325 png_uint_32 istop = channels * row_info->width;
326
327 for (i = 0; i < istop; i++, bp++)
328 {
329
330 png_uint_16 v;
331 int j;
332 int c = (int)(i%channels);
333
334 v = *bp;
335 *bp = 0;
336
337 for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
338 {
339 if (j > 0)
340 *bp |= (png_byte)((v << j) & 0xff);
341
342 else
343 *bp |= (png_byte)((v >> (-j)) & 0xff);
344 }
345 }
346 }
347
348 else
349 {
350 png_bytep bp;
351 png_uint_32 i;
352 png_uint_32 istop = channels * row_info->width;
353
354 for (bp = row, i = 0; i < istop; i++)
355 {
356 int c = (int)(i%channels);
357 png_uint_16 value, v;
358 int j;
359
360 v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
361 value = 0;
362
363 for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
364 {
365 if (j > 0)
366 value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
367
368 else
369 value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
370 }
371 *bp++ = (png_byte)(value >> 8);
372 *bp++ = (png_byte)(value & 0xff);
373 }
374 }
375 }
376}
377#endif
378
379#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
380void /* PRIVATE */
381png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
382{
383 png_debug(1, "in png_do_write_swap_alpha");
384
385 {
386 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
387 {
388 if (row_info->bit_depth == 8)
389 {
390 /* This converts from ARGB to RGBA */
391 png_bytep sp, dp;
392 png_uint_32 i;
393 png_uint_32 row_width = row_info->width;
394
395 for (i = 0, sp = dp = row; i < row_width; i++)
396 {
397 png_byte save = *(sp++);
398 *(dp++) = *(sp++);
399 *(dp++) = *(sp++);
400 *(dp++) = *(sp++);
401 *(dp++) = save;
402 }
403 }
404
405#ifdef PNG_WRITE_16BIT_SUPPORTED
406 else
407 {
408 /* This converts from AARRGGBB to RRGGBBAA */
409 png_bytep sp, dp;
410 png_uint_32 i;
411 png_uint_32 row_width = row_info->width;
412
413 for (i = 0, sp = dp = row; i < row_width; i++)
414 {
415 png_byte save[2];
416 save[0] = *(sp++);
417 save[1] = *(sp++);
418 *(dp++) = *(sp++);
419 *(dp++) = *(sp++);
420 *(dp++) = *(sp++);
421 *(dp++) = *(sp++);
422 *(dp++) = *(sp++);
423 *(dp++) = *(sp++);
424 *(dp++) = save[0];
425 *(dp++) = save[1];
426 }
427 }
428#endif /* PNG_WRITE_16BIT_SUPPORTED */
429 }
430
431 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
432 {
433 if (row_info->bit_depth == 8)
434 {
435 /* This converts from AG to GA */
436 png_bytep sp, dp;
437 png_uint_32 i;
438 png_uint_32 row_width = row_info->width;
439
440 for (i = 0, sp = dp = row; i < row_width; i++)
441 {
442 png_byte save = *(sp++);
443 *(dp++) = *(sp++);
444 *(dp++) = save;
445 }
446 }
447
448#ifdef PNG_WRITE_16BIT_SUPPORTED
449 else
450 {
451 /* This converts from AAGG to GGAA */
452 png_bytep sp, dp;
453 png_uint_32 i;
454 png_uint_32 row_width = row_info->width;
455
456 for (i = 0, sp = dp = row; i < row_width; i++)
457 {
458 png_byte save[2];
459 save[0] = *(sp++);
460 save[1] = *(sp++);
461 *(dp++) = *(sp++);
462 *(dp++) = *(sp++);
463 *(dp++) = save[0];
464 *(dp++) = save[1];
465 }
466 }
467#endif /* PNG_WRITE_16BIT_SUPPORTED */
468 }
469 }
470}
471#endif
472
473#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
474void /* PRIVATE */
475png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
476{
477 png_debug(1, "in png_do_write_invert_alpha");
478
479 {
480 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
481 {
482 if (row_info->bit_depth == 8)
483 {
484 /* This inverts the alpha channel in RGBA */
485 png_bytep sp, dp;
486 png_uint_32 i;
487 png_uint_32 row_width = row_info->width;
488
489 for (i = 0, sp = dp = row; i < row_width; i++)
490 {
491 /* Does nothing
492 *(dp++) = *(sp++);
493 *(dp++) = *(sp++);
494 *(dp++) = *(sp++);
495 */
496 sp+=3; dp = sp;
497 *(dp++) = (png_byte)(255 - *(sp++));
498 }
499 }
500
501#ifdef PNG_WRITE_16BIT_SUPPORTED
502 else
503 {
504 /* This inverts the alpha channel in RRGGBBAA */
505 png_bytep sp, dp;
506 png_uint_32 i;
507 png_uint_32 row_width = row_info->width;
508
509 for (i = 0, sp = dp = row; i < row_width; i++)
510 {
511 /* Does nothing
512 *(dp++) = *(sp++);
513 *(dp++) = *(sp++);
514 *(dp++) = *(sp++);
515 *(dp++) = *(sp++);
516 *(dp++) = *(sp++);
517 *(dp++) = *(sp++);
518 */
519 sp+=6; dp = sp;
520 *(dp++) = (png_byte)(255 - *(sp++));
521 *(dp++) = (png_byte)(255 - *(sp++));
522 }
523 }
524#endif /* PNG_WRITE_16BIT_SUPPORTED */
525 }
526
527 else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
528 {
529 if (row_info->bit_depth == 8)
530 {
531 /* This inverts the alpha channel in GA */
532 png_bytep sp, dp;
533 png_uint_32 i;
534 png_uint_32 row_width = row_info->width;
535
536 for (i = 0, sp = dp = row; i < row_width; i++)
537 {
538 *(dp++) = *(sp++);
539 *(dp++) = (png_byte)(255 - *(sp++));
540 }
541 }
542
543#ifdef PNG_WRITE_16BIT_SUPPORTED
544 else
545 {
546 /* This inverts the alpha channel in GGAA */
547 png_bytep sp, dp;
548 png_uint_32 i;
549 png_uint_32 row_width = row_info->width;
550
551 for (i = 0, sp = dp = row; i < row_width; i++)
552 {
553 /* Does nothing
554 *(dp++) = *(sp++);
555 *(dp++) = *(sp++);
556 */
557 sp+=2; dp = sp;
558 *(dp++) = (png_byte)(255 - *(sp++));
559 *(dp++) = (png_byte)(255 - *(sp++));
560 }
561 }
562#endif /* PNG_WRITE_16BIT_SUPPORTED */
563 }
564 }
565}
566#endif
567#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
568
569#ifdef PNG_MNG_FEATURES_SUPPORTED
570/* Undoes intrapixel differencing */
571void /* PRIVATE */
572png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
573{
574 png_debug(1, "in png_do_write_intrapixel");
575
576 if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
577 {
578 int bytes_per_pixel;
579 png_uint_32 row_width = row_info->width;
580 if (row_info->bit_depth == 8)
581 {
582 png_bytep rp;
583 png_uint_32 i;
584
585 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
586 bytes_per_pixel = 3;
587
588 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
589 bytes_per_pixel = 4;
590
591 else
592 return;
593
594 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
595 {
596 *(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff);
597 *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
598 }
599 }
600
601#ifdef PNG_WRITE_16BIT_SUPPORTED
602 else if (row_info->bit_depth == 16)
603 {
604 png_bytep rp;
605 png_uint_32 i;
606
607 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
608 bytes_per_pixel = 6;
609
610 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
611 bytes_per_pixel = 8;
612
613 else
614 return;
615
616 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
617 {
618 png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
619 png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
620 png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
621 png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
622 png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
623 *(rp ) = (png_byte)((red >> 8) & 0xff);
624 *(rp + 1) = (png_byte)(red & 0xff);
625 *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
626 *(rp + 5) = (png_byte)(blue & 0xff);
627 }
628 }
629#endif /* PNG_WRITE_16BIT_SUPPORTED */
630 }
631}
632#endif /* PNG_MNG_FEATURES_SUPPORTED */
633#endif /* PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwutil.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwutil.c
new file mode 100644
index 0000000..64888f7
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/pngwutil.c
@@ -0,0 +1,3180 @@
1
2/* pngwutil.c - utilities to write a PNG file
3 *
4 * Last changed in libpng 1.5.6 [November 3, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12 */
13
14#include "pngpriv.h"
15
16#ifdef PNG_WRITE_SUPPORTED
17
18#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
19/* Place a 32-bit number into a buffer in PNG byte order. We work
20 * with unsigned numbers for convenience, although one supported
21 * ancillary chunk uses signed (two's complement) numbers.
22 */
23void PNGAPI
24png_save_uint_32(png_bytep buf, png_uint_32 i)
25{
26 buf[0] = (png_byte)((i >> 24) & 0xff);
27 buf[1] = (png_byte)((i >> 16) & 0xff);
28 buf[2] = (png_byte)((i >> 8) & 0xff);
29 buf[3] = (png_byte)(i & 0xff);
30}
31
32#ifdef PNG_SAVE_INT_32_SUPPORTED
33/* The png_save_int_32 function assumes integers are stored in two's
34 * complement format. If this isn't the case, then this routine needs to
35 * be modified to write data in two's complement format. Note that,
36 * the following works correctly even if png_int_32 has more than 32 bits
37 * (compare the more complex code required on read for sign extention.)
38 */
39void PNGAPI
40png_save_int_32(png_bytep buf, png_int_32 i)
41{
42 buf[0] = (png_byte)((i >> 24) & 0xff);
43 buf[1] = (png_byte)((i >> 16) & 0xff);
44 buf[2] = (png_byte)((i >> 8) & 0xff);
45 buf[3] = (png_byte)(i & 0xff);
46}
47#endif
48
49/* Place a 16-bit number into a buffer in PNG byte order.
50 * The parameter is declared unsigned int, not png_uint_16,
51 * just to avoid potential problems on pre-ANSI C compilers.
52 */
53void PNGAPI
54png_save_uint_16(png_bytep buf, unsigned int i)
55{
56 buf[0] = (png_byte)((i >> 8) & 0xff);
57 buf[1] = (png_byte)(i & 0xff);
58}
59#endif
60
61/* Simple function to write the signature. If we have already written
62 * the magic bytes of the signature, or more likely, the PNG stream is
63 * being embedded into another stream and doesn't need its own signature,
64 * we should call png_set_sig_bytes() to tell libpng how many of the
65 * bytes have already been written.
66 */
67void PNGAPI
68png_write_sig(png_structp png_ptr)
69{
70 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
71
72#ifdef PNG_IO_STATE_SUPPORTED
73 /* Inform the I/O callback that the signature is being written */
74 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE;
75#endif
76
77 /* Write the rest of the 8 byte signature */
78 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
79 (png_size_t)(8 - png_ptr->sig_bytes));
80
81 if (png_ptr->sig_bytes < 3)
82 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
83}
84
85/* Write the start of a PNG chunk. The type is the chunk type.
86 * The total_length is the sum of the lengths of all the data you will be
87 * passing in png_write_chunk_data().
88 */
89static void
90png_write_chunk_header(png_structp png_ptr, png_uint_32 chunk_name,
91 png_uint_32 length)
92{
93 png_byte buf[8];
94
95#if defined(PNG_DEBUG) && (PNG_DEBUG > 0)
96 PNG_CSTRING_FROM_CHUNK(buf, chunk_name);
97 png_debug2(0, "Writing %s chunk, length = %lu", buf, (unsigned long)length);
98#endif
99
100 if (png_ptr == NULL)
101 return;
102
103#ifdef PNG_IO_STATE_SUPPORTED
104 /* Inform the I/O callback that the chunk header is being written.
105 * PNG_IO_CHUNK_HDR requires a single I/O call.
106 */
107 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR;
108#endif
109
110 /* Write the length and the chunk name */
111 png_save_uint_32(buf, length);
112 png_save_uint_32(buf + 4, chunk_name);
113 png_write_data(png_ptr, buf, 8);
114
115 /* Put the chunk name into png_ptr->chunk_name */
116 png_ptr->chunk_name = chunk_name;
117
118 /* Reset the crc and run it over the chunk name */
119 png_reset_crc(png_ptr);
120
121 png_calculate_crc(png_ptr, buf + 4, 4);
122
123#ifdef PNG_IO_STATE_SUPPORTED
124 /* Inform the I/O callback that chunk data will (possibly) be written.
125 * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls.
126 */
127 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA;
128#endif
129}
130
131void PNGAPI
132png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_string,
133 png_uint_32 length)
134{
135 png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length);
136}
137
138/* Write the data of a PNG chunk started with png_write_chunk_header().
139 * Note that multiple calls to this function are allowed, and that the
140 * sum of the lengths from these calls *must* add up to the total_length
141 * given to png_write_chunk_header().
142 */
143void PNGAPI
144png_write_chunk_data(png_structp png_ptr, png_const_bytep data,
145 png_size_t length)
146{
147 /* Write the data, and run the CRC over it */
148 if (png_ptr == NULL)
149 return;
150
151 if (data != NULL && length > 0)
152 {
153 png_write_data(png_ptr, data, length);
154
155 /* Update the CRC after writing the data,
156 * in case that the user I/O routine alters it.
157 */
158 png_calculate_crc(png_ptr, data, length);
159 }
160}
161
162/* Finish a chunk started with png_write_chunk_header(). */
163void PNGAPI
164png_write_chunk_end(png_structp png_ptr)
165{
166 png_byte buf[4];
167
168 if (png_ptr == NULL) return;
169
170#ifdef PNG_IO_STATE_SUPPORTED
171 /* Inform the I/O callback that the chunk CRC is being written.
172 * PNG_IO_CHUNK_CRC requires a single I/O function call.
173 */
174 png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC;
175#endif
176
177 /* Write the crc in a single operation */
178 png_save_uint_32(buf, png_ptr->crc);
179
180 png_write_data(png_ptr, buf, (png_size_t)4);
181}
182
183/* Write a PNG chunk all at once. The type is an array of ASCII characters
184 * representing the chunk name. The array must be at least 4 bytes in
185 * length, and does not need to be null terminated. To be safe, pass the
186 * pre-defined chunk names here, and if you need a new one, define it
187 * where the others are defined. The length is the length of the data.
188 * All the data must be present. If that is not possible, use the
189 * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()
190 * functions instead.
191 */
192static void
193png_write_complete_chunk(png_structp png_ptr, png_uint_32 chunk_name,
194 png_const_bytep data, png_size_t length)
195{
196 if (png_ptr == NULL)
197 return;
198
199 /* On 64 bit architectures 'length' may not fit in a png_uint_32. */
200 if (length > PNG_UINT_32_MAX)
201 png_error(png_ptr, "length exceeds PNG maxima");
202
203 png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length);
204 png_write_chunk_data(png_ptr, data, length);
205 png_write_chunk_end(png_ptr);
206}
207
208/* This is the API that calls the internal function above. */
209void PNGAPI
210png_write_chunk(png_structp png_ptr, png_const_bytep chunk_string,
211 png_const_bytep data, png_size_t length)
212{
213 png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data,
214 length);
215}
216
217/* Initialize the compressor for the appropriate type of compression. */
218static void
219png_zlib_claim(png_structp png_ptr, png_uint_32 state)
220{
221 if (!(png_ptr->zlib_state & PNG_ZLIB_IN_USE))
222 {
223 /* If already initialized for 'state' do not re-init. */
224 if (png_ptr->zlib_state != state)
225 {
226 int ret = Z_OK;
227 png_const_charp who = "-";
228
229 /* If actually initialized for another state do a deflateEnd. */
230 if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
231 {
232 ret = deflateEnd(&png_ptr->zstream);
233 who = "end";
234 png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED;
235 }
236
237 /* zlib itself detects an incomplete state on deflateEnd */
238 if (ret == Z_OK) switch (state)
239 {
240# ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
241 case PNG_ZLIB_FOR_TEXT:
242 ret = deflateInit2(&png_ptr->zstream,
243 png_ptr->zlib_text_level, png_ptr->zlib_text_method,
244 png_ptr->zlib_text_window_bits,
245 png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy);
246 who = "text";
247 break;
248# endif
249
250 case PNG_ZLIB_FOR_IDAT:
251 ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
252 png_ptr->zlib_method, png_ptr->zlib_window_bits,
253 png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
254 who = "IDAT";
255 break;
256
257 default:
258 png_error(png_ptr, "invalid zlib state");
259 }
260
261 if (ret == Z_OK)
262 png_ptr->zlib_state = state;
263
264 else /* an error in deflateEnd or deflateInit2 */
265 {
266 size_t pos = 0;
267 char msg[64];
268
269 pos = png_safecat(msg, sizeof msg, pos,
270 "zlib failed to initialize compressor (");
271 pos = png_safecat(msg, sizeof msg, pos, who);
272
273 switch (ret)
274 {
275 case Z_VERSION_ERROR:
276 pos = png_safecat(msg, sizeof msg, pos, ") version error");
277 break;
278
279 case Z_STREAM_ERROR:
280 pos = png_safecat(msg, sizeof msg, pos, ") stream error");
281 break;
282
283 case Z_MEM_ERROR:
284 pos = png_safecat(msg, sizeof msg, pos, ") memory error");
285 break;
286
287 default:
288 pos = png_safecat(msg, sizeof msg, pos, ") unknown error");
289 break;
290 }
291
292 png_error(png_ptr, msg);
293 }
294 }
295
296 /* Here on success, claim the zstream: */
297 png_ptr->zlib_state |= PNG_ZLIB_IN_USE;
298 }
299
300 else
301 png_error(png_ptr, "zstream already in use (internal error)");
302}
303
304/* The opposite: release the stream. It is also reset, this API will warn on
305 * error but will not fail.
306 */
307static void
308png_zlib_release(png_structp png_ptr)
309{
310 if (png_ptr->zlib_state & PNG_ZLIB_IN_USE)
311 {
312 int ret = deflateReset(&png_ptr->zstream);
313
314 png_ptr->zlib_state &= ~PNG_ZLIB_IN_USE;
315
316 if (ret != Z_OK)
317 {
318 png_const_charp err;
319 PNG_WARNING_PARAMETERS(p)
320
321 switch (ret)
322 {
323 case Z_VERSION_ERROR:
324 err = "version";
325 break;
326
327 case Z_STREAM_ERROR:
328 err = "stream";
329 break;
330
331 case Z_MEM_ERROR:
332 err = "memory";
333 break;
334
335 default:
336 err = "unknown";
337 break;
338 }
339
340 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, ret);
341 png_warning_parameter(p, 2, err);
342
343 if (png_ptr->zstream.msg)
344 err = png_ptr->zstream.msg;
345 else
346 err = "[no zlib message]";
347
348 png_warning_parameter(p, 3, err);
349
350 png_formatted_warning(png_ptr, p,
351 "zlib failed to reset compressor: @1(@2): @3");
352 }
353 }
354
355 else
356 png_warning(png_ptr, "zstream not in use (internal error)");
357}
358
359#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
360/* This pair of functions encapsulates the operation of (a) compressing a
361 * text string, and (b) issuing it later as a series of chunk data writes.
362 * The compression_state structure is shared context for these functions
363 * set up by the caller in order to make the whole mess thread-safe.
364 */
365
366typedef struct
367{
368 png_const_bytep input; /* The uncompressed input data */
369 png_size_t input_len; /* Its length */
370 int num_output_ptr; /* Number of output pointers used */
371 int max_output_ptr; /* Size of output_ptr */
372 png_bytep *output_ptr; /* Array of pointers to output */
373} compression_state;
374
375/* Compress given text into storage in the png_ptr structure */
376static int /* PRIVATE */
377png_text_compress(png_structp png_ptr,
378 png_const_charp text, png_size_t text_len, int compression,
379 compression_state *comp)
380{
381 int ret;
382
383 comp->num_output_ptr = 0;
384 comp->max_output_ptr = 0;
385 comp->output_ptr = NULL;
386 comp->input = NULL;
387 comp->input_len = text_len;
388
389 /* We may just want to pass the text right through */
390 if (compression == PNG_TEXT_COMPRESSION_NONE)
391 {
392 comp->input = (png_const_bytep)text;
393 return((int)text_len);
394 }
395
396 if (compression >= PNG_TEXT_COMPRESSION_LAST)
397 {
398 PNG_WARNING_PARAMETERS(p)
399
400 png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d,
401 compression);
402 png_formatted_warning(png_ptr, p, "Unknown compression type @1");
403 }
404
405 /* We can't write the chunk until we find out how much data we have,
406 * which means we need to run the compressor first and save the
407 * output. This shouldn't be a problem, as the vast majority of
408 * comments should be reasonable, but we will set up an array of
409 * malloc'd pointers to be sure.
410 *
411 * If we knew the application was well behaved, we could simplify this
412 * greatly by assuming we can always malloc an output buffer large
413 * enough to hold the compressed text ((1001 * text_len / 1000) + 12)
414 * and malloc this directly. The only time this would be a bad idea is
415 * if we can't malloc more than 64K and we have 64K of random input
416 * data, or if the input string is incredibly large (although this
417 * wouldn't cause a failure, just a slowdown due to swapping).
418 */
419 png_zlib_claim(png_ptr, PNG_ZLIB_FOR_TEXT);
420
421 /* Set up the compression buffers */
422 /* TODO: the following cast hides a potential overflow problem. */
423 png_ptr->zstream.avail_in = (uInt)text_len;
424
425 /* NOTE: assume zlib doesn't overwrite the input */
426 png_ptr->zstream.next_in = (Bytef *)text;
427 png_ptr->zstream.avail_out = png_ptr->zbuf_size;
428 png_ptr->zstream.next_out = png_ptr->zbuf;
429
430 /* This is the same compression loop as in png_write_row() */
431 do
432 {
433 /* Compress the data */
434 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
435
436 if (ret != Z_OK)
437 {
438 /* Error */
439 if (png_ptr->zstream.msg != NULL)
440 png_error(png_ptr, png_ptr->zstream.msg);
441
442 else
443 png_error(png_ptr, "zlib error");
444 }
445
446 /* Check to see if we need more room */
447 if (!(png_ptr->zstream.avail_out))
448 {
449 /* Make sure the output array has room */
450 if (comp->num_output_ptr >= comp->max_output_ptr)
451 {
452 int old_max;
453
454 old_max = comp->max_output_ptr;
455 comp->max_output_ptr = comp->num_output_ptr + 4;
456 if (comp->output_ptr != NULL)
457 {
458 png_bytepp old_ptr;
459
460 old_ptr = comp->output_ptr;
461
462 comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
463 (png_alloc_size_t)
464 (comp->max_output_ptr * png_sizeof(png_charpp)));
465
466 png_memcpy(comp->output_ptr, old_ptr, old_max
467 * png_sizeof(png_charp));
468
469 png_free(png_ptr, old_ptr);
470 }
471 else
472 comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
473 (png_alloc_size_t)
474 (comp->max_output_ptr * png_sizeof(png_charp)));
475 }
476
477 /* Save the data */
478 comp->output_ptr[comp->num_output_ptr] =
479 (png_bytep)png_malloc(png_ptr,
480 (png_alloc_size_t)png_ptr->zbuf_size);
481
482 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
483 png_ptr->zbuf_size);
484
485 comp->num_output_ptr++;
486
487 /* and reset the buffer */
488 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
489 png_ptr->zstream.next_out = png_ptr->zbuf;
490 }
491 /* Continue until we don't have any more to compress */
492 } while (png_ptr->zstream.avail_in);
493
494 /* Finish the compression */
495 do
496 {
497 /* Tell zlib we are finished */
498 ret = deflate(&png_ptr->zstream, Z_FINISH);
499
500 if (ret == Z_OK)
501 {
502 /* Check to see if we need more room */
503 if (!(png_ptr->zstream.avail_out))
504 {
505 /* Check to make sure our output array has room */
506 if (comp->num_output_ptr >= comp->max_output_ptr)
507 {
508 int old_max;
509
510 old_max = comp->max_output_ptr;
511 comp->max_output_ptr = comp->num_output_ptr + 4;
512 if (comp->output_ptr != NULL)
513 {
514 png_bytepp old_ptr;
515
516 old_ptr = comp->output_ptr;
517
518 /* This could be optimized to realloc() */
519 comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
520 (png_alloc_size_t)(comp->max_output_ptr *
521 png_sizeof(png_charp)));
522
523 png_memcpy(comp->output_ptr, old_ptr,
524 old_max * png_sizeof(png_charp));
525
526 png_free(png_ptr, old_ptr);
527 }
528
529 else
530 comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
531 (png_alloc_size_t)(comp->max_output_ptr *
532 png_sizeof(png_charp)));
533 }
534
535 /* Save the data */
536 comp->output_ptr[comp->num_output_ptr] =
537 (png_bytep)png_malloc(png_ptr,
538 (png_alloc_size_t)png_ptr->zbuf_size);
539
540 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
541 png_ptr->zbuf_size);
542
543 comp->num_output_ptr++;
544
545 /* and reset the buffer pointers */
546 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
547 png_ptr->zstream.next_out = png_ptr->zbuf;
548 }
549 }
550 else if (ret != Z_STREAM_END)
551 {
552 /* We got an error */
553 if (png_ptr->zstream.msg != NULL)
554 png_error(png_ptr, png_ptr->zstream.msg);
555
556 else
557 png_error(png_ptr, "zlib error");
558 }
559 } while (ret != Z_STREAM_END);
560
561 /* Text length is number of buffers plus last buffer */
562 text_len = png_ptr->zbuf_size * comp->num_output_ptr;
563
564 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
565 text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
566
567 return((int)text_len);
568}
569
570/* Ship the compressed text out via chunk writes */
571static void /* PRIVATE */
572png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
573{
574 int i;
575
576 /* Handle the no-compression case */
577 if (comp->input)
578 {
579 png_write_chunk_data(png_ptr, comp->input, comp->input_len);
580
581 return;
582 }
583
584#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
585 /* The zbuf_size test is because the code below doesn't work if zbuf_size is
586 * '1'; simply skip it to avoid memory overwrite.
587 */
588 if (comp->input_len >= 2 && comp->input_len < 16384 && png_ptr->zbuf_size > 1)
589 {
590 unsigned int z_cmf; /* zlib compression method and flags */
591
592 /* Optimize the CMF field in the zlib stream. This hack of the zlib
593 * stream is compliant to the stream specification.
594 */
595
596 if (comp->num_output_ptr)
597 z_cmf = comp->output_ptr[0][0];
598 else
599 z_cmf = png_ptr->zbuf[0];
600
601 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
602 {
603 unsigned int z_cinfo;
604 unsigned int half_z_window_size;
605 png_size_t uncompressed_text_size = comp->input_len;
606
607 z_cinfo = z_cmf >> 4;
608 half_z_window_size = 1 << (z_cinfo + 7);
609
610 while (uncompressed_text_size <= half_z_window_size &&
611 half_z_window_size >= 256)
612 {
613 z_cinfo--;
614 half_z_window_size >>= 1;
615 }
616
617 z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
618
619 if (comp->num_output_ptr)
620 {
621
622 if (comp->output_ptr[0][0] != z_cmf)
623 {
624 int tmp;
625
626 comp->output_ptr[0][0] = (png_byte)z_cmf;
627 tmp = comp->output_ptr[0][1] & 0xe0;
628 tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
629 comp->output_ptr[0][1] = (png_byte)tmp;
630 }
631 }
632 else
633 {
634 int tmp;
635
636 png_ptr->zbuf[0] = (png_byte)z_cmf;
637 tmp = png_ptr->zbuf[1] & 0xe0;
638 tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
639 png_ptr->zbuf[1] = (png_byte)tmp;
640 }
641 }
642
643 else
644 png_error(png_ptr,
645 "Invalid zlib compression method or flags in non-IDAT chunk");
646 }
647#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */
648
649 /* Write saved output buffers, if any */
650 for (i = 0; i < comp->num_output_ptr; i++)
651 {
652 png_write_chunk_data(png_ptr, comp->output_ptr[i],
653 (png_size_t)png_ptr->zbuf_size);
654
655 png_free(png_ptr, comp->output_ptr[i]);
656 }
657
658 if (comp->max_output_ptr != 0)
659 png_free(png_ptr, comp->output_ptr);
660
661 /* Write anything left in zbuf */
662 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
663 png_write_chunk_data(png_ptr, png_ptr->zbuf,
664 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
665
666 /* Reset zlib for another zTXt/iTXt or image data */
667 png_zlib_release(png_ptr);
668}
669#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
670
671/* Write the IHDR chunk, and update the png_struct with the necessary
672 * information. Note that the rest of this code depends upon this
673 * information being correct.
674 */
675void /* PRIVATE */
676png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
677 int bit_depth, int color_type, int compression_type, int filter_type,
678 int interlace_type)
679{
680 png_byte buf[13]; /* Buffer to store the IHDR info */
681
682 png_debug(1, "in png_write_IHDR");
683
684 /* Check that we have valid input data from the application info */
685 switch (color_type)
686 {
687 case PNG_COLOR_TYPE_GRAY:
688 switch (bit_depth)
689 {
690 case 1:
691 case 2:
692 case 4:
693 case 8:
694#ifdef PNG_WRITE_16BIT_SUPPORTED
695 case 16:
696#endif
697 png_ptr->channels = 1; break;
698
699 default:
700 png_error(png_ptr,
701 "Invalid bit depth for grayscale image");
702 }
703 break;
704
705 case PNG_COLOR_TYPE_RGB:
706#ifdef PNG_WRITE_16BIT_SUPPORTED
707 if (bit_depth != 8 && bit_depth != 16)
708#else
709 if (bit_depth != 8)
710#endif
711 png_error(png_ptr, "Invalid bit depth for RGB image");
712
713 png_ptr->channels = 3;
714 break;
715
716 case PNG_COLOR_TYPE_PALETTE:
717 switch (bit_depth)
718 {
719 case 1:
720 case 2:
721 case 4:
722 case 8:
723 png_ptr->channels = 1;
724 break;
725
726 default:
727 png_error(png_ptr, "Invalid bit depth for paletted image");
728 }
729 break;
730
731 case PNG_COLOR_TYPE_GRAY_ALPHA:
732 if (bit_depth != 8 && bit_depth != 16)
733 png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
734
735 png_ptr->channels = 2;
736 break;
737
738 case PNG_COLOR_TYPE_RGB_ALPHA:
739#ifdef PNG_WRITE_16BIT_SUPPORTED
740 if (bit_depth != 8 && bit_depth != 16)
741#else
742 if (bit_depth != 8)
743#endif
744 png_error(png_ptr, "Invalid bit depth for RGBA image");
745
746 png_ptr->channels = 4;
747 break;
748
749 default:
750 png_error(png_ptr, "Invalid image color type specified");
751 }
752
753 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
754 {
755 png_warning(png_ptr, "Invalid compression type specified");
756 compression_type = PNG_COMPRESSION_TYPE_BASE;
757 }
758
759 /* Write filter_method 64 (intrapixel differencing) only if
760 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
761 * 2. Libpng did not write a PNG signature (this filter_method is only
762 * used in PNG datastreams that are embedded in MNG datastreams) and
763 * 3. The application called png_permit_mng_features with a mask that
764 * included PNG_FLAG_MNG_FILTER_64 and
765 * 4. The filter_method is 64 and
766 * 5. The color_type is RGB or RGBA
767 */
768 if (
769#ifdef PNG_MNG_FEATURES_SUPPORTED
770 !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
771 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
772 (color_type == PNG_COLOR_TYPE_RGB ||
773 color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
774 (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
775#endif
776 filter_type != PNG_FILTER_TYPE_BASE)
777 {
778 png_warning(png_ptr, "Invalid filter type specified");
779 filter_type = PNG_FILTER_TYPE_BASE;
780 }
781
782#ifdef PNG_WRITE_INTERLACING_SUPPORTED
783 if (interlace_type != PNG_INTERLACE_NONE &&
784 interlace_type != PNG_INTERLACE_ADAM7)
785 {
786 png_warning(png_ptr, "Invalid interlace type specified");
787 interlace_type = PNG_INTERLACE_ADAM7;
788 }
789#else
790 interlace_type=PNG_INTERLACE_NONE;
791#endif
792
793 /* Save the relevent information */
794 png_ptr->bit_depth = (png_byte)bit_depth;
795 png_ptr->color_type = (png_byte)color_type;
796 png_ptr->interlaced = (png_byte)interlace_type;
797#ifdef PNG_MNG_FEATURES_SUPPORTED
798 png_ptr->filter_type = (png_byte)filter_type;
799#endif
800 png_ptr->compression_type = (png_byte)compression_type;
801 png_ptr->width = width;
802 png_ptr->height = height;
803
804 png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
805 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
806 /* Set the usr info, so any transformations can modify it */
807 png_ptr->usr_width = png_ptr->width;
808 png_ptr->usr_bit_depth = png_ptr->bit_depth;
809 png_ptr->usr_channels = png_ptr->channels;
810
811 /* Pack the header information into the buffer */
812 png_save_uint_32(buf, width);
813 png_save_uint_32(buf + 4, height);
814 buf[8] = (png_byte)bit_depth;
815 buf[9] = (png_byte)color_type;
816 buf[10] = (png_byte)compression_type;
817 buf[11] = (png_byte)filter_type;
818 buf[12] = (png_byte)interlace_type;
819
820 /* Write the chunk */
821 png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
822
823 /* Initialize zlib with PNG info */
824 png_ptr->zstream.zalloc = png_zalloc;
825 png_ptr->zstream.zfree = png_zfree;
826 png_ptr->zstream.opaque = (voidpf)png_ptr;
827
828 if (!(png_ptr->do_filter))
829 {
830 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
831 png_ptr->bit_depth < 8)
832 png_ptr->do_filter = PNG_FILTER_NONE;
833
834 else
835 png_ptr->do_filter = PNG_ALL_FILTERS;
836 }
837
838 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
839 {
840 if (png_ptr->do_filter != PNG_FILTER_NONE)
841 png_ptr->zlib_strategy = Z_FILTERED;
842
843 else
844 png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
845 }
846
847 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
848 png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
849
850 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
851 png_ptr->zlib_mem_level = 8;
852
853 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
854 png_ptr->zlib_window_bits = 15;
855
856 if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
857 png_ptr->zlib_method = 8;
858
859#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
860#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
861 if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY))
862 png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY;
863
864 if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL))
865 png_ptr->zlib_text_level = png_ptr->zlib_level;
866
867 if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL))
868 png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level;
869
870 if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS))
871 png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits;
872
873 if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD))
874 png_ptr->zlib_text_method = png_ptr->zlib_method;
875#else
876 png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY;
877 png_ptr->zlib_text_level = png_ptr->zlib_level;
878 png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level;
879 png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits;
880 png_ptr->zlib_text_method = png_ptr->zlib_method;
881#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
882#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
883
884 /* Record that the compressor has not yet been initialized. */
885 png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED;
886
887 png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */
888}
889
890/* Write the palette. We are careful not to trust png_color to be in the
891 * correct order for PNG, so people can redefine it to any convenient
892 * structure.
893 */
894void /* PRIVATE */
895png_write_PLTE(png_structp png_ptr, png_const_colorp palette,
896 png_uint_32 num_pal)
897{
898 png_uint_32 i;
899 png_const_colorp pal_ptr;
900 png_byte buf[3];
901
902 png_debug(1, "in png_write_PLTE");
903
904 if ((
905#ifdef PNG_MNG_FEATURES_SUPPORTED
906 !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
907#endif
908 num_pal == 0) || num_pal > 256)
909 {
910 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
911 {
912 png_error(png_ptr, "Invalid number of colors in palette");
913 }
914
915 else
916 {
917 png_warning(png_ptr, "Invalid number of colors in palette");
918 return;
919 }
920 }
921
922 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
923 {
924 png_warning(png_ptr,
925 "Ignoring request to write a PLTE chunk in grayscale PNG");
926
927 return;
928 }
929
930 png_ptr->num_palette = (png_uint_16)num_pal;
931 png_debug1(3, "num_palette = %d", png_ptr->num_palette);
932
933 png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3));
934#ifdef PNG_POINTER_INDEXING_SUPPORTED
935
936 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
937 {
938 buf[0] = pal_ptr->red;
939 buf[1] = pal_ptr->green;
940 buf[2] = pal_ptr->blue;
941 png_write_chunk_data(png_ptr, buf, (png_size_t)3);
942 }
943
944#else
945 /* This is a little slower but some buggy compilers need to do this
946 * instead
947 */
948 pal_ptr=palette;
949
950 for (i = 0; i < num_pal; i++)
951 {
952 buf[0] = pal_ptr[i].red;
953 buf[1] = pal_ptr[i].green;
954 buf[2] = pal_ptr[i].blue;
955 png_write_chunk_data(png_ptr, buf, (png_size_t)3);
956 }
957
958#endif
959 png_write_chunk_end(png_ptr);
960 png_ptr->mode |= PNG_HAVE_PLTE;
961}
962
963/* Write an IDAT chunk */
964void /* PRIVATE */
965png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
966{
967 png_debug(1, "in png_write_IDAT");
968
969#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
970 if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
971 png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
972 {
973 /* Optimize the CMF field in the zlib stream. This hack of the zlib
974 * stream is compliant to the stream specification.
975 */
976 unsigned int z_cmf = data[0]; /* zlib compression method and flags */
977
978 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
979 {
980 /* Avoid memory underflows and multiplication overflows.
981 *
982 * The conditions below are practically always satisfied;
983 * however, they still must be checked.
984 */
985 if (length >= 2 &&
986 png_ptr->height < 16384 && png_ptr->width < 16384)
987 {
988 /* Compute the maximum possible length of the datastream */
989
990 /* Number of pixels, plus for each row a filter byte
991 * and possibly a padding byte, so increase the maximum
992 * size to account for these.
993 */
994 unsigned int z_cinfo;
995 unsigned int half_z_window_size;
996 png_uint_32 uncompressed_idat_size = png_ptr->height *
997 ((png_ptr->width *
998 png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
999
1000 /* If it's interlaced, each block of 8 rows is sent as up to
1001 * 14 rows, i.e., 6 additional rows, each with a filter byte
1002 * and possibly a padding byte
1003 */
1004 if (png_ptr->interlaced)
1005 uncompressed_idat_size += ((png_ptr->height + 7)/8) *
1006 (png_ptr->bit_depth < 8 ? 12 : 6);
1007
1008 z_cinfo = z_cmf >> 4;
1009 half_z_window_size = 1 << (z_cinfo + 7);
1010
1011 while (uncompressed_idat_size <= half_z_window_size &&
1012 half_z_window_size >= 256)
1013 {
1014 z_cinfo--;
1015 half_z_window_size >>= 1;
1016 }
1017
1018 z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
1019
1020 if (data[0] != z_cmf)
1021 {
1022 int tmp;
1023 data[0] = (png_byte)z_cmf;
1024 tmp = data[1] & 0xe0;
1025 tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
1026 data[1] = (png_byte)tmp;
1027 }
1028 }
1029 }
1030
1031 else
1032 png_error(png_ptr,
1033 "Invalid zlib compression method or flags in IDAT");
1034 }
1035#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */
1036
1037 png_write_complete_chunk(png_ptr, png_IDAT, data, length);
1038 png_ptr->mode |= PNG_HAVE_IDAT;
1039
1040 /* Prior to 1.5.4 this code was replicated in every caller (except at the
1041 * end, where it isn't technically necessary). Since this function has
1042 * flushed the data we can safely reset the zlib output buffer here.
1043 */
1044 png_ptr->zstream.next_out = png_ptr->zbuf;
1045 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1046}
1047
1048/* Write an IEND chunk */
1049void /* PRIVATE */
1050png_write_IEND(png_structp png_ptr)
1051{
1052 png_debug(1, "in png_write_IEND");
1053
1054 png_write_complete_chunk(png_ptr, png_IEND, NULL, (png_size_t)0);
1055 png_ptr->mode |= PNG_HAVE_IEND;
1056}
1057
1058#ifdef PNG_WRITE_gAMA_SUPPORTED
1059/* Write a gAMA chunk */
1060void /* PRIVATE */
1061png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
1062{
1063 png_byte buf[4];
1064
1065 png_debug(1, "in png_write_gAMA");
1066
1067 /* file_gamma is saved in 1/100,000ths */
1068 png_save_uint_32(buf, (png_uint_32)file_gamma);
1069 png_write_complete_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
1070}
1071#endif
1072
1073#ifdef PNG_WRITE_sRGB_SUPPORTED
1074/* Write a sRGB chunk */
1075void /* PRIVATE */
1076png_write_sRGB(png_structp png_ptr, int srgb_intent)
1077{
1078 png_byte buf[1];
1079
1080 png_debug(1, "in png_write_sRGB");
1081
1082 if (srgb_intent >= PNG_sRGB_INTENT_LAST)
1083 png_warning(png_ptr,
1084 "Invalid sRGB rendering intent specified");
1085
1086 buf[0]=(png_byte)srgb_intent;
1087 png_write_complete_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
1088}
1089#endif
1090
1091#ifdef PNG_WRITE_iCCP_SUPPORTED
1092/* Write an iCCP chunk */
1093void /* PRIVATE */
1094png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type,
1095 png_const_charp profile, int profile_len)
1096{
1097 png_size_t name_len;
1098 png_charp new_name;
1099 compression_state comp;
1100 int embedded_profile_len = 0;
1101
1102 png_debug(1, "in png_write_iCCP");
1103
1104 comp.num_output_ptr = 0;
1105 comp.max_output_ptr = 0;
1106 comp.output_ptr = NULL;
1107 comp.input = NULL;
1108 comp.input_len = 0;
1109
1110 if ((name_len = png_check_keyword(png_ptr, name, &new_name)) == 0)
1111 return;
1112
1113 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
1114 png_warning(png_ptr, "Unknown compression type in iCCP chunk");
1115
1116 if (profile == NULL)
1117 profile_len = 0;
1118
1119 if (profile_len > 3)
1120 embedded_profile_len =
1121 ((*( (png_const_bytep)profile ))<<24) |
1122 ((*( (png_const_bytep)profile + 1))<<16) |
1123 ((*( (png_const_bytep)profile + 2))<< 8) |
1124 ((*( (png_const_bytep)profile + 3)) );
1125
1126 if (embedded_profile_len < 0)
1127 {
1128 png_warning(png_ptr,
1129 "Embedded profile length in iCCP chunk is negative");
1130
1131 png_free(png_ptr, new_name);
1132 return;
1133 }
1134
1135 if (profile_len < embedded_profile_len)
1136 {
1137 png_warning(png_ptr,
1138 "Embedded profile length too large in iCCP chunk");
1139
1140 png_free(png_ptr, new_name);
1141 return;
1142 }
1143
1144 if (profile_len > embedded_profile_len)
1145 {
1146 png_warning(png_ptr,
1147 "Truncating profile to actual length in iCCP chunk");
1148
1149 profile_len = embedded_profile_len;
1150 }
1151
1152 if (profile_len)
1153 profile_len = png_text_compress(png_ptr, profile,
1154 (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
1155
1156 /* Make sure we include the NULL after the name and the compression type */
1157 png_write_chunk_header(png_ptr, png_iCCP,
1158 (png_uint_32)(name_len + profile_len + 2));
1159
1160 new_name[name_len + 1] = 0x00;
1161
1162 png_write_chunk_data(png_ptr, (png_bytep)new_name,
1163 (png_size_t)(name_len + 2));
1164
1165 if (profile_len)
1166 {
1167 comp.input_len = profile_len;
1168 png_write_compressed_data_out(png_ptr, &comp);
1169 }
1170
1171 png_write_chunk_end(png_ptr);
1172 png_free(png_ptr, new_name);
1173}
1174#endif
1175
1176#ifdef PNG_WRITE_sPLT_SUPPORTED
1177/* Write a sPLT chunk */
1178void /* PRIVATE */
1179png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette)
1180{
1181 png_size_t name_len;
1182 png_charp new_name;
1183 png_byte entrybuf[10];
1184 png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
1185 png_size_t palette_size = entry_size * spalette->nentries;
1186 png_sPLT_entryp ep;
1187#ifndef PNG_POINTER_INDEXING_SUPPORTED
1188 int i;
1189#endif
1190
1191 png_debug(1, "in png_write_sPLT");
1192
1193 if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
1194 return;
1195
1196 /* Make sure we include the NULL after the name */
1197 png_write_chunk_header(png_ptr, png_sPLT,
1198 (png_uint_32)(name_len + 2 + palette_size));
1199
1200 png_write_chunk_data(png_ptr, (png_bytep)new_name,
1201 (png_size_t)(name_len + 1));
1202
1203 png_write_chunk_data(png_ptr, &spalette->depth, (png_size_t)1);
1204
1205 /* Loop through each palette entry, writing appropriately */
1206#ifdef PNG_POINTER_INDEXING_SUPPORTED
1207 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
1208 {
1209 if (spalette->depth == 8)
1210 {
1211 entrybuf[0] = (png_byte)ep->red;
1212 entrybuf[1] = (png_byte)ep->green;
1213 entrybuf[2] = (png_byte)ep->blue;
1214 entrybuf[3] = (png_byte)ep->alpha;
1215 png_save_uint_16(entrybuf + 4, ep->frequency);
1216 }
1217
1218 else
1219 {
1220 png_save_uint_16(entrybuf + 0, ep->red);
1221 png_save_uint_16(entrybuf + 2, ep->green);
1222 png_save_uint_16(entrybuf + 4, ep->blue);
1223 png_save_uint_16(entrybuf + 6, ep->alpha);
1224 png_save_uint_16(entrybuf + 8, ep->frequency);
1225 }
1226
1227 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
1228 }
1229#else
1230 ep=spalette->entries;
1231 for (i = 0; i>spalette->nentries; i++)
1232 {
1233 if (spalette->depth == 8)
1234 {
1235 entrybuf[0] = (png_byte)ep[i].red;
1236 entrybuf[1] = (png_byte)ep[i].green;
1237 entrybuf[2] = (png_byte)ep[i].blue;
1238 entrybuf[3] = (png_byte)ep[i].alpha;
1239 png_save_uint_16(entrybuf + 4, ep[i].frequency);
1240 }
1241
1242 else
1243 {
1244 png_save_uint_16(entrybuf + 0, ep[i].red);
1245 png_save_uint_16(entrybuf + 2, ep[i].green);
1246 png_save_uint_16(entrybuf + 4, ep[i].blue);
1247 png_save_uint_16(entrybuf + 6, ep[i].alpha);
1248 png_save_uint_16(entrybuf + 8, ep[i].frequency);
1249 }
1250
1251 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
1252 }
1253#endif
1254
1255 png_write_chunk_end(png_ptr);
1256 png_free(png_ptr, new_name);
1257}
1258#endif
1259
1260#ifdef PNG_WRITE_sBIT_SUPPORTED
1261/* Write the sBIT chunk */
1262void /* PRIVATE */
1263png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type)
1264{
1265 png_byte buf[4];
1266 png_size_t size;
1267
1268 png_debug(1, "in png_write_sBIT");
1269
1270 /* Make sure we don't depend upon the order of PNG_COLOR_8 */
1271 if (color_type & PNG_COLOR_MASK_COLOR)
1272 {
1273 png_byte maxbits;
1274
1275 maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
1276 png_ptr->usr_bit_depth);
1277
1278 if (sbit->red == 0 || sbit->red > maxbits ||
1279 sbit->green == 0 || sbit->green > maxbits ||
1280 sbit->blue == 0 || sbit->blue > maxbits)
1281 {
1282 png_warning(png_ptr, "Invalid sBIT depth specified");
1283 return;
1284 }
1285
1286 buf[0] = sbit->red;
1287 buf[1] = sbit->green;
1288 buf[2] = sbit->blue;
1289 size = 3;
1290 }
1291
1292 else
1293 {
1294 if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
1295 {
1296 png_warning(png_ptr, "Invalid sBIT depth specified");
1297 return;
1298 }
1299
1300 buf[0] = sbit->gray;
1301 size = 1;
1302 }
1303
1304 if (color_type & PNG_COLOR_MASK_ALPHA)
1305 {
1306 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
1307 {
1308 png_warning(png_ptr, "Invalid sBIT depth specified");
1309 return;
1310 }
1311
1312 buf[size++] = sbit->alpha;
1313 }
1314
1315 png_write_complete_chunk(png_ptr, png_sBIT, buf, size);
1316}
1317#endif
1318
1319#ifdef PNG_WRITE_cHRM_SUPPORTED
1320/* Write the cHRM chunk */
1321void /* PRIVATE */
1322png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
1323 png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
1324 png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
1325 png_fixed_point blue_y)
1326{
1327 png_byte buf[32];
1328
1329 png_debug(1, "in png_write_cHRM");
1330
1331 /* Each value is saved in 1/100,000ths */
1332#ifdef PNG_CHECK_cHRM_SUPPORTED
1333 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
1334 green_x, green_y, blue_x, blue_y))
1335#endif
1336 {
1337 png_save_uint_32(buf, (png_uint_32)white_x);
1338 png_save_uint_32(buf + 4, (png_uint_32)white_y);
1339
1340 png_save_uint_32(buf + 8, (png_uint_32)red_x);
1341 png_save_uint_32(buf + 12, (png_uint_32)red_y);
1342
1343 png_save_uint_32(buf + 16, (png_uint_32)green_x);
1344 png_save_uint_32(buf + 20, (png_uint_32)green_y);
1345
1346 png_save_uint_32(buf + 24, (png_uint_32)blue_x);
1347 png_save_uint_32(buf + 28, (png_uint_32)blue_y);
1348
1349 png_write_complete_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
1350 }
1351}
1352#endif
1353
1354#ifdef PNG_WRITE_tRNS_SUPPORTED
1355/* Write the tRNS chunk */
1356void /* PRIVATE */
1357png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha,
1358 png_const_color_16p tran, int num_trans, int color_type)
1359{
1360 png_byte buf[6];
1361
1362 png_debug(1, "in png_write_tRNS");
1363
1364 if (color_type == PNG_COLOR_TYPE_PALETTE)
1365 {
1366 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
1367 {
1368 png_warning(png_ptr, "Invalid number of transparent colors specified");
1369 return;
1370 }
1371
1372 /* Write the chunk out as it is */
1373 png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha, (png_size_t)num_trans);
1374 }
1375
1376 else if (color_type == PNG_COLOR_TYPE_GRAY)
1377 {
1378 /* One 16 bit value */
1379 if (tran->gray >= (1 << png_ptr->bit_depth))
1380 {
1381 png_warning(png_ptr,
1382 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1383
1384 return;
1385 }
1386
1387 png_save_uint_16(buf, tran->gray);
1388 png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
1389 }
1390
1391 else if (color_type == PNG_COLOR_TYPE_RGB)
1392 {
1393 /* Three 16 bit values */
1394 png_save_uint_16(buf, tran->red);
1395 png_save_uint_16(buf + 2, tran->green);
1396 png_save_uint_16(buf + 4, tran->blue);
1397#ifdef PNG_WRITE_16BIT_SUPPORTED
1398 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1399#else
1400 if (buf[0] | buf[2] | buf[4])
1401#endif
1402 {
1403 png_warning(png_ptr,
1404 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1405 return;
1406 }
1407
1408 png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
1409 }
1410
1411 else
1412 {
1413 png_warning(png_ptr, "Can't write tRNS with an alpha channel");
1414 }
1415}
1416#endif
1417
1418#ifdef PNG_WRITE_bKGD_SUPPORTED
1419/* Write the background chunk */
1420void /* PRIVATE */
1421png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type)
1422{
1423 png_byte buf[6];
1424
1425 png_debug(1, "in png_write_bKGD");
1426
1427 if (color_type == PNG_COLOR_TYPE_PALETTE)
1428 {
1429 if (
1430#ifdef PNG_MNG_FEATURES_SUPPORTED
1431 (png_ptr->num_palette ||
1432 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
1433#endif
1434 back->index >= png_ptr->num_palette)
1435 {
1436 png_warning(png_ptr, "Invalid background palette index");
1437 return;
1438 }
1439
1440 buf[0] = back->index;
1441 png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
1442 }
1443
1444 else if (color_type & PNG_COLOR_MASK_COLOR)
1445 {
1446 png_save_uint_16(buf, back->red);
1447 png_save_uint_16(buf + 2, back->green);
1448 png_save_uint_16(buf + 4, back->blue);
1449#ifdef PNG_WRITE_16BIT_SUPPORTED
1450 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1451#else
1452 if (buf[0] | buf[2] | buf[4])
1453#endif
1454 {
1455 png_warning(png_ptr,
1456 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
1457
1458 return;
1459 }
1460
1461 png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
1462 }
1463
1464 else
1465 {
1466 if (back->gray >= (1 << png_ptr->bit_depth))
1467 {
1468 png_warning(png_ptr,
1469 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
1470
1471 return;
1472 }
1473
1474 png_save_uint_16(buf, back->gray);
1475 png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
1476 }
1477}
1478#endif
1479
1480#ifdef PNG_WRITE_hIST_SUPPORTED
1481/* Write the histogram */
1482void /* PRIVATE */
1483png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist)
1484{
1485 int i;
1486 png_byte buf[3];
1487
1488 png_debug(1, "in png_write_hIST");
1489
1490 if (num_hist > (int)png_ptr->num_palette)
1491 {
1492 png_debug2(3, "num_hist = %d, num_palette = %d", num_hist,
1493 png_ptr->num_palette);
1494
1495 png_warning(png_ptr, "Invalid number of histogram entries specified");
1496 return;
1497 }
1498
1499 png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
1500
1501 for (i = 0; i < num_hist; i++)
1502 {
1503 png_save_uint_16(buf, hist[i]);
1504 png_write_chunk_data(png_ptr, buf, (png_size_t)2);
1505 }
1506
1507 png_write_chunk_end(png_ptr);
1508}
1509#endif
1510
1511#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
1512 defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
1513/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
1514 * and if invalid, correct the keyword rather than discarding the entire
1515 * chunk. The PNG 1.0 specification requires keywords 1-79 characters in
1516 * length, forbids leading or trailing whitespace, multiple internal spaces,
1517 * and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
1518 *
1519 * The new_key is allocated to hold the corrected keyword and must be freed
1520 * by the calling routine. This avoids problems with trying to write to
1521 * static keywords without having to have duplicate copies of the strings.
1522 */
1523png_size_t /* PRIVATE */
1524png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key)
1525{
1526 png_size_t key_len;
1527 png_const_charp ikp;
1528 png_charp kp, dp;
1529 int kflag;
1530 int kwarn=0;
1531
1532 png_debug(1, "in png_check_keyword");
1533
1534 *new_key = NULL;
1535
1536 if (key == NULL || (key_len = png_strlen(key)) == 0)
1537 {
1538 png_warning(png_ptr, "zero length keyword");
1539 return ((png_size_t)0);
1540 }
1541
1542 png_debug1(2, "Keyword to be checked is '%s'", key);
1543
1544 *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
1545
1546 if (*new_key == NULL)
1547 {
1548 png_warning(png_ptr, "Out of memory while procesing keyword");
1549 return ((png_size_t)0);
1550 }
1551
1552 /* Replace non-printing characters with a blank and print a warning */
1553 for (ikp = key, dp = *new_key; *ikp != '\0'; ikp++, dp++)
1554 {
1555 if ((png_byte)*ikp < 0x20 ||
1556 ((png_byte)*ikp > 0x7E && (png_byte)*ikp < 0xA1))
1557 {
1558 PNG_WARNING_PARAMETERS(p)
1559
1560 png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_02x,
1561 (png_byte)*ikp);
1562 png_formatted_warning(png_ptr, p, "invalid keyword character 0x@1");
1563 *dp = ' ';
1564 }
1565
1566 else
1567 {
1568 *dp = *ikp;
1569 }
1570 }
1571 *dp = '\0';
1572
1573 /* Remove any trailing white space. */
1574 kp = *new_key + key_len - 1;
1575 if (*kp == ' ')
1576 {
1577 png_warning(png_ptr, "trailing spaces removed from keyword");
1578
1579 while (*kp == ' ')
1580 {
1581 *(kp--) = '\0';
1582 key_len--;
1583 }
1584 }
1585
1586 /* Remove any leading white space. */
1587 kp = *new_key;
1588 if (*kp == ' ')
1589 {
1590 png_warning(png_ptr, "leading spaces removed from keyword");
1591
1592 while (*kp == ' ')
1593 {
1594 kp++;
1595 key_len--;
1596 }
1597 }
1598
1599 png_debug1(2, "Checking for multiple internal spaces in '%s'", kp);
1600
1601 /* Remove multiple internal spaces. */
1602 for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
1603 {
1604 if (*kp == ' ' && kflag == 0)
1605 {
1606 *(dp++) = *kp;
1607 kflag = 1;
1608 }
1609
1610 else if (*kp == ' ')
1611 {
1612 key_len--;
1613 kwarn = 1;
1614 }
1615
1616 else
1617 {
1618 *(dp++) = *kp;
1619 kflag = 0;
1620 }
1621 }
1622 *dp = '\0';
1623 if (kwarn)
1624 png_warning(png_ptr, "extra interior spaces removed from keyword");
1625
1626 if (key_len == 0)
1627 {
1628 png_free(png_ptr, *new_key);
1629 png_warning(png_ptr, "Zero length keyword");
1630 }
1631
1632 if (key_len > 79)
1633 {
1634 png_warning(png_ptr, "keyword length must be 1 - 79 characters");
1635 (*new_key)[79] = '\0';
1636 key_len = 79;
1637 }
1638
1639 return (key_len);
1640}
1641#endif
1642
1643#ifdef PNG_WRITE_tEXt_SUPPORTED
1644/* Write a tEXt chunk */
1645void /* PRIVATE */
1646png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text,
1647 png_size_t text_len)
1648{
1649 png_size_t key_len;
1650 png_charp new_key;
1651
1652 png_debug(1, "in png_write_tEXt");
1653
1654 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
1655 return;
1656
1657 if (text == NULL || *text == '\0')
1658 text_len = 0;
1659
1660 else
1661 text_len = png_strlen(text);
1662
1663 /* Make sure we include the 0 after the key */
1664 png_write_chunk_header(png_ptr, png_tEXt,
1665 (png_uint_32)(key_len + text_len + 1));
1666 /*
1667 * We leave it to the application to meet PNG-1.0 requirements on the
1668 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1669 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1670 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1671 */
1672 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1673 (png_size_t)(key_len + 1));
1674
1675 if (text_len)
1676 png_write_chunk_data(png_ptr, (png_const_bytep)text,
1677 (png_size_t)text_len);
1678
1679 png_write_chunk_end(png_ptr);
1680 png_free(png_ptr, new_key);
1681}
1682#endif
1683
1684#ifdef PNG_WRITE_zTXt_SUPPORTED
1685/* Write a compressed text chunk */
1686void /* PRIVATE */
1687png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text,
1688 png_size_t text_len, int compression)
1689{
1690 png_size_t key_len;
1691 png_byte buf;
1692 png_charp new_key;
1693 compression_state comp;
1694
1695 png_debug(1, "in png_write_zTXt");
1696
1697 comp.num_output_ptr = 0;
1698 comp.max_output_ptr = 0;
1699 comp.output_ptr = NULL;
1700 comp.input = NULL;
1701 comp.input_len = 0;
1702
1703 if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
1704 {
1705 png_free(png_ptr, new_key);
1706 return;
1707 }
1708
1709 if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
1710 {
1711 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
1712 png_free(png_ptr, new_key);
1713 return;
1714 }
1715
1716 text_len = png_strlen(text);
1717
1718 /* Compute the compressed data; do it now for the length */
1719 text_len = png_text_compress(png_ptr, text, text_len, compression,
1720 &comp);
1721
1722 /* Write start of chunk */
1723 png_write_chunk_header(png_ptr, png_zTXt,
1724 (png_uint_32)(key_len+text_len + 2));
1725
1726 /* Write key */
1727 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1728 (png_size_t)(key_len + 1));
1729
1730 png_free(png_ptr, new_key);
1731
1732 buf = (png_byte)compression;
1733
1734 /* Write compression */
1735 png_write_chunk_data(png_ptr, &buf, (png_size_t)1);
1736
1737 /* Write the compressed data */
1738 comp.input_len = text_len;
1739 png_write_compressed_data_out(png_ptr, &comp);
1740
1741 /* Close the chunk */
1742 png_write_chunk_end(png_ptr);
1743}
1744#endif
1745
1746#ifdef PNG_WRITE_iTXt_SUPPORTED
1747/* Write an iTXt chunk */
1748void /* PRIVATE */
1749png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key,
1750 png_const_charp lang, png_const_charp lang_key, png_const_charp text)
1751{
1752 png_size_t lang_len, key_len, lang_key_len, text_len;
1753 png_charp new_lang;
1754 png_charp new_key = NULL;
1755 png_byte cbuf[2];
1756 compression_state comp;
1757
1758 png_debug(1, "in png_write_iTXt");
1759
1760 comp.num_output_ptr = 0;
1761 comp.max_output_ptr = 0;
1762 comp.output_ptr = NULL;
1763 comp.input = NULL;
1764
1765 if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
1766 return;
1767
1768 if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0)
1769 {
1770 png_warning(png_ptr, "Empty language field in iTXt chunk");
1771 new_lang = NULL;
1772 lang_len = 0;
1773 }
1774
1775 if (lang_key == NULL)
1776 lang_key_len = 0;
1777
1778 else
1779 lang_key_len = png_strlen(lang_key);
1780
1781 if (text == NULL)
1782 text_len = 0;
1783
1784 else
1785 text_len = png_strlen(text);
1786
1787 /* Compute the compressed data; do it now for the length */
1788 text_len = png_text_compress(png_ptr, text, text_len, compression - 2,
1789 &comp);
1790
1791
1792 /* Make sure we include the compression flag, the compression byte,
1793 * and the NULs after the key, lang, and lang_key parts
1794 */
1795
1796 png_write_chunk_header(png_ptr, png_iTXt, (png_uint_32)(
1797 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
1798 + key_len
1799 + lang_len
1800 + lang_key_len
1801 + text_len));
1802
1803 /* We leave it to the application to meet PNG-1.0 requirements on the
1804 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1805 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1806 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1807 */
1808 png_write_chunk_data(png_ptr, (png_bytep)new_key, (png_size_t)(key_len + 1));
1809
1810 /* Set the compression flag */
1811 if (compression == PNG_ITXT_COMPRESSION_NONE ||
1812 compression == PNG_TEXT_COMPRESSION_NONE)
1813 cbuf[0] = 0;
1814
1815 else /* compression == PNG_ITXT_COMPRESSION_zTXt */
1816 cbuf[0] = 1;
1817
1818 /* Set the compression method */
1819 cbuf[1] = 0;
1820
1821 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
1822
1823 cbuf[0] = 0;
1824 png_write_chunk_data(png_ptr, (new_lang ? (png_const_bytep)new_lang : cbuf),
1825 (png_size_t)(lang_len + 1));
1826
1827 png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf),
1828 (png_size_t)(lang_key_len + 1));
1829
1830 png_write_compressed_data_out(png_ptr, &comp);
1831
1832 png_write_chunk_end(png_ptr);
1833
1834 png_free(png_ptr, new_key);
1835 png_free(png_ptr, new_lang);
1836}
1837#endif
1838
1839#ifdef PNG_WRITE_oFFs_SUPPORTED
1840/* Write the oFFs chunk */
1841void /* PRIVATE */
1842png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
1843 int unit_type)
1844{
1845 png_byte buf[9];
1846
1847 png_debug(1, "in png_write_oFFs");
1848
1849 if (unit_type >= PNG_OFFSET_LAST)
1850 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
1851
1852 png_save_int_32(buf, x_offset);
1853 png_save_int_32(buf + 4, y_offset);
1854 buf[8] = (png_byte)unit_type;
1855
1856 png_write_complete_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
1857}
1858#endif
1859#ifdef PNG_WRITE_pCAL_SUPPORTED
1860/* Write the pCAL chunk (described in the PNG extensions document) */
1861void /* PRIVATE */
1862png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
1863 png_int_32 X1, int type, int nparams, png_const_charp units,
1864 png_charpp params)
1865{
1866 png_size_t purpose_len, units_len, total_len;
1867 png_size_tp params_len;
1868 png_byte buf[10];
1869 png_charp new_purpose;
1870 int i;
1871
1872 png_debug1(1, "in png_write_pCAL (%d parameters)", nparams);
1873
1874 if (type >= PNG_EQUATION_LAST)
1875 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
1876
1877 purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
1878 png_debug1(3, "pCAL purpose length = %d", (int)purpose_len);
1879 units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
1880 png_debug1(3, "pCAL units length = %d", (int)units_len);
1881 total_len = purpose_len + units_len + 10;
1882
1883 params_len = (png_size_tp)png_malloc(png_ptr,
1884 (png_alloc_size_t)(nparams * png_sizeof(png_size_t)));
1885
1886 /* Find the length of each parameter, making sure we don't count the
1887 * null terminator for the last parameter.
1888 */
1889 for (i = 0; i < nparams; i++)
1890 {
1891 params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
1892 png_debug2(3, "pCAL parameter %d length = %lu", i,
1893 (unsigned long)params_len[i]);
1894 total_len += params_len[i];
1895 }
1896
1897 png_debug1(3, "pCAL total length = %d", (int)total_len);
1898 png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len);
1899 png_write_chunk_data(png_ptr, (png_const_bytep)new_purpose, purpose_len);
1900 png_save_int_32(buf, X0);
1901 png_save_int_32(buf + 4, X1);
1902 buf[8] = (png_byte)type;
1903 buf[9] = (png_byte)nparams;
1904 png_write_chunk_data(png_ptr, buf, (png_size_t)10);
1905 png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len);
1906
1907 png_free(png_ptr, new_purpose);
1908
1909 for (i = 0; i < nparams; i++)
1910 {
1911 png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]);
1912 }
1913
1914 png_free(png_ptr, params_len);
1915 png_write_chunk_end(png_ptr);
1916}
1917#endif
1918
1919#ifdef PNG_WRITE_sCAL_SUPPORTED
1920/* Write the sCAL chunk */
1921void /* PRIVATE */
1922png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width,
1923 png_const_charp height)
1924{
1925 png_byte buf[64];
1926 png_size_t wlen, hlen, total_len;
1927
1928 png_debug(1, "in png_write_sCAL_s");
1929
1930 wlen = png_strlen(width);
1931 hlen = png_strlen(height);
1932 total_len = wlen + hlen + 2;
1933
1934 if (total_len > 64)
1935 {
1936 png_warning(png_ptr, "Can't write sCAL (buffer too small)");
1937 return;
1938 }
1939
1940 buf[0] = (png_byte)unit;
1941 png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */
1942 png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */
1943
1944 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
1945 png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len);
1946}
1947#endif
1948
1949#ifdef PNG_WRITE_pHYs_SUPPORTED
1950/* Write the pHYs chunk */
1951void /* PRIVATE */
1952png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
1953 png_uint_32 y_pixels_per_unit,
1954 int unit_type)
1955{
1956 png_byte buf[9];
1957
1958 png_debug(1, "in png_write_pHYs");
1959
1960 if (unit_type >= PNG_RESOLUTION_LAST)
1961 png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
1962
1963 png_save_uint_32(buf, x_pixels_per_unit);
1964 png_save_uint_32(buf + 4, y_pixels_per_unit);
1965 buf[8] = (png_byte)unit_type;
1966
1967 png_write_complete_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
1968}
1969#endif
1970
1971#ifdef PNG_WRITE_tIME_SUPPORTED
1972/* Write the tIME chunk. Use either png_convert_from_struct_tm()
1973 * or png_convert_from_time_t(), or fill in the structure yourself.
1974 */
1975void /* PRIVATE */
1976png_write_tIME(png_structp png_ptr, png_const_timep mod_time)
1977{
1978 png_byte buf[7];
1979
1980 png_debug(1, "in png_write_tIME");
1981
1982 if (mod_time->month > 12 || mod_time->month < 1 ||
1983 mod_time->day > 31 || mod_time->day < 1 ||
1984 mod_time->hour > 23 || mod_time->second > 60)
1985 {
1986 png_warning(png_ptr, "Invalid time specified for tIME chunk");
1987 return;
1988 }
1989
1990 png_save_uint_16(buf, mod_time->year);
1991 buf[2] = mod_time->month;
1992 buf[3] = mod_time->day;
1993 buf[4] = mod_time->hour;
1994 buf[5] = mod_time->minute;
1995 buf[6] = mod_time->second;
1996
1997 png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
1998}
1999#endif
2000
2001/* Initializes the row writing capability of libpng */
2002void /* PRIVATE */
2003png_write_start_row(png_structp png_ptr)
2004{
2005#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2006 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2007
2008 /* Start of interlace block */
2009 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2010
2011 /* Offset to next interlace block */
2012 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2013
2014 /* Start of interlace block in the y direction */
2015 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
2016
2017 /* Offset to next interlace block in the y direction */
2018 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
2019#endif
2020
2021 png_alloc_size_t buf_size;
2022 int usr_pixel_depth;
2023
2024 png_debug(1, "in png_write_start_row");
2025
2026 usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth;
2027 buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1;
2028
2029 /* 1.5.6: added to allow checking in the row write code. */
2030 png_ptr->transformed_pixel_depth = png_ptr->pixel_depth;
2031 png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth;
2032
2033 /* Set up row buffer */
2034 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
2035
2036 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
2037
2038#ifdef PNG_WRITE_FILTER_SUPPORTED
2039 /* Set up filtering buffer, if using this filter */
2040 if (png_ptr->do_filter & PNG_FILTER_SUB)
2041 {
2042 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
2043
2044 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
2045 }
2046
2047 /* We only need to keep the previous row if we are using one of these. */
2048 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
2049 {
2050 /* Set up previous row buffer */
2051 png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size);
2052
2053 if (png_ptr->do_filter & PNG_FILTER_UP)
2054 {
2055 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
2056 png_ptr->rowbytes + 1);
2057
2058 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
2059 }
2060
2061 if (png_ptr->do_filter & PNG_FILTER_AVG)
2062 {
2063 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
2064 png_ptr->rowbytes + 1);
2065
2066 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
2067 }
2068
2069 if (png_ptr->do_filter & PNG_FILTER_PAETH)
2070 {
2071 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
2072 png_ptr->rowbytes + 1);
2073
2074 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
2075 }
2076 }
2077#endif /* PNG_WRITE_FILTER_SUPPORTED */
2078
2079#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2080 /* If interlaced, we need to set up width and height of pass */
2081 if (png_ptr->interlaced)
2082 {
2083 if (!(png_ptr->transformations & PNG_INTERLACE))
2084 {
2085 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
2086 png_pass_ystart[0]) / png_pass_yinc[0];
2087
2088 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
2089 png_pass_start[0]) / png_pass_inc[0];
2090 }
2091
2092 else
2093 {
2094 png_ptr->num_rows = png_ptr->height;
2095 png_ptr->usr_width = png_ptr->width;
2096 }
2097 }
2098
2099 else
2100#endif
2101 {
2102 png_ptr->num_rows = png_ptr->height;
2103 png_ptr->usr_width = png_ptr->width;
2104 }
2105
2106 png_zlib_claim(png_ptr, PNG_ZLIB_FOR_IDAT);
2107 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
2108 png_ptr->zstream.next_out = png_ptr->zbuf;
2109}
2110
2111/* Internal use only. Called when finished processing a row of data. */
2112void /* PRIVATE */
2113png_write_finish_row(png_structp png_ptr)
2114{
2115#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2116 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2117
2118 /* Start of interlace block */
2119 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2120
2121 /* Offset to next interlace block */
2122 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2123
2124 /* Start of interlace block in the y direction */
2125 static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
2126
2127 /* Offset to next interlace block in the y direction */
2128 static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
2129#endif
2130
2131 int ret;
2132
2133 png_debug(1, "in png_write_finish_row");
2134
2135 /* Next row */
2136 png_ptr->row_number++;
2137
2138 /* See if we are done */
2139 if (png_ptr->row_number < png_ptr->num_rows)
2140 return;
2141
2142#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2143 /* If interlaced, go to next pass */
2144 if (png_ptr->interlaced)
2145 {
2146 png_ptr->row_number = 0;
2147 if (png_ptr->transformations & PNG_INTERLACE)
2148 {
2149 png_ptr->pass++;
2150 }
2151
2152 else
2153 {
2154 /* Loop until we find a non-zero width or height pass */
2155 do
2156 {
2157 png_ptr->pass++;
2158
2159 if (png_ptr->pass >= 7)
2160 break;
2161
2162 png_ptr->usr_width = (png_ptr->width +
2163 png_pass_inc[png_ptr->pass] - 1 -
2164 png_pass_start[png_ptr->pass]) /
2165 png_pass_inc[png_ptr->pass];
2166
2167 png_ptr->num_rows = (png_ptr->height +
2168 png_pass_yinc[png_ptr->pass] - 1 -
2169 png_pass_ystart[png_ptr->pass]) /
2170 png_pass_yinc[png_ptr->pass];
2171
2172 if (png_ptr->transformations & PNG_INTERLACE)
2173 break;
2174
2175 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
2176
2177 }
2178
2179 /* Reset the row above the image for the next pass */
2180 if (png_ptr->pass < 7)
2181 {
2182 if (png_ptr->prev_row != NULL)
2183 png_memset(png_ptr->prev_row, 0,
2184 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
2185 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
2186
2187 return;
2188 }
2189 }
2190#endif
2191
2192 /* If we get here, we've just written the last row, so we need
2193 to flush the compressor */
2194 do
2195 {
2196 /* Tell the compressor we are done */
2197 ret = deflate(&png_ptr->zstream, Z_FINISH);
2198
2199 /* Check for an error */
2200 if (ret == Z_OK)
2201 {
2202 /* Check to see if we need more room */
2203 if (!(png_ptr->zstream.avail_out))
2204 {
2205 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
2206 png_ptr->zstream.next_out = png_ptr->zbuf;
2207 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
2208 }
2209 }
2210
2211 else if (ret != Z_STREAM_END)
2212 {
2213 if (png_ptr->zstream.msg != NULL)
2214 png_error(png_ptr, png_ptr->zstream.msg);
2215
2216 else
2217 png_error(png_ptr, "zlib error");
2218 }
2219 } while (ret != Z_STREAM_END);
2220
2221 /* Write any extra space */
2222 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
2223 {
2224 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
2225 png_ptr->zstream.avail_out);
2226 }
2227
2228 png_zlib_release(png_ptr);
2229 png_ptr->zstream.data_type = Z_BINARY;
2230}
2231
2232#ifdef PNG_WRITE_INTERLACING_SUPPORTED
2233/* Pick out the correct pixels for the interlace pass.
2234 * The basic idea here is to go through the row with a source
2235 * pointer and a destination pointer (sp and dp), and copy the
2236 * correct pixels for the pass. As the row gets compacted,
2237 * sp will always be >= dp, so we should never overwrite anything.
2238 * See the default: case for the easiest code to understand.
2239 */
2240void /* PRIVATE */
2241png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
2242{
2243 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2244
2245 /* Start of interlace block */
2246 static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2247
2248 /* Offset to next interlace block */
2249 static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2250
2251 png_debug(1, "in png_do_write_interlace");
2252
2253 /* We don't have to do anything on the last pass (6) */
2254 if (pass < 6)
2255 {
2256 /* Each pixel depth is handled separately */
2257 switch (row_info->pixel_depth)
2258 {
2259 case 1:
2260 {
2261 png_bytep sp;
2262 png_bytep dp;
2263 int shift;
2264 int d;
2265 int value;
2266 png_uint_32 i;
2267 png_uint_32 row_width = row_info->width;
2268
2269 dp = row;
2270 d = 0;
2271 shift = 7;
2272
2273 for (i = png_pass_start[pass]; i < row_width;
2274 i += png_pass_inc[pass])
2275 {
2276 sp = row + (png_size_t)(i >> 3);
2277 value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
2278 d |= (value << shift);
2279
2280 if (shift == 0)
2281 {
2282 shift = 7;
2283 *dp++ = (png_byte)d;
2284 d = 0;
2285 }
2286
2287 else
2288 shift--;
2289
2290 }
2291 if (shift != 7)
2292 *dp = (png_byte)d;
2293
2294 break;
2295 }
2296
2297 case 2:
2298 {
2299 png_bytep sp;
2300 png_bytep dp;
2301 int shift;
2302 int d;
2303 int value;
2304 png_uint_32 i;
2305 png_uint_32 row_width = row_info->width;
2306
2307 dp = row;
2308 shift = 6;
2309 d = 0;
2310
2311 for (i = png_pass_start[pass]; i < row_width;
2312 i += png_pass_inc[pass])
2313 {
2314 sp = row + (png_size_t)(i >> 2);
2315 value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
2316 d |= (value << shift);
2317
2318 if (shift == 0)
2319 {
2320 shift = 6;
2321 *dp++ = (png_byte)d;
2322 d = 0;
2323 }
2324
2325 else
2326 shift -= 2;
2327 }
2328 if (shift != 6)
2329 *dp = (png_byte)d;
2330
2331 break;
2332 }
2333
2334 case 4:
2335 {
2336 png_bytep sp;
2337 png_bytep dp;
2338 int shift;
2339 int d;
2340 int value;
2341 png_uint_32 i;
2342 png_uint_32 row_width = row_info->width;
2343
2344 dp = row;
2345 shift = 4;
2346 d = 0;
2347 for (i = png_pass_start[pass]; i < row_width;
2348 i += png_pass_inc[pass])
2349 {
2350 sp = row + (png_size_t)(i >> 1);
2351 value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
2352 d |= (value << shift);
2353
2354 if (shift == 0)
2355 {
2356 shift = 4;
2357 *dp++ = (png_byte)d;
2358 d = 0;
2359 }
2360
2361 else
2362 shift -= 4;
2363 }
2364 if (shift != 4)
2365 *dp = (png_byte)d;
2366
2367 break;
2368 }
2369
2370 default:
2371 {
2372 png_bytep sp;
2373 png_bytep dp;
2374 png_uint_32 i;
2375 png_uint_32 row_width = row_info->width;
2376 png_size_t pixel_bytes;
2377
2378 /* Start at the beginning */
2379 dp = row;
2380
2381 /* Find out how many bytes each pixel takes up */
2382 pixel_bytes = (row_info->pixel_depth >> 3);
2383
2384 /* Loop through the row, only looking at the pixels that matter */
2385 for (i = png_pass_start[pass]; i < row_width;
2386 i += png_pass_inc[pass])
2387 {
2388 /* Find out where the original pixel is */
2389 sp = row + (png_size_t)i * pixel_bytes;
2390
2391 /* Move the pixel */
2392 if (dp != sp)
2393 png_memcpy(dp, sp, pixel_bytes);
2394
2395 /* Next pixel */
2396 dp += pixel_bytes;
2397 }
2398 break;
2399 }
2400 }
2401 /* Set new row width */
2402 row_info->width = (row_info->width +
2403 png_pass_inc[pass] - 1 -
2404 png_pass_start[pass]) /
2405 png_pass_inc[pass];
2406
2407 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
2408 row_info->width);
2409 }
2410}
2411#endif
2412
2413/* This filters the row, chooses which filter to use, if it has not already
2414 * been specified by the application, and then writes the row out with the
2415 * chosen filter.
2416 */
2417static void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row,
2418 png_size_t row_bytes);
2419
2420#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
2421#define PNG_HISHIFT 10
2422#define PNG_LOMASK ((png_uint_32)0xffffL)
2423#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
2424void /* PRIVATE */
2425png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
2426{
2427 png_bytep best_row;
2428#ifdef PNG_WRITE_FILTER_SUPPORTED
2429 png_bytep prev_row, row_buf;
2430 png_uint_32 mins, bpp;
2431 png_byte filter_to_do = png_ptr->do_filter;
2432 png_size_t row_bytes = row_info->rowbytes;
2433#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2434 int num_p_filters = png_ptr->num_prev_filters;
2435#endif
2436
2437 png_debug(1, "in png_write_find_filter");
2438
2439#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2440 if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
2441 {
2442 /* These will never be selected so we need not test them. */
2443 filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
2444 }
2445#endif
2446
2447 /* Find out how many bytes offset each pixel is */
2448 bpp = (row_info->pixel_depth + 7) >> 3;
2449
2450 prev_row = png_ptr->prev_row;
2451#endif
2452 best_row = png_ptr->row_buf;
2453#ifdef PNG_WRITE_FILTER_SUPPORTED
2454 row_buf = best_row;
2455 mins = PNG_MAXSUM;
2456
2457 /* The prediction method we use is to find which method provides the
2458 * smallest value when summing the absolute values of the distances
2459 * from zero, using anything >= 128 as negative numbers. This is known
2460 * as the "minimum sum of absolute differences" heuristic. Other
2461 * heuristics are the "weighted minimum sum of absolute differences"
2462 * (experimental and can in theory improve compression), and the "zlib
2463 * predictive" method (not implemented yet), which does test compressions
2464 * of lines using different filter methods, and then chooses the
2465 * (series of) filter(s) that give minimum compressed data size (VERY
2466 * computationally expensive).
2467 *
2468 * GRR 980525: consider also
2469 *
2470 * (1) minimum sum of absolute differences from running average (i.e.,
2471 * keep running sum of non-absolute differences & count of bytes)
2472 * [track dispersion, too? restart average if dispersion too large?]
2473 *
2474 * (1b) minimum sum of absolute differences from sliding average, probably
2475 * with window size <= deflate window (usually 32K)
2476 *
2477 * (2) minimum sum of squared differences from zero or running average
2478 * (i.e., ~ root-mean-square approach)
2479 */
2480
2481
2482 /* We don't need to test the 'no filter' case if this is the only filter
2483 * that has been chosen, as it doesn't actually do anything to the data.
2484 */
2485 if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE)
2486 {
2487 png_bytep rp;
2488 png_uint_32 sum = 0;
2489 png_size_t i;
2490 int v;
2491
2492 for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
2493 {
2494 v = *rp;
2495 sum += (v < 128) ? v : 256 - v;
2496 }
2497
2498#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2499 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2500 {
2501 png_uint_32 sumhi, sumlo;
2502 int j;
2503 sumlo = sum & PNG_LOMASK;
2504 sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
2505
2506 /* Reduce the sum if we match any of the previous rows */
2507 for (j = 0; j < num_p_filters; j++)
2508 {
2509 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
2510 {
2511 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2512 PNG_WEIGHT_SHIFT;
2513
2514 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2515 PNG_WEIGHT_SHIFT;
2516 }
2517 }
2518
2519 /* Factor in the cost of this filter (this is here for completeness,
2520 * but it makes no sense to have a "cost" for the NONE filter, as
2521 * it has the minimum possible computational cost - none).
2522 */
2523 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
2524 PNG_COST_SHIFT;
2525
2526 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
2527 PNG_COST_SHIFT;
2528
2529 if (sumhi > PNG_HIMASK)
2530 sum = PNG_MAXSUM;
2531
2532 else
2533 sum = (sumhi << PNG_HISHIFT) + sumlo;
2534 }
2535#endif
2536 mins = sum;
2537 }
2538
2539 /* Sub filter */
2540 if (filter_to_do == PNG_FILTER_SUB)
2541 /* It's the only filter so no testing is needed */
2542 {
2543 png_bytep rp, lp, dp;
2544 png_size_t i;
2545
2546 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2547 i++, rp++, dp++)
2548 {
2549 *dp = *rp;
2550 }
2551
2552 for (lp = row_buf + 1; i < row_bytes;
2553 i++, rp++, lp++, dp++)
2554 {
2555 *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
2556 }
2557
2558 best_row = png_ptr->sub_row;
2559 }
2560
2561 else if (filter_to_do & PNG_FILTER_SUB)
2562 {
2563 png_bytep rp, dp, lp;
2564 png_uint_32 sum = 0, lmins = mins;
2565 png_size_t i;
2566 int v;
2567
2568#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2569 /* We temporarily increase the "minimum sum" by the factor we
2570 * would reduce the sum of this filter, so that we can do the
2571 * early exit comparison without scaling the sum each time.
2572 */
2573 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2574 {
2575 int j;
2576 png_uint_32 lmhi, lmlo;
2577 lmlo = lmins & PNG_LOMASK;
2578 lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
2579
2580 for (j = 0; j < num_p_filters; j++)
2581 {
2582 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
2583 {
2584 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2585 PNG_WEIGHT_SHIFT;
2586
2587 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2588 PNG_WEIGHT_SHIFT;
2589 }
2590 }
2591
2592 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
2593 PNG_COST_SHIFT;
2594
2595 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
2596 PNG_COST_SHIFT;
2597
2598 if (lmhi > PNG_HIMASK)
2599 lmins = PNG_MAXSUM;
2600
2601 else
2602 lmins = (lmhi << PNG_HISHIFT) + lmlo;
2603 }
2604#endif
2605
2606 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2607 i++, rp++, dp++)
2608 {
2609 v = *dp = *rp;
2610
2611 sum += (v < 128) ? v : 256 - v;
2612 }
2613
2614 for (lp = row_buf + 1; i < row_bytes;
2615 i++, rp++, lp++, dp++)
2616 {
2617 v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
2618
2619 sum += (v < 128) ? v : 256 - v;
2620
2621 if (sum > lmins) /* We are already worse, don't continue. */
2622 break;
2623 }
2624
2625#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2626 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2627 {
2628 int j;
2629 png_uint_32 sumhi, sumlo;
2630 sumlo = sum & PNG_LOMASK;
2631 sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
2632
2633 for (j = 0; j < num_p_filters; j++)
2634 {
2635 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
2636 {
2637 sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
2638 PNG_WEIGHT_SHIFT;
2639
2640 sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
2641 PNG_WEIGHT_SHIFT;
2642 }
2643 }
2644
2645 sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
2646 PNG_COST_SHIFT;
2647
2648 sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
2649 PNG_COST_SHIFT;
2650
2651 if (sumhi > PNG_HIMASK)
2652 sum = PNG_MAXSUM;
2653
2654 else
2655 sum = (sumhi << PNG_HISHIFT) + sumlo;
2656 }
2657#endif
2658
2659 if (sum < mins)
2660 {
2661 mins = sum;
2662 best_row = png_ptr->sub_row;
2663 }
2664 }
2665
2666 /* Up filter */
2667 if (filter_to_do == PNG_FILTER_UP)
2668 {
2669 png_bytep rp, dp, pp;
2670 png_size_t i;
2671
2672 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2673 pp = prev_row + 1; i < row_bytes;
2674 i++, rp++, pp++, dp++)
2675 {
2676 *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
2677 }
2678
2679 best_row = png_ptr->up_row;
2680 }
2681
2682 else if (filter_to_do & PNG_FILTER_UP)
2683 {
2684 png_bytep rp, dp, pp;
2685 png_uint_32 sum = 0, lmins = mins;
2686 png_size_t i;
2687 int v;
2688
2689
2690#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2691 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2692 {
2693 int j;
2694 png_uint_32 lmhi, lmlo;
2695 lmlo = lmins & PNG_LOMASK;
2696 lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
2697
2698 for (j = 0; j < num_p_filters; j++)
2699 {
2700 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
2701 {
2702 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2703 PNG_WEIGHT_SHIFT;
2704
2705 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2706 PNG_WEIGHT_SHIFT;
2707 }
2708 }
2709
2710 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
2711 PNG_COST_SHIFT;
2712
2713 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
2714 PNG_COST_SHIFT;
2715
2716 if (lmhi > PNG_HIMASK)
2717 lmins = PNG_MAXSUM;
2718
2719 else
2720 lmins = (lmhi << PNG_HISHIFT) + lmlo;
2721 }
2722#endif
2723
2724 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2725 pp = prev_row + 1; i < row_bytes; i++)
2726 {
2727 v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
2728
2729 sum += (v < 128) ? v : 256 - v;
2730
2731 if (sum > lmins) /* We are already worse, don't continue. */
2732 break;
2733 }
2734
2735#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2736 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2737 {
2738 int j;
2739 png_uint_32 sumhi, sumlo;
2740 sumlo = sum & PNG_LOMASK;
2741 sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
2742
2743 for (j = 0; j < num_p_filters; j++)
2744 {
2745 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
2746 {
2747 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2748 PNG_WEIGHT_SHIFT;
2749
2750 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2751 PNG_WEIGHT_SHIFT;
2752 }
2753 }
2754
2755 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
2756 PNG_COST_SHIFT;
2757
2758 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
2759 PNG_COST_SHIFT;
2760
2761 if (sumhi > PNG_HIMASK)
2762 sum = PNG_MAXSUM;
2763
2764 else
2765 sum = (sumhi << PNG_HISHIFT) + sumlo;
2766 }
2767#endif
2768
2769 if (sum < mins)
2770 {
2771 mins = sum;
2772 best_row = png_ptr->up_row;
2773 }
2774 }
2775
2776 /* Avg filter */
2777 if (filter_to_do == PNG_FILTER_AVG)
2778 {
2779 png_bytep rp, dp, pp, lp;
2780 png_uint_32 i;
2781
2782 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2783 pp = prev_row + 1; i < bpp; i++)
2784 {
2785 *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
2786 }
2787
2788 for (lp = row_buf + 1; i < row_bytes; i++)
2789 {
2790 *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
2791 & 0xff);
2792 }
2793 best_row = png_ptr->avg_row;
2794 }
2795
2796 else if (filter_to_do & PNG_FILTER_AVG)
2797 {
2798 png_bytep rp, dp, pp, lp;
2799 png_uint_32 sum = 0, lmins = mins;
2800 png_size_t i;
2801 int v;
2802
2803#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2804 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2805 {
2806 int j;
2807 png_uint_32 lmhi, lmlo;
2808 lmlo = lmins & PNG_LOMASK;
2809 lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
2810
2811 for (j = 0; j < num_p_filters; j++)
2812 {
2813 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
2814 {
2815 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2816 PNG_WEIGHT_SHIFT;
2817
2818 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2819 PNG_WEIGHT_SHIFT;
2820 }
2821 }
2822
2823 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
2824 PNG_COST_SHIFT;
2825
2826 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
2827 PNG_COST_SHIFT;
2828
2829 if (lmhi > PNG_HIMASK)
2830 lmins = PNG_MAXSUM;
2831
2832 else
2833 lmins = (lmhi << PNG_HISHIFT) + lmlo;
2834 }
2835#endif
2836
2837 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2838 pp = prev_row + 1; i < bpp; i++)
2839 {
2840 v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
2841
2842 sum += (v < 128) ? v : 256 - v;
2843 }
2844
2845 for (lp = row_buf + 1; i < row_bytes; i++)
2846 {
2847 v = *dp++ =
2848 (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
2849
2850 sum += (v < 128) ? v : 256 - v;
2851
2852 if (sum > lmins) /* We are already worse, don't continue. */
2853 break;
2854 }
2855
2856#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2857 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2858 {
2859 int j;
2860 png_uint_32 sumhi, sumlo;
2861 sumlo = sum & PNG_LOMASK;
2862 sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
2863
2864 for (j = 0; j < num_p_filters; j++)
2865 {
2866 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
2867 {
2868 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
2869 PNG_WEIGHT_SHIFT;
2870
2871 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
2872 PNG_WEIGHT_SHIFT;
2873 }
2874 }
2875
2876 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
2877 PNG_COST_SHIFT;
2878
2879 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
2880 PNG_COST_SHIFT;
2881
2882 if (sumhi > PNG_HIMASK)
2883 sum = PNG_MAXSUM;
2884
2885 else
2886 sum = (sumhi << PNG_HISHIFT) + sumlo;
2887 }
2888#endif
2889
2890 if (sum < mins)
2891 {
2892 mins = sum;
2893 best_row = png_ptr->avg_row;
2894 }
2895 }
2896
2897 /* Paeth filter */
2898 if (filter_to_do == PNG_FILTER_PAETH)
2899 {
2900 png_bytep rp, dp, pp, cp, lp;
2901 png_size_t i;
2902
2903 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2904 pp = prev_row + 1; i < bpp; i++)
2905 {
2906 *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
2907 }
2908
2909 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2910 {
2911 int a, b, c, pa, pb, pc, p;
2912
2913 b = *pp++;
2914 c = *cp++;
2915 a = *lp++;
2916
2917 p = b - c;
2918 pc = a - c;
2919
2920#ifdef PNG_USE_ABS
2921 pa = abs(p);
2922 pb = abs(pc);
2923 pc = abs(p + pc);
2924#else
2925 pa = p < 0 ? -p : p;
2926 pb = pc < 0 ? -pc : pc;
2927 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
2928#endif
2929
2930 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
2931
2932 *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
2933 }
2934 best_row = png_ptr->paeth_row;
2935 }
2936
2937 else if (filter_to_do & PNG_FILTER_PAETH)
2938 {
2939 png_bytep rp, dp, pp, cp, lp;
2940 png_uint_32 sum = 0, lmins = mins;
2941 png_size_t i;
2942 int v;
2943
2944#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
2945 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
2946 {
2947 int j;
2948 png_uint_32 lmhi, lmlo;
2949 lmlo = lmins & PNG_LOMASK;
2950 lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
2951
2952 for (j = 0; j < num_p_filters; j++)
2953 {
2954 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
2955 {
2956 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
2957 PNG_WEIGHT_SHIFT;
2958
2959 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
2960 PNG_WEIGHT_SHIFT;
2961 }
2962 }
2963
2964 lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
2965 PNG_COST_SHIFT;
2966
2967 lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
2968 PNG_COST_SHIFT;
2969
2970 if (lmhi > PNG_HIMASK)
2971 lmins = PNG_MAXSUM;
2972
2973 else
2974 lmins = (lmhi << PNG_HISHIFT) + lmlo;
2975 }
2976#endif
2977
2978 for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
2979 pp = prev_row + 1; i < bpp; i++)
2980 {
2981 v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
2982
2983 sum += (v < 128) ? v : 256 - v;
2984 }
2985
2986 for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
2987 {
2988 int a, b, c, pa, pb, pc, p;
2989
2990 b = *pp++;
2991 c = *cp++;
2992 a = *lp++;
2993
2994#ifndef PNG_SLOW_PAETH
2995 p = b - c;
2996 pc = a - c;
2997#ifdef PNG_USE_ABS
2998 pa = abs(p);
2999 pb = abs(pc);
3000 pc = abs(p + pc);
3001#else
3002 pa = p < 0 ? -p : p;
3003 pb = pc < 0 ? -pc : pc;
3004 pc = (p + pc) < 0 ? -(p + pc) : p + pc;
3005#endif
3006 p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
3007#else /* PNG_SLOW_PAETH */
3008 p = a + b - c;
3009 pa = abs(p - a);
3010 pb = abs(p - b);
3011 pc = abs(p - c);
3012
3013 if (pa <= pb && pa <= pc)
3014 p = a;
3015
3016 else if (pb <= pc)
3017 p = b;
3018
3019 else
3020 p = c;
3021#endif /* PNG_SLOW_PAETH */
3022
3023 v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
3024
3025 sum += (v < 128) ? v : 256 - v;
3026
3027 if (sum > lmins) /* We are already worse, don't continue. */
3028 break;
3029 }
3030
3031#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
3032 if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
3033 {
3034 int j;
3035 png_uint_32 sumhi, sumlo;
3036 sumlo = sum & PNG_LOMASK;
3037 sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
3038
3039 for (j = 0; j < num_p_filters; j++)
3040 {
3041 if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
3042 {
3043 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
3044 PNG_WEIGHT_SHIFT;
3045
3046 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
3047 PNG_WEIGHT_SHIFT;
3048 }
3049 }
3050
3051 sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
3052 PNG_COST_SHIFT;
3053
3054 sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
3055 PNG_COST_SHIFT;
3056
3057 if (sumhi > PNG_HIMASK)
3058 sum = PNG_MAXSUM;
3059
3060 else
3061 sum = (sumhi << PNG_HISHIFT) + sumlo;
3062 }
3063#endif
3064
3065 if (sum < mins)
3066 {
3067 best_row = png_ptr->paeth_row;
3068 }
3069 }
3070#endif /* PNG_WRITE_FILTER_SUPPORTED */
3071
3072 /* Do the actual writing of the filtered row data from the chosen filter. */
3073 png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1);
3074
3075#ifdef PNG_WRITE_FILTER_SUPPORTED
3076#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
3077 /* Save the type of filter we picked this time for future calculations */
3078 if (png_ptr->num_prev_filters > 0)
3079 {
3080 int j;
3081
3082 for (j = 1; j < num_p_filters; j++)
3083 {
3084 png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
3085 }
3086
3087 png_ptr->prev_filters[j] = best_row[0];
3088 }
3089#endif
3090#endif /* PNG_WRITE_FILTER_SUPPORTED */
3091}
3092
3093
3094/* Do the actual writing of a previously filtered row. */
3095static void
3096png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row,
3097 png_size_t avail/*includes filter byte*/)
3098{
3099 png_debug(1, "in png_write_filtered_row");
3100
3101 png_debug1(2, "filter = %d", filtered_row[0]);
3102 /* Set up the zlib input buffer */
3103
3104 png_ptr->zstream.next_in = filtered_row;
3105 png_ptr->zstream.avail_in = 0;
3106 /* Repeat until we have compressed all the data */
3107 do
3108 {
3109 int ret; /* Return of zlib */
3110
3111 /* Record the number of bytes available - zlib supports at least 65535
3112 * bytes at one step, depending on the size of the zlib type 'uInt', the
3113 * maximum size zlib can write at once is ZLIB_IO_MAX (from pngpriv.h).
3114 * Use this because on 16 bit systems 'rowbytes' can be up to 65536 (i.e.
3115 * one more than 16 bits) and, in this case 'rowbytes+1' can overflow a
3116 * uInt. ZLIB_IO_MAX can be safely reduced to cause zlib to be called
3117 * with smaller chunks of data.
3118 */
3119 if (png_ptr->zstream.avail_in == 0)
3120 {
3121 if (avail > ZLIB_IO_MAX)
3122 {
3123 png_ptr->zstream.avail_in = ZLIB_IO_MAX;
3124 avail -= ZLIB_IO_MAX;
3125 }
3126
3127 else
3128 {
3129 /* So this will fit in the available uInt space: */
3130 png_ptr->zstream.avail_in = (uInt)avail;
3131 avail = 0;
3132 }
3133 }
3134
3135 /* Compress the data */
3136 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
3137
3138 /* Check for compression errors */
3139 if (ret != Z_OK)
3140 {
3141 if (png_ptr->zstream.msg != NULL)
3142 png_error(png_ptr, png_ptr->zstream.msg);
3143
3144 else
3145 png_error(png_ptr, "zlib error");
3146 }
3147
3148 /* See if it is time to write another IDAT */
3149 if (!(png_ptr->zstream.avail_out))
3150 {
3151 /* Write the IDAT and reset the zlib output buffer */
3152 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
3153 }
3154 /* Repeat until all data has been compressed */
3155 } while (avail > 0 || png_ptr->zstream.avail_in > 0);
3156
3157 /* Swap the current and previous rows */
3158 if (png_ptr->prev_row != NULL)
3159 {
3160 png_bytep tptr;
3161
3162 tptr = png_ptr->prev_row;
3163 png_ptr->prev_row = png_ptr->row_buf;
3164 png_ptr->row_buf = tptr;
3165 }
3166
3167 /* Finish row - updates counters and flushes zlib if last row */
3168 png_write_finish_row(png_ptr);
3169
3170#ifdef PNG_WRITE_FLUSH_SUPPORTED
3171 png_ptr->flush_rows++;
3172
3173 if (png_ptr->flush_dist > 0 &&
3174 png_ptr->flush_rows >= png_ptr->flush_dist)
3175 {
3176 png_write_flush(png_ptr);
3177 }
3178#endif
3179}
3180#endif /* PNG_WRITE_SUPPORTED */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/PRJ0041.mak b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/PRJ0041.mak
new file mode 100644
index 0000000..d8b3aff
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/PRJ0041.mak
@@ -0,0 +1,21 @@
1# Prevent "Cannot find missing dependency..." warnings while compiling
2# pngwin.rc (PRJ0041).
3
4all: $(IntDir)\alloc.h \
5 $(IntDir)\fp.h \
6 $(IntDir)\m68881.h \
7 $(IntDir)\mem.h \
8 $(IntDir)\pngusr.h \
9 $(IntDir)\strings.h \
10 $(IntDir)\unistd.h \
11 $(IntDir)\unixio.h
12
13$(IntDir)\alloc.h \
14$(IntDir)\fp.h \
15$(IntDir)\m68881.h \
16$(IntDir)\mem.h \
17$(IntDir)\pngusr.h \
18$(IntDir)\strings.h \
19$(IntDir)\unistd.h \
20$(IntDir)\unixio.h:
21 @!echo.>$@
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README.txt
new file mode 100644
index 0000000..6edc04c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README.txt
@@ -0,0 +1,58 @@
1Microsoft Developer Studio Project File, Format Version 7.10 for libpng.
2
3Copyright (C) 2004 Simon-Pierre Cadieux.
4
5This code is released under the libpng license.
6For conditions of distribution and use, see copyright notice in png.h
7
8NOTE: This project will be removed from libpng-1.5.0. It has
9been replaced with the "vstudio" project.
10
11Assumptions:
12* The libpng source files are in ..\..
13* The zlib source files are in ..\..\..\zlib
14* The zlib project file is in . /* Warning: This is until the zlib project
15 files get intergrated into the next zlib release. The final zlib project
16 directory will then be ..\..\..\zlib\projects\visualc71. */
17
18To use:
19
201) On the main menu, select "File | Open Solution".
21 Open "libpng.sln".
22
232) Display the Solution Explorer view (Ctrl+Alt+L)
24
253) Set one of the project as the StartUp project. If you just want to build the
26 binaries set "libpng" as the startup project (Select "libpng" tree view
27 item + Project | Set as StartUp project). If you want to build and test the
28 binaries set it to "pngtest" (Select "pngtest" tree view item +
29 Project | Set as StartUp project)
30
314) Select "Build | Configuration Manager...".
32 Choose the configuration you wish to build.
33
345) Select "Build | Clean Solution".
35
366) Select "Build | Build Solution (Ctrl-Shift-B)"
37
38This project builds the libpng binaries as follows:
39
40* Win32_DLL_Release\libpng15.dll DLL build
41* Win32_DLL_Debug\libpng15d.dll DLL build (debug version)
42* Win32_DLL_VB\libpng15vb.dll DLL build for Visual Basic, using stdcall
43* Win32_LIB_Release\libpng.lib static build
44* Win32_LIB_Debug\libpngd.lib static build (debug version)
45
46Notes:
47
48If you change anything in the source files, or select different compiler
49settings, please change the DLL name to something different than any of
50the above names. Also, make sure that in your "pngusr.h" you define
51PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX according to the
52instructions provided in "pngconf.h".
53
54All DLLs built by this project use the Microsoft dynamic C runtime library
55MSVCR71.DLL (MSVCR71D.DLL for debug versions). If you distribute any of the
56above mentioned libraries you may have to include this DLL in your package.
57For a list of files that are redistributable in Visual Studio see
58$(VCINSTALLDIR)\redist.txt.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README_zlib.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README_zlib.txt
new file mode 100644
index 0000000..56a735b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/README_zlib.txt
@@ -0,0 +1,44 @@
1/* WARNING: This file was put in the LibPNG distribution for convenience only.
2 It is expected to be part of the next zlib release under
3 "projects\visualc71\README.txt." */
4
5Microsoft Developer Studio Project File, Format Version 7.10 for zlib.
6
7Copyright (C) 2004 Simon-Pierre Cadieux.
8Copyright (C) 2004 Cosmin Truta.
9
10This code is released under the libpng license.
11For conditions of distribution and use, see copyright notice in zlib.h.
12
13NOTE: This project will be removed from libpng-1.5.0. It has
14been replaced with the "vstudio" project.
15
16To use:
17
181) On the main menu, select "File | Open Solution".
19 Open "zlib.sln".
20
212) Display the Solution Explorer view (Ctrl+Alt+L)
22
233) Set one of the project as the StartUp project. If you just want to build the
24 binaries set "zlib" as the startup project (Select "zlib" tree view item +
25 Project | Set as StartUp project). If you want to build and test the
26 binaries set it to "example" (Select "example" tree view item + Project |
27 Set as StartUp project), If you want to build the minigzip utility set it to
28 "minigzip" (Select "minigzip" tree view item + Project | Set as StartUp
29 project
30
314) Select "Build | Configuration Manager...".
32 Choose the configuration you wish to build.
33
345) Select "Build | Clean Solution".
35
366) Select "Build | Build Solution (Ctrl-Shift-B)"
37
38This project builds the zlib binaries as follows:
39
40* Win32_DLL_Release\zlib1.dll DLL build
41* Win32_DLL_Debug\zlib1d.dll DLL build (debug version)
42* Win32_LIB_Release\zlib.lib static build
43* Win32_LIB_Debug\zlibd.lib static build (debug version)
44
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.sln b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.sln
new file mode 100644
index 0000000..adce68a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.sln
@@ -0,0 +1,60 @@
1Microsoft Visual Studio Solution File, Format Version 8.00
2Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng.vcproj", "{0008960E-E0DD-41A6-8265-00B31DDB4C21}"
3 ProjectSection(ProjectDependencies) = postProject
4 {2D4F8105-7D21-454C-9932-B47CAB71A5C0} = {2D4F8105-7D21-454C-9932-B47CAB71A5C0}
5 EndProjectSection
6EndProject
7Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngtest", "pngtest.vcproj", "{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}"
8 ProjectSection(ProjectDependencies) = postProject
9 {0008960E-E0DD-41A6-8265-00B31DDB4C21} = {0008960E-E0DD-41A6-8265-00B31DDB4C21}
10 EndProjectSection
11EndProject
12Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib.vcproj", "{2D4F8105-7D21-454C-9932-B47CAB71A5C0}"
13 ProjectSection(ProjectDependencies) = postProject
14 EndProjectSection
15EndProject
16Global
17 GlobalSection(SolutionConfiguration) = preSolution
18 DLL Debug = DLL Debug
19 DLL Release = DLL Release
20 DLL VB = DLL VB
21 LIB Debug = LIB Debug
22 LIB Release = LIB Release
23 EndGlobalSection
24 GlobalSection(ProjectConfiguration) = postSolution
25 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.ActiveCfg = DLL Debug|Win32
26 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.Build.0 = DLL Debug|Win32
27 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.ActiveCfg = DLL Release|Win32
28 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.Build.0 = DLL Release|Win32
29 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.ActiveCfg = DLL VB|Win32
30 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.Build.0 = DLL VB|Win32
31 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.ActiveCfg = LIB Debug|Win32
32 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.Build.0 = LIB Debug|Win32
33 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.ActiveCfg = LIB Release|Win32
34 {0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.Build.0 = LIB Release|Win32
35 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.ActiveCfg = DLL Debug|Win32
36 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.Build.0 = DLL Debug|Win32
37 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.ActiveCfg = DLL Release|Win32
38 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.Build.0 = DLL Release|Win32
39 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.ActiveCfg = DLL VB|Win32
40 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.Build.0 = DLL VB|Win32
41 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.ActiveCfg = LIB Debug|Win32
42 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.Build.0 = LIB Debug|Win32
43 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.ActiveCfg = LIB Release|Win32
44 {FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.Build.0 = LIB Release|Win32
45 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.ActiveCfg = DLL Debug|Win32
46 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.Build.0 = DLL Debug|Win32
47 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.ActiveCfg = DLL Release|Win32
48 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.Build.0 = DLL Release|Win32
49 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.ActiveCfg = DLL Release|Win32
50 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.Build.0 = DLL Release|Win32
51 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.ActiveCfg = LIB Debug|Win32
52 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.Build.0 = LIB Debug|Win32
53 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.ActiveCfg = LIB Release|Win32
54 {2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.Build.0 = LIB Release|Win32
55 EndGlobalSection
56 GlobalSection(ExtensibilityGlobals) = postSolution
57 EndGlobalSection
58 GlobalSection(ExtensibilityAddIns) = postSolution
59 EndGlobalSection
60EndGlobal
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.vcproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.vcproj
new file mode 100644
index 0000000..e17f4f7
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/libpng.vcproj
@@ -0,0 +1,419 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.10"
5 Name="libpng"
6 RootNamespace="libpng">
7 <Platforms>
8 <Platform
9 Name="Win32"/>
10 </Platforms>
11 <Configurations>
12 <Configuration
13 Name="DLL Release|Win32"
14 OutputDirectory=".\Win32_DLL_Release"
15 IntermediateDirectory=".\Win32_DLL_Release"
16 ConfigurationType="2">
17 <Tool
18 Name="VCCLCompilerTool"
19 InlineFunctionExpansion="1"
20 AdditionalIncludeDirectories="..\..;..\..\..\zlib"
21 PreprocessorDefinitions="WIN32;NDEBUG;PNG_BUILD_DLL;ZLIB_DLL;_CRT_SECURE_NO_WARNINGS"
22 StringPooling="TRUE"
23 RuntimeLibrary="2"
24 EnableFunctionLevelLinking="TRUE"
25 UsePrecompiledHeader="3"
26 PrecompiledHeaderThrough="pngpriv.h"
27 WarningLevel="3"
28 CompileAs="0"/>
29 <Tool
30 Name="VCCustomBuildTool"/>
31 <Tool
32 Name="VCLinkerTool"
33 OutputFile="$(OutDir)/libpng15.dll"
34 LinkIncremental="1"/>
35 <Tool
36 Name="VCMIDLTool"/>
37 <Tool
38 Name="VCPostBuildEventTool"/>
39 <Tool
40 Name="VCPreBuildEventTool"
41 CommandLine="copy ..\..\scripts\pnglibconf.h.prebuilt ..\..\pnglibconf.h"/>
42 <Tool
43 Name="VCPreLinkEventTool"/>
44 <Tool
45 Name="VCResourceCompilerTool"
46 PreprocessorDefinitions="NDEBUG"
47 Culture="1033"
48 AdditionalIncludeDirectories="..\..;..\..\..\zlib;$(IntDir)"/>
49 <Tool
50 Name="VCWebServiceProxyGeneratorTool"/>
51 <Tool
52 Name="VCXMLDataGeneratorTool"/>
53 <Tool
54 Name="VCWebDeploymentTool"/>
55 <Tool
56 Name="VCManagedWrapperGeneratorTool"/>
57 <Tool
58 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
59 </Configuration>
60 <Configuration
61 Name="DLL Debug|Win32"
62 OutputDirectory=".\Win32_DLL_Debug"
63 IntermediateDirectory=".\Win32_DLL_Debug"
64 ConfigurationType="2">
65 <Tool
66 Name="VCCLCompilerTool"
67 Optimization="0"
68 AdditionalIncludeDirectories="..\..;..\..\..\zlib"
69 PreprocessorDefinitions="WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;PNG_BUILD_DLL;ZLIB_DLL;_CRT_SECURE_NO_WARNINGS"
70 BasicRuntimeChecks="3"
71 RuntimeLibrary="3"
72 UsePrecompiledHeader="3"
73 PrecompiledHeaderThrough="pngpriv.h"
74 WarningLevel="3"
75 DebugInformationFormat="4"
76 CompileAs="0"/>
77 <Tool
78 Name="VCCustomBuildTool"/>
79 <Tool
80 Name="VCLinkerTool"
81 OutputFile="$(OutDir)/libpng15d.dll"
82 GenerateDebugInformation="TRUE"/>
83 <Tool
84 Name="VCMIDLTool"/>
85 <Tool
86 Name="VCPostBuildEventTool"/>
87 <Tool
88 Name="VCPreBuildEventTool"
89 CommandLine="copy ..\..\scripts\pnglibconf.h.prebuilt ..\..\pnglibconf.h"/>
90 <Tool
91 Name="VCPreLinkEventTool"/>
92 <Tool
93 Name="VCResourceCompilerTool"
94 PreprocessorDefinitions="_DEBUG,PNG_DEBUG=1"
95 Culture="1033"
96 AdditionalIncludeDirectories="..\..;..\..\..\zlib;$(IntDir)"/>
97 <Tool
98 Name="VCWebServiceProxyGeneratorTool"/>
99 <Tool
100 Name="VCXMLDataGeneratorTool"/>
101 <Tool
102 Name="VCWebDeploymentTool"/>
103 <Tool
104 Name="VCManagedWrapperGeneratorTool"/>
105 <Tool
106 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
107 </Configuration>
108 <Configuration
109 Name="DLL VB|Win32"
110 OutputDirectory=".\Win32_DLL_VB"
111 IntermediateDirectory=".\Win32_DLL_VB"
112 ConfigurationType="2">
113 <Tool
114 Name="VCCLCompilerTool"
115 InlineFunctionExpansion="1"
116 AdditionalIncludeDirectories="..\..;..\..\..\zlib"
117 PreprocessorDefinitions="WIN32;NDEBUG;PNG_BUILD_DLL;ZLIB_DLL;PNGAPI=__stdcall;PNG_NO_MODULEDEF;PNG_LIBPNG_SPECIALBUILD;PNG_USER_PRIVATEBUILD;_CRT_SECURE_NO_WARNINGS"
118 StringPooling="TRUE"
119 RuntimeLibrary="2"
120 EnableFunctionLevelLinking="TRUE"
121 UsePrecompiledHeader="3"
122 PrecompiledHeaderThrough="pngpriv.h"
123 WarningLevel="3"
124 CompileAs="0"/>
125 <Tool
126 Name="VCCustomBuildTool"/>
127 <Tool
128 Name="VCLinkerTool"
129 OutputFile="$(OutDir)/libpng15vb.dll"
130 LinkIncremental="1"/>
131 <Tool
132 Name="VCMIDLTool"/>
133 <Tool
134 Name="VCPostBuildEventTool"/>
135 <Tool
136 Name="VCPreBuildEventTool"
137 CommandLine="copy ..\..\scripts\pnglibconf.h.prebuilt ..\..\pnglibconf.h"/>
138 <Tool
139 Name="VCPreLinkEventTool"/>
140 <Tool
141 Name="VCResourceCompilerTool"
142 AdditionalOptions="/d PNG_NO_PEDANTIC_WARNINGS /d PNG_LIBPNG_DLLFNAME_POSTFIX=&quot;&quot;&quot;&quot;VB&quot;&quot;&quot;&quot; /d PNG_LIBPNG_SPECIALBUILD=&quot;&quot;&quot;&quot;__stdcall calling convention used for exported functions&quot;&quot;&quot;&quot;"
143 PreprocessorDefinitions="NDEBUG"
144 Culture="1033"
145 AdditionalIncludeDirectories="..\..;..\..\..\zlib;$(IntDir)"/>
146 <Tool
147 Name="VCWebServiceProxyGeneratorTool"/>
148 <Tool
149 Name="VCXMLDataGeneratorTool"/>
150 <Tool
151 Name="VCWebDeploymentTool"/>
152 <Tool
153 Name="VCManagedWrapperGeneratorTool"/>
154 <Tool
155 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
156 </Configuration>
157 <Configuration
158 Name="LIB Release|Win32"
159 OutputDirectory=".\Win32_LIB_Release"
160 IntermediateDirectory=".\Win32_LIB_Release"
161 ConfigurationType="4">
162 <Tool
163 Name="VCCLCompilerTool"
164 InlineFunctionExpansion="1"
165 AdditionalIncludeDirectories="..\..;..\..\..\zlib"
166 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS"
167 StringPooling="TRUE"
168 RuntimeLibrary="0"
169 EnableFunctionLevelLinking="TRUE"
170 UsePrecompiledHeader="3"
171 PrecompiledHeaderThrough="pngpriv.h"
172 WarningLevel="3"
173 CompileAs="0"/>
174 <Tool
175 Name="VCCustomBuildTool"/>
176 <Tool
177 Name="VCLibrarianTool"
178 OutputFile="$(OutDir)/libpng.lib"/>
179 <Tool
180 Name="VCMIDLTool"/>
181 <Tool
182 Name="VCPostBuildEventTool"/>
183 <Tool
184 Name="VCPreBuildEventTool"
185 CommandLine="copy ..\..\scripts\pnglibconf.h.prebuilt ..\..\pnglibconf.h"/>
186 <Tool
187 Name="VCPreLinkEventTool"/>
188 <Tool
189 Name="VCResourceCompilerTool"/>
190 <Tool
191 Name="VCWebServiceProxyGeneratorTool"/>
192 <Tool
193 Name="VCXMLDataGeneratorTool"/>
194 <Tool
195 Name="VCManagedWrapperGeneratorTool"/>
196 <Tool
197 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
198 </Configuration>
199 <Configuration
200 Name="LIB Debug|Win32"
201 OutputDirectory=".\Win32_LIB_Debug"
202 IntermediateDirectory=".\Win32_LIB_Debug"
203 ConfigurationType="4">
204 <Tool
205 Name="VCCLCompilerTool"
206 Optimization="0"
207 AdditionalIncludeDirectories="..\..;..\..\..\zlib"
208 PreprocessorDefinitions="WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;_CRT_SECURE_NO_WARNINGS"
209 BasicRuntimeChecks="3"
210 RuntimeLibrary="1"
211 UsePrecompiledHeader="3"
212 PrecompiledHeaderThrough="pngpriv.h"
213 WarningLevel="3"
214 DebugInformationFormat="4"
215 CompileAs="0"/>
216 <Tool
217 Name="VCCustomBuildTool"/>
218 <Tool
219 Name="VCLibrarianTool"
220 OutputFile="$(OutDir)/libpngd.lib"/>
221 <Tool
222 Name="VCMIDLTool"/>
223 <Tool
224 Name="VCPostBuildEventTool"/>
225 <Tool
226 Name="VCPreBuildEventTool"
227 CommandLine="copy ..\..\scripts\pnglibconf.h.prebuilt ..\..\pnglibconf.h"/>
228 <Tool
229 Name="VCPreLinkEventTool"/>
230 <Tool
231 Name="VCResourceCompilerTool"/>
232 <Tool
233 Name="VCWebServiceProxyGeneratorTool"/>
234 <Tool
235 Name="VCXMLDataGeneratorTool"/>
236 <Tool
237 Name="VCManagedWrapperGeneratorTool"/>
238 <Tool
239 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
240 </Configuration>
241 </Configurations>
242 <References>
243 </References>
244 <Files>
245 <Filter
246 Name="Source Files"
247 Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
248 <File
249 RelativePath="..\..\png.c">
250 <FileConfiguration
251 Name="DLL Release|Win32">
252 <Tool
253 Name="VCCLCompilerTool"
254 UsePrecompiledHeader="0"/>
255 </FileConfiguration>
256 <FileConfiguration
257 Name="DLL Debug|Win32">
258 <Tool
259 Name="VCCLCompilerTool"
260 UsePrecompiledHeader="0"/>
261 </FileConfiguration>
262 <FileConfiguration
263 Name="DLL VB|Win32">
264 <Tool
265 Name="VCCLCompilerTool"
266 UsePrecompiledHeader="0"/>
267 </FileConfiguration>
268 <FileConfiguration
269 Name="LIB Release|Win32">
270 <Tool
271 Name="VCCLCompilerTool"
272 UsePrecompiledHeader="0"/>
273 </FileConfiguration>
274 <FileConfiguration
275 Name="LIB Debug|Win32">
276 <Tool
277 Name="VCCLCompilerTool"
278 UsePrecompiledHeader="0"/>
279 </FileConfiguration>
280 </File>
281 <File
282 RelativePath="..\..\pngerror.c">
283 <FileConfiguration
284 Name="DLL Release|Win32">
285 <Tool
286 Name="VCCLCompilerTool"
287 UsePrecompiledHeader="1"/>
288 </FileConfiguration>
289 <FileConfiguration
290 Name="DLL Debug|Win32">
291 <Tool
292 Name="VCCLCompilerTool"
293 UsePrecompiledHeader="1"/>
294 </FileConfiguration>
295 <FileConfiguration
296 Name="DLL VB|Win32">
297 <Tool
298 Name="VCCLCompilerTool"
299 UsePrecompiledHeader="1"/>
300 </FileConfiguration>
301 <FileConfiguration
302 Name="LIB Release|Win32">
303 <Tool
304 Name="VCCLCompilerTool"
305 UsePrecompiledHeader="1"/>
306 </FileConfiguration>
307 <FileConfiguration
308 Name="LIB Debug|Win32">
309 <Tool
310 Name="VCCLCompilerTool"
311 UsePrecompiledHeader="1"/>
312 </FileConfiguration>
313 </File>
314 <File
315 RelativePath="..\..\pngget.c">
316 </File>
317 <File
318 RelativePath="..\..\pngmem.c">
319 </File>
320 <File
321 RelativePath="..\..\pngpread.c">
322 </File>
323 <File
324 RelativePath="..\..\pngread.c">
325 </File>
326 <File
327 RelativePath="..\..\pngrio.c">
328 </File>
329 <File
330 RelativePath="..\..\pngrtran.c">
331 </File>
332 <File
333 RelativePath="..\..\pngrutil.c">
334 </File>
335 <File
336 RelativePath="..\..\pngset.c">
337 </File>
338 <File
339 RelativePath="..\..\pngtrans.c">
340 </File>
341 <File
342 RelativePath="..\..\pngwio.c">
343 </File>
344 <File
345 RelativePath="..\..\pngwrite.c">
346 </File>
347 <File
348 RelativePath="..\..\pngwtran.c">
349 </File>
350 <File
351 RelativePath="..\..\pngwutil.c">
352 </File>
353 </Filter>
354 <Filter
355 Name="Header Files"
356 Filter="h;hpp;hxx;hm;inl">
357 <File
358 RelativePath="..\..\png.h">
359 </File>
360 <File
361 RelativePath="..\..\pngconf.h">
362 </File>
363 <File
364 RelativePath="..\..\pngpriv.h">
365 </File>
366 </Filter>
367 <Filter
368 Name="Resource Files"
369 Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
370 <File
371 RelativePath="..\..\scripts\pngwin.rc">
372 <FileConfiguration
373 Name="LIB Release|Win32"
374 ExcludedFromBuild="TRUE">
375 <Tool
376 Name="VCResourceCompilerTool"/>
377 </FileConfiguration>
378 <FileConfiguration
379 Name="LIB Debug|Win32"
380 ExcludedFromBuild="TRUE">
381 <Tool
382 Name="VCResourceCompilerTool"/>
383 </FileConfiguration>
384 </File>
385 </Filter>
386 <File
387 RelativePath=".\PRJ0041.mak">
388 <FileConfiguration
389 Name="DLL Release|Win32">
390 <Tool
391 Name="VCCustomBuildTool"
392 Description="Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings."
393 CommandLine="nmake -f PRJ0041.mak IntDir=$(IntDir)"
394 Outputs="$(IntDir)\alloc.h;$(IntDir)\fp.h;$(IntDir)\m68881.h;$(IntDir)\mem.h;$(IntDir)\pngusr.h;$(IntDir)\strings.h;$(IntDir)\unistd.h;$(IntDir)\unixio.h"/>
395 </FileConfiguration>
396 <FileConfiguration
397 Name="DLL Debug|Win32">
398 <Tool
399 Name="VCCustomBuildTool"
400 Description="Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings."
401 CommandLine="nmake -f PRJ0041.mak IntDir=$(IntDir)"
402 Outputs="$(IntDir)\alloc.h;$(IntDir)\fp.h;$(IntDir)\m68881.h;$(IntDir)\mem.h;$(IntDir)\pngusr.h;$(IntDir)\strings.h;$(IntDir)\unistd.h;$(IntDir)\unixio.h"/>
403 </FileConfiguration>
404 <FileConfiguration
405 Name="DLL VB|Win32">
406 <Tool
407 Name="VCCustomBuildTool"
408 Description="Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings."
409 CommandLine="nmake -f PRJ0041.mak IntDir=$(IntDir)"
410 Outputs="$(IntDir)\alloc.h;$(IntDir)\fp.h;$(IntDir)\m68881.h;$(IntDir)\mem.h;$(IntDir)\pngusr.h;$(IntDir)\strings.h;$(IntDir)\unistd.h;$(IntDir)\unixio.h"/>
411 </FileConfiguration>
412 </File>
413 <File
414 RelativePath="README.txt">
415 </File>
416 </Files>
417 <Globals>
418 </Globals>
419</VisualStudioProject>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/pngtest.vcproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/pngtest.vcproj
new file mode 100644
index 0000000..ac82ff9
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/pngtest.vcproj
@@ -0,0 +1,267 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.10"
5 Name="pngtest"
6 RootNamespace="pngtest">
7 <Platforms>
8 <Platform
9 Name="Win32"/>
10 </Platforms>
11 <Configurations>
12 <Configuration
13 Name="DLL Release|Win32"
14 OutputDirectory=".\Win32_DLL_Release\Test"
15 IntermediateDirectory=".\Win32_DLL_Release\Test"
16 ConfigurationType="1">
17 <Tool
18 Name="VCCLCompilerTool"
19 InlineFunctionExpansion="1"
20 AdditionalIncludeDirectories="..\..\scripts;..\..\..\zlib"
21 PreprocessorDefinitions="WIN32;NDEBUG;PNG_DLL;PNG_NO_STDIO;_CRT_SECURE_NO_WARNINGS"
22 StringPooling="TRUE"
23 RuntimeLibrary="2"
24 EnableFunctionLevelLinking="TRUE"
25 WarningLevel="3"
26 CompileAs="0"/>
27 <Tool
28 Name="VCCustomBuildTool"
29 Description="Testing..."
30 CommandLine="set path=$(OutDir)\..;$(OutDir)\..\ZLib
31$(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
32 Outputs="$(IntDir)\pngout.png"/>
33 <Tool
34 Name="VCLinkerTool"
35 OutputFile="$(OutDir)/pngtest.exe"
36 LinkIncremental="1"
37 SubSystem="1"/>
38 <Tool
39 Name="VCMIDLTool"/>
40 <Tool
41 Name="VCPostBuildEventTool"/>
42 <Tool
43 Name="VCPreBuildEventTool"/>
44 <Tool
45 Name="VCPreLinkEventTool"/>
46 <Tool
47 Name="VCResourceCompilerTool"/>
48 <Tool
49 Name="VCWebServiceProxyGeneratorTool"/>
50 <Tool
51 Name="VCXMLDataGeneratorTool"/>
52 <Tool
53 Name="VCWebDeploymentTool"/>
54 <Tool
55 Name="VCManagedWrapperGeneratorTool"/>
56 <Tool
57 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
58 </Configuration>
59 <Configuration
60 Name="DLL Debug|Win32"
61 OutputDirectory=".\Win32_DLL_Debug\Test"
62 IntermediateDirectory=".\Win32_DLL_Debug\Test"
63 ConfigurationType="1">
64 <Tool
65 Name="VCCLCompilerTool"
66 Optimization="0"
67 AdditionalIncludeDirectories="..\..\scripts;..\..\..\zlib"
68 PreprocessorDefinitions="WIN32;_DEBUG;PNG_DLL;PNG_NO_STDIO;_CRT_SECURE_NO_WARNINGS"
69 BasicRuntimeChecks="3"
70 RuntimeLibrary="3"
71 WarningLevel="3"
72 DebugInformationFormat="4"
73 CompileAs="0"/>
74 <Tool
75 Name="VCCustomBuildTool"
76 Description="Testing..."
77 CommandLine="set path=$(OutDir)\..;$(OutDir)\..\ZLib
78$(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
79 Outputs="$(IntDir)\pngout.png"/>
80 <Tool
81 Name="VCLinkerTool"
82 OutputFile="$(OutDir)/pngtest.exe"
83 GenerateDebugInformation="TRUE"
84 SubSystem="1"
85 TargetMachine="1"/>
86 <Tool
87 Name="VCMIDLTool"/>
88 <Tool
89 Name="VCPostBuildEventTool"/>
90 <Tool
91 Name="VCPreBuildEventTool"/>
92 <Tool
93 Name="VCPreLinkEventTool"/>
94 <Tool
95 Name="VCResourceCompilerTool"/>
96 <Tool
97 Name="VCWebServiceProxyGeneratorTool"/>
98 <Tool
99 Name="VCXMLDataGeneratorTool"/>
100 <Tool
101 Name="VCWebDeploymentTool"/>
102 <Tool
103 Name="VCManagedWrapperGeneratorTool"/>
104 <Tool
105 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
106 </Configuration>
107 <Configuration
108 Name="DLL VB|Win32"
109 OutputDirectory=".\Win32_DLL_VB\Test"
110 IntermediateDirectory=".\Win32_DLL_VB\Test"
111 ConfigurationType="1">
112 <Tool
113 Name="VCCLCompilerTool"
114 InlineFunctionExpansion="1"
115 AdditionalIncludeDirectories="..\..\scripts;..\..\..\zlib"
116 PreprocessorDefinitions="WIN32;NDEBUG;PNG_DLL;PNG_NO_STDIO;PNGAPI=__stdcall;PNG_USER_PRIVATEBUILD;_CRT_SECURE_NO_WARNINGS"
117 StringPooling="TRUE"
118 RuntimeLibrary="2"
119 EnableFunctionLevelLinking="TRUE"
120 WarningLevel="2"
121 CallingConvention="2"
122 CompileAs="0"/>
123 <Tool
124 Name="VCCustomBuildTool"
125 Description="Testing..."
126 CommandLine="set path=$(OutDir)\..;$(OutDir)\..\..\Win32_DLL_Release\ZLib
127$(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
128 Outputs="$(IntDir)\pngout.png"/>
129 <Tool
130 Name="VCLinkerTool"
131 OutputFile="$(OutDir)/pngtest.exe"
132 LinkIncremental="1"
133 IgnoreDefaultLibraryNames="$(IntDir)\libpng15b.lib"
134 SubSystem="1"
135 TargetMachine="1"/>
136 <Tool
137 Name="VCMIDLTool"/>
138 <Tool
139 Name="VCPostBuildEventTool"/>
140 <Tool
141 Name="VCPreBuildEventTool"/>
142 <Tool
143 Name="VCPreLinkEventTool"/>
144 <Tool
145 Name="VCResourceCompilerTool"/>
146 <Tool
147 Name="VCWebServiceProxyGeneratorTool"/>
148 <Tool
149 Name="VCXMLDataGeneratorTool"/>
150 <Tool
151 Name="VCWebDeploymentTool"/>
152 <Tool
153 Name="VCManagedWrapperGeneratorTool"/>
154 <Tool
155 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
156 </Configuration>
157 <Configuration
158 Name="LIB Release|Win32"
159 OutputDirectory=".\Win32_LIB_Release\Test"
160 IntermediateDirectory=".\Win32_LIB_Release\Test"
161 ConfigurationType="1">
162 <Tool
163 Name="VCCLCompilerTool"
164 InlineFunctionExpansion="1"
165 AdditionalIncludeDirectories="..\..\scripts;..\..\..\zlib"
166 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS"
167 StringPooling="TRUE"
168 RuntimeLibrary="0"
169 EnableFunctionLevelLinking="TRUE"
170 WarningLevel="3"
171 CompileAs="0"/>
172 <Tool
173 Name="VCCustomBuildTool"
174 Description="Testing..."
175 CommandLine="set path=$(OutDir)\..;$(OutDir)\..\ZLib
176$(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
177 Outputs="$(IntDir)\pngout.png"/>
178 <Tool
179 Name="VCLinkerTool"
180 OutputFile="$(OutDir)/pngtest.exe"
181 LinkIncremental="1"
182 SubSystem="1"
183 TargetMachine="1"/>
184 <Tool
185 Name="VCMIDLTool"/>
186 <Tool
187 Name="VCPostBuildEventTool"/>
188 <Tool
189 Name="VCPreBuildEventTool"/>
190 <Tool
191 Name="VCPreLinkEventTool"/>
192 <Tool
193 Name="VCResourceCompilerTool"/>
194 <Tool
195 Name="VCWebServiceProxyGeneratorTool"/>
196 <Tool
197 Name="VCXMLDataGeneratorTool"/>
198 <Tool
199 Name="VCWebDeploymentTool"/>
200 <Tool
201 Name="VCManagedWrapperGeneratorTool"/>
202 <Tool
203 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
204 </Configuration>
205 <Configuration
206 Name="LIB Debug|Win32"
207 OutputDirectory=".\Win32_LIB_Debug\Test"
208 IntermediateDirectory=".\Win32_LIB_Debug\Test"
209 ConfigurationType="1">
210 <Tool
211 Name="VCCLCompilerTool"
212 Optimization="0"
213 AdditionalIncludeDirectories="..\..\scripts;..\..\..\zlib"
214 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS"
215 BasicRuntimeChecks="3"
216 RuntimeLibrary="1"
217 WarningLevel="3"
218 DebugInformationFormat="4"
219 CompileAs="0"/>
220 <Tool
221 Name="VCCustomBuildTool"
222 Description="Testing..."
223 CommandLine="set path=$(OutDir)\..;$(OutDir)\..\ZLib
224$(TargetPath) ..\..\pngtest.png $(IntDir)\pngout.png"
225 Outputs="$(IntDir)\pngout.png"/>
226 <Tool
227 Name="VCLinkerTool"
228 OutputFile="$(OutDir)/pngtest.exe"
229 GenerateDebugInformation="TRUE"
230 SubSystem="1"
231 TargetMachine="1"/>
232 <Tool
233 Name="VCMIDLTool"/>
234 <Tool
235 Name="VCPostBuildEventTool"/>
236 <Tool
237 Name="VCPreBuildEventTool"/>
238 <Tool
239 Name="VCPreLinkEventTool"/>
240 <Tool
241 Name="VCResourceCompilerTool"/>
242 <Tool
243 Name="VCWebServiceProxyGeneratorTool"/>
244 <Tool
245 Name="VCXMLDataGeneratorTool"/>
246 <Tool
247 Name="VCWebDeploymentTool"/>
248 <Tool
249 Name="VCManagedWrapperGeneratorTool"/>
250 <Tool
251 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
252 </Configuration>
253 </Configurations>
254 <References>
255 </References>
256 <Files>
257 <Filter
258 Name="Source Files"
259 Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
260 <File
261 RelativePath="..\..\pngtest.c">
262 </File>
263 </Filter>
264 </Files>
265 <Globals>
266 </Globals>
267</VisualStudioProject>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/zlib.vcproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/zlib.vcproj
new file mode 100644
index 0000000..614b869
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/visualc71/zlib.vcproj
@@ -0,0 +1,391 @@
1<?xml version="1.0" encoding="Windows-1252"?>
2<VisualStudioProject
3 ProjectType="Visual C++"
4 Version="7.10"
5 Name="zlib">
6 <Platforms>
7 <Platform
8 Name="Win32"/>
9 </Platforms>
10 <Configurations>
11 <Configuration
12 Name="DLL Release|Win32"
13 OutputDirectory=".\Win32_DLL_Release\ZLib"
14 IntermediateDirectory=".\Win32_DLL_Release\ZLib"
15 ConfigurationType="2">
16 <Tool
17 Name="VCCLCompilerTool"
18 InlineFunctionExpansion="1"
19 AdditionalIncludeDirectories="..\..\..\zlib"
20 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS"
21 StringPooling="TRUE"
22 RuntimeLibrary="2"
23 EnableFunctionLevelLinking="TRUE"
24 WarningLevel="3"
25 CompileAs="1"/>
26 <Tool
27 Name="VCCustomBuildTool"/>
28 <Tool
29 Name="VCLinkerTool"
30 OutputFile="$(OutDir)\zlib1.dll"
31 LinkIncremental="1"
32 ModuleDefinitionFile="..\..\..\zlib\win32\zlib.def"/>
33 <Tool
34 Name="VCMIDLTool"/>
35 <Tool
36 Name="VCPostBuildEventTool"/>
37 <Tool
38 Name="VCPreBuildEventTool"/>
39 <Tool
40 Name="VCPreLinkEventTool"/>
41 <Tool
42 Name="VCResourceCompilerTool"
43 PreprocessorDefinitions="NDEBUG"
44 Culture="1033"/>
45 <Tool
46 Name="VCWebServiceProxyGeneratorTool"/>
47 <Tool
48 Name="VCXMLDataGeneratorTool"/>
49 <Tool
50 Name="VCWebDeploymentTool"/>
51 <Tool
52 Name="VCManagedWrapperGeneratorTool"/>
53 <Tool
54 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
55 </Configuration>
56 <Configuration
57 Name="DLL Debug|Win32"
58 OutputDirectory=".\Win32_DLL_Debug\ZLib"
59 IntermediateDirectory=".\Win32_DLL_Debug\ZLib"
60 ConfigurationType="2">
61 <Tool
62 Name="VCCLCompilerTool"
63 Optimization="0"
64 AdditionalIncludeDirectories="..\..\..\zlib"
65 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS"
66 BasicRuntimeChecks="3"
67 RuntimeLibrary="3"
68 WarningLevel="3"
69 DebugInformationFormat="4"
70 CompileAs="1"/>
71 <Tool
72 Name="VCCustomBuildTool"/>
73 <Tool
74 Name="VCLinkerTool"
75 OutputFile="$(OutDir)\zlib1d.dll"
76 ModuleDefinitionFile="..\..\..\zlib\win32\zlib.def"
77 GenerateDebugInformation="TRUE"/>
78 <Tool
79 Name="VCMIDLTool"/>
80 <Tool
81 Name="VCPostBuildEventTool"/>
82 <Tool
83 Name="VCPreBuildEventTool"/>
84 <Tool
85 Name="VCPreLinkEventTool"/>
86 <Tool
87 Name="VCResourceCompilerTool"
88 PreprocessorDefinitions="_DEBUG"
89 Culture="1033"/>
90 <Tool
91 Name="VCWebServiceProxyGeneratorTool"/>
92 <Tool
93 Name="VCXMLDataGeneratorTool"/>
94 <Tool
95 Name="VCWebDeploymentTool"/>
96 <Tool
97 Name="VCManagedWrapperGeneratorTool"/>
98 <Tool
99 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
100 </Configuration>
101 <Configuration
102 Name="LIB Release|Win32"
103 OutputDirectory=".\Win32_LIB_Release\ZLib"
104 IntermediateDirectory=".\Win32_LIB_Release\ZLib"
105 ConfigurationType="4">
106 <Tool
107 Name="VCCLCompilerTool"
108 InlineFunctionExpansion="1"
109 AdditionalIncludeDirectories="..\..\..\zlib"
110 PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS"
111 StringPooling="TRUE"
112 RuntimeLibrary="0"
113 EnableFunctionLevelLinking="TRUE"
114 WarningLevel="3"
115 CompileAs="1"/>
116 <Tool
117 Name="VCCustomBuildTool"/>
118 <Tool
119 Name="VCLibrarianTool"
120 OutputFile="$(OutDir)\zlib.lib"/>
121 <Tool
122 Name="VCMIDLTool"/>
123 <Tool
124 Name="VCPostBuildEventTool"/>
125 <Tool
126 Name="VCPreBuildEventTool"/>
127 <Tool
128 Name="VCPreLinkEventTool"/>
129 <Tool
130 Name="VCResourceCompilerTool"/>
131 <Tool
132 Name="VCWebServiceProxyGeneratorTool"/>
133 <Tool
134 Name="VCXMLDataGeneratorTool"/>
135 <Tool
136 Name="VCManagedWrapperGeneratorTool"/>
137 <Tool
138 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
139 </Configuration>
140 <Configuration
141 Name="LIB Debug|Win32"
142 OutputDirectory=".\Win32_LIB_Debug\ZLib"
143 IntermediateDirectory=".\Win32_LIB_Debug\ZLib"
144 ConfigurationType="4">
145 <Tool
146 Name="VCCLCompilerTool"
147 Optimization="0"
148 AdditionalIncludeDirectories="..\..\..\zlib"
149 PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS"
150 BasicRuntimeChecks="3"
151 RuntimeLibrary="1"
152 WarningLevel="3"
153 DebugInformationFormat="4"
154 CompileAs="1"/>
155 <Tool
156 Name="VCCustomBuildTool"/>
157 <Tool
158 Name="VCLibrarianTool"
159 OutputFile="$(OutDir)\zlibd.lib"/>
160 <Tool
161 Name="VCMIDLTool"/>
162 <Tool
163 Name="VCPostBuildEventTool"/>
164 <Tool
165 Name="VCPreBuildEventTool"/>
166 <Tool
167 Name="VCPreLinkEventTool"/>
168 <Tool
169 Name="VCResourceCompilerTool"/>
170 <Tool
171 Name="VCWebServiceProxyGeneratorTool"/>
172 <Tool
173 Name="VCXMLDataGeneratorTool"/>
174 <Tool
175 Name="VCManagedWrapperGeneratorTool"/>
176 <Tool
177 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
178 </Configuration>
179 </Configurations>
180 <References>
181 </References>
182 <Files>
183 <Filter
184 Name="Source Files"
185 Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
186 <File
187 RelativePath="..\..\..\zlib\adler32.c">
188 </File>
189 <File
190 RelativePath="..\..\..\zlib\compress.c">
191 </File>
192 <File
193 RelativePath="..\..\..\zlib\crc32.c">
194 </File>
195 <File
196 RelativePath="..\..\..\zlib\deflate.c">
197 </File>
198 <File
199 RelativePath="..\..\..\zlib\gzlib.c">
200 </File>
201 <File
202 RelativePath="..\..\..\zlib\gzclose.c">
203 </File>
204 <File
205 RelativePath="..\..\..\zlib\gzread.c">
206 </File>
207 <File
208 RelativePath="..\..\..\zlib\gzwrite.c">
209 </File>
210 <File
211 RelativePath="..\..\..\zlib\infback.c">
212 </File>
213 <File
214 RelativePath="..\..\..\zlib\inffast.c">
215 </File>
216 <File
217 RelativePath="..\..\..\zlib\inflate.c">
218 </File>
219 <File
220 RelativePath="..\..\..\zlib\inftrees.c">
221 </File>
222 <File
223 RelativePath="..\..\..\zlib\trees.c">
224 </File>
225 <File
226 RelativePath="..\..\..\zlib\uncompr.c">
227 </File>
228 <File
229 RelativePath="..\..\..\zlib\win32\zlib.def">
230 <FileConfiguration
231 Name="LIB Release|Win32"
232 ExcludedFromBuild="TRUE">
233 <Tool
234 Name="VCCustomBuildTool"/>
235 </FileConfiguration>
236 <FileConfiguration
237 Name="LIB Debug|Win32"
238 ExcludedFromBuild="TRUE">
239 <Tool
240 Name="VCCustomBuildTool"/>
241 </FileConfiguration>
242 </File>
243 <File
244 RelativePath="..\..\..\zlib\zutil.c">
245 </File>
246 </Filter>
247 <Filter
248 Name="Header Files"
249 Filter="h;hpp;hxx;hm;inl">
250 <File
251 RelativePath="..\..\..\zlib\crc32.h">
252 </File>
253 <File
254 RelativePath="..\..\..\zlib\deflate.h">
255 </File>
256 <File
257 RelativePath="..\..\..\zlib\inffast.h">
258 </File>
259 <File
260 RelativePath="..\..\..\zlib\inffixed.h">
261 </File>
262 <File
263 RelativePath="..\..\..\zlib\inflate.h">
264 </File>
265 <File
266 RelativePath="..\..\..\zlib\inftrees.h">
267 </File>
268 <File
269 RelativePath="..\..\..\zlib\trees.h">
270 </File>
271 <File
272 RelativePath="..\..\..\zlib\zconf.h">
273 </File>
274 <File
275 RelativePath="..\..\..\zlib\zlib.h">
276 </File>
277 <File
278 RelativePath="..\..\..\zlib\zutil.h">
279 </File>
280 </Filter>
281 <Filter
282 Name="Resource Files"
283 Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
284 <File
285 RelativePath="..\..\..\zlib\win32\zlib1.rc">
286 <FileConfiguration
287 Name="LIB Release|Win32"
288 ExcludedFromBuild="TRUE">
289 <Tool
290 Name="VCResourceCompilerTool"/>
291 </FileConfiguration>
292 <FileConfiguration
293 Name="LIB Debug|Win32"
294 ExcludedFromBuild="TRUE">
295 <Tool
296 Name="VCResourceCompilerTool"/>
297 </FileConfiguration>
298 </File>
299 </Filter>
300 <Filter
301 Name="Assembler Files (Unsupported)"
302 Filter="asm;obj;c;cpp;cxx;h;hpp;hxx">
303 <File
304 RelativePath="..\..\..\zlib\contrib\masmx86\gvmat32.asm">
305 <FileConfiguration
306 Name="DLL Release|Win32"
307 ExcludedFromBuild="TRUE">
308 <Tool
309 Name="VCCustomBuildTool"/>
310 </FileConfiguration>
311 <FileConfiguration
312 Name="DLL Debug|Win32"
313 ExcludedFromBuild="TRUE">
314 <Tool
315 Name="VCCustomBuildTool"/>
316 </FileConfiguration>
317 <FileConfiguration
318 Name="LIB Release|Win32"
319 ExcludedFromBuild="TRUE">
320 <Tool
321 Name="VCCustomBuildTool"/>
322 </FileConfiguration>
323 <FileConfiguration
324 Name="LIB Debug|Win32"
325 ExcludedFromBuild="TRUE">
326 <Tool
327 Name="VCCustomBuildTool"/>
328 </FileConfiguration>
329 </File>
330 <File
331 RelativePath="..\..\..\zlib\contrib\masmx86\gvmat32c.c">
332 <FileConfiguration
333 Name="DLL Release|Win32"
334 ExcludedFromBuild="TRUE">
335 <Tool
336 Name="VCCLCompilerTool"/>
337 </FileConfiguration>
338 <FileConfiguration
339 Name="DLL Debug|Win32"
340 ExcludedFromBuild="TRUE">
341 <Tool
342 Name="VCCLCompilerTool"/>
343 </FileConfiguration>
344 <FileConfiguration
345 Name="LIB Release|Win32"
346 ExcludedFromBuild="TRUE">
347 <Tool
348 Name="VCCLCompilerTool"/>
349 </FileConfiguration>
350 <FileConfiguration
351 Name="LIB Debug|Win32"
352 ExcludedFromBuild="TRUE">
353 <Tool
354 Name="VCCLCompilerTool"/>
355 </FileConfiguration>
356 </File>
357 <File
358 RelativePath="..\..\..\zlib\contrib\masmx86\inffas32.asm">
359 <FileConfiguration
360 Name="DLL Release|Win32"
361 ExcludedFromBuild="TRUE">
362 <Tool
363 Name="VCCustomBuildTool"/>
364 </FileConfiguration>
365 <FileConfiguration
366 Name="DLL Debug|Win32"
367 ExcludedFromBuild="TRUE">
368 <Tool
369 Name="VCCustomBuildTool"/>
370 </FileConfiguration>
371 <FileConfiguration
372 Name="LIB Release|Win32"
373 ExcludedFromBuild="TRUE">
374 <Tool
375 Name="VCCustomBuildTool"/>
376 </FileConfiguration>
377 <FileConfiguration
378 Name="LIB Debug|Win32"
379 ExcludedFromBuild="TRUE">
380 <Tool
381 Name="VCCustomBuildTool"/>
382 </FileConfiguration>
383 </File>
384 </Filter>
385 <File
386 RelativePath="README.txt">
387 </File>
388 </Files>
389 <Globals>
390 </Globals>
391</VisualStudioProject>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/libpng/libpng.vcxproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/libpng/libpng.vcxproj
new file mode 100644
index 0000000..165bfa6
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/libpng/libpng.vcxproj
@@ -0,0 +1,233 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug Library|Win32">
5 <Configuration>Debug Library</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|Win32">
9 <Configuration>Debug</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release Library|Win32">
13 <Configuration>Release Library</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|Win32">
17 <Configuration>Release</Configuration>
18 <Platform>Win32</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <PropertyGroup Label="Globals">
22 <ProjectGuid>{D6973076-9317-4EF2-A0B8-B7A18AC0713E}</ProjectGuid>
23 <Keyword>Win32Proj</Keyword>
24 <RootNamespace>libpng</RootNamespace>
25 </PropertyGroup>
26 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27 <Import Project="$(SolutionDir)\zlib.props" />
28 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29 <ConfigurationType>DynamicLibrary</ConfigurationType>
30 <CharacterSet>MultiByte</CharacterSet>
31 <WholeProgramOptimization>true</WholeProgramOptimization>
32 </PropertyGroup>
33 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
34 <ConfigurationType>StaticLibrary</ConfigurationType>
35 <CharacterSet>MultiByte</CharacterSet>
36 </PropertyGroup>
37 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
38 <ConfigurationType>DynamicLibrary</ConfigurationType>
39 <WholeProgramOptimization>true</WholeProgramOptimization>
40 <CharacterSet>MultiByte</CharacterSet>
41 </PropertyGroup>
42 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
43 <ConfigurationType>StaticLibrary</ConfigurationType>
44 <CharacterSet>MultiByte</CharacterSet>
45 </PropertyGroup>
46 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
47 <ImportGroup Label="ExtensionSettings">
48 </ImportGroup>
49 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
50 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
51 </ImportGroup>
52 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
53 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
54 </ImportGroup>
55 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
56 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
57 </ImportGroup>
58 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
59 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
60 </ImportGroup>
61 <PropertyGroup Label="UserMacros" />
62 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
63 <LinkIncremental>false</LinkIncremental>
64 <CustomBuildBeforeTargets>
65 </CustomBuildBeforeTargets>
66 <TargetName>$(ProjectName)15</TargetName>
67 </PropertyGroup>
68 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
69 <LinkIncremental>false</LinkIncremental>
70 <CustomBuildBeforeTargets />
71 <TargetName>$(ProjectName)15</TargetName>
72 </PropertyGroup>
73 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
74 <LinkIncremental>false</LinkIncremental>
75 <CustomBuildBeforeTargets>
76 </CustomBuildBeforeTargets>
77 <TargetName>$(ProjectName)15</TargetName>
78 </PropertyGroup>
79 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
80 <LinkIncremental>false</LinkIncremental>
81 <CustomBuildBeforeTargets />
82 <TargetName>$(ProjectName)15</TargetName>
83 </PropertyGroup>
84 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
85 <ClCompile>
86 <PrecompiledHeader>Use</PrecompiledHeader>
87 <WarningLevel>Level4</WarningLevel>
88 <MinimalRebuild>false</MinimalRebuild>
89 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
90 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
91 <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92 <IntrinsicFunctions>true</IntrinsicFunctions>
93 <FunctionLevelLinking>true</FunctionLevelLinking>
94 <FloatingPointExceptions>false</FloatingPointExceptions>
95 <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
96 <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>
97 <BrowseInformation>true</BrowseInformation>
98 <CompileAs>CompileAsC</CompileAs>
99 <StringPooling>true</StringPooling>
100 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
101 <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
102 <TreatWarningAsError>true</TreatWarningAsError>
103 <Optimization>Disabled</Optimization>
104 </ClCompile>
105 <Link>
106 <SubSystem>Windows</SubSystem>
107 <GenerateDebugInformation>true</GenerateDebugInformation>
108 <AdditionalDependencies>zlib.lib</AdditionalDependencies>
109 <Version>15</Version>
110 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
111 </Link>
112 </ItemDefinitionGroup>
113 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
114 <ClCompile>
115 <PrecompiledHeader>Use</PrecompiledHeader>
116 <WarningLevel>Level4</WarningLevel>
117 <MinimalRebuild>false</MinimalRebuild>
118 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
119 <Optimization>Disabled</Optimization>
120 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
121 <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
122 <IntrinsicFunctions>true</IntrinsicFunctions>
123 <FunctionLevelLinking>true</FunctionLevelLinking>
124 <FloatingPointExceptions>false</FloatingPointExceptions>
125 <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
126 <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>
127 <BrowseInformation>true</BrowseInformation>
128 <CompileAs>CompileAsC</CompileAs>
129 <StringPooling>true</StringPooling>
130 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
131 <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
132 <TreatWarningAsError>true</TreatWarningAsError>
133 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
134 </ClCompile>
135 <Link>
136 <SubSystem>Windows</SubSystem>
137 <GenerateDebugInformation>true</GenerateDebugInformation>
138 </Link>
139 </ItemDefinitionGroup>
140 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
141 <ClCompile>
142 <WarningLevel>Level4</WarningLevel>
143 <PrecompiledHeader>Use</PrecompiledHeader>
144 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
145 <FunctionLevelLinking>true</FunctionLevelLinking>
146 <IntrinsicFunctions>true</IntrinsicFunctions>
147 <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
148 <FloatingPointExceptions>false</FloatingPointExceptions>
149 <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
150 <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>
151 <BrowseInformation>true</BrowseInformation>
152 <CompileAs>CompileAsC</CompileAs>
153 <StringPooling>true</StringPooling>
154 <MinimalRebuild>false</MinimalRebuild>
155 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
156 <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
157 <TreatWarningAsError>true</TreatWarningAsError>
158 <Optimization>Full</Optimization>
159 </ClCompile>
160 <Link>
161 <SubSystem>Windows</SubSystem>
162 <GenerateDebugInformation>true</GenerateDebugInformation>
163 <EnableCOMDATFolding>true</EnableCOMDATFolding>
164 <OptimizeReferences>true</OptimizeReferences>
165 <AdditionalDependencies>zlib.lib</AdditionalDependencies>
166 <Version>15</Version>
167 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
168 </Link>
169 </ItemDefinitionGroup>
170 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
171 <ClCompile>
172 <WarningLevel>Level4</WarningLevel>
173 <PrecompiledHeader>Use</PrecompiledHeader>
174 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
175 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
176 <FunctionLevelLinking>true</FunctionLevelLinking>
177 <IntrinsicFunctions>true</IntrinsicFunctions>
178 <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
179 <FloatingPointExceptions>false</FloatingPointExceptions>
180 <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>
181 <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>
182 <BrowseInformation>true</BrowseInformation>
183 <CompileAs>CompileAsC</CompileAs>
184 <StringPooling>true</StringPooling>
185 <MinimalRebuild>false</MinimalRebuild>
186 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
187 <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
188 <TreatWarningAsError>true</TreatWarningAsError>
189 <Optimization>Full</Optimization>
190 <WholeProgramOptimization>true</WholeProgramOptimization>
191 </ClCompile>
192 <Link>
193 <SubSystem>Windows</SubSystem>
194 <GenerateDebugInformation>true</GenerateDebugInformation>
195 <EnableCOMDATFolding>true</EnableCOMDATFolding>
196 <OptimizeReferences>true</OptimizeReferences>
197 </Link>
198 <Lib>
199 <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
200 </Lib>
201 </ItemDefinitionGroup>
202 <ItemGroup>
203 <ClCompile Include="..\..\..\png.c">
204 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
205 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">Create</PrecompiledHeader>
206 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
207 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">Create</PrecompiledHeader>
208 </ClCompile>
209 <ClCompile Include="..\..\..\pngerror.c" />
210 <ClCompile Include="..\..\..\pngget.c" />
211 <ClCompile Include="..\..\..\pngmem.c" />
212 <ClCompile Include="..\..\..\pngpread.c" />
213 <ClCompile Include="..\..\..\pngread.c" />
214 <ClCompile Include="..\..\..\pngrio.c" />
215 <ClCompile Include="..\..\..\pngrtran.c" />
216 <ClCompile Include="..\..\..\pngrutil.c" />
217 <ClCompile Include="..\..\..\pngset.c" />
218 <ClCompile Include="..\..\..\pngtrans.c" />
219 <ClCompile Include="..\..\..\pngwio.c" />
220 <ClCompile Include="..\..\..\pngwrite.c" />
221 <ClCompile Include="..\..\..\pngwtran.c" />
222 <ClCompile Include="..\..\..\pngwutil.c" />
223 </ItemGroup>
224 <ItemGroup>
225 <ResourceCompile Include="..\..\..\scripts\pngwin.rc">
226 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">true</ExcludedFromBuild>
227 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">true</ExcludedFromBuild>
228 </ResourceCompile>
229 </ItemGroup>
230 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
231 <ImportGroup Label="ExtensionTargets">
232 </ImportGroup>
233</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj
new file mode 100644
index 0000000..58ee997
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj
@@ -0,0 +1,60 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Release|Win32">
5 <Configuration>Release</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 </ItemGroup>
9 <PropertyGroup Label="Globals">
10 <ProjectGuid>{EB33566E-DA7F-4D28-9077-88C0B7C77E35}</ProjectGuid>
11 <RootNamespace>pnglibconf</RootNamespace>
12 </PropertyGroup>
13 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
14 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
15 <ConfigurationType>Application</ConfigurationType>
16 <UseDebugLibraries>false</UseDebugLibraries>
17 <WholeProgramOptimization>true</WholeProgramOptimization>
18 <CharacterSet>MultiByte</CharacterSet>
19 </PropertyGroup>
20 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
21 <ImportGroup Label="ExtensionSettings">
22 </ImportGroup>
23 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
24 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
25 </ImportGroup>
26 <PropertyGroup Label="UserMacros" />
27 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
28 <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>
29 </PropertyGroup>
30 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
31 <ClCompile>
32 <WarningLevel>Level3</WarningLevel>
33 <Optimization>MaxSpeed</Optimization>
34 <FunctionLevelLinking>true</FunctionLevelLinking>
35 <IntrinsicFunctions>true</IntrinsicFunctions>
36 </ClCompile>
37 <Link>
38 <GenerateDebugInformation>true</GenerateDebugInformation>
39 <EnableCOMDATFolding>true</EnableCOMDATFolding>
40 <OptimizeReferences>true</OptimizeReferences>
41 </Link>
42 <CustomBuildStep>
43 <Command>copy ..\..\..\scripts\pnglibconf.h.prebuilt ..\..\..\pnglibconf.h</Command>
44 </CustomBuildStep>
45 <CustomBuildStep>
46 <Message>Generating pnglibconf.h</Message>
47 </CustomBuildStep>
48 <CustomBuildStep>
49 <Outputs>..\..\..\pnglibconf.h</Outputs>
50 </CustomBuildStep>
51 <CustomBuildStep>
52 <Inputs>..\..\..\scripts\pnglibconf.h.prebuilt</Inputs>
53 </CustomBuildStep>
54 </ItemDefinitionGroup>
55 <ItemGroup>
56 </ItemGroup>
57 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
58 <ImportGroup Label="ExtensionTargets">
59 </ImportGroup>
60</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngtest/pngtest.vcxproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngtest/pngtest.vcxproj
new file mode 100644
index 0000000..bdbd839
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngtest/pngtest.vcxproj
@@ -0,0 +1,219 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug Library|Win32">
5 <Configuration>Debug Library</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|Win32">
9 <Configuration>Debug</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release Library|Win32">
13 <Configuration>Release Library</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|Win32">
17 <Configuration>Release</Configuration>
18 <Platform>Win32</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <PropertyGroup Label="Globals">
22 <ProjectGuid>{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}</ProjectGuid>
23 <Keyword>Win32Proj</Keyword>
24 <RootNamespace>pngtest</RootNamespace>
25 </PropertyGroup>
26 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27 <Import Project="$(SolutionDir)\zlib.props" />
28 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29 <ConfigurationType>Application</ConfigurationType>
30 <CharacterSet>Unicode</CharacterSet>
31 </PropertyGroup>
32 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
33 <ConfigurationType>Application</ConfigurationType>
34 <CharacterSet>Unicode</CharacterSet>
35 </PropertyGroup>
36 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37 <ConfigurationType>Application</ConfigurationType>
38 <CharacterSet>Unicode</CharacterSet>
39 </PropertyGroup>
40 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
41 <ConfigurationType>Application</ConfigurationType>
42 <CharacterSet>Unicode</CharacterSet>
43 </PropertyGroup>
44 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
45 <ImportGroup Label="ExtensionSettings">
46 </ImportGroup>
47 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
48 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
49 </ImportGroup>
50 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
51 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
52 </ImportGroup>
53 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
54 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
55 </ImportGroup>
56 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
57 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
58 </ImportGroup>
59 <PropertyGroup Label="UserMacros" />
60 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61 <LinkIncremental>false</LinkIncremental>
62 <CustomBuildAfterTargets />
63 </PropertyGroup>
64 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
65 <LinkIncremental>false</LinkIncremental>
66 <CustomBuildAfterTargets />
67 </PropertyGroup>
68 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
69 <LinkIncremental>false</LinkIncremental>
70 <CustomBuildAfterTargets />
71 </PropertyGroup>
72 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
73 <LinkIncremental>false</LinkIncremental>
74 <CustomBuildAfterTargets />
75 </PropertyGroup>
76 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77 <ClCompile>
78 <PrecompiledHeader>NotUsing</PrecompiledHeader>
79 <WarningLevel>Level4</WarningLevel>
80 <MinimalRebuild>false</MinimalRebuild>
81 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
82 <Optimization>Disabled</Optimization>
83 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
84 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
85 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
86 <DisableSpecificWarnings>4996</DisableSpecificWarnings>
87 <CompileAsManaged>false</CompileAsManaged>
88 <TreatWarningAsError>true</TreatWarningAsError>
89 <IntrinsicFunctions>true</IntrinsicFunctions>
90 <StringPooling>true</StringPooling>
91 <FunctionLevelLinking>false</FunctionLevelLinking>
92 <BrowseInformation>true</BrowseInformation>
93 <FloatingPointExceptions>false</FloatingPointExceptions>
94 </ClCompile>
95 <Link>
96 <SubSystem>Console</SubSystem>
97 <GenerateDebugInformation>true</GenerateDebugInformation>
98 <AdditionalDependencies>libpng15.lib</AdditionalDependencies>
99 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
100 </Link>
101 <CustomBuildStep>
102 <Message>Executing PNG test program</Message>
103 <Command>"$(OutDir)pngtest.exe" ..\..\..\pngtest.png "$(IntDir)pngout.png"</Command>
104 <Outputs>$(IntDir)pngout.png</Outputs>
105 <Inputs>..\..\..\pngtest.png;$(OutDir)pngtest.exe</Inputs>
106 </CustomBuildStep>
107 </ItemDefinitionGroup>
108 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
109 <ClCompile>
110 <PrecompiledHeader>NotUsing</PrecompiledHeader>
111 <WarningLevel>Level4</WarningLevel>
112 <MinimalRebuild>false</MinimalRebuild>
113 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
114 <Optimization>Disabled</Optimization>
115 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
116 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
117 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
119 <DisableSpecificWarnings>4996</DisableSpecificWarnings>
120 <CompileAsManaged>false</CompileAsManaged>
121 <TreatWarningAsError>true</TreatWarningAsError>
122 <IntrinsicFunctions>true</IntrinsicFunctions>
123 <StringPooling>true</StringPooling>
124 <FunctionLevelLinking>false</FunctionLevelLinking>
125 <BrowseInformation>true</BrowseInformation>
126 <FloatingPointExceptions>false</FloatingPointExceptions>
127 </ClCompile>
128 <Link>
129 <SubSystem>Console</SubSystem>
130 <GenerateDebugInformation>true</GenerateDebugInformation>
131 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
132 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
133 </Link>
134 <CustomBuildStep>
135 <Message>Executing PNG test program</Message>
136 <Command>"$(OutDir)pngtest.exe" ..\..\..\pngtest.png "$(IntDir)pngout.png"</Command>
137 <Outputs>$(IntDir)pngout.png</Outputs>
138 <Inputs>..\..\..\pngtest.png;$(OutDir)pngtest.exe</Inputs>
139 </CustomBuildStep>
140 </ItemDefinitionGroup>
141 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
142 <ClCompile>
143 <WarningLevel>Level4</WarningLevel>
144 <PrecompiledHeader>NotUsing</PrecompiledHeader>
145 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
146 <Optimization>Full</Optimization>
147 <FunctionLevelLinking>false</FunctionLevelLinking>
148 <IntrinsicFunctions>true</IntrinsicFunctions>
149 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
150 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
151 <DisableSpecificWarnings>4996</DisableSpecificWarnings>
152 <CompileAsManaged>false</CompileAsManaged>
153 <TreatWarningAsError>true</TreatWarningAsError>
154 <StringPooling>true</StringPooling>
155 <MinimalRebuild>false</MinimalRebuild>
156 <BrowseInformation>true</BrowseInformation>
157 <WholeProgramOptimization>true</WholeProgramOptimization>
158 <FloatingPointExceptions>false</FloatingPointExceptions>
159 </ClCompile>
160 <Link>
161 <SubSystem>Console</SubSystem>
162 <GenerateDebugInformation>true</GenerateDebugInformation>
163 <EnableCOMDATFolding>true</EnableCOMDATFolding>
164 <OptimizeReferences>true</OptimizeReferences>
165 <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
166 <AdditionalDependencies>libpng15.lib</AdditionalDependencies>
167 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
168 </Link>
169 <CustomBuildStep>
170 <Message>Executing PNG test program</Message>
171 <Command>"$(OutDir)pngtest.exe" ..\..\..\pngtest.png "$(IntDir)pngout.png"</Command>
172 <Outputs>$(IntDir)pngout.png</Outputs>
173 <Inputs>..\..\..\pngtest.png;$(OutDir)pngtest.exe</Inputs>
174 </CustomBuildStep>
175 </ItemDefinitionGroup>
176 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
177 <ClCompile>
178 <WarningLevel>Level4</WarningLevel>
179 <PrecompiledHeader>NotUsing</PrecompiledHeader>
180 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
181 <Optimization>Full</Optimization>
182 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
183 <FunctionLevelLinking>false</FunctionLevelLinking>
184 <IntrinsicFunctions>true</IntrinsicFunctions>
185 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
186 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
187 <DisableSpecificWarnings>4996</DisableSpecificWarnings>
188 <CompileAsManaged>false</CompileAsManaged>
189 <TreatWarningAsError>true</TreatWarningAsError>
190 <StringPooling>true</StringPooling>
191 <MinimalRebuild>false</MinimalRebuild>
192 <BrowseInformation>true</BrowseInformation>
193 <WholeProgramOptimization>true</WholeProgramOptimization>
194 <FloatingPointExceptions>false</FloatingPointExceptions>
195 </ClCompile>
196 <Link>
197 <SubSystem>Console</SubSystem>
198 <GenerateDebugInformation>true</GenerateDebugInformation>
199 <EnableCOMDATFolding>true</EnableCOMDATFolding>
200 <OptimizeReferences>true</OptimizeReferences>
201 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
202 <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
203 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
204 </Link>
205 <CustomBuildStep>
206 <Message>Executing PNG test program</Message>
207 <Command>$(OutDir)pngtest.exe ..\..\..\pngtest.png $(IntDir)pngout.png</Command>
208 <Command>"$(OutDir)pngtest.exe" ..\..\..\pngtest.png "$(IntDir)pngout.png"</Command>
209 <Outputs>$(IntDir)pngout.png</Outputs>
210 <Inputs>..\..\..\pngtest.png;$(OutDir)pngtest.exe</Inputs>
211 </CustomBuildStep>
212 </ItemDefinitionGroup>
213 <ItemGroup>
214 <ClCompile Include="..\..\..\pngtest.c" />
215 </ItemGroup>
216 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
217 <ImportGroup Label="ExtensionTargets">
218 </ImportGroup>
219</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj
new file mode 100644
index 0000000..56b6fd6
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj
@@ -0,0 +1,218 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug Library|Win32">
5 <Configuration>Debug Library</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|Win32">
9 <Configuration>Debug</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release Library|Win32">
13 <Configuration>Release Library</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|Win32">
17 <Configuration>Release</Configuration>
18 <Platform>Win32</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <PropertyGroup Label="Globals">
22 <ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>
23 <Keyword>Win32Proj</Keyword>
24 <RootNamespace>pngvalid</RootNamespace>
25 </PropertyGroup>
26 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27 <Import Project="$(SolutionDir)\zlib.props" />
28 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29 <ConfigurationType>Application</ConfigurationType>
30 <CharacterSet>Unicode</CharacterSet>
31 </PropertyGroup>
32 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
33 <ConfigurationType>Application</ConfigurationType>
34 <CharacterSet>Unicode</CharacterSet>
35 </PropertyGroup>
36 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
37 <ConfigurationType>Application</ConfigurationType>
38 <CharacterSet>Unicode</CharacterSet>
39 </PropertyGroup>
40 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
41 <ConfigurationType>Application</ConfigurationType>
42 <CharacterSet>Unicode</CharacterSet>
43 </PropertyGroup>
44 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
45 <ImportGroup Label="ExtensionSettings">
46 </ImportGroup>
47 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
48 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
49 </ImportGroup>
50 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
51 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
52 </ImportGroup>
53 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
54 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
55 </ImportGroup>
56 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
57 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
58 </ImportGroup>
59 <PropertyGroup Label="UserMacros" />
60 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61 <LinkIncremental>false</LinkIncremental>
62 <CustomBuildAfterTargets />
63 </PropertyGroup>
64 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
65 <LinkIncremental>false</LinkIncremental>
66 <CustomBuildAfterTargets />
67 </PropertyGroup>
68 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
69 <LinkIncremental>false</LinkIncremental>
70 <CustomBuildAfterTargets />
71 </PropertyGroup>
72 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
73 <LinkIncremental>false</LinkIncremental>
74 <CustomBuildAfterTargets />
75 </PropertyGroup>
76 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
77 <ClCompile>
78 <PrecompiledHeader>NotUsing</PrecompiledHeader>
79 <WarningLevel>Level4</WarningLevel>
80 <MinimalRebuild>false</MinimalRebuild>
81 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
82 <Optimization>Disabled</Optimization>
83 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
84 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
85 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
86 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
87 <CompileAsManaged>false</CompileAsManaged>
88 <TreatWarningAsError>true</TreatWarningAsError>
89 <IntrinsicFunctions>true</IntrinsicFunctions>
90 <StringPooling>true</StringPooling>
91 <FunctionLevelLinking>false</FunctionLevelLinking>
92 <BrowseInformation>true</BrowseInformation>
93 <FloatingPointExceptions>false</FloatingPointExceptions>
94 </ClCompile>
95 <Link>
96 <SubSystem>Console</SubSystem>
97 <GenerateDebugInformation>true</GenerateDebugInformation>
98 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
99 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
100 </Link>
101 <CustomBuildStep>
102 <Message>Executing PNG validation program</Message>
103 <Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
104 <Outputs>$(IntDir)pngvalid.out</Outputs>
105 <Inputs>$(OutDir)pngvalid.exe</Inputs>
106 </CustomBuildStep>
107 </ItemDefinitionGroup>
108 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
109 <ClCompile>
110 <PrecompiledHeader>NotUsing</PrecompiledHeader>
111 <WarningLevel>Level4</WarningLevel>
112 <MinimalRebuild>false</MinimalRebuild>
113 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
114 <Optimization>Disabled</Optimization>
115 <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
116 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
117 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
119 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
120 <CompileAsManaged>false</CompileAsManaged>
121 <TreatWarningAsError>true</TreatWarningAsError>
122 <IntrinsicFunctions>true</IntrinsicFunctions>
123 <StringPooling>true</StringPooling>
124 <FunctionLevelLinking>false</FunctionLevelLinking>
125 <BrowseInformation>true</BrowseInformation>
126 <FloatingPointExceptions>false</FloatingPointExceptions>
127 </ClCompile>
128 <Link>
129 <SubSystem>Console</SubSystem>
130 <GenerateDebugInformation>true</GenerateDebugInformation>
131 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
132 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
133 </Link>
134 <CustomBuildStep>
135 <Message>Executing PNG validation program</Message>
136 <Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
137 <Outputs>$(IntDir)pngvalid.out</Outputs>
138 <Inputs>$(OutDir)pngvalid.exe</Inputs>
139 </CustomBuildStep>
140 </ItemDefinitionGroup>
141 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
142 <ClCompile>
143 <WarningLevel>Level4</WarningLevel>
144 <PrecompiledHeader>NotUsing</PrecompiledHeader>
145 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
146 <Optimization>Full</Optimization>
147 <FunctionLevelLinking>false</FunctionLevelLinking>
148 <IntrinsicFunctions>true</IntrinsicFunctions>
149 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
150 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
151 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
152 <CompileAsManaged>false</CompileAsManaged>
153 <TreatWarningAsError>true</TreatWarningAsError>
154 <StringPooling>true</StringPooling>
155 <MinimalRebuild>false</MinimalRebuild>
156 <BrowseInformation>true</BrowseInformation>
157 <WholeProgramOptimization>true</WholeProgramOptimization>
158 <FloatingPointExceptions>false</FloatingPointExceptions>
159 </ClCompile>
160 <Link>
161 <SubSystem>Console</SubSystem>
162 <GenerateDebugInformation>true</GenerateDebugInformation>
163 <EnableCOMDATFolding>true</EnableCOMDATFolding>
164 <OptimizeReferences>true</OptimizeReferences>
165 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
166 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
167 <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
168 </Link>
169 <CustomBuildStep>
170 <Message>Executing PNG validation program</Message>
171 <Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
172 <Outputs>$(IntDir)pngvalid.out</Outputs>
173 <Inputs>$(OutDir)pngvalid.exe</Inputs>
174 </CustomBuildStep>
175 </ItemDefinitionGroup>
176 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
177 <ClCompile>
178 <WarningLevel>Level4</WarningLevel>
179 <PrecompiledHeader>NotUsing</PrecompiledHeader>
180 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
181 <Optimization>Full</Optimization>
182 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
183 <FunctionLevelLinking>false</FunctionLevelLinking>
184 <IntrinsicFunctions>true</IntrinsicFunctions>
185 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
186 <AdditionalIncludeDirectories>$(ZLibSrcDir);..\..\..\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
187 <DisableSpecificWarnings>4996;4127</DisableSpecificWarnings>
188 <CompileAsManaged>false</CompileAsManaged>
189 <TreatWarningAsError>true</TreatWarningAsError>
190 <StringPooling>true</StringPooling>
191 <MinimalRebuild>false</MinimalRebuild>
192 <BrowseInformation>true</BrowseInformation>
193 <WholeProgramOptimization>true</WholeProgramOptimization>
194 <FloatingPointExceptions>false</FloatingPointExceptions>
195 </ClCompile>
196 <Link>
197 <SubSystem>Console</SubSystem>
198 <GenerateDebugInformation>true</GenerateDebugInformation>
199 <EnableCOMDATFolding>true</EnableCOMDATFolding>
200 <OptimizeReferences>true</OptimizeReferences>
201 <AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies>
202 <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
203 <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
204 </Link>
205 <CustomBuildStep>
206 <Message>Executing PNG validation program</Message>
207 <Command>"$(OutDir)pngvalid.exe" --touch "$(IntDir)pngvalid.out"</Command>
208 <Outputs>$(IntDir)pngvalid.out</Outputs>
209 <Inputs>$(OutDir)pngvalid.exe</Inputs>
210 </CustomBuildStep>
211 </ItemDefinitionGroup>
212 <ItemGroup>
213 <ClCompile Include="..\..\..\contrib\libtests\pngvalid.c" />
214 </ItemGroup>
215 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
216 <ImportGroup Label="ExtensionTargets">
217 </ImportGroup>
218</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/readme.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/readme.txt
new file mode 100644
index 0000000..4828f55
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/readme.txt
@@ -0,0 +1,64 @@
1
2VisualStudio instructions
3
4libpng version 1.5.9 - February 18, 2012
5
6Copyright (c) 1998-2010 Glenn Randers-Pehrson
7
8This code is released under the libpng license.
9For conditions of distribution and use, see the disclaimer
10and license in png.h
11
12This directory contains support for building libpng under MicroSoft
13VisualStudio 2010. It may also work under later versions of VisualStudio.
14You should be familiar with VisualStudio before using this directory.
15
16Initial preparations
17====================
18You must enter some information in zlib.props before attempting to build
19with this 'solution'. Please read and edit zlib.props first. You will
20probably not be familiar with the contents of zlib.props - do not worry,
21it is mostly harmless.
22
23This is all you need to do to build the 'release' and 'release library'
24configurations.
25
26Debugging
27=========
28The release configurations default to /Ox optimization. Full debugging
29information is produced (in the .pdb), but if you encounter a problem the
30optimization may make it difficult to debug. Simply rebuild with a lower
31optimization level (e.g. /Od.)
32
33Linking your application
34========================
35Normally you should link against the 'release' configuration. This builds a
36DLL for libpng 1.5 with the default runtime options used by Visual Studio
372010. In particular the runtime library is the "MultiThreaded DLL" version.
38If you use Visual Studio defaults to build your application you will have no
39problems.
40
41If you don't use the Visual Studio defaults your application must still be built
42with the default runtime option (/MD). If, for some reason, it is not then your
43application will crash inside libpng15.dll as soon as libpng tries to read
44from a file handle you pass in.
45
46If you do not want to use the DLL, for example for a very small application,
47the 'release library' configuration may be more appropriate. This is built
48with a non-standard runtime library - the "MultiThreaded" version. When you
49build your application it must be compiled with this option (/MT), otherwise
50it will not build (if you are lucky) or crash (if you are not.)
51
52Stop reading here
53=================
54You have enough information to build a working application.
55
56Debug versions have limited support
57===================================
58This solution includes limited support for debug versions of libpng. You
59do not need these unless your own solution itself uses debug builds (it is
60far more effective to debug on the release builds, there is no point building
61a special debug build.)
62
63The debug build of libpng is minimally supported. Support for debug builds of
64zlib is also minimal. You really don't want to do this.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/vstudio.sln b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/vstudio.sln
new file mode 100644
index 0000000..c6c50e4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/vstudio.sln
@@ -0,0 +1,87 @@
1Microsoft Visual Studio Solution File, Format Version 11.00
2# Visual Studio 2010
3Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "libpng\libpng.vcxproj", "{D6973076-9317-4EF2-A0B8-B7A18AC0713E}"
4 ProjectSection(ProjectDependencies) = postProject
5 {60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
6 {EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
7 EndProjectSection
8EndProject
9Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngtest", "pngtest\pngtest.vcxproj", "{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}"
10 ProjectSection(ProjectDependencies) = postProject
11 {60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
12 {EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
13 {D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
14 EndProjectSection
15EndProject
16Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "zlib", "zlib\zlib.vcxproj", "{60F89955-91C6-3A36-8000-13C592FEC2DF}"
17EndProject
18Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pngvalid", "pngvalid\pngvalid.vcxproj", "{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}"
19 ProjectSection(ProjectDependencies) = postProject
20 {60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}
21 {EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}
22 {D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}
23 EndProjectSection
24EndProject
25Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pnglibconf", "pnglibconf\pnglibconf.vcxproj", "{EB33566E-DA7F-4D28-9077-88C0B7C77E35}"
26EndProject
27Global
28 GlobalSection(SolutionConfigurationPlatforms) = preSolution
29 Debug Library|Win32 = Debug Library|Win32
30 Debug|Win32 = Debug|Win32
31 Release Library|Win32 = Release Library|Win32
32 Release|Win32 = Release|Win32
33 EndGlobalSection
34 GlobalSection(ProjectConfigurationPlatforms) = postSolution
35 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
36 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug Library|Win32.Build.0 = Debug Library|Win32
37 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.ActiveCfg = Debug|Win32
38 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.Build.0 = Debug|Win32
39 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release Library|Win32.ActiveCfg = Release Library|Win32
40 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release Library|Win32.Build.0 = Release Library|Win32
41 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.ActiveCfg = Release|Win32
42 {D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.Build.0 = Release|Win32
43 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
44 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug Library|Win32.Build.0 = Debug Library|Win32
45 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug|Win32.ActiveCfg = Debug|Win32
46 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug|Win32.Build.0 = Debug|Win32
47 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release Library|Win32.ActiveCfg = Release Library|Win32
48 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release Library|Win32.Build.0 = Release Library|Win32
49 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.ActiveCfg = Release|Win32
50 {228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.Build.0 = Release|Win32
51 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
52 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug Library|Win32.Build.0 = Debug Library|Win32
53 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|Win32.ActiveCfg = Debug|Win32
54 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|Win32.Build.0 = Debug|Win32
55 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Release Library|Win32.ActiveCfg = Release Library|Win32
56 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Release Library|Win32.Build.0 = Release Library|Win32
57 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|Win32.ActiveCfg = Release|Win32
58 {60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|Win32.Build.0 = Release|Win32
59 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
60 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.Build.0 = Debug Library|Win32
61 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.ActiveCfg = Debug|Win32
62 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.Build.0 = Debug|Win32
63 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.ActiveCfg = Release Library|Win32
64 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.Build.0 = Release Library|Win32
65 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.ActiveCfg = Release|Win32
66 {9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.Build.0 = Release|Win32
67 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug Library|Win32.ActiveCfg = Release|Win32
68 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug Library|Win32.Build.0 = Release|Win32
69 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug|Win32.ActiveCfg = Release|Win32
70 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug|Win32.Build.0 = Release|Win32
71 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release Library|Win32.ActiveCfg = Release|Win32
72 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release Library|Win32.Build.0 = Release|Win32
73 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release|Win32.ActiveCfg = Release|Win32
74 {EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release|Win32.Build.0 = Release|Win32
75 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug Library|Win32.ActiveCfg = Debug Library|Win32
76 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug Library|Win32.Build.0 = Debug Library|Win32
77 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug|Win32.ActiveCfg = Debug|Win32
78 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug|Win32.Build.0 = Debug|Win32
79 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release Library|Win32.ActiveCfg = Release Library|Win32
80 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release Library|Win32.Build.0 = Release Library|Win32
81 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.ActiveCfg = Release|Win32
82 {277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.Build.0 = Release|Win32
83 EndGlobalSection
84 GlobalSection(SolutionProperties) = preSolution
85 HideSolutionNode = FALSE
86 EndGlobalSection
87EndGlobal
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib.props b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib.props
new file mode 100644
index 0000000..eaec606
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib.props
@@ -0,0 +1,37 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3 * zlib.props - location of zlib source
4 *
5 * libpng version 1.5.9 - February 18, 2012
6 *
7 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
12
13 * You must edit this file to record the location of the zlib
14 * source code.
15 -->
16
17<Project ToolsVersion="4.0"
18 xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
19 <PropertyGroup Label="Globals">
20 <!-- Place the name of the directory containing the source of zlib used for
21 debugging in this property.
22
23 The directory need only contain the '.c' and '.h' files from the
24 source.
25
26 If you use a relative directory name (as below) then it must be
27 relative to the project directories; these are one level deepers than
28 the directories containing this file.
29
30 If the version of zlib you use does not match that used when the
31 distribution was built you will get warnings from pngtest that the zlib
32 versions do not match. The zlib version used in this build is recorded
33 below:
34 -->
35 <ZLibSrcDir>..\..\..\..\zlib-1.2.5</ZLibSrcDir>
36 </PropertyGroup>
37</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib/zlib.vcxproj b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib/zlib.vcxproj
new file mode 100644
index 0000000..45dbeb5
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/projects/vstudio/zlib/zlib.vcxproj
@@ -0,0 +1,174 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug Library|Win32">
5 <Configuration>Debug Library</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|Win32">
9 <Configuration>Debug</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 <ProjectConfiguration Include="Release Library|Win32">
13 <Configuration>Release Library</Configuration>
14 <Platform>Win32</Platform>
15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|Win32">
17 <Configuration>Release</Configuration>
18 <Platform>Win32</Platform>
19 </ProjectConfiguration>
20 </ItemGroup>
21 <ItemGroup>
22 <ClCompile Include="$(ZLibSrcDir)\adler32.c" />
23 <ClCompile Include="$(ZLibSrcDir)\compress.c" />
24 <ClCompile Include="$(ZLibSrcDir)\crc32.c" />
25 <ClCompile Include="$(ZLibSrcDir)\deflate.c" />
26 <ClCompile Include="$(ZLibSrcDir)\infback.c" />
27 <ClCompile Include="$(ZLibSrcDir)\inffast.c" />
28 <ClCompile Include="$(ZLibSrcDir)\inflate.c" />
29 <ClCompile Include="$(ZLibSrcDir)\inftrees.c" />
30 <ClCompile Include="$(ZLibSrcDir)\trees.c" />
31 <ClCompile Include="$(ZLibSrcDir)\uncompr.c" />
32 <ClCompile Include="$(ZLibSrcDir)\zutil.c" />
33 </ItemGroup>
34 <PropertyGroup Label="Globals">
35 <Keyword>Win32Proj</Keyword>
36 </PropertyGroup>
37 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
38 <Import Project="$(SolutionDir)\zlib.props" />
39 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="Configuration">
40 <ConfigurationType>StaticLibrary</ConfigurationType>
41 </PropertyGroup>
42 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
43 <ConfigurationType>StaticLibrary</ConfigurationType>
44 </PropertyGroup>
45 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="Configuration">
46 <ConfigurationType>StaticLibrary</ConfigurationType>
47 </PropertyGroup>
48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
49 <ConfigurationType>StaticLibrary</ConfigurationType>
50 </PropertyGroup>
51 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
52 <ConfigurationType>StaticLibrary</ConfigurationType>
53 </PropertyGroup>
54 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55 <ImportGroup Label="ExtensionSettings">
56 </ImportGroup>
57 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'" Label="PropertySheets">
58 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
59 </ImportGroup>
60 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
61 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
62 </ImportGroup>
63 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'" Label="PropertySheets">
64 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
65 </ImportGroup>
66 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
67 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68 </ImportGroup>
69 <PropertyGroup Label="UserMacros" />
70 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
71 <LinkIncremental>true</LinkIncremental>
72 </PropertyGroup>
73 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74 <LinkIncremental>true</LinkIncremental>
75 </PropertyGroup>
76 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
77 <LinkIncremental>true</LinkIncremental>
78 </PropertyGroup>
79 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
80 <LinkIncremental>true</LinkIncremental>
81 </PropertyGroup>
82 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
83 <LinkIncremental>true</LinkIncremental>
84 </PropertyGroup>
85 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug Library|Win32'">
86 <ClCompile>
87 <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
88 <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
89 <WarningLevel>TurnOffAllWarnings</WarningLevel>
90 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
91 <Optimization>Disabled</Optimization>
92 <BrowseInformation>true</BrowseInformation>
93 </ClCompile>
94 <Link>
95 <TargetMachine>MachineX86</TargetMachine>
96 <GenerateDebugInformation>true</GenerateDebugInformation>
97 <SubSystem>Windows</SubSystem>
98 </Link>
99 </ItemDefinitionGroup>
100 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
101 <ClCompile>
102 <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
103 <WarningLevel>TurnOffAllWarnings</WarningLevel>
104 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
105 <Optimization>Disabled</Optimization>
106 <BrowseInformation>true</BrowseInformation>
107 </ClCompile>
108 <Link>
109 <TargetMachine>MachineX86</TargetMachine>
110 <GenerateDebugInformation>true</GenerateDebugInformation>
111 <SubSystem>Windows</SubSystem>
112 </Link>
113 </ItemDefinitionGroup>
114 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release Library|Win32'">
115 <ClCompile>
116 <WarningLevel>Level3</WarningLevel>
117 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
118 <Optimization>Full</Optimization>
119 <IntrinsicFunctions>true</IntrinsicFunctions>
120 <WholeProgramOptimization>true</WholeProgramOptimization>
121 <BufferSecurityCheck>false</BufferSecurityCheck>
122 <BrowseInformation>true</BrowseInformation>
123 <FunctionLevelLinking>true</FunctionLevelLinking>
124 <TreatWarningAsError>true</TreatWarningAsError>
125 <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
126 </ClCompile>
127 <Link>
128 <TargetMachine>MachineX86</TargetMachine>
129 <GenerateDebugInformation>true</GenerateDebugInformation>
130 <SubSystem>Windows</SubSystem>
131 </Link>
132 <Lib>
133 <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
134 </Lib>
135 </ItemDefinitionGroup>
136 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
137 <ClCompile>
138 <WarningLevel>Level3</WarningLevel>
139 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
140 <Optimization>Full</Optimization>
141 <IntrinsicFunctions>true</IntrinsicFunctions>
142 <WholeProgramOptimization>true</WholeProgramOptimization>
143 <BufferSecurityCheck>false</BufferSecurityCheck>
144 <BrowseInformation>true</BrowseInformation>
145 <FunctionLevelLinking>true</FunctionLevelLinking>
146 <TreatWarningAsError>true</TreatWarningAsError>
147 </ClCompile>
148 <Link>
149 <TargetMachine>MachineX86</TargetMachine>
150 <GenerateDebugInformation>true</GenerateDebugInformation>
151 <SubSystem>Windows</SubSystem>
152 </Link>
153 <Lib>
154 <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
155 </Lib>
156 </ItemDefinitionGroup>
157 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
158 <ClCompile>
159 <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
160 <WarningLevel>Level3</WarningLevel>
161 <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
162 </ClCompile>
163 <Link>
164 <TargetMachine>MachineX86</TargetMachine>
165 <GenerateDebugInformation>true</GenerateDebugInformation>
166 <SubSystem>Windows</SubSystem>
167 <EnableCOMDATFolding>true</EnableCOMDATFolding>
168 <OptimizeReferences>true</OptimizeReferences>
169 </Link>
170 </ItemDefinitionGroup>
171 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
172 <ImportGroup Label="ExtensionTargets">
173 </ImportGroup>
174</Project>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/README.txt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/README.txt
new file mode 100644
index 0000000..e0a229f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/README.txt
@@ -0,0 +1,76 @@
1
2Makefiles for libpng version 1.5.9 - February 18, 2012
3
4pnglibconf.h.prebuilt => Stores configuration settings
5 makefile.linux => Linux/ELF makefile
6 (gcc, creates libpng15.so.15.1.5.9)
7 makefile.gcc => Generic makefile (gcc, creates static libpng.a)
8 makefile.knr => Archaic UNIX Makefile that converts files with
9 ansi2knr (Requires ansi2knr.c from
10 ftp://ftp.cs.wisc.edu/ghost)
11 makefile.acorn => Acorn makefile
12 makefile.aix => AIX/gcc makefile
13 makefile.amiga => Amiga makefile
14 makefile.atari => Atari makefile
15 makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode)
16 makefile.beos => beos makefile
17 makefile.bor => Borland makefile (uses bcc)
18 makefile.cegcc => minge32ce for Windows CE makefile
19 makefile.darwin => Darwin makefile, can use on MacosX
20 makefile.dec => DEC Alpha UNIX makefile
21 makefile.dj2 => DJGPP 2 makefile
22 makefile.elf => Linux/ELF makefile symbol versioning,
23 (gcc, creates libpng15.so.15.1.5.9)
24 makefile.freebsd => FreeBSD makefile
25 makefile.gcc => Generic gcc makefile
26 makefile.hpgcc => HPUX makefile using gcc
27 makefile.hpux => HPUX (10.20 and 11.00) makefile
28 makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64-bit
29 makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
30 makefile.intel => Intel C/C++ version 4.0 and later
31 makefile.mips => MIPS makefile
32 makefile.msc => Microsoft C makefile
33 makefile.netbsd => NetBSD/cc makefile, makes libpng.so.
34 makefile.openbsd => OpenBSD makefile
35 makefile.os2 => OS/2 Makefile (gcc and emx, requires libpng.def)
36 makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
37 makefile.sggcc => Silicon Graphics (gcc,
38 creates libpng15.so.15.1.5.9)
39 makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
40 makefile.solaris => Solaris 2.X makefile (gcc,
41 creates libpng15.so.15.1.5.9)
42 makefile.so9 => Solaris 9 makefile (gcc,
43 creates libpng15.so.15.1.5.9)
44 makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
45 makefile.sunos => Sun makefile
46 makefile.32sunu => Sun Ultra 32-bit makefile
47 makefile.64sunu => Sun Ultra 64-bit makefile
48 makefile.tc3 => Turbo C 3.0 makefile
49 makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and later
50 makevms.com => VMS build script
51 smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
52 (Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
53
54Other supporting scripts:
55 README.txt => This file
56 descrip.mms => VMS makefile for MMS or MMK
57 libpng-config-body.in => used by several makefiles to create libpng-config
58 libpng-config-head.in => used by several makefiles to create libpng-config
59 libpng.pc.in => Used by several makefiles to create libpng.pc
60 pngwin.rc => Used by the visualc71 project.
61 pngwin.def => Used by makefile.os2
62 pngwin.dfn => Used to maintain pngwin.def
63 SCOPTIONS.ppc => Used with smakefile.ppc
64
65checksym.awk => Used for maintaining pnglibconf.h
66def.dfn => Used for maintaining pnglibconf.h
67options.awk => Used for maintaining pnglibconf.h
68pnglibconf.dfa => Used for maintaining pnglibconf.h
69pnglibconf.mak => Used for maintaining pnglibconf.h
70sym.dfn => Used for symbol versioning
71symbols.def => Used for symbol versioning
72symbols.dfn => Used for symbol versioning
73vers.dfn => Used for symbol versioning
74
75
76Further information can be found in comments in the individual makefiles.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/SCOPTIONS.ppc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/SCOPTIONS.ppc
new file mode 100644
index 0000000..7090fd4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/SCOPTIONS.ppc
@@ -0,0 +1,7 @@
1OPTIMIZE
2OPTPEEP
3OPTTIME
4OPTSCHED
5AUTOREGISTER
6PARMS=REGISTERS
7INCLUDEDIR=hlp:ppc/include
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/checksym.awk b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/checksym.awk
new file mode 100644
index 0000000..5bafa8c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/checksym.awk
@@ -0,0 +1,161 @@
1#!/bin/awk -f
2# Check a list of symbols against the master definition
3# (official) list. Arguments:
4#
5# awk -f checksym.awk official-def list-to-check
6#
7# Output is a file in the current directory called 'symbols.new',
8# stdout holds error messages. Error code indicates success or
9# failure.
10#
11# NOTE: this is a pure, old fashioned, awk script. It will
12# work with any awk
13
14BEGIN{
15 err=0
16 master="" # master file
17 official[1] = "" # defined symbols from master file
18 symbol[1] = "" # defined symbols from png.h
19 removed[1] = "" # removed symbols from png.h
20 lasto = 0 # last ordinal value from png.h
21 mastero = 0 # highest ordinal in master file
22 symbolo = 0 # highest ordinal in png.h
23 missing = "error"# log an error on missing symbols
24}
25
26# Read existing definitions from the master file (the first
27# file on the command line.) This must be a def file and it
28# has definition lines (others are ignored) of the form:
29#
30# symbol @ordinal
31#
32master == "" {
33 master = FILENAME
34}
35FILENAME==master && NF==2 && $2~/^@/ && $1!~/^;/ {
36 o=0+substr($2,2)
37 if (o > 0) {
38 if (official[o] == "") {
39 official[o] = $1
40 if (o > mastero) mastero = o
41 next
42 } else
43 print master ": duplicated symbol:", official[o] ":", $0
44 } else
45 print master ": bad export line format:", $0
46 err = 1
47}
48FILENAME==master && $1==";missing" && NF==2{
49 # This allows the master file to control how missing symbols
50 # are handled; symbols that aren't in either the master or
51 # the new file. Valid values are 'ignore', 'warning' and
52 # 'error'
53 missing = $2
54}
55FILENAME==master {
56 next
57}
58
59# Read new definitions, these are free form but the lines must
60# just be symbol definitions. Lines will be commented out for
61# 'removed' symbols, introduced in png.h using PNG_REMOVED rather
62# than PNG_EXPORT. Use symbols.dfn or pngwin.dfn to generate the
63# input file.
64#
65# symbol @ordinal # two fields, exported symbol
66# ; symbol @ordinal # three fields, removed symbol
67# ; @ordinal # two fields, the last ordinal
68NF==2 && $1 == ";" && $2 ~ /^@[1-9][0-9]*$/ { # last ordinal
69 o=0+substr($2,2)
70 if (lasto == 0 || lasto == o)
71 lasto=o
72 else {
73 print "png.h: duplicated last ordinal:", lasto, o
74 err = 1
75 }
76 next
77}
78NF==3 && $1 == ";" && $3 ~ /^@[1-9][0-9]*$/ { # removed symbol
79 o=0+substr($3,2)
80 if (removed[o] == "" || removed[o] == $2) {
81 removed[o] = $2
82 if (o > symbolo) symbolo = o
83 } else {
84 print "png.h: duplicated removed symbol", o ": '" removed[o] "' != '" $2 "'"
85 err = 1
86 }
87 next
88}
89NF==2 && $2 ~ /^@[1-9][0-9]*$/ { # exported symbol
90 o=0+substr($2,2)
91 if (symbol[o] == "" || symbol[o] == $1) {
92 symbol[o] = $1
93 if (o > symbolo) symbolo = o
94 } else {
95 print "png.h: duplicated symbol", o ": '" symbol[o] "' != '" $1 "'"
96 err = 1
97 }
98}
99{
100 next # skip all other lines
101}
102
103# At the end check for symbols marked as both duplicated and removed
104END{
105 if (symbolo > lasto) {
106 print "highest symbol ordinal in png.h,", symbolo ", exceeds last ordinal from png.h", lasto
107 err = 1
108 }
109 if (mastero > lasto) {
110 print "highest symbol ordinal in", master ",", mastero ", exceeds last ordinal from png.h", lasto
111 err = 1
112 }
113 unexported=0
114 for (o=1; o<=lasto; ++o) {
115 if (symbol[o] == "" && removed[o] == "") {
116 if (unexported == 0) unexported = o
117 if (official[o] == "") {
118 # missing in export list too, so ok
119 if (o < lasto) continue
120 }
121 }
122 if (unexported != 0) {
123 # Symbols in the .def but not in the new file are errors, but
124 # the 'unexported' symbols aren't in either. By default this
125 # is an error too (see the setting of 'missing' at the start),
126 # but this can be reset on the command line or by stuff in the
127 # file - see the comments above.
128 if (missing != "ignore") {
129 if (o-1 > unexported)
130 print "png.h:", missing ": missing symbols:", unexported "-" o-1
131 else
132 print "png.h:", missing ": missing symbol:", unexported
133 if (missing != "warning")
134 err = 1
135 }
136 unexported = 0
137 }
138 if (symbol[o] != "" && removed[o] != "") {
139 print "png.h: symbol", o, "both exported as '" symbol[o] "' and removed as '" removed[o] "'"
140 err = 1
141 } else if (symbol[o] != official[o]) {
142 # either the symbol is missing somewhere or it changed
143 err = 1
144 if (symbol[o] == "")
145 print "png.h: symbol", o, "is exported as '" official[o] "' in", master
146 else if (official[o] == "")
147 print "png.h: exported symbol", o, "'" symbol[o] "' not present in", master
148 else
149 print "png.h: exported symbol", o, "'" symbol[o] "' exists as '" official[o] "' in", master
150 }
151
152 # Finally generate symbols.new
153 if (symbol[o] != "")
154 print " " symbol[o], "@" o > "symbols.new"
155 }
156
157 if (err != 0) {
158 print "*** A new list is in symbols.new ***"
159 exit 1
160 }
161}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/chkfmt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/chkfmt
new file mode 100644
index 0000000..80b4917
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/chkfmt
@@ -0,0 +1,137 @@
1#!/bin/sh
2#
3# Check the format of the source files in the current directory - checks for a
4# line length of 80 characters max and no tab characters.
5#
6# Optionally arguments are files or directories to check.
7#
8# -v: output the long lines (makes fixing them easier)
9# -e: spawn an editor for each file that needs a change ($EDITOR must be
10# defined). When using -e the script MUST be run from an interactive
11# command line.
12verbose=
13edit=
14vers=
15test "$1" = "-v" && {
16 shift
17 verbose=yes
18}
19test "$1" = "-e" && {
20 shift
21 if test -n "$EDITOR"
22 then
23 edit=yes
24
25 # Copy the standard streams for the editor
26 exec 3>&0 4>&1 5>&2
27 else
28 echo "chkfmt -e: EDITOR must be defined" >&2
29 exit 1
30 fi
31}
32
33# Function to edit a single file - if the file isn't changed ask the user
34# whether or not to continue. This stuff only works if the script is run from
35# the command line (otherwise, don't specify -e or you will be sorry).
36doed(){
37 cp "$file" "$file".orig
38 "$EDITOR" "$file" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1
39 if cmp -s "$file".orig "$file"
40 then
41 rm "$file".orig
42 echo -n "$file: file not changed, type anything to continue: " >&5
43 read ans 0>&3
44 test -n "$ans" || return 1
45 fi
46 return 0
47}
48
49# In beta versions the version string which appears in files can be a little
50# long and cause spuriously overlong lines. To avoid this subtitute the version
51# string with a 'standard' version a.b.cc before checking for long lines.
52if test -r png.h
53then
54 vers="`sed -n -e \
55 's/^#define PNG_LIBPNG_VER_STRING .\([0-9]\.[0-9]\.[0-9][0-9a-z]*\).$/\1/p' \
56 png.h`"
57 echo "chkfmt: checking version $vers"
58fi
59if test -z "$vers"
60then
61 echo "chkfmt: png.h not found, ignoring version number" >&2
62fi
63
64test -n "$1" || set -- .
65find "$@" \( -type d \( -name '.git' -o -name '.libs' -o -name 'projects' \) \
66 -prune \) -o \( -type f \
67 ! -name '*.[oa]' ! -name '*.l[oa]' ! -name '*.png' ! -name '*.out' \
68 ! -name '*.jpg' ! -name '*.patch' ! -name '*.obj' ! -name '*.exe' \
69 ! -name '*.com' ! -name '*.tar.*' ! -name '*.zip' ! -name '*.ico' \
70 ! -name '*.res' ! -name '*.rc' ! -name '*.mms' ! -name '*.rej' \
71 ! -name '*.dsp' ! -name '*.orig' ! -name '*.dfn' ! -name '*.swp' \
72 ! -name '~*' ! -name '*.3' \
73 ! -name 'missing' ! -name 'mkinstalldirs' ! -name 'depcomp' \
74 ! -name 'aclocal.m4' ! -name 'install-sh' ! -name 'Makefile.in' \
75 ! -name 'ltmain.sh' ! -name 'config*' -print \) | {
76 st=0
77 while read file
78 do
79 case "$file" in
80 *.mak|*[Mm]akefile.*|*[Mm]akefile)
81 # Makefiles require tabs, dependency lines can be this long.
82 check_tabs=
83 line_length=100;;
84 *.awk)
85 # Includes literal tabs
86 check_tabs=
87 # The following is arbitrary
88 line_length=132;;
89 *contrib/*/*.[ch])
90 check_tabs=yes
91 line_length=96;;
92 *)
93 check_tabs=yes
94 line_length=80;;
95 esac
96
97 # Note that vers can only contain 0-9, . and a-z
98 if test -n "$vers"
99 then
100 sed -e "s/$vers/a.b.cc/g" "$file" >"$file".$$
101 else
102 cp "$file" "$file".$$
103 fi
104 splt="`fold -$line_length "$file".$$ | diff -c "$file".$$ -`"
105 rm "$file".$$
106
107 if test -n "$splt"
108 then
109 echo "$file: lines too long"
110 st=1
111 if test -n "$EDITOR" -a -n "$edit"
112 then
113 doed "$file" || exit 1
114 elif test -n "$verbose"
115 then
116 echo "$splt"
117 fi
118 fi
119 if test -n "$check_tabs"
120 then
121 tab="`tr -c -d '\t' <"$file"`"
122 if test -n "$tab"
123 then
124 echo "$file: file contains tab characters"
125 st=1
126 if test -n "$EDITOR" -a -n "$edit"
127 then
128 doed "$file" || exit 1
129 elif test -n "$verbose"
130 then
131 echo "$splt"
132 fi
133 fi
134 fi
135 done
136 exit $st
137}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/def.dfn b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/def.dfn
new file mode 100644
index 0000000..c7ed8ab
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/def.dfn
@@ -0,0 +1,38 @@
1/* def.dfn - define format of libpng.def
2 *
3 * Last changed in libpng version 1.5.7 [December 15, 2011]
4 * Copyright (c) 2010-2011 Glenn Randers-Pehrson
5 *
6 * This code is released under the libpng license.
7 * For conditions of distribution and use, see the disclaimer
8 * and license in png.h
9 */
10
11/* These macros exist to make the header and trailer shorter below: */
12#define S PNG_DEFN_MAGIC
13#define E PNG_DEFN_END
14
15/* Write the export file header: */
16S-;---------------------------------------------------------------E
17S-; LIBPNG module definition file for OS/2-E
18S-;---------------------------------------------------------------E
19S--E
20S-; If you give the library an explicit name one or other files-E
21S-; may need modifying to support the new name on one or more-E
22S-; systems.-E
23S-LIBRARY-E
24S-OS2 DESCRIPTION "PNG image compression library"-E
25S-OS2 CODE PRELOAD MOVEABLE DISCARDABLE-E
26S--E
27S-EXPORTS-E
28S-;Version 1.5.0beta58-E
29
30/* NOTE: PNG_JOIN is interpreted by the calling script as a signal to
31 * join the two things on either side, so we can do symbol
32 * substitution within the name, regular C ## joins the pp-tokens,
33 * not their final values.
34 */
35#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
36 PNG_DEFN_MAGIC- SYMBOL_PREFIX PNG_JOIN name-PNG_DEFN_END
37
38#include "../png.h"
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/descrip.mms b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/descrip.mms
new file mode 100644
index 0000000..9ba2d5f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/descrip.mms
@@ -0,0 +1,52 @@
1
2cc_defs = /inc=$(ZLIBSRC)
3c_deb =
4
5.ifdef __DECC__
6pref = /prefix=all
7.endif
8
9
10
11OBJS = png.obj, pngset.obj, pngget.obj, pngrutil.obj, pngtrans.obj,\
12 pngwutil.obj, pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj,\
13 pngwtran.obj, pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj
14
15
16CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
17
18all : pngtest.exe libpng.olb
19 @ write sys$output " pngtest available"
20
21libpng.olb : libpng.olb($(OBJS))
22 @ write sys$output " Libpng available"
23
24
25pngtest.exe : pngtest.obj libpng.olb
26 link pngtest,libpng.olb/lib,$(ZLIBSRC)libz.olb/lib
27
28test : pngtest.exe
29 run pngtest
30
31clean :
32 delete *.obj;*,*.exe;
33
34
35# Other dependencies.
36png.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
37pngpread.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
38pngset.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
39pngget.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
40pngread.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
41pngrtran.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
42pngrutil.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
43pngerror.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
44pngmem.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
45pngrio.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
46pngwio.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
47pngtrans.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
48pngwrite.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
49pngwtran.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
50pngwutil.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h, pnginfo.h, pngdebug.h
51
52pngtest.obj : png.h, pngconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-body.in b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-body.in
new file mode 100644
index 0000000..0db8898
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-body.in
@@ -0,0 +1,96 @@
1
2usage()
3{
4 cat <<EOF
5Usage: libpng-config [OPTION] ...
6
7Known values for OPTION are:
8
9 --prefix print libpng prefix
10 --libdir print path to directory containing library
11 --libs print library linking information
12 --ccopts print compiler options
13 --cppflags print pre-processor flags
14 --cflags print preprocessor flags, I_opts, and compiler options
15 --I_opts print "-I" include options
16 --L_opts print linker "-L" flags for dynamic linking
17 --R_opts print dynamic linker "-R" or "-rpath" flags
18 --ldopts print linker options
19 --ldflags print linker flags (ldopts, L_opts, R_opts, and libs)
20 --static revise subsequent outputs for static linking
21 --help print this help and exit
22 --version print version information
23EOF
24
25 exit $1
26}
27
28if test $# -eq 0; then
29 usage 1
30fi
31
32while test $# -gt 0; do
33 case "$1" in
34
35 --prefix)
36 echo ${prefix}
37 ;;
38
39 --version)
40 echo ${version}
41 exit 0
42 ;;
43
44 --help)
45 usage 0
46 ;;
47
48 --ccopts)
49 echo ${ccopts}
50 ;;
51
52 --cppflags)
53 echo ${cppflags}
54 ;;
55
56 --cflags)
57 echo ${I_opts} ${cppflags} ${ccopts}
58 ;;
59
60 --libdir)
61 echo ${libdir}
62 ;;
63
64 --libs)
65 echo ${libs}
66 ;;
67
68 --I_opts)
69 echo ${I_opts}
70 ;;
71
72 --L_opts)
73 echo ${L_opts}
74 ;;
75
76 --R_opts)
77 echo ${R_opts}
78 ;;
79
80 --ldflags)
81 echo ${ldflags} ${L_opts} ${R_opts} ${libs}
82 ;;
83
84 --static)
85 R_opts=""
86 ;;
87
88 *)
89 usage
90 exit 1
91 ;;
92 esac
93 shift
94done
95
96exit 0
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-head.in b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-head.in
new file mode 100644
index 0000000..154bb39
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng-config-head.in
@@ -0,0 +1,24 @@
1#! /bin/sh
2
3# libpng-config
4# provides configuration info for libpng.
5
6# Copyright (C) 2002 Glenn Randers-Pehrson
7
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# Modeled after libxml-config.
13
14version=1.5.9
15prefix=""
16libdir=""
17libs=""
18I_opts=""
19L_opts=""
20R_opts=""
21cppflags=""
22ccopts=""
23ldopts=""
24
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng.pc.in b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng.pc.in
new file mode 100644
index 0000000..2f647c2
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/libpng.pc.in
@@ -0,0 +1,10 @@
1prefix=@prefix@
2exec_prefix=@exec_prefix@
3libdir=@libdir@
4includedir=@includedir@/libpng15
5
6Name: libpng
7Description: Loads and saves PNG files
8Version: 1.5.9
9Libs: -L${libdir} -lpng15
10Cflags: -I${includedir}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.32sunu b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.32sunu
new file mode 100644
index 0000000..a6279ad
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.32sunu
@@ -0,0 +1,241 @@
1# makefile for libpng on Solaris 2.x with cc
2# Contributed by William L. Sebok, based on makefile.linux
3# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson
4# Copyright (C) 1998 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME=libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22CC=cc
23AR_RC=ar rc
24MKDIR_P=mkdir -p
25LN_SF=ln -f -s
26RANLIB=echo
27RM_F=/bin/rm -f
28
29SUN_CC_FLAGS=-fast -xtarget=ultra
30SUN_LD_FLAGS=-fast -xtarget=ultra
31
32# where make install puts libpng.a, libpng15.so and libpng15/png.h
33prefix=/a
34exec_prefix=$(prefix)
35
36# Where the zlib library and include files are located
37# Changing these to ../zlib poses a security risk. If you want
38# to have zlib in an adjacent directory, specify the full path instead of "..".
39#ZLIBLIB=../zlib
40#ZLIBINC=../zlib
41
42ZLIBLIB=/usr/lib
43ZLIBINC=/usr/include
44
45WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
46 -Wmissing-declarations -Wtraditional -Wcast-align \
47 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
48CFLAGS=-I$(ZLIBINC) $(SUN_CC_FLAGS) \
49 # $(WARNMORE) -g -DPNG_DEBUG=5
50LDFLAGS=$(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) libpng.a -lz -lm
51
52INCPATH=$(prefix)/include
53LIBPATH=$(exec_prefix)/lib
54MANPATH=$(prefix)/man
55BINPATH=$(exec_prefix)/bin
56
57# override DESTDIR= on the make install command line to easily support
58# installing into a temporary location. Example:
59#
60# make install DESTDIR=/tmp/build/libpng
61#
62# If you're going to install into a temporary location
63# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
64# you execute make install.
65DESTDIR=
66
67DB=$(DESTDIR)$(BINPATH)
68DI=$(DESTDIR)$(INCPATH)
69DL=$(DESTDIR)$(LIBPATH)
70DM=$(DESTDIR)$(MANPATH)
71
72OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
73 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
74 pngwtran.o pngmem.o pngerror.o pngpread.o
75
76OBJSDLL = $(OBJS:.o=.pic.o)
77
78.SUFFIXES: .c .o .pic.o
79
80.c.pic.o:
81 $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c
82
83all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
84
85include scripts/pnglibconf.mak
86DELETE = $(RM_F)
87DFNFLAGS = $(DEFS) $(CPPFLAGS)
88
89libpng.a: $(OBJS)
90 $(AR_RC) $@ $(OBJS)
91 $(RANLIB) $@
92
93libpng.pc:
94 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
95 -e s!@exec_prefix@!$(exec_prefix)! \
96 -e s!@libdir@!$(LIBPATH)! \
97 -e s!@includedir@!$(INCPATH)! \
98 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
99
100libpng-config:
101 ( cat scripts/libpng-config-head.in; \
102 echo prefix=\"$(prefix)\"; \
103 echo libdir=\"$(LIBPATH)\"; \
104 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
105 echo L_opts=\"-L$(LIBPATH)\"; \
106 echo R_opts=\"-R$(LIBPATH)\"; \
107 echo ccopts=\"-xtarget=ultra\"; \
108 echo ldopts=\"-xtarget=ultra\"; \
109 echo libs=\"-lpng15 -lz -lm\"; \
110 cat scripts/libpng-config-body.in ) > libpng-config
111 chmod +x libpng-config
112
113$(LIBSO): $(LIBSOMAJ)
114 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
115
116$(LIBSOMAJ): $(OBJSDLL)
117 @case "`type ld`" in *ucb*) \
118 echo; \
119 echo '## WARNING:'; \
120 echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \
121 echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \
122 echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \
123 echo '## The environment variable LD_LIBRARY_PATH should not be set'; \
124 echo '## at all. If it is, things are likely to break because of'; \
125 echo '## the libucb dependency that is created.'; \
126 echo; \
127 ;; \
128 esac
129 $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \
130 -o $(LIBSOMAJ) $(OBJSDLL)
131
132pngtest: pngtest.o $(LIBSO)
133 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
134
135test: pngtest
136 ./pngtest
137
138install-headers: png.h pngconf.h pnglibconf.h
139 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
140 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
141 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
142 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
143 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
144 -@$(RM_F) $(DI)/libpng
145 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
146
147install-static: install-headers libpng.a
148 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
149 cp libpng.a $(DL)/$(LIBNAME).a
150 chmod 644 $(DL)/$(LIBNAME).a
151 -@$(RM_F) $(DL)/libpng.a
152 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
153
154install-shared: install-headers $(LIBSOMAJ) libpng.pc
155 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
156 -@$(RM_F) $(DL)/$(LIBSO)
157 -@$(RM_F) $(DL)/$(LIBSOREL)
158 -@$(RM_F) $(DL)/$(OLDSO)
159 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
160 chmod 755 $(DL)/$(LIBSOREL)
161 (cd $(DL); \
162 $(LN_SF) $(LIBSOREL) $(LIBSO); \
163 $(LN_SF) $(LIBSO) $(OLDSO))
164 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
165 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
166 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
167 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
168 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
169 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
170
171install-man: libpng.3 libpngpf.3 png.5
172 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
173 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
174 -@$(RM_F) $(DM)/man3/libpng.3
175 -@$(RM_F) $(DM)/man3/libpngpf.3
176 cp libpng.3 $(DM)/man3
177 cp libpngpf.3 $(DM)/man3
178 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
179 -@$(RM_F) $(DM)/man5/png.5
180 cp png.5 $(DM)/man5
181
182install-config: libpng-config
183 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
184 -@$(RM_F) $(DB)/libpng-config
185 -@$(RM_F) $(DB)/$(LIBNAME)-config
186 cp libpng-config $(DB)/$(LIBNAME)-config
187 chmod 755 $(DB)/$(LIBNAME)-config
188 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
189
190install: install-static install-shared install-man install-config
191
192# If you installed in $(DESTDIR), test-installed won't work until you
193# move the library to its final location. Use test-dd to test it
194# before then.
195
196test-dd:
197 echo
198 echo Testing installed dynamic shared library in $(DL).
199 $(CC) $(SUN_CC_FLAGS) -I$(DI) -I$(ZLIBINC) \
200 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
201 -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \
202 $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)
203 ./pngtestd pngtest.png
204
205test-installed:
206 echo
207 echo Testing installed dynamic shared library.
208 $(CC) $(SUN_CC_FLAGS) -I$(ZLIBINC) \
209 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
210 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \
211 $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)
212 ./pngtesti pngtest.png
213
214clean:
215 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
216 libpng-config $(LIBSO) $(LIBSOMAJ)* \
217 libpng.pc
218
219DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
220writelock:
221 chmod a-w *.[ch35] $(DOCS) scripts/*
222
223# DO NOT DELETE THIS LINE -- make depend depends on it.
224
225png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
236pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
237pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
238pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
239pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
240
241pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.64sunu b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.64sunu
new file mode 100644
index 0000000..5a5195d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.64sunu
@@ -0,0 +1,241 @@
1# makefile for libpng on Solaris 2.x with cc
2# Contributed by William L. Sebok, based on makefile.linux
3# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson
4# Copyright (C) 1998 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME=libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22CC=cc
23AR_RC=ar rc
24MKDIR_P=mkdir -p
25LN_SF=ln -f -s
26RANLIB=echo
27RM_F=/bin/rm -f
28
29SUN_CC_FLAGS=-fast -xtarget=ultra -xarch=v9
30SUN_LD_FLAGS=-fast -xtarget=ultra -xarch=v9
31
32# where make install puts libpng.a, libpng15.so and libpng15/png.h
33prefix=/a
34exec_prefix=$(prefix)
35
36# Where the zlib library and include files are located
37# Changing these to ../zlib poses a security risk. If you want
38# to have zlib in an adjacent directory, specify the full path instead of "..".
39#ZLIBLIB=../zlib
40#ZLIBINC=../zlib
41
42ZLIBLIB=/usr/lib
43ZLIBINC=/usr/include
44
45WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
46 -Wmissing-declarations -Wtraditional -Wcast-align \
47 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
48CFLAGS=-I$(ZLIBINC) $(SUN_CC_FLAGS) \
49 # $(WARNMORE) -g -DPNG_DEBUG=5
50LDFLAGS=-L. -R. $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng15 -lz -lm
51
52INCPATH=$(prefix)/include
53LIBPATH=$(exec_prefix)/lib
54MANPATH=$(prefix)/man
55BINPATH=$(exec_prefix)/bin
56
57# override DESTDIR= on the make install command line to easily support
58# installing into a temporary location. Example:
59#
60# make install DESTDIR=/tmp/build/libpng
61#
62# If you're going to install into a temporary location
63# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
64# you execute make install.
65DESTDIR=
66
67DB=$(DESTDIR)$(BINPATH)
68DI=$(DESTDIR)$(INCPATH)
69DL=$(DESTDIR)$(LIBPATH)
70DM=$(DESTDIR)$(MANPATH)
71
72OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
73 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
74 pngwtran.o pngmem.o pngerror.o pngpread.o
75
76OBJSDLL = $(OBJS:.o=.pic.o)
77
78.SUFFIXES: .c .o .pic.o
79
80.c.pic.o:
81 $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c
82
83all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
84
85include scripts/pnglibconf.mak
86DELETE = $(RM_F)
87DFNFLAGS = $(DEFS) $(CPPFLAGS)
88
89libpng.a: $(OBJS)
90 $(AR_RC) $@ $(OBJS)
91 $(RANLIB) $@
92
93libpng.pc:
94 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
95 -e s!@exec_prefix@!$(exec_prefix)! \
96 -e s!@libdir@!$(LIBPATH)! \
97 -e s!@includedir@!$(INCPATH)! \
98 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
99
100libpng-config:
101 ( cat scripts/libpng-config-head.in; \
102 echo prefix=\"$(prefix)\"; \
103 echo libdir=\"$(LIBPATH)\"; \
104 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
105 echo L_opts=\"-L$(LIBPATH)\"; \
106 echo R_opts=\"-R$(LIBPATH)\"; \
107 echo ccopts=\"-xtarget=ultra -xarch=v9\"; \
108 echo ldopts=\"-xtarget=ultra -xarch=v9\"; \
109 echo libs=\"-lpng15 -lz -lm\"; \
110 cat scripts/libpng-config-body.in ) > libpng-config
111 chmod +x libpng-config
112
113$(LIBSO): $(LIBSOMAJ)
114 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
115
116$(LIBSOMAJ): $(OBJSDLL)
117 @case "`type ld`" in *ucb*) \
118 echo; \
119 echo '## WARNING:'; \
120 echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \
121 echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \
122 echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \
123 echo '## The environment variable LD_LIBRARY_PATH should not be set'; \
124 echo '## at all. If it is, things are likely to break because of'; \
125 echo '## the libucb dependency that is created.'; \
126 echo; \
127 ;; \
128 esac
129 $(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \
130 -o $(LIBSOMAJ) $(OBJSDLL)
131
132pngtest: pngtest.o $(LIBSO)
133 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
134
135test: pngtest
136 ./pngtest
137
138install-headers: png.h pngconf.h
139 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
140 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
141 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
142 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
143 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
144 -@$(RM_F) $(DI)/libpng
145 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
146
147install-static: install-headers libpng.a
148 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
149 cp libpng.a $(DL)/$(LIBNAME).a
150 chmod 644 $(DL)/$(LIBNAME).a
151 -@$(RM_F) $(DL)/libpng.a
152 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
153
154install-shared: install-headers $(LIBSOMAJ) libpng.pc
155 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
156 -@$(RM_F) $(DL)/$(LIBSO)
157 -@$(RM_F) $(DL)/$(LIBSOREL)
158 -@$(RM_F) $(DL)/$(OLDSO)
159 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
160 chmod 755 $(DL)/$(LIBSOREL)
161 (cd $(DL); \
162 $(LN_SF) $(LIBSOREL) $(LIBSO); \
163 $(LN_SF) $(LIBSO) $(OLDSO))
164 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
165 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
166 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
167 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
168 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
169 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
170
171install-man: libpng.3 libpngpf.3 png.5
172 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
173 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
174 -@$(RM_F) $(DM)/man3/libpng.3
175 -@$(RM_F) $(DM)/man3/libpngpf.3
176 cp libpng.3 $(DM)/man3
177 cp libpngpf.3 $(DM)/man3
178 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
179 -@$(RM_F) $(DM)/man5/png.5
180 cp png.5 $(DM)/man5
181
182install-config: libpng-config
183 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
184 -@$(RM_F) $(DB)/libpng-config
185 -@$(RM_F) $(DB)/$(LIBNAME)-config
186 cp libpng-config $(DB)/$(LIBNAME)-config
187 chmod 755 $(DB)/$(LIBNAME)-config
188 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
189
190install: install-static install-shared install-man install-config
191
192# If you installed in $(DESTDIR), test-installed won't work until you
193# move the library to its final location. Use test-dd to test it
194# before then.
195
196test-dd:
197 echo
198 echo Testing installed dynamic shared library in $(DL).
199 $(CC) $(SUN_CC_FLAGS) -I$(DI) -I$(ZLIBINC) \
200 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
201 -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \
202 $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)
203 ./pngtestd pngtest.png
204
205test-installed:
206 echo
207 echo Testing installed dynamic shared library.
208 $(CC) $(SUN_CC_FLAGS) -I$(ZLIBINC) \
209 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
210 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \
211 $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)
212 ./pngtesti pngtest.png
213
214clean:
215 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
216 libpng-config $(LIBSO) $(LIBSOMAJ)* \
217 libpng.pc
218
219DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
220writelock:
221 chmod a-w *.[ch35] $(DOCS) scripts/*
222
223# DO NOT DELETE THIS LINE -- make depend depends on it.
224
225png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
236pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
237pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
238pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
239pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
240
241pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.acorn b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.acorn
new file mode 100644
index 0000000..4181913
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.acorn
@@ -0,0 +1,57 @@
1# Project: libpng
2
3
4# Toolflags:
5CCflags = -c -depend !Depend -IC:,Zlib: -g -throwback -DRISCOS -fnah
6C++flags = -c -depend !Depend -IC: -throwback
7Linkflags = -aif -c++ -o $@
8ObjAsmflags = -throwback -NoCache -depend !Depend
9CMHGflags =
10LibFileflags = -c -l -o $@
11Squeezeflags = -o $@
12
13# Final targets:
14@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
15 @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \
16 @.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
17 LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \
18 @.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \
19 @.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
20@.mm-libpng-lib: @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \
21 @.mm.pngpread @.mm.pngset @.mm.pngget @.mm.pngread @.mm.pngrtran \
22 @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil
23 LibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio \
24 @.mm.pngwio @.mm.pngmem @.mm.pngpread @.mm.pngset @.mm.pngget \
25 @.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \
26 @.mm.pngwtran @.mm.pngwutil
27
28
29# User-editable dependencies:
30# (C) Copyright 1997 Tom Tanner
31Test: @.pngtest
32 <Prefix$Dir>.pngtest
33 @remove <Prefix$Dir>.pngtest
34
35#It would be nice if you could stop "make" listing from here on!
36@.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
37 Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
38
39.SUFFIXES: .o .mm .c
40
41.c.mm:
42 MemCheck.CC cc $(ccflags) -o $@ LibPng:$<
43.c.o:
44 cc $(ccflags) -o $@ $<
45
46# See scripts.mak.libpngconf for how to generate this:
47@.h.libpngconf: @.scripts.h.libpngconf
48 copy @.scripts.h.libpngconf $@
49
50# Static dependencies:
51@.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
52@.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \
53@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil \
54@.o.pngtest: @.h.libpngconf
55
56
57# Dynamic dependencies:
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.aix b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.aix
new file mode 100644
index 0000000..1b1e18f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.aix
@@ -0,0 +1,121 @@
1# makefile for libpng using gcc (generic, static library)
2# Copyright (C) 2002, 2006-2009 Glenn Randers-Pehrson
3# Copyright (C) 2000 Cosmin Truta
4# Copyright (C) 2000 Marc O. Gloor (AIX support added, from makefile.gcc)
5# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Location of the zlib library and include files
12ZLIBINC = ../zlib
13ZLIBLIB = ../zlib
14
15# Compiler, linker, lib and other tools
16CC = gcc
17LD = $(CC)
18AR_RC = ar rcs
19MKDIR_P = mkdir -p
20RANLIB = ranlib
21RM_F = rm -f
22LN_SF = ln -f -s
23
24LIBNAME=libpng15
25PNGMAJ = 15
26
27prefix=/usr/local
28INCPATH=$(prefix)/include
29LIBPATH=$(prefix)/lib
30
31# override DESTDIR= on the make install command line to easily support
32# installing into a temporary location. Example:
33#
34# make install DESTDIR=/tmp/build/libpng
35#
36# If you're going to install into a temporary location
37# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
38# you execute make install.
39DESTDIR=
40
41DI=$(DESTDIR)$(INCPATH)
42DL=$(DESTDIR)$(LIBPATH)
43
44CDEBUG = -g -DPNG_DEBUG=5
45LDDEBUG =
46CRELEASE = -O2
47LDRELEASE = -s
48WARNMORE=-W -Wall
49CFLAGS = -I$(ZLIBINC) $(WARNMORE) $(CRELEASE)
50LDFLAGS = -L. -L$(ZLIBLIB) -lpng15 -lz -lm $(LDRELEASE)
51
52# File extensions
53O=.o
54A=.a
55E=
56
57# Variables
58OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \
59 pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \
60 pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
61
62# Targets
63all: $(LIBNAME)$(A) pngtest$(E)
64
65include scripts/pnglibconf.mak
66REMOVE = $(RM_F)
67DFNFLAGS = $(DEFS) $(CPPFLAGS)
68
69$(LIBNAME)$(A): $(OBJS)
70 $(AR_RC) $@ $(OBJS)
71 $(RANLIB) $@
72
73test: pngtest$(E)
74 ./pngtest$(E)
75
76pngtest$(E): pngtest$(O) $(LIBNAME)$(A)
77 $(LD) -o $@ pngtest$(O) $(LDFLAGS)
78
79install: $(LIBNAME)$(A)
80 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
81 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
82 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
83 -@$(RM_F) $(DI)/$(LIBNAME)/png.h
84 -@$(RM_F) $(DI)/$(LIBNAME)/pngconf.h
85 -@$(RM_F) $(DI)/$(LIBNAME)/pnglibconf.h
86 -@$(RM_F) $(DI)/png.h
87 -@$(RM_F) $(DI)/pngconf.h
88 -@$(RM_F) $(DI)/pnglibconf.h
89 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
90 chmod 644 $(DI)/$(LIBNAME)/png.h \
91 $(DI)/$(LIBNAME)/pngconf.h \
92 $(DI)/$(LIBNAME)/pnglibconf.h
93 -@$(RM_F) -r $(DI)/libpng
94 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
95 -@$(RM_F) $(DL)/$(LIBNAME)$(A)
96 -@$(RM_F) $(DL)/libpng$(A)
97 cp $(LIBNAME)$(A) $(DL)/$(LIBNAME)$(A)
98 chmod 644 $(DL)/$(LIBNAME)$(A)
99 (cd $(DL); $(LN_SF) $(LIBNAME)$(A) libpng$(A))
100 (cd $(DI); $(LN_SF) libpng/* .;)
101
102clean:
103 $(RM_F) *.o $(LIBNAME)$(A) pngtest pngout.png pnglibconf.h
104
105png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
106pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
107pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
108pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
109pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
110pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
111pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
112pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
113pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
114pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
115pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
116pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
117pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
118pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
119pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
120
121pngtest$(O): png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.amiga b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.amiga
new file mode 100644
index 0000000..f23f254
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.amiga
@@ -0,0 +1,56 @@
1# Commodore Amiga Makefile
2# makefile for libpng and SAS C V6.5x compiler
3# Copyright (C) 1995-2000 Wolf Faust
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8#
9# Location/path of zlib include files
10ZLIB=/zlib
11#compiler
12CC=sc
13#compiler flags
14# WARNING: a bug in V6.51 causes bad code with OPTGO
15# So use V6.55 or set NOOPTGO!!!!!!!!!
16CFLAGS= NOSTKCHK PARMS=REG OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL\
17 OPTLOOP OPTRDEP=4 OPTDEP=4 OPTCOMP=4 INCLUDEDIR=$(ZLIB) \
18 DEFINE=PNG_INTERNAL
19#linker flags
20LDFLAGS= SD ND BATCH
21#link libs
22LDLIBS= libpng.lib libgz.lib LIB:scm.lib LIB:sc.lib Lib:amiga.lib
23# linker
24LN= slink
25# file deletion command
26RM= delete quiet
27# file copy command?
28CP= copy
29# library (.lib) file creation command
30AR= oml
31# make directory command
32MKDIR= makedir
33
34OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
35 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
36 pngwtran.o pngmem.o pngerror.o pngpread.o
37
38all: libpng.lib pngtest
39
40libpng.lib: $(OBJS)
41-$(RM) libpng.lib
42$(AR) libpng.lib r $(OBJS)
43
44$(OBJS): pngpriv.h png.h pngconf.h pnglibconf.h pnginfo.h pngstruct.h pngdebug.h
45
46pnglibconf.h: scripts/pnglibconf.h.prebuilt
47$(CP) scripts/pnglibconf.h.prebuilt pnglibconf.h
48
49pngtest: pngtest.o libpng.lib
50$(LN) <WITH <
51$(LDFLAGS)
52TO pngtest
53FROM LIB:c.o pngtest.o
54LIB $(LDLIBS)
55<
56
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.atari b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.atari
new file mode 100644
index 0000000..aa28ce5
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.atari
@@ -0,0 +1,63 @@
1# makefile for libpng
2# Copyright (C) 2002 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8#
9# Modified for LC56/ATARI assumes libz.lib is in same dir and uses default
10# rules for library management
11#
12CFLAGS=-I..\zlib -O
13LBR = png.lib
14LDFLAGS=-lpng -lz -lm
15
16# where make install puts libpng.a and png.h
17prefix=/usr/local
18INCPATH=$(prefix)/include
19LIBPATH=$(prefix)/lib
20
21# override DESTDIR= on the make install command line to easily support
22# installing into a temporary location. Example:
23#
24# make install DESTDIR=/tmp/build/libpng
25#
26# If you're going to install into a temporary location
27# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
28# you execute make install.
29DESTDIR=
30
31OBJS = $(LBR)(png.o) $(LBR)(pngset.o) $(LBR)(pngget.o) $(LBR)(pngrutil.o)\
32 $(LBR)(pngtrans.o) $(LBR)(pngwutil.o)\
33 $(LBR)(pngread.o) $(LBR)(pngerror.o) $(LBR)(pngwrite.o)\
34 $(LBR)(pngrtran.o) $(LBR)(pngwtran.o)\
35 $(LBR)(pngmem.o) $(LBR)(pngrio.o) $(LBR)(pngwio.o) $(LBR)(pngpread.o)
36
37all: $(LBR) pngtest.ttp
38
39$(LBR): $(OBJS)
40
41$(OBJS): pngpriv.h png.h pngconf.h pnglibconf.h pnginfo.h pngstruct.h pngdebug.h
42
43pnglibconf.h: scripts/pnglibconf.h.prebuilt
44 cp scripts/pnglibconf.h.prebuilt pnglibconf.h
45
46pngtest.ttp: pngtest.o $(LBR)
47 $(CC) $(CFLAGS) $(LDFLAGS) -o$@ pngtest.o
48
49install: libpng.a
50 -@mkdir $(DESTDIR)$(INCPATH)
51 -@mkdir $(DESTDIR)$(INCPATH)/libpng
52 -@mkdir $(DESTDIR)$(LIBPATH)
53 -@rm -f $(DESTDIR)$(INCPATH)/png.h
54 -@rm -f $(DESTDIR)$(INCPATH)/pngconf.h
55 -@rm -f $(DESTDIR)$(INCPATH)/pnglibconf.h
56 cp png.h $(DESTDIR)$(INCPATH)/libpng
57 cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
58 cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
59 chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
60 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
61 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
62 (cd $(DESTDIR)$(INCPATH); ln -f -s $(LIBNAME) libpng; \
63 ln -f -s $(LIBNAME)/* .)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bc32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bc32
new file mode 100644
index 0000000..48311e9
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bc32
@@ -0,0 +1,151 @@
1# Makefile for libpng
2# 32-bit Borland C++ (Note: All modules are compiled in C mode)
3# To build the library, do:
4# "make -fmakefile.bc32"
5#
6# -------------------- 32-bit Borland C++ --------------------
7
8### Absolutely necessary for this makefile to work
9.AUTODEPEND
10
11## Where zlib.h, zconf.h and zlib.lib are
12ZLIB_DIR=..\zlib
13
14## Compiler, linker and lib stuff
15CC=bcc32
16LD=bcc32
17LIB=tlib
18
19# -3 = 386, -4 = 486, -5 = Pentium etc.
20!ifndef TARGET_CPU
21#TARGET_CPU=-6
22!endif
23
24# Use this if you don't want Borland's fancy exception handling
25# (Caution: doesn't work with CBuilderX)
26#NOEHLIB=noeh32.lib
27
28!ifdef DEBUG
29CDEBUG=-v
30LDEBUG=-v
31!else
32CDEBUG=
33LDEBUG=
34!endif
35
36# STACKOFLOW=1
37!ifdef STACKOFLOW
38CDEBUG=$(CDEBUG) -N
39LDEBUG=$(LDEBUG) -N
40!endif
41
42# -O2 optimize for speed
43# -d merge duplicate strings
44# -k- turn off standard stack frame
45# -w display all warnings
46CFLAGS=-I$(ZLIB_DIR) -O2 -d -k- -w $(TARGET_CPU) $(CDEBUG)
47
48# -M generate map file
49LDFLAGS=-L$(ZLIB_DIR) -M $(LDEBUG)
50
51## Variables
52OBJS = \
53 png.obj \
54 pngerror.obj \
55 pngget.obj \
56 pngmem.obj \
57 pngpread.obj \
58 pngread.obj \
59 pngrio.obj \
60 pngrtran.obj \
61 pngrutil.obj \
62 pngset.obj \
63 pngtrans.obj \
64 pngwio.obj \
65 pngwrite.obj \
66 pngwtran.obj \
67 pngwutil.obj
68
69LIBOBJS = \
70 +png.obj \
71 +pngerror.obj \
72 +pngget.obj \
73 +pngmem.obj \
74 +pngpread.obj \
75 +pngread.obj \
76 +pngrio.obj \
77 +pngrtran.obj \
78 +pngrutil.obj \
79 +pngset.obj \
80 +pngtrans.obj \
81 +pngwio.obj \
82 +pngwrite.obj \
83 +pngwtran.obj \
84 +pngwutil.obj
85
86LIBNAME=libpng.lib
87
88## Implicit rules
89# Braces let make "batch" calls to the compiler,
90# 2 calls instead of 12; space is important.
91.c.obj:
92 $(CC) $(CFLAGS) -c {$*.c }
93
94.c.exe:
95 $(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) zlib.lib $(NOEHLIB)
96
97.obj.exe:
98 $(LD) $(LDFLAGS) $*.obj $(LIBNAME) zlib.lib $(NOEHLIB)
99
100## Major targets
101all: libpng pngtest
102
103libpng: $(LIBNAME)
104
105pngtest: pngtest.exe
106
107test: pngtest.exe
108 pngtest
109
110## Minor Targets
111
112# see scripts\pnglibconf.mak for how to make this file
113# with different options
114pnglibconf.h: scripts\pnglibconf.h.prebuilt
115 copy scripts\pnglibconf.h.prebuilt $@
116
117png.obj: png.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
118pngerror.obj: pngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
119pngget.obj: pngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
120pngmem.obj: pngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
121pngpread.obj: pngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
122pngread.obj: pngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
123pngrio.obj: pngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
124pngrtran.obj: pngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
125pngrutil.obj: pngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
126pngset.obj: pngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
127pngtrans.obj: pngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
128pngwio.obj: pngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
129pngwrite.obj: pngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
130pngwtran.obj: pngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
131pngwutil.obj: pngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
132pngtest.obj: pngtest.c png.h pngconf.h pnglibconf.h
133
134$(LIBNAME): $(OBJS)
135 -del $(LIBNAME)
136 $(LIB) $(LIBNAME) @&&|
137$(LIBOBJS), libpng
138|
139
140# Cleanup
141clean:
142 -del pnglibconf.h
143 -del *.obj
144 -del $(LIBNAME)
145 -del pngtest.exe
146 -del *.lst
147 -del *.map
148 -del *.tds
149 -del pngout.png
150
151# End of makefile for libpng
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.beos b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.beos
new file mode 100644
index 0000000..ff1743c
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.beos
@@ -0,0 +1,215 @@
1# makefile for libpng on BeOS x86 ELF with gcc
2# modified from makefile.linux by Sander Stoks
3# Copyright (C) 2002, 2006, 2008, 2010-2011 Glenn Randers-Pehrson
4# Copyright (C) 1999 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME=libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22CC=gcc
23AR_RC=ar rc
24MKDIR_P=mkdir -p
25LN_SF=ln -sf
26RANLIB=ranlib
27RM_F=/bin/rm -f
28
29# Where the zlib library and include files are located
30ZLIBLIB=/usr/local/lib
31ZLIBINC=/usr/local/include
32
33ALIGN=
34# For i386:
35# ALIGN=-malign-loops=2 -malign-functions=2
36
37WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
38 -Wmissing-declarations -Wtraditional -Wcast-align \
39 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
40
41# On BeOS, -O1 is actually better than -O3. This is a known bug but it's
42# still here in R4.5
43CFLAGS=-I$(ZLIBINC) -W -Wall -O1 -funroll-loops \
44 $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
45# LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz
46LDFLAGS=-L. -Wl,-soname=$(LIBSOMAJ) -L$(ZLIBLIB) -lz
47
48# where make install puts libpng.a, libpng15.so*, and png.h
49prefix=/usr/local
50exec_prefix=$(prefix)
51INCPATH=$(prefix)/include
52LIBPATH=$(exec_prefix)/lib
53MANPATH=$(prefix)/man
54BINPATH=$(exec_prefix)/bin
55
56# override DESTDIR= on the make install command line to easily support
57# installing into a temporary location. Example:
58#
59# make install DESTDIR=/tmp/build/libpng
60#
61# If you're going to install into a temporary location
62# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
63# you execute make install.
64DESTDIR=
65
66DB=$(DESTDIR)$(BINPATH)
67DI=$(DESTDIR)$(INCPATH)
68DL=$(DESTDIR)$(LIBPATH)
69DM=$(DESTDIR)$(MANPATH)
70
71OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
72 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
73 pngwtran.o pngmem.o pngerror.o pngpread.o
74
75OBJSDLL = $(OBJS)
76
77.SUFFIXES: .c .o
78
79all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
80
81# try include scripts/pnglibconf.mak for more options
82pnglibconf.h: scripts/pnglibconf.h.prebuilt
83 cp scripts/pnglibconf.h.prebuilt $@
84
85libpng.a: $(OBJS)
86 $(AR_RC) $@ $(OBJS)
87 $(RANLIB) $@
88
89libpng.pc:
90 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
91 -e s!@exec_prefix@!$(exec_prefix)! \
92 -e s!@libdir@!$(LIBPATH)! \
93 -e s!@includedir@!$(INCPATH)! \
94 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
95
96libpng-config:
97 ( cat scripts/libpng-config-head.in; \
98 echo prefix=\"$(prefix)\"; \
99 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
100 echo libs=\"-lpng15 -lz \"; \
101 cat scripts/libpng-config-body.in ) > libpng-config
102 chmod +x libpng-config
103
104$(LIBSO): $(LIBSOMAJ)
105 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
106 cp $(LIBSO)* /boot/home/config/lib
107
108$(LIBSOMAJ): $(OBJSDLL)
109 $(CC) -nostart -Wl,-soname,$(LIBSOMAJ) -o \
110 $(LIBSOMAJ) $(OBJSDLL) $(LDFLAGS)
111
112pngtest: pngtest.o $(LIBSO)
113 $(CC) -L$(ZLIBLIB) -L. -lz -lpng15 -o pngtest pngtest.o
114
115test: pngtest
116 ./pngtest
117
118install-headers: png.h pngconf.h pnglibconf.h
119 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
120 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
121 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
122 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
123 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
124 -@$(RM_F) $(DI)/libpng
125 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
126
127install-static: install-headers libpng.a
128 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
129 cp libpng.a $(DL)/$(LIBNAME).a
130 chmod 644 $(DL)/$(LIBNAME).a
131 -@$(RM_F) $(DL)/libpng.a
132 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
133
134install-shared: install-headers $(LIBSOMAJ) libpng.pc
135 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
136 -@$(RM_F) $(DL)/$(LIBSO)
137 -@$(RM_F) $(DL)/$(LIBSOREL)
138 -@$(RM_F) $(DL)/$(OLDSO)
139 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
140 chmod 755 $(DL)/$(LIBSOREL)
141 (cd $(DL); \
142 $(LN_SF) $(LIBSOREL) $(LIBSO); \
143 $(LN_SF) $(LIBSO) $(OLDSO))
144 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
145 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
146 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
147 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
148 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
149 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
150
151install-man: libpng.3 libpngpf.3 png.5
152 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
153 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
154 -@$(RM_F) $(DM)/man3/libpng.3
155 -@$(RM_F) $(DM)/man3/libpngpf.3
156 cp libpng.3 $(DM)/man3
157 cp libpngpf.3 $(DM)/man3
158 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
159 -@$(RM_F) $(DM)/man5/png.5
160 cp png.5 $(DM)/man5
161
162install-config: libpng-config
163 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
164 -@$(RM_F) $(DB)/libpng-config
165 -@$(RM_F) $(DB)/$(LIBNAME)-config
166 cp libpng-config $(DB)/$(LIBNAME)-config
167 chmod 755 $(DB)/$(LIBNAME)-config
168 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
169
170install: install-static install-shared install-man install-config
171
172# If you installed in $(DESTDIR), test-installed won't work until you
173# move the library to its final location. Use test-dd to test it
174# before then.
175
176test-dd:
177 echo
178 echo Testing installed dynamic shared library in $(DL).
179 $(CC) -I$(DI) $(CFLAGS) \
180 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
181 -L$(DL) -L$(ZLIBLIB) -Wl,-rpath $(ZLIBLIB):$(DL) \
182 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
183 ./pngtestd pngtest.png
184
185test-installed:
186 $(CC) $(CFLAGS) \
187 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
188 -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \
189 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
190 ./pngtesti pngtest.png
191
192clean:
193 $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \
194 $(LIBSO) $(LIBSOMAJ)* pngtesti \
195 pnglibconf.h libpng.pc
196
197# DO NOT DELETE THIS LINE -- make depend depends on it.
198
199png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
200pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
201pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
202pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
203pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
204pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
205pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
206pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
207pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
208pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
209pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
210pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
211pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
212pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214
215pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bor b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bor
new file mode 100644
index 0000000..8251503
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.bor
@@ -0,0 +1,161 @@
1# Makefile for libpng
2# 16-bit Borland C++ (Note: All modules are compiled in C mode)
3# To build the library, do:
4# "make -fmakefile.bor -DMODEL=c"
5# or: "make -fmakefile.bor -DMODEL=l"
6#
7# ------------ Borland C++ ------------
8
9### Absolutely necessary for this makefile to work
10.AUTODEPEND
11
12## Where zlib.h, zconf.h and zlib_MODEL.lib are
13ZLIB_DIR=..\zlib
14
15## Compiler, linker and lib stuff
16CC=bcc
17LD=bcc
18LIB=tlib
19
20!ifndef MODEL
21MODEL=l
22!endif
23
24MODEL_ARG=-m$(MODEL)
25
26#TARGET_CPU=3
27# 2 = 286, 3 = 386, etc.
28!ifndef TARGET_CPU
29TARGET_CPU=2
30!endif
31
32# Use this if you don't want Borland's fancy exception handling
33# (for Borland C++ 4.0 or later)
34#NOEHLIB=noeh$(MODEL).lib
35
36!ifdef DEBUG
37CDEBUG=-v
38LDEBUG=-v
39!else
40CDEBUG=
41LDEBUG=
42!endif
43
44# STACKOFLOW=1
45!ifdef STACKOFLOW
46CDEBUG=$(CDEBUG) -N
47LDEBUG=$(LDEBUG) -N
48!endif
49
50# -X- turn on dependency generation in the object file
51# -w set all warnings on
52# -O2 optimize for speed
53# -Z global optimization
54CFLAGS=-O2 -Z -X- -w -I$(ZLIB_DIR) -$(TARGET_CPU) $(MODEL_ARG) $(CDEBUG)
55
56# -M generate map file
57LDFLAGS=-M -L$(ZLIB_DIR) $(MODEL_ARG) $(LDEBUG)
58
59## Variables
60
61OBJS = \
62 png.obj \
63 pngerror.obj \
64 pngget.obj \
65 pngmem.obj \
66 pngpread.obj \
67 pngread.obj \
68 pngrio.obj \
69 pngrtran.obj \
70 pngrutil.obj \
71 pngset.obj \
72 pngtrans.obj \
73 pngwio.obj \
74 pngwrite.obj \
75 pngwtran.obj \
76 pngwutil.obj
77
78LIBOBJS = \
79 +png.obj \
80 +pngerror.obj \
81 +pngget.obj \
82 +pngmem.obj \
83 +pngpread.obj \
84 +pngread.obj \
85 +pngrio.obj \
86 +pngrtran.obj \
87 +pngrutil.obj \
88 +pngset.obj \
89 +pngtrans.obj \
90 +pngwio.obj \
91 +pngwrite.obj \
92 +pngwtran.obj \
93 +pngwutil.obj
94
95LIBNAME=libpng$(MODEL).lib
96
97## Implicit rules
98
99# Braces let make "batch" calls to the compiler,
100# 2 calls instead of 12; space is important.
101.c.obj:
102 $(CC) $(CFLAGS) -c {$*.c }
103
104.c.exe:
105 $(CC) $(CFLAGS) $(LDFLAGS) $*.c $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)
106
107## Major targets
108
109all: libpng pngtest
110
111# try !inlude scripts\pnglibconf.mak for more options
112pnglibconf.h: scripts\pnglibconf.h.prebuilt
113 copy scripts\pnglibconf.h.prebuilt $@
114
115libpng: $(LIBNAME)
116
117pngtest: pngtest$(MODEL).exe
118
119test: pngtest$(MODEL).exe
120 pngtest$(MODEL)
121
122## Minor Targets
123
124png.obj: png.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
125pngerror.obj: pngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
126pngget.obj: pngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
127pngmem.obj: pngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
128pngpread.obj: pngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
129pngread.obj: pngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
130pngrio.obj: pngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
131pngrtran.obj: pngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
132pngrutil.obj: pngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
133pngset.obj: pngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
134pngtrans.obj: pngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
135pngwio.obj: pngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
136pngwrite.obj: pngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
137pngwtran.obj: pngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
138pngwutil.obj: pngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
139
140$(LIBNAME): $(OBJS)
141 -del $(LIBNAME)
142 $(LIB) $(LIBNAME) @&&|
143$(LIBOBJS), libpng$(MODEL)
144|
145
146pngtest$(MODEL).obj: pngtest.c png.h pngconf.h pnglibconf.h
147 $(CC) $(CFLAGS) -opngtest$(MODEL) -c pngtest.c
148
149pngtest$(MODEL).exe: pngtest$(MODEL).obj
150 $(LD) $(LDFLAGS) pngtest$(MODEL).obj $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)
151
152# Clean up anything else you want
153clean:
154 -del pnglibconf.h
155 -del *.obj
156 -del *.exe
157 -del *.lib
158 -del *.lst
159 -del *.map
160
161# End of makefile for libpng
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.cegcc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.cegcc
new file mode 100644
index 0000000..6d4f6ef
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.cegcc
@@ -0,0 +1,116 @@
1# Makefile for creating Windows CE release archives, with the
2# mingw32ce compiler.
3
4# Last updated: 22-Jul-2008
5
6# Copyright (C) 2008 Vincent Torri
7
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# To get some help, type
13#
14# make help
15#
16# To create the archives
17#
18# make
19#
20# To remove everything, type:
21#
22# make clean
23
24VERMAJ = 1
25VERMIN = 5
26VERMIC = 9
27VER = $(VERMAJ).$(VERMIN).$(VERMIC)
28NAME = libpng
29PACKAGE = $(NAME)-$(VER)
30
31BIN = libpng15-0.dll
32LIB = libpng15.a libpng15.dll.a libpng.a libpng.dll.a
33INCLUDE = png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
34PC = libpng15.pc libpng.pc
35
36MANIFESTVERBIN = "Libpng-$(VER): Binary files"
37MANIFESTVERDEV = "Libpng-$(VER): Developer files"
38MANIFESTVERDESC = "Libpng: the official PNG reference library"
39
40all: $(NAME)
41
42$(NAME): remove-old copy-src compilation copy manifest archive
43 @echo " * Removal of the directories"
44 @rm -rf $(PACKAGE)/ $(PACKAGE)-bin/ $(PACKAGE)-dev/
45
46remove-old:
47 @echo " * Removal of the old files"
48 @rm -rf $(PACKAGE)-bin*
49 @rm -rf $(PACKAGE)-dev*
50
51copy-src:
52 @echo " * Copy of source files"
53 @cp -R ../src/$(PACKAGE) .
54 @echo " * Creation of directories and files"
55 @mkdir -p $(PACKAGE)-bin/bin
56 @mkdir -p $(PACKAGE)-bin/manifest
57 @mkdir -p $(PACKAGE)-dev/lib/pkgconfig
58 @mkdir -p $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN)
59 @mkdir -p $(PACKAGE)-dev/manifest
60 @touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.mft
61 @touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.ver
62 @touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.mft
63 @touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.ver
64
65compilation:
66 @echo " * Compilation of $(PACKAGE)"
67 cd $(PACKAGE) && CPPFLAGS="$(CPPFLAGS) -DPNG_CONSOLE_IO_SUPPORTED -D_WIN32_WCE=0x0420" \
68 CFLAGS="$(CFLAGS) -mms-bitfields -O3 -pipe -fomit-frame-pointer" \
69 LDFLAGS="$(LDFLAGS) -Wl,--enable-auto-import -Wl,-s" \
70 ./configure --prefix=/opt/wince --host=arm-mingw32ce && make
71
72copy:
73 @echo " * Copy of binary and development files"
74 @for i in $(BIN); do \
75 cp $(PACKAGE)/.libs/$$i $(PACKAGE)-bin/bin; \
76 done
77 @for i in $(LIB); do \
78 cp $(PACKAGE)/.libs/$$i $(PACKAGE)-dev/lib; \
79 done
80 @for i in $(INCLUDE); do \
81 cp $(PACKAGE)/$$i $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN); \
82 done
83 @for i in $(PC); do \
84 cp $(PACKAGE)/$$i $(PACKAGE)-dev/lib/pkgconfig; \
85 done
86
87manifest:
88 @echo " * Creation of the manifest"
89 @cd $(PACKAGE)-bin && find * >> manifest/$(PACKAGE)-bin.mft
90 @cd $(PACKAGE)-bin && \
91 echo $(MANIFESTVERBIN) >> manifest/$(PACKAGE)-bin.ver && \
92 echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-bin.ver
93 @cd $(PACKAGE)-dev && find * >> manifest/$(PACKAGE)-dev.mft
94 @cd $(PACKAGE)-dev && \
95 echo $(MANIFESTVERDEV) >> manifest/$(PACKAGE)-dev.ver && \
96 echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-dev.ver
97
98archive:
99 @echo " * Creation of the archives"
100 @tar cf $(PACKAGE)-bin.tar $(PACKAGE)-bin
101 @bzip2 -9 $(PACKAGE)-bin.tar
102 @tar cf $(PACKAGE)-dev.tar $(PACKAGE)-dev
103 @bzip2 -9 $(PACKAGE)-dev.tar
104
105clean:
106 @echo " * Cleaning"
107 @rm -rf $(PACKAGE)*
108
109help:
110 @echo
111 @echo "To create the archives, type:"
112 @echo " make"
113 @echo
114 @echo "To remove everything, type:"
115 @echo " make clean"
116 @echo
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.darwin b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.darwin
new file mode 100644
index 0000000..bb62b09
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.darwin
@@ -0,0 +1,220 @@
1# makefile for libpng on Darwin / Mac OS X
2# Copyright (C) 2002, 2004, 2006, 2008, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 2001 Christoph Pfisterer
4# derived from makefile.linux:
5# Copyright (C) 1998, 1999 Greg Roelofs
6# Copyright (C) 1996, 1997 Andreas Dilger
7#
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# where "make install" puts libpng.a, libpng15.dylib, png.h, pngconf.h,
13# and pnglibconf.h
14prefix=/usr/local
15exec_prefix=$(prefix)
16
17# Where the zlib library and include files are located
18#ZLIBLIB=/usr/local/lib
19#ZLIBINC=/usr/local/include
20ZLIBLIB=../zlib
21ZLIBINC=../zlib
22
23# Library name:
24LIBNAME = libpng15
25PNGMAJ = 15
26
27# Shared library names:
28LIBSO=$(LIBNAME).dylib
29LIBSOMAJ=$(LIBNAME).$(PNGMAJ).dylib
30LIBSOREL=$(LIBNAME).$(PNGMAJ).$(RELEASE).dylib
31OLDSO=libpng.dylib
32
33# Utilities:
34CC=cc
35AR_RC=ar rc
36MKDIR_P=mkdir -p
37LN_SF=ln -sf
38RANLIB=ranlib
39RM_F=/bin/rm -f
40ARCH="-arch i386 -arch x86_64"
41
42# CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops
43CFLAGS=-I$(ZLIBINC) -W -Wall -O -funroll-loops $(ARCH)
44LDFLAGS=-L. -L$(ZLIBLIB) -lpng15 -lz $(ARCH)
45
46INCPATH=$(prefix)/include
47LIBPATH=$(exec_prefix)/lib
48MANPATH=$(prefix)/man
49BINPATH=$(exec_prefix)/bin
50
51# override DESTDIR= on the make install command line to easily support
52# installing into a temporary location. Example:
53#
54# make install DESTDIR=/tmp/build/libpng
55#
56# If you're going to install into a temporary location
57# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
58# you execute make install.
59DESTDIR=
60
61DB=$(DESTDIR)$(BINPATH)
62DI=$(DESTDIR)$(INCPATH)
63DL=$(DESTDIR)$(LIBPATH)
64DM=$(DESTDIR)$(MANPATH)
65
66OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
67 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
68 pngwtran.o pngmem.o pngerror.o pngpread.o
69
70OBJSDLL = $(OBJS:.o=.pic.o)
71
72.SUFFIXES: .c .o .pic.o
73
74.c.pic.o:
75 $(CC) -c $(CFLAGS) -fno-common -o $@ $*.c
76
77all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
78
79# see scripts/pnglibconf.mak for more options
80pnglibconf.h: scripts/pnglibconf.h.prebuilt
81 cp scripts/pnglibconf.h.prebuilt $@
82
83libpng.a: $(OBJS)
84 $(AR_RC) $@ $(OBJS)
85 $(RANLIB) $@
86
87libpng.pc:
88 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
89 -e s!@exec_prefix@!$(exec_prefix)! \
90 -e s!@libdir@!$(LIBPATH)! \
91 -e s!@includedir@!$(INCPATH)! \
92 -e s!-lpng15!-lpng15\ -lz! > libpng.pc
93
94libpng-config:
95 ( cat scripts/libpng-config-head.in; \
96 echo prefix=\"$(prefix)\"; \
97 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
98 echo L_opts=\"-L$(LIBPATH)\"; \
99 echo libs=\"-lpng15 -lz\"; \
100 cat scripts/libpng-config-body.in ) > libpng-config
101 chmod +x libpng-config
102
103$(LIBSO): $(LIBSOMAJ)
104 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
105
106$(LIBSOMAJ): $(OBJSDLL)
107 $(CC) -dynamiclib \
108 -install_name $(LIBPATH)/$(LIBSOMAJ) \
109 -current_version 15 -compatibility_version 15 \
110 -o $(LIBSOMAJ) \
111 $(OBJSDLL) -L$(ZLIBLIB) -lz
112
113pngtest: pngtest.o $(LIBSO)
114 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
115
116test: pngtest
117 ./pngtest
118
119install-headers: png.h pngconf.h pnglibconf.h
120 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
121 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
122 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
123 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
124 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
125 -@$(RM_F) $(DI)/libpng
126 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
127
128install-static: install-headers libpng.a
129 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
130 cp libpng.a $(DL)/$(LIBNAME).a
131 chmod 644 $(DL)/$(LIBNAME).a
132 $(RANLIB) $(DL)/$(LIBNAME).a
133 -@$(RM_F) $(DL)/libpng.a
134 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
135
136install-shared: install-headers $(LIBSOMAJ) libpng.pc
137 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
138 -@$(RM_F) $(DL)/$(LIBSO)
139 -@$(RM_F) $(DL)/$(LIBSOREL)
140 -@$(RM_F) $(DL)/$(OLDSO)
141 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
142 chmod 755 $(DL)/$(LIBSOREL)
143 (cd $(DL); \
144 $(LN_SF) $(LIBSOREL) $(LIBSO); \
145 $(LN_SF) $(LIBSO) $(OLDSO))
146 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
147 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
148 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
149 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
150 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
151 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
152
153install-man: libpng.3 libpngpf.3 png.5
154 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
155 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
156 -@$(RM_F) $(DM)/man3/libpng.3
157 -@$(RM_F) $(DM)/man3/libpngpf.3
158 cp libpng.3 $(DM)/man3
159 cp libpngpf.3 $(DM)/man3
160 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
161 -@$(RM_F) $(DM)/man5/png.5
162 cp png.5 $(DM)/man5
163
164install-config: libpng-config
165 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
166 -@$(RM_F) $(DB)/libpng-config
167 -@$(RM_F) $(DB)/$(LIBNAME)-config
168 cp libpng-config $(DB)/$(LIBNAME)-config
169 chmod 755 $(DB)/$(LIBNAME)-config
170 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
171
172install: install-static install-shared install-man install-config
173
174# If you installed in $(DESTDIR), test-installed won't work until you
175# move the library to its final location. Use test-dd to test it
176# before then.
177
178test-dd:
179 echo
180 echo Testing installed dynamic shared library in $(DL).
181 $(CC) -I$(DI) -I$(ZLIBINC) \
182 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
183 -L$(DL) -L$(ZLIBLIB) \
184 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
185 ./pngtestd pngtest.png
186
187test-installed:
188 $(CC) $(CFLAGS) \
189 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
190 -L$(ZLIBLIB) \
191 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
192 ./pngtesti pngtest.png
193
194clean:
195 $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \
196 libpng.pc $(LIBNAME).*dylib pngtesti pnglibconf.h
197
198DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
199writelock:
200 chmod a-w *.[ch35] $(DOCS) scripts/*
201
202# DO NOT DELETE THIS LINE -- make depend depends on it.
203
204png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
205pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
206pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
207pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
208pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
209pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
210pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
211pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
212pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219
220pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dec b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dec
new file mode 100644
index 0000000..5687ca1
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dec
@@ -0,0 +1,202 @@
1# makefile for libpng on DEC Alpha Unix
2# Copyright (C) 2000-2002, 2006, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# Library name:
10PNGMAJ = 15
11LIBNAME = libpng15
12
13# Shared library names:
14LIBSO=$(LIBNAME).so
15LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
16LIBSOREL=$(LIBSOMAJ).$(RELEASE)
17OLDSO=libpng.so
18
19# Utilities:
20AR_RC=ar rc
21CC=cc
22MKDIR_P=mkdir
23LN_SF=ln -f -s
24RANLIB=ranlib
25RM_F=/bin/rm -f
26
27# where make install puts libpng.a and png.h
28prefix=/usr/local
29exec_prefix=$(prefix)
30INCPATH=$(prefix)/include
31LIBPATH=$(exec_prefix)/lib
32MANPATH=$(prefix)/man
33BINPATH=$(exec_prefix)/bin
34
35# override DESTDIR= on the make install command line to easily support
36# installing into a temporary location. Example:
37#
38# make install DESTDIR=/tmp/build/libpng
39#
40# If you're going to install into a temporary location
41# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
42# you execute make install.
43DESTDIR=
44
45DB=$(DESTDIR)$(BINPATH)
46DI=$(DESTDIR)$(INCPATH)
47DL=$(DESTDIR)$(LIBPATH)
48DM=$(DESTDIR)$(MANPATH)
49
50# Where the zlib library and include files are located
51#ZLIBLIB=/usr/local/lib
52#ZLIBINC=/usr/local/include
53ZLIBLIB=../zlib
54ZLIBINC=../zlib
55
56CFLAGS=-std -w1 -I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
57LDFLAGS=-L$(ZLIBLIB) -rpath $(ZLIBLIB) libpng.a -lz -lm
58
59OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
60 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
61 pngwtran.o pngmem.o pngerror.o pngpread.o
62
63all: $(LIBSO) libpng.a pngtest libpng.pc libpng-config
64
65# see scripts/pnglibconf.mak for more options
66pnglibconf.h: scripts/pnglibconf.h.prebuilt
67 cp scripts/pnglibconf.h.prebuilt $@
68
69libpng.a: $(OBJS)
70 $(AR_RC) $@ $(OBJS)
71 $(RANLIB) $@
72
73libpng.pc:
74 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
75 -e s!@exec_prefix@!$(exec_prefix)! \
76 -e s!@libdir@!$(LIBPATH)! \
77 -e s!@includedir@!$(INCPATH)! \
78 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
79
80libpng-config:
81 ( cat scripts/libpng-config-head.in; \
82 echo prefix=\"$(prefix)\"; \
83 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
84 echo ccopts=\"-std\"; \
85 echo L_opts=\"-L$(LIBPATH)\"; \
86 echo libs=\"-lpng15 -lz -lm\"; \
87 cat scripts/libpng-config-body.in ) > libpng-config
88 chmod +x libpng-config
89
90$(LIBSO): $(LIBSOMAJ)
91 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
92
93$(LIBSOMAJ): $(OBJS)
94 $(CC) -shared -o $@ $(OBJS) -L$(ZLIBLIB) \
95 -soname $(LIBSOMAJ)
96
97pngtest: pngtest.o libpng.a
98 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
99
100test: pngtest
101 ./pngtest
102
103install-headers: png.h pngconf.h pnglibconf.h
104 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
105 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
106 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
107 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
108 -@/bin/rm -f $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
109 -@/bin/rm -f $(DI)/libpng
110 (cd $(DI); $(LN_SF)(LIBNAME) libpng; $(LN_SF)(LIBNAME)/* .)
111
112install-static: install-headers libpng.a
113 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
114 cp libpng.a $(DL)/$(LIBNAME).a
115 chmod 644 $(DL)/$(LIBNAME).a
116 -@/bin/rm -f $(DL)/libpng.a
117 (cd $(DL); $(LN_SF)(LIBNAME).a libpng.a)
118
119install-shared: install-headers $(LIBSOMAJ) libpng.pc
120 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
121 -@$(RM_F) $(DL)/$(LIBSO)
122 -@$(RM_F) $(DL)/$(LIBSOREL)
123 -@$(RM_F) $(DL)/$(OLDSO)
124 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
125 chmod 755 $(DL)/$(LIBSOREL)
126 (cd $(DL); \
127 $(LN_SF) $(LIBSOREL) $(LIBSO); \
128 $(LN_SF) $(LIBSO) $(OLDSO))
129 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
130 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
131 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
132 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
133 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
134 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
135
136install-man: libpng.3 libpngpf.3 png.5
137 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
138 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
139 -@/bin/rm -f $(DM)/man3/libpng.3
140 -@/bin/rm -f $(DM)/man3/libpngpf.3
141 cp libpng.3 $(DM)/man3
142 cp libpngpf.3 $(DM)/man3
143 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
144 -@/bin/rm -f $(DM)/man5/png.5
145 cp png.5 $(DM)/man5
146
147install-config: libpng-config
148 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
149 -@/bin/rm -f $(DB)/libpng-config
150 -@/bin/rm -f $(DB)/$(LIBNAME)-config
151 cp libpng-config $(DB)/$(LIBNAME)-config
152 chmod 755 $(DB)/$(LIBNAME)-config
153 (cd $(DB); $(LN_SF)(LIBNAME)-config libpng-config)
154
155install: install-static install-shared install-man install-config
156
157# If you installed in $(DESTDIR), test-installed won't work until you
158# move the library to its final location. Use test-dd to test it
159# before then.
160
161test-dd:
162 echo
163 echo Testing installed dynamic shared library in $(DL).
164 $(CC) -w1 -I$(DI) -I$(ZLIBINC) \
165 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
166 -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL) \
167 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
168 ./pngtestd pngtest.png
169
170test-installed:
171 echo
172 echo Testing installed dynamic shared library.
173 $(CC) -w1 -I$(ZLIBINC) \
174 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
175 -L$(ZLIBLIB) -R$(ZLIBLIB) \
176 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
177 ./pngtesti pngtest.png
178
179clean:
180 /bin/rm -f *.o libpng.a pngtest pngtesti pngout.png \
181 libpng-config $(LIBSO) $(LIBSOMAJ)* \
182 libpng.pc pnglibconf.h
183
184# DO NOT DELETE THIS LINE -- make depend depends on it.
185
186png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
187pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
188pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
189pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
190pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
191pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
192pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
193pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
194pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
195pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
196pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
197pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
198pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
199pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
200pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
201
202pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dj2 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dj2
new file mode 100644
index 0000000..48fea81
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.dj2
@@ -0,0 +1,62 @@
1# DJGPP (DOS gcc) makefile for libpng
2# Copyright (C) 2002, 2006, 2009-2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# where make install will put libpng.a and png.h
10#prefix=/usr/local
11prefix=.
12INCPATH=$(prefix)/include
13LIBPATH=$(prefix)/lib
14
15CC=gcc
16CFLAGS=-I../zlib -O -DPNG_NO_SNPRINTF
17LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
18
19RANLIB=ranlib
20
21OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
22 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \
23 pngmem.o pngerror.o pngpread.o
24
25all: libpng.a pngtest
26
27# see scripts/pnglibconf.mak for more options
28pnglibconf.h: scripts/pnglibconf.h.prebuilt
29 cp scripts/pnglibconf.h.prebuilt $@
30
31libpng.a: $(OBJS)
32 ar rc $@ $(OBJS)
33 $(RANLIB) $@
34
35pngtest: pngtest.o libpng.a
36 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
37 coff2exe pngtest
38
39test: pngtest
40 ./pngtest
41clean:
42 rm -f *.o libpng.a pngtest pngout.png pnglibconf.h
43
44# DO NOT DELETE THIS LINE -- make depend depends on it.
45
46png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
47pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
48pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
49pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
50pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
51pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
52pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
53pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
54pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
55pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
56pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
57pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
58pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
59pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
60pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
61
62pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.elf b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.elf
new file mode 100644
index 0000000..ceea7fc
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.elf
@@ -0,0 +1,263 @@
1# makefile for libpng.a and libpng15.so on Linux ELF with gcc
2# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2011 Greg Roelofs
3# and Glenn Randers-Pehrson
4# Copyright (C) 1996, 1997 Andreas Dilger
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10# Modified for Debian by Junichi Uekawa and Josselin Mouette
11# Major modifications are:
12# * link libpng explicitly with libz and libm
13# * $(OLDSO).15 is a symlink rather than a different library
14# * versioned symbols
15
16# Library name:
17LIBNAME = libpng15
18PNGMAJ = 15
19
20# Shared library names:
21LIBSO=$(LIBNAME).so
22LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
23LIBSOREL=$(LIBSOMAJ).$(RELEASE)
24OLDSO=libpng.so
25OLDSOMAJ=libpng.so.15
26
27# Utilities:
28AR_RC=ar rc
29CC=gcc
30MKDIR_P=mkdir -p
31LN_SF=ln -sf
32RANLIB=ranlib
33RM_F=/bin/rm -f
34
35# where "make install" puts libpng15.a, libpng15.so*,
36# libpng15/png.h, libpng15/pngconf.h, and libpng15/pnglibconf.h
37# Prefix must be a full pathname.
38prefix=/usr/local
39exec_prefix=$(prefix)
40
41# Where the zlib library and include files are located.
42ZLIBLIB=/usr/local/lib
43ZLIBINC=/usr/local/include
44# ZLIBLIB=../zlib
45# ZLIBINC=../zlib
46
47ALIGN=
48# for i386:
49#ALIGN=-malign-loops=2 -malign-functions=2
50
51WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
52 -Wmissing-declarations -Wtraditional -Wcast-align \
53 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
54
55# for pgcc version 2.95.1, -O3 is buggy; don't use it.
56
57CFLAGS=-W -Wall -D_REENTRANT -O2 \
58 $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
59
60LDFLAGS=-L. -lpng15
61LDFLAGS_A=libpng.a -lz -lm
62LIBADDFLAGS=-lz -lm
63
64
65INCPATH=$(prefix)/include
66LIBPATH=$(exec_prefix)/lib
67MANPATH=$(prefix)/man
68BINPATH=$(exec_prefix)/bin
69
70# override DESTDIR= on the make install command line to easily support
71# installing into a temporary location. Example:
72#
73# make install DESTDIR=/tmp/build/libpng
74#
75# If you're going to install into a temporary location
76# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
77# you execute make install.
78DESTDIR=
79
80DB=$(DESTDIR)$(BINPATH)
81DI=$(DESTDIR)$(INCPATH)
82DL=$(DESTDIR)$(LIBPATH)
83DM=$(DESTDIR)$(MANPATH)
84
85OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
86 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
87 pngwtran.o pngmem.o pngerror.o pngpread.o
88
89OBJSDLL = $(OBJS:.o=.pic.o)
90
91.SUFFIXES: .c .o .pic.o
92
93.c.pic.o:
94 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
95
96all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config
97
98# see scripts/pnglibconf.mak for more options
99pnglibconf.h: scripts/pnglibconf.h.prebuilt
100 cp scripts/pnglibconf.h.prebuilt $@
101
102libpng.a: $(OBJS)
103 $(AR_RC) $@ $(OBJS)
104 $(RANLIB) $@
105
106libpng.pc:
107 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
108 -e s!@exec_prefix@!$(exec_prefix)! \
109 -e s!@libdir@!$(LIBPATH)! \
110 -e s!@includedir@!$(INCPATH)! \
111 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
112
113libpng.syms: png.h pngconf.h pnglibconf.h
114 $(CC) $(CFLAGS) -E -DPNG_BUILDSYMS -DPNG_INTERNAL png.h |\
115 awk -F '[\t [\\]();]' -v PNGMAJ=$(PNGMAJ) 'BEGIN{printf("PNG15_%s {global:\n",PNGMAJ)}\
116 { for (i=1;i+2<=NF;++i)\
117 if ($$(i)=="PNG_FUNCTION_EXPORT" && $$(i+2)=="END")\
118 print $$(i+1) ";";\
119 for (i=1;i+1<=NF;++i)\
120 if ($$(i)=="PNG_DATA_EXPORT")\
121 print $$(i+1) ";";}\
122 END{print "local: *; };"}' >$@.new
123 $(RM_F) $@
124 mv $@.new $@
125
126libpng-config:
127 ( cat scripts/libpng-config-head.in; \
128 echo prefix=\"$(prefix)\"; \
129 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
130 echo L_opts=\"\"; \
131 echo R_opts=\"\"; \
132 echo libs=\"-lpng15\"; \
133 echo all_libs=\"-lpng15 $(LIBADDFLAGS)\"; \
134 cat scripts/libpng-config-body.in ) > libpng-config
135 chmod +x libpng-config
136
137$(LIBSO): $(LIBSOMAJ)
138 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
139
140$(LIBSOMAJ): $(OBJSDLL) libpng.syms
141 $(CC) -shared -Wl,-soname,$(LIBSOMAJ) \
142 -Wl,-version-script,libpng.syms \
143 -o $(LIBSOMAJ) \
144 $(OBJSDLL)
145
146pngtest: pngtest.o $(LIBSO)
147 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
148
149pngtest-static: pngtest.o libpng.a
150 $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A)
151
152test: pngtest pngtest-static
153 @echo ""
154 @echo " Running pngtest dynamically linked with $(LIBSO):"
155 @echo ""
156 LD_LIBRARY_PATH=".:${LD_LIBRARY_PATH}" ./pngtest
157 @echo ""
158 @echo " Running pngtest statically linked with libpng.a:"
159 @echo ""
160 ./pngtest-static
161
162install-headers: png.h pngconf.h pnglibconf.h
163 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
164 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
165 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
166 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
167 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
168 -@$(RM_F) $(DI)/libpng
169 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
170
171install-static: install-headers libpng.a
172 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
173 cp libpng.a $(DL)/$(LIBNAME).a
174 chmod 644 $(DL)/$(LIBNAME).a
175 -@$(RM_F) $(DL)/libpng.a
176 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
177
178install-shared: install-headers $(LIBSOMAJ) libpng.pc
179 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
180 -@$(RM_F) $(DL)/$(LIBSO)
181 -@$(RM_F) $(DL)/$(LIBSOREL)
182 -@$(RM_F) $(DL)/$(OLDSO)
183 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
184 chmod 755 $(DL)/$(LIBSOREL)
185 (cd $(DL); \
186 $(LN_SF) $(LIBSOREL) $(LIBSO); \
187 $(LN_SF) $(LIBSO) $(OLDSO))
188 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
189 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
190 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
191 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
192 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
193 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
194
195install-man: libpng.3 libpngpf.3 png.5
196 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
197 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
198 -@$(RM_F) $(DM)/man3/libpng.3
199 -@$(RM_F) $(DM)/man3/libpngpf.3
200 cp libpng.3 $(DM)/man3
201 cp libpngpf.3 $(DM)/man3
202 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
203 -@$(RM_F) $(DM)/man5/png.5
204 cp png.5 $(DM)/man5
205
206install-config: libpng-config
207 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
208 -@$(RM_F) $(DB)/libpng-config
209 -@$(RM_F) $(DB)/$(LIBNAME)-config
210 cp libpng-config $(DB)/$(LIBNAME)-config
211 chmod 755 $(DB)/$(LIBNAME)-config
212 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
213
214install: install-static install-shared install-man install-config
215
216# If you installed in $(DESTDIR), test-installed won't work until you
217# move the library to its final location. Use test-dd to test it
218# before then.
219
220test-dd:
221 echo
222 echo Testing installed dynamic shared library in $(DL).
223 $(CC) -I$(DI) -I$(ZLIBINC) \
224 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
225 -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \
226 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
227 ./pngtestd pngtest.png
228
229test-installed:
230 $(CC) -I$(ZLIBINC) \
231 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
232 -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \
233 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
234 ./pngtesti pngtest.png
235
236clean:
237 $(RM_F) *.o libpng.a libpng.syms pngtest pngout.png libpng-config \
238 $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \
239 libpng.pc pnglibconf.h
240
241DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
242writelock:
243 chmod a-w *.[ch35] $(DOCS) scripts/*
244
245# DO NOT DELETE THIS LINE -- make depend depends on it.
246
247png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
248pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
249pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
250pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
251pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
252pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
253pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
254pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
255pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
256pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
257pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
258pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
259pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
260pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
261pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
262
263pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.freebsd b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.freebsd
new file mode 100644
index 0000000..ced7be2
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.freebsd
@@ -0,0 +1,53 @@
1# makefile for libpng under FreeBSD
2# Copyright (C) 2002, 2007, 2009 Glenn Randers-Pehrson and Andrey A. Chernov
3#
4# This code is released under the libpng license.
5# For conditions of distribution and use, see the disclaimer
6# and license in png.h
7
8PREFIX?= /usr/local
9SHLIB_VER?= 15
10
11LIB= png
12SHLIB_MAJOR= ${SHLIB_VER}
13SHLIB_MINOR= 0
14NOPROFILE= YES
15NOOBJ= YES
16
17# where make install puts libpng.a and png.h
18DESTDIR= ${PREFIX}
19LIBDIR= /lib
20INCS= png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
21INCSDIR= /include/libpng
22INCDIR= ${INCSDIR} # for 4.x bsd.lib.mk
23MAN= libpng.3 libpngpf.3 png.5
24MANDIR= /man/man
25SYMLINKS= libpng/png.h ${INCSDIR}/../png.h \
26 libpng/pngconf.h ${INCSDIR}/../pngconf.h \
27 libpng/pnglibconf.h ${INCSDIR}/../pnglibconf.h
28LDADD+= -lm -lz
29DPADD+= ${LIBM} ${LIBZ}
30
31CFLAGS+= -I.
32
33SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
34 pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
35 pngwtran.c pngmem.c pngerror.c pngpread.c
36
37pngtest: pngtest.o libpng.a
38 ${CC} ${CFLAGS} -L. -static -o pngtest pngtest.o -lpng -lz -lm
39
40CLEANFILES= pngtest pngtest.o pngout.png
41
42test: pngtest
43 ./pngtest
44
45# see scripts/pnglibconf.mak for more options
46pnglibconf.h: scripts/pnglibconf.h.prebuilt
47 cp scripts/pnglibconf.h.prebuilt $@
48
49DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
50writelock:
51 chmod a-w *.[ch35] $(DOCS) scripts/*
52
53.include <bsd.lib.mk>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.gcc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.gcc
new file mode 100644
index 0000000..c871f7d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.gcc
@@ -0,0 +1,87 @@
1# makefile for libpng using gcc (generic, static library)
2# Copyright (C) 2008 Glenn Randers-Pehrson
3# Copyright (C) 2000 Cosmin Truta
4# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10# Location of the zlib library and include files
11ZLIBINC = ../zlib
12ZLIBLIB = ../zlib
13
14# Compiler, linker, lib and other tools
15CC = gcc
16LD = $(CC)
17AR_RC = ar rcs
18RANLIB = ranlib
19RM_F = rm -f
20
21CDEBUG = -g -DPNG_DEBUG=5
22LDDEBUG =
23CRELEASE = -O2
24LDRELEASE = -s
25#CFLAGS = -W -Wall $(CDEBUG)
26CFLAGS = -W -Wall $(CRELEASE)
27#LDFLAGS = $(LDDEBUG)
28LDFLAGS = $(LDRELEASE)
29LIBS = -lz -lm
30
31# File extensions
32O=.o
33A=.a
34EXE=
35
36# Variables
37OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \
38 pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \
39 pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
40
41# Targets
42all: static
43
44# see scripts/pnglibconf.mak for more options
45pnglibconf.h: scripts/pnglibconf.h.prebuilt
46 cp scripts/pnglibconf.h.prebuilt $@
47
48.c$(O):
49 $(CC) -c $(CFLAGS) -I$(ZLIBINC) $<
50
51static: libpng$(A) pngtest$(EXE)
52
53shared:
54 @echo This is a generic makefile that cannot create shared libraries.
55 @echo Please use a configuration that is specific to your platform.
56 @false
57
58libpng$(A): $(OBJS)
59 $(AR_RC) $@ $(OBJS)
60 $(RANLIB) $@
61
62test: pngtest$(EXE)
63 ./pngtest$(EXE)
64
65pngtest$(EXE): pngtest$(O) libpng$(A)
66 $(LD) $(LDFLAGS) -L$(ZLIBLIB) -o $@ pngtest$(O) libpng$(A) $(LIBS)
67
68clean:
69 $(RM_F) *$(O) libpng$(A) pngtest$(EXE) pngout.png pnglibconf.h
70
71png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
72pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
73pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
74pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
75pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
76pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
77pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
78pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
79pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
80pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
81pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
82pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
83pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
84pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
85pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
86
87pngtest$(O): png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hp64 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hp64
new file mode 100644
index 0000000..0f4f7ac
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hp64
@@ -0,0 +1,224 @@
1# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product.
2# Copyright (C) 1999-2002, 2006, 2009, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42
4# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10# Where the zlib library and include files are located
11ZLIBLIB=/opt/zlib/lib
12ZLIBINC=/opt/zlib/include
13
14# Note that if you plan to build a libpng shared library, zlib must also
15# be a shared library, which zlib's configure does not do. After running
16# zlib's configure, edit the appropriate lines of makefile to read:
17# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \
18# LDSHARED=ld -b
19# SHAREDLIB=libz.sl
20
21# Library name:
22LIBNAME = libpng15
23PNGMAJ = 15
24
25# Shared library names:
26LIBSO=$(LIBNAME).sl
27LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)
28LIBSOREL=$(LIBSOMAJ).$(RELEASE)
29OLDSO=libpng.sl
30
31# Utilities:
32AR_RC=ar rc
33CC=cc
34MKDIR_P=mkdir -p
35LN_SF=ln -sf
36RANLIB=ranlib
37RM_F=/bin/rm -f
38
39CFLAGS=-I$(ZLIBINC) -O -Ae -Wl,+vnocompatwarnings +DD64 \
40-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +Z -DHAVE_UNISTD_H -DUSE_MMAP
41# Caution: be sure you have built zlib with the same CFLAGS.
42CCFLAGS=-I$(ZLIBINC) -O -Ae -Wl,+vnocompatwarnings +DD64 \
43-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 +Z -DHAVE_UNISTD_H -DUSE_MMAP
44
45LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
46
47# where make install puts libpng.a, libpng15.sl, and png.h
48prefix=/opt/libpng
49exec_prefix=$(prefix)
50INCPATH=$(prefix)/include
51LIBPATH=$(exec_prefix)/lib
52MANPATH=$(prefix)/man
53BINPATH=$(exec_prefix)/bin
54
55# override DESTDIR= on the make install command line to easily support
56# installing into a temporary location. Example:
57#
58# make install DESTDIR=/tmp/build/libpng
59#
60# If you're going to install into a temporary location
61# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
62# you execute make install.
63DESTDIR=
64
65DB=$(DESTDIR)$(BINPATH)
66DI=$(DESTDIR)$(INCPATH)
67DL=$(DESTDIR)$(LIBPATH)
68DM=$(DESTDIR)$(MANPATH)
69
70OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
71 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
72 pngwtran.o pngmem.o pngerror.o pngpread.o
73
74OBJSDLL = $(OBJS:.o=.pic.o)
75
76.SUFFIXES: .c .o .pic.o
77
78.c.pic.o:
79 $(CC) -c $(CFLAGS) +z -o $@ $*.c
80
81all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
82
83# see scripts/pnglibconf.mak for more options
84pnglibconf.h: scripts/pnglibconf.h.prebuilt
85 cp scripts/pnglibconf.h.prebuilt $@
86
87libpng.a: $(OBJS)
88 $(AR_RC) $@ $(OBJS)
89 $(RANLIB) $@
90
91libpng.pc:
92 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
93 -e s!@exec_prefix@!$(exec_prefix)! \
94 -e s!@libdir@!$(LIBPATH)! \
95 -e s!@includedir@!$(INCPATH)! \
96 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
97
98libpng-config:
99 ( cat scripts/libpng-config-head.in; \
100 echo prefix=\"$(prefix)\"; \
101 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
102 echo ccopts=\"-Ae +DA1.1 +DS2.0\"; \
103 echo L_opts=\"-L$(LIBPATH)\"; \
104 echo libs=\"-lpng15 -lz -lm\"; \
105 cat scripts/libpng-config-body.in ) > libpng-config
106 chmod +x libpng-config
107
108$(LIBSO): $(LIBSOMAJ)
109 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
110
111$(LIBSOMAJ): $(OBJSDLL)
112 $(LD) -b +s \
113 +h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)
114
115pngtest: pngtest.o libpng.a
116 $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
117
118test: pngtest
119 ./pngtest
120
121install-headers: png.h pngconf.h pnglibconf.h
122 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
123 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
124 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
125 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
126 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
127 -@$(RM_F) $(DI)/libpng
128 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
129
130install-static: install-headers libpng.a
131 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
132 cp libpng.a $(DL)/$(LIBNAME).a
133 chmod 644 $(DL)/$(LIBNAME).a
134 -@$(RM_F) $(DL)/libpng.a
135 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
136
137install-shared: install-headers $(LIBSOMAJ) libpng.pc
138 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
139 -@$(RM_F) $(DL)/$(LIBSO)
140 -@$(RM_F) $(DL)/$(LIBSOREL)
141 -@$(RM_F) $(DL)/$(OLDSO)
142 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
143 chmod 755 $(DL)/$(LIBSOREL)
144 (cd $(DL); \
145 $(LN_SF) $(LIBSOREL) $(LIBSO); \
146 $(LN_SF) $(LIBSO) $(OLDSO))
147 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
148 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
149 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
150 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
151 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
152 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
153
154install-man: libpng.3 libpngpf.3 png.5
155 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
156 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
157 -@$(RM_F) $(DM)/man3/libpng.3
158 -@$(RM_F) $(DM)/man3/libpngpf.3
159 cp libpng.3 $(DM)/man3
160 cp libpngpf.3 $(DM)/man3
161 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
162 -@$(RM_F) $(DM)/man5/png.5
163 cp png.5 $(DM)/man5
164
165install-config: libpng-config
166 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
167 -@$(RM_F) $(DB)/libpng-config
168 -@$(RM_F) $(DB)/$(LIBNAME)-config
169 cp libpng-config $(DB)/$(LIBNAME)-config
170 chmod 755 $(DB)/$(LIBNAME)-config
171 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
172
173install: install-static install-shared install-man install-config
174
175# If you installed in $(DESTDIR), test-installed won't work until you
176# move the library to its final location. Use test-dd to test it
177# before then.
178
179test-dd:
180 echo
181 echo Testing installed dynamic shared library in $(DL).
182 $(CC) -I$(DI) -I$(ZLIBINC) $(CCFLAGS) \
183 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
184 -L$(DL) -L$(ZLIBLIB) \
185 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
186 ./pngtestd pngtest.png
187
188test-installed:
189 echo
190 echo Testing installed dynamic shared library.
191 $(CC) $(CCFLAGS) \
192 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
193 -L$(ZLIBLIB) \
194 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
195 ./pngtesti pngtest.png
196
197clean:
198 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
199 libpng-config $(LIBSO) $(LIBSOMAJ)* \
200 libpng.pc pnglibconf.h
201
202DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
203writelock:
204 chmod a-w *.[ch35] $(DOCS) scripts/*
205
206# DO NOT DELETE THIS LINE -- make depend depends on it.
207
208png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
209pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
210pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
211pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
212pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
220pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223
224pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpgcc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpgcc
new file mode 100644
index 0000000..28ca7bb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpgcc
@@ -0,0 +1,230 @@
1# makefile for libpng on HP-UX using GCC with the HP ANSI/C linker.
2# Copyright (C) 2002, 2006-2008, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 2001, Laurent faillie
4# Copyright (C) 1998, 1999 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME = libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).sl
17LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.sl
20
21# Utilities:
22CC=gcc
23LD=ld
24AR_RC=ar rc
25MKDIR_P=mkdir -p
26LN_SF=ln -sf
27RANLIB=ranlib
28RM_F=/bin/rm -f
29
30# where "make install" puts libpng.a, $(OLDSO)*, png.h, pngconf.h
31# and pnglibconf.h
32prefix=/usr/local
33exec_prefix=$(prefix)
34
35# Where the zlib library and include files are located
36ZLIBLIB=/opt/zlib/lib
37ZLIBINC=/opt/zlib/include
38
39# Note that if you plan to build a libpng shared library, zlib must also
40# be a shared library, which zlib's configure does not do. After running
41# zlib's configure, edit the appropriate lines of makefile to read:
42# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \
43# LDSHARED=ld -b
44# SHAREDLIB=libz.sl
45
46ALIGN=
47# for i386:
48#ALIGN=-malign-loops=2 -malign-functions=2
49
50WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
51 -Wmissing-declarations -Wtraditional -Wcast-align \
52 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
53
54# for pgcc version 2.95.1, -O3 is buggy; don't use it.
55
56CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops -DPNG_NO_MMX_CODE \
57 $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
58#LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng15 -lz -lm
59LDFLAGS=-L. -L$(ZLIBLIB) -lpng15 -lz -lm
60
61INCPATH=$(prefix)/include
62LIBPATH=$(exec_prefix)/lib
63MANPATH=$(prefix)/man
64BINPATH=$(exec_prefix)/bin
65
66# override DESTDIR= on the make install command line to easily support
67# installing into a temporary location. Example:
68#
69# make install DESTDIR=/tmp/build/libpng
70#
71# If you're going to install into a temporary location
72# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
73# you execute make install.
74DESTDIR=
75
76DB=$(DESTDIR)$(BINPATH)
77DI=$(DESTDIR)$(INCPATH)
78DL=$(DESTDIR)$(LIBPATH)
79DM=$(DESTDIR)$(MANPATH)
80
81OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
82 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
83 pngwtran.o pngmem.o pngerror.o pngpread.o
84
85OBJSDLL = $(OBJS:.o=.pic.o)
86
87.SUFFIXES: .c .o .pic.o
88
89.c.pic.o:
90 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
91
92all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
93
94libpng.a: $(OBJS)
95 $(AR_RC) $@ $(OBJS)
96 $(RANLIB) $@
97
98libpng.pc:
99 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
100 -e s!@exec_prefix@!$(exec_prefix)! \
101 -e s!@libdir@!$(LIBPATH)! \
102 -e s!@includedir@!$(INCPATH)! \
103 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
104
105libpng-config:
106 ( cat scripts/libpng-config-head.in; \
107 echo prefix=\"$(prefix)\"; \
108 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
109 echo libs=\"-lpng15 -lz -lm\"; \
110 cat scripts/libpng-config-body.in ) > libpng-config
111 chmod +x libpng-config
112
113$(LIBSO): $(LIBSOMAJ)
114 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
115
116$(LIBSOMAJ): $(OBJSDLL)
117 $(LD) -b +s \
118 +h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)
119
120pngtest: pngtest.o $(LIBSO)
121 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
122
123test: pngtest
124 ./pngtest
125
126
127install-headers: png.h pngconf.h pnglibconf.h
128 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
129 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
130 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
131 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
132 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
133 -@$(RM_F) $(DI)/libpng
134 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
135
136install-static: install-headers libpng.a
137 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
138 cp libpng.a $(DL)/$(LIBNAME).a
139 chmod 644 $(DL)/$(LIBNAME).a
140 -@$(RM_F) $(DL)/libpng.a
141 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
142
143install-shared: install-headers $(LIBSOMAJ) libpng.pc
144 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
145 -@$(RM_F) $(DL)/$(LIBSO)
146 -@$(RM_F) $(DL)/$(LIBSOREL)
147 -@$(RM_F) $(DL)/$(OLDSO)
148 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
149 chmod 755 $(DL)/$(LIBSOREL)
150 (cd $(DL); \
151 $(LN_SF) $(LIBSOREL) $(LIBSO); \
152 $(LN_SF) $(LIBSO) $(OLDSO))
153 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
154 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
155 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
156 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
157 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
158 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
159
160install-man: libpng.3 libpngpf.3 png.5
161 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
162 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
163 -@$(RM_F) $(DM)/man3/libpng.3
164 -@$(RM_F) $(DM)/man3/libpngpf.3
165 cp libpng.3 $(DM)/man3
166 cp libpngpf.3 $(DM)/man3
167 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
168 -@$(RM_F) $(DM)/man5/png.5
169 cp png.5 $(DM)/man5
170
171install-config: libpng-config
172 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
173 -@$(RM_F) $(DB)/libpng-config
174 -@$(RM_F) $(DB)/$(LIBNAME)-config
175 cp libpng-config $(DB)/$(LIBNAME)-config
176 chmod 755 $(DB)/$(LIBNAME)-config
177 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
178
179install: install-static install-shared install-man install-config
180
181# If you installed in $(DESTDIR), test-installed won't work until you
182# move the library to its final location. Use test-dd to test it
183# before then.
184
185test-dd:
186 echo
187 echo Testing installed dynamic shared library in $(DL).
188 $(CC) -I$(DI) -I$(ZLIBINC) \
189 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
190 -L$(DL) -L$(ZLIBLIB) -Wl,-rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \
191 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
192 ./pngtestd pngtest.png
193
194test-installed:
195 echo
196 echo Testing installed dynamic shared library.
197 $(CC) -I$(ZLIBINC) \
198 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
199 -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \
200 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
201 ./pngtesti pngtest.png
202
203clean:
204 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
205 libpng-config $(LIBSO) $(LIBSOMAJ)* \
206 libpng.pc pnglibconf.h
207
208DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
209writelock:
210 chmod a-w *.[ch35] $(DOCS) scripts/*
211
212# DO NOT DELETE THIS LINE -- make depend depends on it.
213
214png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
220pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229
230pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpux b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpux
new file mode 100644
index 0000000..fd3a20d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.hpux
@@ -0,0 +1,221 @@
1# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product.
2# Copyright (C) 1999-2002, 2006, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42
4# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10# Where the zlib library and include files are located
11ZLIBLIB=/opt/zlib/lib
12ZLIBINC=/opt/zlib/include
13
14# Note that if you plan to build a libpng shared library, zlib must also
15# be a shared library, which zlib's configure does not do. After running
16# zlib's configure, edit the appropriate lines of makefile to read:
17# CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \
18# LDSHARED=ld -b
19# SHAREDLIB=libz.sl
20
21# Library name:
22LIBNAME = libpng15
23PNGMAJ = 15
24
25# Shared library names:
26LIBSO=$(LIBNAME).sl
27LIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)
28LIBSOREL=$(LIBSOMAJ).$(RELEASE)
29OLDSO=libpng.sl
30
31# Utilities:
32AR_RC=ar rc
33CC=cc
34MKDIR_P=mkdir -p
35LN_SF=ln -sf
36RANLIB=ranlib
37RM_F=/bin/rm -f
38
39# where make install puts libpng.a, libpng15.sl, and png.h
40prefix=/opt/libpng
41exec_prefix=$(prefix)
42INCPATH=$(prefix)/include
43LIBPATH=$(exec_prefix)/lib
44MANPATH=$(prefix)/man
45BINPATH=$(exec_prefix)/bin
46
47CFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0
48# Caution: be sure you have built zlib with the same CFLAGS.
49CCFLAGS=-I$(ZLIBINC) -O -Ae +DA1.1 +DS2.0
50LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
51
52# override DESTDIR= on the make install command line to easily support
53# installing into a temporary location. Example:
54#
55# make install DESTDIR=/tmp/build/libpng
56#
57# If you're going to install into a temporary location
58# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
59# you execute make install.
60DESTDIR=
61
62DB=$(DESTDIR)$(BINPATH)
63DI=$(DESTDIR)$(INCPATH)
64DL=$(DESTDIR)$(LIBPATH)
65DM=$(DESTDIR)$(MANPATH)
66
67OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
68 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
69 pngwtran.o pngmem.o pngerror.o pngpread.o
70
71OBJSDLL = $(OBJS:.o=.pic.o)
72
73.SUFFIXES: .c .o .pic.o
74
75.c.pic.o:
76 $(CC) -c $(CFLAGS) +z -o $@ $*.c
77
78all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
79
80# see scripts/pnglibconf.mak for more options
81pnglibconf.h: scripts/pnglibconf.h.prebuilt
82 cp scripts/pnglibconf.h.prebuilt $@
83
84libpng.a: $(OBJS)
85 $(AR_RC) $@ $(OBJS)
86 $(RANLIB) $@
87
88libpng.pc:
89 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
90 -e s!@exec_prefix@!$(exec_prefix)! \
91 -e s!@libdir@!$(LIBPATH)! \
92 -e s!@includedir@!$(INCPATH)! \
93 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
94
95libpng-config:
96 ( cat scripts/libpng-config-head.in; \
97 echo prefix=\"$(prefix)\"; \
98 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
99 echo ccopts=\"-Ae +DA1.1 +DS2.0\"; \
100 echo L_opts=\"-L$(LIBPATH)\"; \
101 echo libs=\"-lpng15 -lz -lm\"; \
102 cat scripts/libpng-config-body.in ) > libpng-config
103 chmod +x libpng-config
104
105$(LIBSO): $(LIBSOMAJ)
106 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
107
108$(LIBSOMAJ): $(OBJSDLL)
109 $(LD) -b +s \
110 +h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)
111
112pngtest: pngtest.o libpng.a
113 $(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
114
115test: pngtest
116 ./pngtest
117
118install-headers: png.h pngconf.h pnglibconf.h
119 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
120 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
121 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
122 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
123 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
124 -@$(RM_F) $(DI)/libpng
125 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
126
127install-static: install-headers libpng.a
128 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
129 cp libpng.a $(DL)/$(LIBNAME).a
130 chmod 644 $(DL)/$(LIBNAME).a
131 -@$(RM_F) $(DL)/libpng.a
132 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
133
134install-shared: install-headers $(LIBSOMAJ) libpng.pc
135 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
136 -@$(RM_F) $(DL)/$(LIBSO)
137 -@$(RM_F) $(DL)/$(LIBSOREL)
138 -@$(RM_F) $(DL)/$(OLDSO)
139 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
140 chmod 755 $(DL)/$(LIBSOREL)
141 (cd $(DL); \
142 $(LN_SF) $(LIBSOREL) $(LIBSO); \
143 $(LN_SF) $(LIBSO) $(OLDSO))
144 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
145 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
146 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
147 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
148 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
149 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
150
151install-man: libpng.3 libpngpf.3 png.5
152 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
153 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
154 -@$(RM_F) $(DM)/man3/libpng.3
155 -@$(RM_F) $(DM)/man3/libpngpf.3
156 cp libpng.3 $(DM)/man3
157 cp libpngpf.3 $(DM)/man3
158 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
159 -@$(RM_F) $(DM)/man5/png.5
160 cp png.5 $(DM)/man5
161
162install-config: libpng-config
163 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
164 -@$(RM_F) $(DB)/libpng-config
165 -@$(RM_F) $(DB)/$(LIBNAME)-config
166 cp libpng-config $(DB)/$(LIBNAME)-config
167 chmod 755 $(DB)/$(LIBNAME)-config
168 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
169
170install: install-static install-shared install-man install-config
171
172# If you installed in $(DESTDIR), test-installed won't work until you
173# move the library to its final location. Use test-dd to test it
174# before then.
175
176test-dd:
177 echo
178 echo Testing installed dynamic shared library in $(DL).
179 $(CC) -I$(DI) -I$(ZLIBINC) $(CCFLAGS) \
180 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
181 -L$(DL) -L$(ZLIBLIB) \
182 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
183 ./pngtestd pngtest.png
184
185test-installed:
186 echo
187 echo Testing installed dynamic shared library.
188 $(CC) $(CCFLAGS) \
189 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
190 -L$(ZLIBLIB) \
191 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
192 ./pngtesti pngtest.png
193
194clean:
195 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
196 libpng-config $(LIBSO) $(LIBSOMAJ)* \
197 libpng.pc pnglibconf.h
198
199DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
200writelock:
201 chmod a-w *.[ch35] $(DOCS) scripts/*
202
203# DO NOT DELETE THIS LINE -- make depend depends on it.
204
205png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
206pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
207pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
208pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
209pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
210pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
211pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
212pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
220
221pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ibmc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ibmc
new file mode 100644
index 0000000..8c9440a
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ibmc
@@ -0,0 +1,82 @@
1# Makefile for libpng (static)
2# IBM C version 3.x for Win32 and OS/2
3# Copyright (C) 2006 Glenn Randers-Pehrson
4# Copyright (C) 2000 Cosmin Truta
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9#
10# Notes:
11# Derived from makefile.std
12# All modules are compiled in C mode
13# Tested under Win32, expected to work under OS/2
14# Can be easily adapted for IBM VisualAge/C++ for AIX
15
16# Location of the zlib library and include files
17ZLIBINC = ../zlib
18ZLIBLIB = ../zlib
19
20# Compiler, linker, lib and other tools
21CC = icc
22LD = ilink
23AR = ilib
24RM = del
25
26CFLAGS = -I$(ZLIBINC) -Mc -O2 -W3
27LDFLAGS =
28
29# File extensions
30O=.obj
31A=.lib
32E=.exe
33
34# Variables
35OBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \
36 pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \
37 pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
38
39LIBS = libpng$(A) $(ZLIBLIB)/zlib$(A)
40
41# Targets
42all: libpng$(A) pngtest$(E)
43
44# see scripts/pnglibconf.mak for more options
45pnglibconf.h: scripts/pnglibconf.h.prebuilt
46 cp scripts/pnglibconf.h.prebuilt $@
47
48libpng$(A): $(OBJS)
49 $(AR) -out:$@ $(OBJS)
50
51test: pngtest$(E)
52 pngtest$(E)
53
54pngtest: pngtest$(E)
55
56pngtest$(E): pngtest$(O) libpng$(A)
57 $(LD) $(LDFLAGS) pngtest$(O) $(LIBS)
58
59clean:
60 $(RM) *$(O)
61 $(RM) libpng$(A)
62 $(RM) pnglibconf.h
63 $(RM) pngtest$(E)
64 $(RM) pngout.png
65
66png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
67pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
68pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
69pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
70pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
71pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
72pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
73pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
74pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
75pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
76pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
77pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
78pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
79pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
80pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
81
82pngtest$(O): png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.intel b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.intel
new file mode 100644
index 0000000..4231078
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.intel
@@ -0,0 +1,110 @@
1# Makefile for libpng
2# Microsoft Visual C++ with Intel C/C++ Compiler 4.0 and later
3
4# Copyright (C) 2006 Glenn Randers-Pehrson
5# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is
6# copyright 1995 Guy Eric Schalnat, Group 42, Inc.
7#
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11#
12# To use, do "nmake /f scripts\makefile.intel"
13#
14# ------------------- Intel C/C++ Compiler 4.0 and later -------------------
15
16# Where the zlib library and include files are located
17ZLIBLIB=..\zlib
18ZLIBINC=..\zlib
19
20# Target CPU
21CPU=6 # Pentium II
22#CPU=5 # Pentium
23
24# Calling convention
25CALLING=r # __fastcall
26#CALLING=z # __stdcall
27#CALLING=d # __cdecl
28
29# Uncomment next to put error messages in a file
30#ERRFILE=>>pngerrs
31
32# --------------------------------------------------------------------------
33
34CC=icl -c
35CFLAGS=-O2 -G$(CPU)$(CALLING) -Qip -Qunroll4 -I$(ZLIBINC) -nologo
36LD=link
37LDFLAGS=/SUBSYSTEM:CONSOLE /NOLOGO
38
39O=.obj
40
41OBJS=png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) \
42pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) \
43pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
44
45all: test
46
47# see scripts/pnglibconf.mak for more options
48pnglibconf.h: scripts/pnglibconf.h.prebuilt
49 cp scripts/pnglibconf.h.prebuilt $@
50
51png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
52 $(CC) $(CFLAGS) $*.c $(ERRFILE)
53
54pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
55 $(CC) $(CFLAGS) $*.c $(ERRFILE)
56
57pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
58 $(CC) $(CFLAGS) $*.c $(ERRFILE)
59
60pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
61 $(CC) $(CFLAGS) $*.c $(ERRFILE)
62
63pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
64 $(CC) $(CFLAGS) $*.c $(ERRFILE)
65
66pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
67 $(CC) $(CFLAGS) $*.c $(ERRFILE)
68
69pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
70 $(CC) $(CFLAGS) $*.c $(ERRFILE)
71
72pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
73 $(CC) $(CFLAGS) $*.c $(ERRFILE)
74
75pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
76 $(CC) $(CFLAGS) $*.c $(ERRFILE)
77
78pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
79 $(CC) $(CFLAGS) $*.c $(ERRFILE)
80
81pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
82 $(CC) $(CFLAGS) $*.c $(ERRFILE)
83
84pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
85 $(CC) $(CFLAGS) $*.c $(ERRFILE)
86
87pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
88 $(CC) $(CFLAGS) $*.c $(ERRFILE)
89
90pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
91 $(CC) $(CFLAGS) $*.c $(ERRFILE)
92
93pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
94 $(CC) $(CFLAGS) $*.c $(ERRFILE)
95
96libpng.lib: $(OBJS)
97 if exist libpng.lib del libpng.lib
98 lib /NOLOGO /OUT:libpng.lib $(OBJS)
99
100pngtest.exe: pngtest.obj libpng.lib
101 $(LD) $(LDFLAGS) /OUT:pngtest.exe pngtest.obj libpng.lib $(ZLIBLIB)\zlib.lib
102
103pngtest$(O): png.h pngconf.h pnglibconf.h
104 $(CC) $(CFLAGS) $*.c $(ERRFILE)
105
106test: pngtest.exe
107 pngtest.exe
108
109
110# End of makefile for libpng
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.knr b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.knr
new file mode 100644
index 0000000..912c542
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.knr
@@ -0,0 +1,109 @@
1# makefile for libpng
2# Copyright (C) 2002, 2006, 2009 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8#
9# This makefile requires the file ansi2knr.c, which you can get
10# from the Ghostscript ftp site at ftp://ftp.cs.wisc.edu/ghost/
11# If you have libjpeg, you probably already have ansi2knr.c in the jpeg
12# source distribution.
13
14# where make install puts libpng.a and png.h
15prefix=/usr/local
16INCPATH=$(prefix)/include
17LIBPATH=$(prefix)/lib
18
19# override DESTDIR= on the make install command line to easily support
20# installing into a temporary location. Example:
21#
22# make install DESTDIR=/tmp/build/libpng
23#
24# If you're going to install into a temporary location
25# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
26# you execute make install.
27DESTDIR=
28
29CC=cc
30CFLAGS=-I../zlib -O
31LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
32# flags for ansi2knr
33ANSI2KNRFLAGS=
34
35RANLIB=ranlib
36#RANLIB=echo
37
38OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
39 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
40 pngwtran.o pngmem.o pngerror.o pngpread.o
41
42all: ansi2knr libpng.a pngtest
43
44# see scripts/pnglibconf.mak for more options
45pnglibconf.h: scripts/pnglibconf.h.prebuilt
46 cp scripts/pnglibconf.h.prebuilt $@
47
48# general rule to allow ansi2knr to work
49.c.o:
50 ./ansi2knr $*.c T$*.c
51 $(CC) $(CFLAGS) -c T$*.c
52 rm -f T$*.c $*.o
53 mv T$*.o $*.o
54
55ansi2knr: ansi2knr.c
56 $(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c
57
58libpng.a: ansi2knr $(OBJS)
59 ar rc $@ $(OBJS)
60 $(RANLIB) $@
61
62pngtest: pngtest.o libpng.a
63 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
64
65test: pngtest
66 ./pngtest
67
68install: libpng.a png.h pngconf.h pnglibconf.h
69 -@mkdir $(DESTDIR)$(INCPATH)
70 -@mkdir $(DESTDIR)$(INCPATH)/libpng
71 -@mkdir $(DESTDIR)$(LIBPATH)
72 -@rm -f $(DESTDIR)$(INCPATH)/png.h
73 -@rm -f $(DESTDIR)$(INCPATH)/pngconf.h
74 cp png.h $(DESTDIR)$(INCPATH)/libpng
75 cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
76 cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
77 chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
78 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
79 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
80 (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)
81 cp libpng.a $(DESTDIR)$(LIBPATH)
82 chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a
83
84clean:
85 rm -f *.o libpng.a pngtest pngout.png ansi2knr pnglibconf.h
86
87DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
88writelock:
89 chmod a-w *.[ch35] $(DOCS) scripts/*
90
91# DO NOT DELETE THIS LINE -- make depend depends on it.
92
93png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
94pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
95pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
96pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
97pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
98pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
99pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
100pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
101pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
102pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
103pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
104pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
105pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
106pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
107pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
108
109pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.linux b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.linux
new file mode 100644
index 0000000..95680f6
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.linux
@@ -0,0 +1,239 @@
1# makefile for libpng.a and libpng15.so on Linux ELF with gcc
2# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2011 Greg Roelofs and
3# Glenn Randers-Pehrson
4# Copyright (C) 1996, 1997 Andreas Dilger
5#
6# This code is released under the libpng license.
7# For conditions of distribution and use, see the disclaimer
8# and license in png.h
9
10# Library name:
11LIBNAME = libpng15
12PNGMAJ = 15
13RELEASE = 9
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22AR_RC=ar rc
23CC=gcc
24MKDIR_P=mkdir -p
25LN_SF=ln -sf
26RANLIB=ranlib
27RM_F=/bin/rm -f
28
29# where "make install" puts libpng15.a, libpng15.so*,
30# libpng15/png.h, libpng15/pngconf.h, and libpng15/pnglibconf.h
31# Prefix must be a full pathname.
32prefix=/usr/local
33exec_prefix=$(prefix)
34
35# Where the zlib library and include files are located.
36#ZLIBLIB=/usr/local/lib
37#ZLIBINC=/usr/local/include
38ZLIBLIB=../zlib
39ZLIBINC=../zlib
40
41ALIGN=
42# for i386:
43#ALIGN=-malign-loops=2 -malign-functions=2
44
45WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
46 -Wmissing-declarations -Wtraditional -Wcast-align \
47 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
48
49# for pgcc version 2.95.1, -O3 is buggy; don't use it.
50
51CFLAGS=-I$(ZLIBINC) -W -Wall -O3 -funroll-loops \
52 $(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5
53
54LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng15 -lz -lm
55LDFLAGS_A=-L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) libpng.a -lz -lm
56
57INCPATH=$(prefix)/include
58LIBPATH=$(exec_prefix)/lib
59MANPATH=$(prefix)/man
60BINPATH=$(exec_prefix)/bin
61
62# override DESTDIR= on the make install command line to easily support
63# installing into a temporary location. Example:
64#
65# make install DESTDIR=/tmp/build/libpng
66#
67# If you're going to install into a temporary location
68# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
69# you execute make install.
70DESTDIR=
71
72DB=$(DESTDIR)$(BINPATH)
73DI=$(DESTDIR)$(INCPATH)
74DL=$(DESTDIR)$(LIBPATH)
75DM=$(DESTDIR)$(MANPATH)
76
77OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
78 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
79 pngwtran.o pngmem.o pngerror.o pngpread.o
80
81OBJSDLL = $(OBJS:.o=.pic.o)
82
83.SUFFIXES: .c .o .pic.o
84
85.c.pic.o:
86 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
87
88all: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config
89
90# see scripts/pnglibconf.mak for more options
91pnglibconf.h: scripts/pnglibconf.h.prebuilt
92 cp scripts/pnglibconf.h.prebuilt $@
93
94libpng.a: $(OBJS)
95 $(AR_RC) $@ $(OBJS)
96 $(RANLIB) $@
97
98libpng.pc:
99 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
100 -e s!@exec_prefix@!$(exec_prefix)! \
101 -e s!@libdir@!$(LIBPATH)! \
102 -e s!@includedir@!$(INCPATH)! \
103 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
104
105libpng-config:
106 ( cat scripts/libpng-config-head.in; \
107 echo prefix=\"$(prefix)\"; \
108 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
109 echo L_opts=\"-L$(LIBPATH)\"; \
110 echo R_opts=\"-Wl,-rpath,$(LIBPATH)\"; \
111 echo libs=\"-lpng15 -lz -lm\"; \
112 cat scripts/libpng-config-body.in ) > libpng-config
113 chmod +x libpng-config
114
115$(LIBSO): $(LIBSOMAJ)
116 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
117
118$(LIBSOMAJ): $(OBJSDLL)
119 $(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)
120
121pngtest: pngtest.o $(LIBSO)
122 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
123
124pngtest-static: pngtest.o libpng.a
125 $(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A)
126
127test: pngtest pngtest-static
128 @echo ""
129 @echo " Running pngtest dynamically linked with $(LIBSO):"
130 @echo ""
131 ./pngtest
132 @echo ""
133 @echo " Running pngtest statically linked with libpng.a:"
134 @echo ""
135 ./pngtest-static
136
137install-headers: png.h pngconf.h pnglibconf.h
138 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
139 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
140 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
141 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
142 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
143 -@$(RM_F) $(DI)/libpng
144 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
145
146install-static: install-headers libpng.a
147 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
148 cp libpng.a $(DL)/$(LIBNAME).a
149 chmod 644 $(DL)/$(LIBNAME).a
150 -@$(RM_F) $(DL)/libpng.a
151 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
152
153install-shared: install-headers $(LIBSOMAJ) libpng.pc
154 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
155 -@$(RM_F) $(DL)/$(LIBSO)
156 -@$(RM_F) $(DL)/$(LIBSOREL)
157 -@$(RM_F) $(DL)/$(OLDSO)
158 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
159 chmod 755 $(DL)/$(LIBSOREL)
160 (cd $(DL); \
161 $(LN_SF) $(LIBSOREL) $(LIBSO); \
162 $(LN_SF) $(LIBSO) $(OLDSO))
163
164 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
165 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
166 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
167 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
168 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
169 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
170
171install-man: libpng.3 libpngpf.3 png.5
172 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
173 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
174 -@$(RM_F) $(DM)/man3/libpng.3
175 -@$(RM_F) $(DM)/man3/libpngpf.3
176 cp libpng.3 $(DM)/man3
177 cp libpngpf.3 $(DM)/man3
178 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
179 -@$(RM_F) $(DM)/man5/png.5
180 cp png.5 $(DM)/man5
181
182install-config: libpng-config
183 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
184 -@$(RM_F) $(DB)/libpng-config
185 -@$(RM_F) $(DB)/$(LIBNAME)-config
186 cp libpng-config $(DB)/$(LIBNAME)-config
187 chmod 755 $(DB)/$(LIBNAME)-config
188 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
189
190install: install-static install-shared install-man install-config
191
192# If you installed in $(DESTDIR), test-installed won't work until you
193# move the library to its final location. Use test-dd to test it
194# before then.
195
196test-dd:
197 echo
198 echo Testing installed dynamic shared library in $(DL).
199 $(CC) -I$(DI) -I$(ZLIBINC) \
200 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
201 -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \
202 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
203 ./pngtestd pngtest.png
204
205test-installed:
206 $(CC) -I$(ZLIBINC) \
207 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
208 -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \
209 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
210 ./pngtesti pngtest.png
211
212clean:
213 $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \
214 $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \
215 libpng.pc pnglibconf.h
216
217DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
218writelock:
219 chmod a-w *.[ch35] $(DOCS) scripts/*
220
221# DO NOT DELETE THIS LINE -- make depend depends on it.
222
223png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
236pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
237pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
238
239pngtest.o: png.h pngconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.mips b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.mips
new file mode 100644
index 0000000..bd254fc
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.mips
@@ -0,0 +1,94 @@
1# makefile for libpng
2# Copyright (C) Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# where make install puts libpng.a and png.h
10prefix=/usr/local
11INCPATH=$(prefix)/include
12LIBPATH=$(prefix)/lib
13
14# override DESTDIR= on the make install command line to easily support
15# installing into a temporary location. Example:
16#
17# make install DESTDIR=/tmp/build/libpng
18#
19# If you're going to install into a temporary location
20# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
21# you execute make install.
22DESTDIR=
23
24CC=cc
25CFLAGS=-I../zlib -O -systype sysv -DSYSV -w -Dmips
26#CFLAGS=-O
27LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
28
29#RANLIB=ranlib
30RANLIB=echo
31
32OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
33 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
34 pngwtran.o pngmem.o pngerror.o pngpread.o
35
36all: libpng.a pngtest
37
38# see scripts/pnglibconf.mak for more options
39pnglibconf.h: scripts/pnglibconf.h.prebuilt
40 cp scripts/pnglibconf.h.prebuilt $@
41
42libpng.a: $(OBJS)
43 ar rc $@ $(OBJS)
44 $(RANLIB) $@
45
46pngtest: pngtest.o libpng.a
47 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
48
49test: pngtest
50 ./pngtest
51
52install: libpng.a
53 -@mkdir $(DESTDIR)$(INCPATH)
54 -@mkdir $(DESTDIR)$(INCPATH)/libpng
55 -@mkdir $(DESTDIR)$(LIBPATH)
56 -@rm -f $(DESTDIR)$(INCPATH)/png.h
57 -@rm -f $(DESTDIR)$(INCPATH)/pngconf.h
58 -@rm -f $(DESTDIR)$(INCPATH)/pnglibconf.h
59 cp png.h $(DESTDIR)$(INCPATH)/libpng
60 cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
61 cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
62 chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
63 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
64 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
65 (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)
66 cp libpng.a $(DESTDIR)$(LIBPATH)
67 chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a
68
69clean:
70 rm -f *.o libpng.a pngtest pngout.png pnglibconf.h
71
72DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
73writelock:
74 chmod a-w *.[ch35] $(DOCS) scripts/*
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
79pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
80pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
81pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
82pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
83pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
84pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
85pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
86pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
87pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
88pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
89pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
90pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
91pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
92pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
93
94pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.msc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.msc
new file mode 100644
index 0000000..25adbb4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.msc
@@ -0,0 +1,95 @@
1# makefile for libpng
2# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
3# Copyright (C) 2006, 2009 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8#
9# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib
10
11# -------- Microsoft C 5.1 and later, does not use assembler code --------
12MODEL=L
13CFLAGS=-Oait -Gs -nologo -W3 -A$(MODEL) -I..\zlib
14#-Ox generates bad code with MSC 5.1
15CC=cl
16LD=link
17LDFLAGS=/e/st:0x1500/noe
18O=.obj
19
20#uncomment next to put error messages in a file
21ERRFILE= >> pngerrs
22
23# variables
24OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
25OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
26OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
27
28all: libpng.lib
29
30# see scripts/pnglibconf.mak for more options
31pnglibconf.h: scripts/pnglibconf.h.prebuilt
32 cp scripts/pnglibconf.h.prebuilt $@
33
34png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
35 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
36
37pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
38 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
39
40pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
41 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
42
43pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
44 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
45
46pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
47 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
48
49pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
50 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
51
52pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
53 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
54
55pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
56 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
57
58pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
59 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
60
61pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
62 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
63
64pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
65 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
66
67pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
68 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
69
70pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
71 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
72
73pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
74 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
75
76pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
77 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
78
79libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
80 del libpng.lib
81 lib libpng $(OBJS1);
82 lib libpng $(OBJS2);
83 lib libpng $(OBJS3);
84
85pngtest$(O): png.h pngconf.h pnglibconf.h
86 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
87
88pngtest.exe: pngtest.obj libpng.lib
89 $(LD) $(LDFLAGS) pngtest.obj,,,libpng.lib ..\zlib\zlib.lib ;
90
91test: pngtest.exe
92 pngtest
93
94# End of makefile for libpng
95
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ne12bsd b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ne12bsd
new file mode 100644
index 0000000..526284f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.ne12bsd
@@ -0,0 +1,50 @@
1# makefile for libpng for NetBSD for the standard
2# make obj && make depend && make && make test
3# make includes && make install
4# Copyright (C) 2002 Patrick R.L. Welche
5# Copyright (C) 2007, 2009 Glenn Randers-Pehrson
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# You should also run makefile.netbsd
12
13LOCALBASE?=/usr/local
14LIBDIR= ${LOCALBASE}/lib
15MANDIR= ${LOCALBASE}/man
16INCSDIR=${LOCALBASE}/include/libpng15
17
18LIB= png15
19SHLIB_MAJOR= 0
20SHLIB_MINOR= 1.5.9
21SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
22 pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
23 pngwtran.c pngmem.c pngerror.c pngpread.c
24INCS= png.h pngconf.h pnglibconf.h
25MAN= libpng.3 libpngpf.3 png.5
26
27CPPFLAGS+=-I${.CURDIR}
28
29# We should be able to do something like this instead of the manual
30# uncommenting, but it core dumps for me at the moment:
31# .if ${MACHINE_ARCH} == "i386"
32# MKLINT= no
33# .endif
34
35CLEANFILES+=pngtest.o pngtest pnglibconf.h
36
37# see scripts/pnglibconf.mak for more options
38pnglibconf.h: scripts/pnglibconf.h.prebuilt
39 cp scripts/pnglibconf.h.prebuilt $@
40
41pngtest.o: pngtest.c
42 ${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET}
43
44pngtest: pngtest.o libpng.a
45 ${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm
46
47test: pngtest
48 cd ${.CURDIR} && ${.OBJDIR}/pngtest
49
50.include <bsd.lib.mk>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.netbsd b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.netbsd
new file mode 100644
index 0000000..5dec277
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.netbsd
@@ -0,0 +1,50 @@
1# makefile for libpng for NetBSD for the standard
2# make obj && make depend && make && make test
3# make includes && make install
4# Copyright (C) 2002 Patrick R.L. Welche
5# Copyright (C) 2007-2009 Glenn Randers-Pehrson
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# You should also run makefile.ne15bsd
12
13LOCALBASE?=/usr/local
14LIBDIR= ${LOCALBASE}/lib
15MANDIR= ${LOCALBASE}/man
16INCSDIR=${LOCALBASE}/include
17
18LIB= png
19SHLIB_MAJOR= 15
20SHLIB_MINOR= 1.5.9
21SRCS= png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
22 pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
23 pngwtran.c pngmem.c pngerror.c pngpread.c
24INCS= png.h pngconf.h pnglibconf.h
25MAN= libpng.3 libpngpf.3 png.5
26
27CPPFLAGS+=-I${.CURDIR}
28
29# We should be able to do something like this instead of the manual
30# uncommenting, but it core dumps for me at the moment:
31# .if ${MACHINE_ARCH} == "i386"
32# MKLINT= no
33# .endif
34
35CLEANFILES+=pngtest.o pngtest pnglibconf.h
36
37# see scripts/pnglibconf.mak for more options
38pnglibconf.h: scripts/pnglibconf.h.prebuilt
39 cp scripts/pnglibconf.h.prebuilt $@
40
41pngtest.o: pngtest.c
42 ${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET}
43
44pngtest: pngtest.o libpng.a
45 ${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm
46
47test: pngtest
48 cd ${.CURDIR} && ${.OBJDIR}/pngtest
49
50.include <bsd.lib.mk>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.openbsd b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.openbsd
new file mode 100644
index 0000000..c4e7e07
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.openbsd
@@ -0,0 +1,82 @@
1# makefile for libpng
2# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
3# Copyright (C) 2007-2009 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9PREFIX?= /usr/local
10LIBDIR= ${PREFIX}/lib
11MANDIR= ${PREFIX}/man/cat
12
13SHLIB_MAJOR= 15
14SHLIB_MINOR= 1.5.9
15
16LIB= png
17SRCS= png.c pngerror.c pngget.c pngmem.c pngpread.c \
18 pngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngtrans.c \
19 pngwio.c pngwrite.c pngwtran.c pngwutil.c
20
21HDRS= png.h pngconf.h pnglibconf.h
22
23CFLAGS+= -W -Wall
24CPPFLAGS+= -I${.CURDIR}
25
26NOPROFILE= Yes
27
28CLEANFILES+= pngtest.o pngtest pnglibconf.h
29
30MAN= libpng.3 libpngpf.3 png.5
31DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \
32 libpng-manual.txt
33
34# see scripts/pnglibconf.mak for more options
35pnglibconf.h: scripts/pnglibconf.h.prebuilt
36 cp scripts/pnglibconf.h.prebuilt $@
37
38pngtest.o: pngtest.c
39 ${CC} ${CPPFLAGS} ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}
40
41pngtest: pngtest.o
42 ${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} -L${.OBJDIR} -lpng -lz -lm
43
44test: pngtest
45 cd ${.OBJDIR} && env \
46 LD_LIBRARY_PATH="${.OBJDIR}" ${.OBJDIR}/pngtest
47
48beforeinstall:
49 if [ ! -d ${DESTDIR}${PREFIX}/include/libpng ]; then \
50 ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/include; \
51 fi
52 if [ ! -d ${DESTDIR}${LIBDIR} ]; then \
53 ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}; \
54 fi
55 if [ ! -d ${DESTDIR}${LIBDIR}/debug ]; then \
56 ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}/debug; \
57 fi
58 if [ ! -d ${DESTDIR}${MANDIR}3 ]; then \
59 ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}3; \
60 fi
61 if [ ! -d ${DESTDIR}${MANDIR}5 ]; then \
62 ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}5; \
63 fi
64 if [ ! -d ${DESTDIR}${PREFIX}/share/doc/png ]; then \
65 ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/share/doc/png; \
66 fi
67
68afterinstall:
69 @rm -f ${DESTDIR}${LIBDIR}/libpng_pic.a
70 @rm -f ${DESTDIR}${LIBDIR}/debug/libpng.a
71 @rm -f ${DESTDIR}${PREFIX}/include/png.h
72 @rm -f ${DESTDIR}${PREFIX}/include/pngconf.h
73 @rm -f ${DESTDIR}${PREFIX}/include/pnglibconf.h
74 @rmdir ${DESTDIR}${LIBDIR}/debug 2>/dev/null || true
75 ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
76 -m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include
77 ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
78 -m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include
79 ${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \
80 -m ${NONBINMODE} ${DOCS} ${DESTDIR}${PREFIX}/share/doc/png
81
82.include <bsd.lib.mk>
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sco b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sco
new file mode 100644
index 0000000..9841e89
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sco
@@ -0,0 +1,218 @@
1# makefile for SCO OSr5 ELF and Unixware 7 with Native cc
2# Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx
3# force ELF build dynamic linking, SONAME setting in lib and RPATH in app
4# Copyright (C) 2002, 2006, 2010-2011 Glenn Randers-Pehrson
5# Copyright (C) 1998 Greg Roelofs
6# Copyright (C) 1996, 1997 Andreas Dilger
7#
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# Library name:
13LIBNAME = libpng15
14PNGMAJ = 15
15
16# Shared library names:
17LIBSO=$(LIBNAME).so
18LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
19LIBSOREL=$(LIBSOMAJ).$(RELEASE)
20OLDSO=libpng.so
21
22# Utilities:
23CC=cc
24AR_RC=ar rc
25MKDIR_P=mkdir
26LN_SF=ln -f -s
27RANLIB=echo
28RM_F=/bin/rm -f
29
30# where make install puts libpng.a, $(OLDSO)*, and png.h
31prefix=/usr/local
32exec_prefix=$(prefix)
33
34# Where the zlib library and include files are located
35#ZLIBLIB=/usr/local/lib
36#ZLIBINC=/usr/local/include
37ZLIBLIB=../zlib
38ZLIBINC=../zlib
39
40CFLAGS= -dy -belf -I$(ZLIBINC) -O3
41LDFLAGS=-L. -L$(ZLIBLIB) -lpng15 -lz -lm
42
43INCPATH=$(prefix)/include
44LIBPATH=$(exec_prefix)/lib
45MANPATH=$(prefix)/man
46BINPATH=$(exec_prefix)/bin
47
48# override DESTDIR= on the make install command line to easily support
49# installing into a temporary location. Example:
50#
51# make install DESTDIR=/tmp/build/libpng
52#
53# If you're going to install into a temporary location
54# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
55# you execute make install.
56DESTDIR=
57
58DB=$(DESTDIR)$(BINPATH)
59DI=$(DESTDIR)$(INCPATH)
60DL=$(DESTDIR)$(LIBPATH)
61DM=$(DESTDIR)$(MANPATH)
62
63OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
64 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
65 pngwtran.o pngmem.o pngerror.o pngpread.o
66
67OBJSDLL = $(OBJS:.o=.pic.o)
68
69.SUFFIXES: .c .o .pic.o
70
71.c.pic.o:
72 $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c
73
74all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
75
76# see scripts/pnglibconf.mak for more options
77pnglibconf.h: scripts/pnglibconf.h.prebuilt
78 cp scripts/pnglibconf.h.prebuilt $@
79
80libpng.a: $(OBJS)
81 $(AR_RC) $@ $(OBJS)
82 $(RANLIB) $@
83
84libpng.pc:
85 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
86 -e s!@exec_prefix@!$(exec_prefix)! \
87 -e s!@libdir@!$(LIBPATH)! \
88 -e s!@includedir@!$(INCPATH)! \
89 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
90
91libpng-config:
92 ( cat scripts/libpng-config-head.in; \
93 echo prefix=\"$(prefix)\"; \
94 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
95 echo ccopts=\"-belf\"; \
96 echo L_opts=\"-L$(LIBPATH)\"; \
97 echo libs=\"-lpng15 -lz -lm\"; \
98 cat scripts/libpng-config-body.in ) > libpng-config
99 chmod +x libpng-config
100
101$(LIBSO): $(LIBSOMAJ)
102 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
103
104$(LIBSOMAJ): $(OBJSDLL)
105 $(CC) -G -Wl,-h,$(LIBSOMAJ) -o $(LIBSOMAJ) \
106 $(OBJSDLL)
107
108pngtest: pngtest.o $(LIBSO)
109 LD_RUN_PATH=.:$(ZLIBLIB) $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
110
111test: pngtest
112 ./pngtest
113
114install-headers: png.h pngconf.h pnglibconf.h
115 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
116 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
117 -@$(RM_F) $(DI)/png.h
118 -@$(RM_F) $(DI)/pngconf.h
119 -@$(RM_F) $(DI)/pnglibconf.h
120 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
121 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
122 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
123 -@$(RM_F) $(DI)/libpng
124 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
125
126install-static: install-headers libpng.a
127 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
128 cp libpng.a $(DL)/$(LIBNAME).a
129 chmod 644 $(DL)/$(LIBNAME).a
130 -@$(RM_F) $(DL)/libpng.a
131 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
132
133install-shared: install-headers $(LIBSOMAJ) libpng.pc
134 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
135 -@$(RM_F) $(DL)/$(LIBSO)
136 -@$(RM_F) $(DL)/$(LIBSOREL)
137 -@$(RM_F) $(DL)/$(OLDSO)
138 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
139 chmod 755 $(DL)/$(LIBSOREL)
140 (cd $(DL); \
141 $(LN_SF) $(LIBSOREL) $(LIBSO); \
142 $(LN_SF) $(LIBSO) $(OLDSO))
143 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
144 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
145 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
146 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
147 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
148 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
149
150install-man: libpng.3 libpngpf.3 png.5
151 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
152 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
153 -@$(RM_F) $(DM)/man3/libpng.3
154 -@$(RM_F) $(DM)/man3/libpngpf.3
155 cp libpng.3 $(DM)/man3
156 cp libpngpf.3 $(DM)/man3
157 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
158 -@$(RM_F) $(DM)/man5/png.5
159 cp png.5 $(DM)/man5
160
161install-config: libpng-config
162 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
163 -@$(RM_F) $(DB)/libpng-config
164 -@$(RM_F) $(DB)/$(LIBNAME)-config
165 cp libpng-config $(DB)/$(LIBNAME)-config
166 chmod 755 $(DB)/$(LIBNAME)-config
167 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
168
169install: install-static install-shared install-man install-config
170
171# If you installed in $(DESTDIR), test-installed won't work until you
172# move the library to its final location. Use test-dd to test it
173# before then.
174
175test-dd:
176 echo
177 echo Testing installed dynamic shared library in $(DL).
178 $(CC) -I$(DI) $(CFLAGS) \
179 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
180 -L$(DL) -L$(ZLIBLIB) \
181 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
182 ./pngtestd pngtest.png
183
184test-installed:
185 $(CC) $(CFLAGS) \
186 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
187 -L$(ZLIBLIB) \
188 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
189 ./pngtesti pngtest.png
190
191clean:
192 $(RM_F) *.o libpng.a pngtest pngout.png libpng-config \
193 $(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \
194 pnglibconf.h libpng.pc
195
196DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
197writelock:
198 chmod a-w *.[ch35] $(DOCS) scripts/*
199
200# DO NOT DELETE THIS LINE -- make depend depends on it.
201
202png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
203pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
204pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
205pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
206pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
207pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
208pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
209pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
210pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
211pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
212pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217
218pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sggcc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sggcc
new file mode 100644
index 0000000..acc1006
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sggcc
@@ -0,0 +1,228 @@
1# makefile for libpng.a and libpng15.so, SGI IRIX with 'cc'
2# Copyright (C) 2001-2002, 2006, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# Library name:
10LIBNAME=libpng15
11PNGMAJ = 15
12
13# Shared library names:
14LIBSO=$(LIBNAME).so
15LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
16LIBSOREL=$(LIBSOMAJ).$(RELEASE)
17OLDSO=libpng.so
18
19# Utilities:
20AR_RC=ar rc
21CC=gcc
22MKDIR_P=mkdir -p
23LN_SF=ln -sf
24RANLIB=echo
25RM_F=/bin/rm -f
26
27# Where make install puts libpng.a, libpng15.so, and libpng15/png.h
28# Prefix must be a full pathname.
29
30prefix=/usr/local
31exec_prefix=$(prefix)
32
33# Where the zlib library and include files are located
34#ZLIBLIB=/usr/local/lib32
35#ZLIBINC=/usr/local/include
36#ZLIBLIB=/usr/local/lib
37#ZLIBINC=/usr/local/include
38ZLIBLIB=../zlib
39ZLIBINC=../zlib
40
41# ABI can be blank to use default for your system, -32, -o32, -n32, or -64
42# See "man abi". zlib must be built with the same ABI.
43ABI=
44
45WARNMORE= # -g -DPNG_DEBUG=5
46CFLAGS=$(ABI) -I$(ZLIBINC) -O $(WARNMORE) -fPIC -mabi=n32
47LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
48LDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \
49 -set_version sgi$(PNGMAJ).0
50# See "man dso" for info about shared objects
51
52INCPATH=$(prefix)/include
53LIBPATH=$(exec_prefix)/lib
54#LIBPATH=$(exec_prefix)/lib32
55MANPATH=$(prefix)/man
56BINPATH=$(exec_prefix)/bin
57
58# override DESTDIR= on the make install command line to easily support
59# installing into a temporary location. Example:
60#
61# make install DESTDIR=/tmp/build/libpng
62#
63# If you're going to install into a temporary location
64# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
65# you execute make install.
66DESTDIR=
67
68DB=$(DESTDIR)$(BINPATH)
69DI=$(DESTDIR)$(INCPATH)
70DL=$(DESTDIR)$(LIBPATH)
71DM=$(DESTDIR)$(MANPATH)
72
73OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
74 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
75 pngwtran.o pngmem.o pngerror.o pngpread.o
76
77all: libpng.a pngtest shared libpng.pc libpng-config
78
79# see scripts/pnglibconf.mak for more options
80pnglibconf.h: scripts/pnglibconf.h.prebuilt
81 cp scripts/pnglibconf.h.prebuilt $@
82
83libpng.a: $(OBJS)
84 $(AR_RC) $@ $(OBJS)
85 $(RANLIB) $@
86
87shared: $(LIBSOMAJ)
88
89libpng.pc:
90 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
91 -e s!@exec_prefix@!$(exec_prefix)! \
92 -e s!@libdir@!$(LIBPATH)! \
93 -e s!@includedir@!$(INCPATH)! \
94 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
95
96libpng-config:
97 ( cat scripts/libpng-config-head.in; \
98 echo prefix=\"$(prefix)\"; \
99 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
100 echo ccopts=\"$(ABI)\"; \
101 echo cppflags=\"\"; \
102 echo ldopts=\"$(ABI)\"; \
103 echo L_opts=\"-L$(LIBPATH)\"; \
104 echo libdir=\"$(LIBPATH)\"; \
105 echo libs=\"-lpng15 -lz -lm\"; \
106 cat scripts/libpng-config-body.in ) > libpng-config
107 chmod +x libpng-config
108
109$(LIBSO): $(LIBSOMAJ)
110 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
111
112$(LIBSOMAJ): $(OBJS)
113 $(LDSHARED) -o $@ $(OBJS)
114 $(RM_F) $(LIBSO) $(LIBSOMAJ)
115
116pngtest: pngtest.o libpng.a
117 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
118
119test: pngtest
120 echo
121 echo Testing local static library.
122 ./pngtest
123
124install-headers: png.h pngconf.h pnglibconf.h
125 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
126 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
127 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
128 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
129 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
130 -@$(RM_F) $(DI)/libpng
131 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
132
133install-static: install-headers libpng.a
134 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
135 cp libpng.a $(DL)/$(LIBNAME).a
136 chmod 644 $(DL)/$(LIBNAME).a
137 -@$(RM_F) $(DL)/libpng.a
138 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
139
140install-shared: install-headers $(LIBSOMAJ) libpng.pc
141 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
142 -@$(RM_F) $(DL)/$(LIBSO)
143 -@$(RM_F) $(DL)/$(LIBSOREL)
144 -@$(RM_F) $(DL)/$(OLDSO)
145 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
146 chmod 755 $(DL)/$(LIBSOREL)
147 (cd $(DL); \
148 $(LN_SF) $(LIBSOREL) $(LIBSO); \
149 $(LN_SF) $(LIBSO) $(OLDSO))
150 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
151 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
152 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
153 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
154 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
155 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
156
157install-man: libpng.3 libpngpf.3 png.5
158 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
159 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
160 -@$(RM_F) $(DM)/man3/libpng.3
161 -@$(RM_F) $(DM)/man3/libpngpf.3
162 cp libpng.3 $(DM)/man3
163 cp libpngpf.3 $(DM)/man3
164 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
165 -@$(RM_F) $(DM)/man5/png.5
166 cp png.5 $(DM)/man5
167
168install-config: libpng-config
169 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
170 -@$(RM_F) $(DB)/libpng-config
171 -@$(RM_F) $(DB)/$(LIBNAME)-config
172 cp libpng-config $(DB)/$(LIBNAME)-config
173 chmod 755 $(DB)/$(LIBNAME)-config
174 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
175
176install: install-static install-shared install-man install-config
177
178# If you installed in $(DESTDIR), test-installed won't work until you
179# move the library to its final location. Use test-dd to test it
180# before then.
181
182test-dd:
183 echo
184 echo Testing installed dynamic shared library in $(DL).
185 $(CC) -I$(DI) -I$(ZLIBINC) \
186 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
187 -L$(DL) -L$(ZLIBLIB) \
188 -rpath $(ZLIBLIB):$(DL) \
189 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
190 ./pngtestd pngtest.png
191
192test-installed:
193 echo
194 echo Testing installed dynamic shared library.
195 $(CC) -I$(ZLIBINC) \
196 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
197 -L$(ZLIBLIB) \
198 -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \
199 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
200 ./pngtesti pngtest.png
201
202clean:
203 $(RM_F) libpng.a pngtest pngtesti pngout.png libpng.pc \
204 so_locations libpng-config $(LIBSO) $(LIBSOMAJ)* pnglibconf.h
205
206DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
207writelock:
208 chmod a-w *.[ch35] $(DOCS) scripts/*
209
210# DO NOT DELETE THIS LINE -- make depend depends on it.
211
212png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
213pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
220pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227
228pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sgi b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sgi
new file mode 100644
index 0000000..ab44f2d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sgi
@@ -0,0 +1,229 @@
1# makefile for libpng.a and libpng15.so, SGI IRIX with 'cc'
2# Copyright (C) 2001-2002, 2006, 2007, 2010-2011 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# Library name:
10LIBNAME=libpng15
11PNGMAJ = 15
12
13# Shared library names:
14LIBSO=$(LIBNAME).so
15LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
16LIBSOREL=$(LIBSOMAJ).$(RELEASE)
17OLDSO=libpng.so
18
19# Utilities:
20AR_RC=ar rc
21CC=cc
22MKDIR_P=mkdir -p
23LN_SF=ln -sf
24RANLIB=echo
25RM_F=/bin/rm -f
26
27# Where make install puts libpng.a, libpng15.so, and libpng15/png.h
28# Prefix must be a full pathname.
29
30prefix=/usr/local
31exec_prefix=$(prefix)
32
33# Where the zlib library and include files are located
34#ZLIBLIB=/usr/local/lib32
35#ZLIBINC=/usr/local/include
36#ZLIBLIB=/usr/local/lib
37#ZLIBINC=/usr/local/include
38ZLIBLIB=../zlib
39ZLIBINC=../zlib
40
41# ABI can be blank to use default for your system, -32, -o32, -n32, or -64
42# See "man abi". zlib must be built with the same ABI.
43ABI=
44
45WARNMORE=-fullwarn
46# Note: -KPIC is the default anyhow
47#CFLAGS= $(ABI) -I$(ZLIBINC) -O $(WARNMORE) -KPIC # -g -DPNG_DEBUG=5
48CFLAGS=$(ABI) -I$(ZLIBINC) -O $(WARNMORE)
49LDFLAGS_A=$(ABI) -L. -L$(ZLIBLIB) -lpng15 -lz -lm
50LDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm
51LDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \
52 -set_version sgi$(PNGMAJ).0
53# See "man dso" for info about shared objects
54
55INCPATH=$(prefix)/include
56LIBPATH=$(exec_prefix)/lib
57#LIBPATH=$(exec_prefix)/lib32
58MANPATH=$(prefix)/man
59BINPATH=$(exec_prefix)/bin
60
61# override DESTDIR= on the make install command line to easily support
62# installing into a temporary location. Example:
63#
64# make install DESTDIR=/tmp/build/libpng
65#
66# If you're going to install into a temporary location
67# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
68# you execute make install.
69DESTDIR=
70
71DB=$(DESTDIR)$(BINPATH)
72DI=$(DESTDIR)$(INCPATH)
73DL=$(DESTDIR)$(LIBPATH)
74DM=$(DESTDIR)$(MANPATH)
75
76OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
77 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
78 pngwtran.o pngmem.o pngerror.o pngpread.o
79
80all: libpng.a pngtest shared libpng.pc libpng-config
81
82# see scripts/pnglibconf.mak for more options
83pnglibconf.h: scripts/pnglibconf.h.prebuilt
84 cp scripts/pnglibconf.h.prebuilt $@
85
86libpng.a: $(OBJS)
87 $(AR_RC) $@ $(OBJS)
88 $(RANLIB) $@
89
90libpng.pc:
91 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
92 -e s!@exec_prefix@!$(exec_prefix)! \
93 -e s!@libdir@!$(LIBPATH)! \
94 -e s!@includedir@!$(INCPATH)! \
95 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
96
97libpng-config:
98 ( cat scripts/libpng-config-head.in; \
99 echo prefix=\"$(prefix)\"; \
100 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
101 echo ccopts=\"$(ABI)\"; \
102 echo ldopts=\"$(ABI)\"; \
103 echo L_opts=\"-L$(LIBPATH)\"; \
104 echo libdir=\"$(LIBPATH)\"; \
105 echo libs=\"-lpng15 -lz -lm\"; \
106 cat scripts/libpng-config-body.in ) > libpng-config
107 chmod +x libpng-config
108
109$(LIBSO): $(LIBSOMAJ)
110 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
111
112$(LIBSOMAJ): $(OBJS)
113 $(LDSHARED) -o $@ $(OBJS)
114 $(RM_F) $(LIBSO) $(LIBSOMAJ)
115
116pngtest: pngtest.o libpng.a
117 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
118
119test: pngtest
120 echo
121 echo Testing local static library.
122 ./pngtest
123
124install-headers: png.h pngconf.h pnglibconf.h
125 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
126 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
127 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
128 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
129 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
130 -@$(RM_F) $(DI)/libpng
131 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
132
133install-static: install-headers libpng.a
134 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
135 cp libpng.a $(DL)/$(LIBNAME).a
136 chmod 644 $(DL)/$(LIBNAME).a
137 -@$(RM_F) $(DL)/libpng.a
138 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
139
140install-shared: install-headers $(LIBSOMAJ) libpng.pc
141 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
142 -@$(RM_F) $(DL)/$(LIBSO)
143 -@$(RM_F) $(DL)/$(LIBSOREL)
144 -@$(RM_F) $(DL)/$(OLDSO)
145 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
146 chmod 755 $(DL)/$(LIBSOREL)
147 (cd $(DL); \
148 $(LN_SF) $(LIBSOREL) $(LIBSO); \
149 $(LN_SF) $(LIBSO) $(OLDSO))
150 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
151 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
152 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
153 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
154 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
155 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
156
157install-man: libpng.3 libpngpf.3 png.5
158 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
159 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
160 -@$(RM_F) $(DM)/man3/libpng.3
161 -@$(RM_F) $(DM)/man3/libpngpf.3
162 cp libpng.3 $(DM)/man3
163 cp libpngpf.3 $(DM)/man3
164 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
165 -@$(RM_F) $(DM)/man5/png.5
166 cp png.5 $(DM)/man5
167
168install-config: libpng-config
169 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
170 -@$(RM_F) $(DB)/libpng-config
171 -@$(RM_F) $(DB)/$(LIBNAME)-config
172 cp libpng-config $(DB)/$(LIBNAME)-config
173 chmod 755 $(DB)/$(LIBNAME)-config
174 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
175
176install: install-static install-shared install-man install-config
177
178# If you installed in $(DESTDIR), test-installed won't work until you
179# move the library to its final location. Use test-dd to test it
180# before then.
181
182test-dd:
183 echo
184 echo Testing installed dynamic shared library in $(DL).
185 $(CC) -I$(DI) -I$(ZLIBINC) \
186 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
187 -L$(DL) -L$(ZLIBLIB) \
188 -rpath $(ZLIBLIB):$(DL) \
189 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`
190 ./pngtestd pngtest.png
191
192test-installed:
193 echo
194 echo Testing installed dynamic shared library.
195 $(CC) -I$(ZLIBINC) \
196 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
197 -L$(ZLIBLIB) \
198 -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \
199 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`
200 ./pngtesti pngtest.png
201
202clean:
203 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png libpng.pc libpng-config \
204 $(LIBSO) $(LIBSOMAJ)* \
205 so_locations pnglibconf.h
206
207DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
208writelock:
209 chmod a-w *.[ch35] $(DOCS) scripts/*
210
211# DO NOT DELETE THIS LINE -- make depend depends on it.
212
213png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
214pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
215pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
216pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
217pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
218pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
219pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
220pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228
229pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.so9 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.so9
new file mode 100644
index 0000000..967b342
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.so9
@@ -0,0 +1,239 @@
1# makefile for libpng on Solaris 9 (beta) with Forte cc
2# Updated by Chad Schrock for Solaris 9
3# Contributed by William L. Sebok, based on makefile.linux
4# Copyright (C) 2002, 2006, 2008, 2010-2011 Glenn Randers-Pehrson
5# Copyright (C) 1998-2001 Greg Roelofs
6# Copyright (C) 1996-1997 Andreas Dilger
7#
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# Library name:
13PNGMAJ = 15
14LIBNAME = libpng15
15
16# Shared library names:
17LIBSO=$(LIBNAME).so
18LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
19LIBSOREL=$(LIBSOMAJ).$(RELEASE)
20OLDSO=libpng.so
21
22# Utilities:
23# gcc 2.95 doesn't work.
24CC=cc
25AR_RC=ar rc
26MKDIR_P=mkdir -p
27LN_SF=ln -f -s
28RANLIB=echo
29RM_F=/bin/rm -f
30
31# Where make install puts libpng.a, $(OLDSO)*, and png.h
32prefix=/usr/local
33exec_prefix=$(prefix)
34
35# Where the zlib library and include files are located
36# Changing these to ../zlib poses a security risk. If you want
37# to have zlib in an adjacent directory, specify the full path instead of "..".
38#ZLIBLIB=../zlib
39#ZLIBINC=../zlib
40#ZLIBLIB=/usr/local/lib
41#ZLIBINC=/usr/local/include
42#Use the preinstalled zlib that comes with Solaris 9:
43ZLIBLIB=/usr/lib
44ZLIBINC=/usr/include
45
46#WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
47 -Wmissing-declarations -Wtraditional -Wcast-align \
48 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
49#CFLAGS=-I$(ZLIBINC) -W -Wall -O3 $(WARNMORE) -g -DPNG_DEBUG=5 -DPNG_NO_MMX_CODE
50CFLAGS=-I$(ZLIBINC) -O3 -DPNG_NO_MMX_CODE
51LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng15 -lz -lm
52
53INCPATH=$(prefix)/include
54LIBPATH=$(exec_prefix)/lib
55MANPATH=$(prefix)/man
56BINPATH=$(exec_prefix)/bin
57
58# override DESTDIR= on the make install command line to easily support
59# installing into a temporary location. Example:
60#
61# make install DESTDIR=/tmp/build/libpng
62#
63# If you're going to install into a temporary location
64# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
65# you execute make install.
66DESTDIR=
67
68DB=$(DESTDIR)$(BINPATH)
69DI=$(DESTDIR)$(INCPATH)
70DL=$(DESTDIR)$(LIBPATH)
71DM=$(DESTDIR)$(MANPATH)
72
73OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
74 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
75 pngwtran.o pngmem.o pngerror.o pngpread.o
76
77OBJSDLL = $(OBJS:.o=.pic.o)
78
79.SUFFIXES: .c .o .pic.o
80
81.c.pic.o:
82 $(CC) -c $(CFLAGS) -KPIC -o $@ $*.c
83
84all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
85
86# see scripts/pnglibconf.mak for more options
87pnglibconf.h: scripts/pnglibconf.h.prebuilt
88 cp scripts/pnglibconf.h.prebuilt $@
89
90libpng.a: $(OBJS)
91 $(AR_RC) $@ $(OBJS)
92 $(RANLIB) $@
93
94libpng.pc:
95 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
96 -e s!@exec_prefix@!$(exec_prefix)! \
97 -e s!@libdir@!$(LIBPATH)! \
98 -e s!@includedir@!$(INCPATH)! \
99 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
100
101libpng-config:
102 ( cat scripts/libpng-config-head.in; \
103 echo prefix=\"$(prefix)\"; \
104 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
105 echo L_opts=\"-L$(LIBPATH)\"; \
106 echo R_opts=\"-R$(LIBPATH)\"; \
107 echo libs=\"-lpng15 -lz -lm\"; \
108 cat scripts/libpng-config-body.in ) > libpng-config
109 chmod +x libpng-config
110
111$(LIBSO): $(LIBSOMAJ)
112 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
113
114$(LIBSOMAJ): $(OBJSDLL)
115 @case "`type ld`" in *ucb*) \
116 echo; \
117 echo '## WARNING:'; \
118 echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \
119 echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \
120 echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \
121 echo '## The environment variable LD_LIBRARY_PATH should not be set'; \
122 echo '## at all. If it is, things are likely to break because of'; \
123 echo '## the libucb dependency that is created.'; \
124 echo; \
125 ;; \
126 esac
127 $(LD) -G -h $(LIBSOMAJ) \
128 -o $(LIBSOMAJ) $(OBJSDLL)
129
130pngtest: pngtest.o $(LIBSO)
131 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
132
133test: pngtest
134 ./pngtest
135
136install-headers: png.h pngconf.h pnglibconf.h
137 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
138 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
139 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
140 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
141 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
142 -@$(RM_F) $(DI)/libpng
143 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
144
145install-static: install-headers libpng.a
146 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
147 cp libpng.a $(DL)/$(LIBNAME).a
148 chmod 644 $(DL)/$(LIBNAME).a
149 -@$(RM_F) $(DL)/libpng.a
150 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
151
152install-shared: install-headers $(LIBSOMAJ) libpng.pc
153 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
154 -@$(RM_F) $(DL)/$(LIBSO)
155 -@$(RM_F) $(DL)/$(LIBSOREL)
156 -@$(RM_F) $(DL)/$(OLDSO)
157 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
158 chmod 755 $(DL)/$(LIBSOREL)
159 (cd $(DL); \
160 $(LN_SF) $(LIBSOREL) $(LIBSO); \
161 $(LN_SF) $(LIBSO) $(OLDSO))
162 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
163 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
164 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
165 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
166 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
167 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
168
169install-man: libpng.3 libpngpf.3 png.5
170 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
171 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
172 -@$(RM_F) $(DM)/man3/libpng.3
173 -@$(RM_F) $(DM)/man3/libpngpf.3
174 cp libpng.3 $(DM)/man3
175 cp libpngpf.3 $(DM)/man3
176 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
177 -@$(RM_F) $(DM)/man5/png.5
178 cp png.5 $(DM)/man5
179
180install-config: libpng-config
181 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
182 -@$(RM_F) $(DB)/libpng-config
183 -@$(RM_F) $(DB)/$(LIBNAME)-config
184 cp libpng-config $(DB)/$(LIBNAME)-config
185 chmod 755 $(DB)/$(LIBNAME)-config
186 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
187
188install: install-static install-shared install-man install-config
189
190# If you installed in $(DESTDIR), test-installed won't work until you
191# move the library to its final location. Use test-dd to test it
192# before then.
193
194test-dd:
195 echo
196 echo Testing installed dynamic shared library in $(DL).
197 $(CC) -I$(DI) -I$(ZLIBINC) \
198 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
199 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \
200 -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL)
201 ./pngtestd pngtest.png
202
203test-installed:
204 echo
205 echo Testing installed dynamic shared library.
206 $(CC) -I$(ZLIBINC) \
207 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
208 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \
209 -L$(ZLIBLIB) -R$(ZLIBLIB)
210 ./pngtesti pngtest.png
211
212clean:
213 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
214 libpng-config $(LIBSO) $(LIBSOMAJ)* \
215 libpng.pc pnglibconf.h
216
217DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
218writelock:
219 chmod a-w *.[ch35] $(DOCS) scripts/*
220
221# DO NOT DELETE THIS LINE -- make depend depends on it.
222
223png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
236pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
237pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
238
239pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris
new file mode 100644
index 0000000..03fb314
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris
@@ -0,0 +1,236 @@
1# makefile for libpng on Solaris 2.x with gcc
2# Copyright (C) 2004, 2006-2008, 2010-2011 Glenn Randers-Pehrson
3# Contributed by William L. Sebok, based on makefile.linux
4# Copyright (C) 1998 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6#
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME = libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22AR_RC=ar rc
23CC=gcc
24MKDIR_P=mkdir -p
25LN_SF=ln -f -s
26RANLIB=echo
27RM_F=/bin/rm -f
28
29# Where make install puts libpng.a, libpng15.so*, and png.h
30prefix=/usr/local
31exec_prefix=$(prefix)
32
33# Where the zlib library and include files are located
34# Changing these to ../zlib poses a security risk. If you want
35# to have zlib in an adjacent directory, specify the full path instead of "..".
36#ZLIBLIB=../zlib
37#ZLIBINC=../zlib
38
39ZLIBLIB=/usr/local/lib
40ZLIBINC=/usr/local/include
41
42WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
43 -Wmissing-declarations -Wtraditional -Wcast-align \
44 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
45CFLAGS=-I$(ZLIBINC) -W -Wall -O \
46 # $(WARNMORE) -g -DPNG_DEBUG=5
47LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng15 -lz -lm
48
49INCPATH=$(prefix)/include
50LIBPATH=$(exec_prefix)/lib
51MANPATH=$(prefix)/man
52BINPATH=$(exec_prefix)/bin
53
54# override DESTDIR= on the make install command line to easily support
55# installing into a temporary location. Example:
56#
57# make install DESTDIR=/tmp/build/libpng
58#
59# If you're going to install into a temporary location
60# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
61# you execute make install.
62DESTDIR=
63
64DB=$(DESTDIR)$(BINPATH)
65DI=$(DESTDIR)$(INCPATH)
66DL=$(DESTDIR)$(LIBPATH)
67DM=$(DESTDIR)$(MANPATH)
68
69OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
70 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
71 pngwtran.o pngmem.o pngerror.o pngpread.o
72
73OBJSDLL = $(OBJS:.o=.pic.o)
74
75.SUFFIXES: .c .o .pic.o
76
77.c.pic.o:
78 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
79
80all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
81
82# see scripts/pnglibconf.mak for more options
83pnglibconf.h: scripts/pnglibconf.h.prebuilt
84 cp scripts/pnglibconf.h.prebuilt $@
85
86libpng.a: $(OBJS)
87 $(AR_RC) $@ $(OBJS)
88 $(RANLIB) $@
89
90libpng.pc:
91 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
92 -e s!@exec_prefix@!$(exec_prefix)! \
93 -e s!@libdir@!$(LIBPATH)! \
94 -e s!@includedir@!$(INCPATH)! \
95 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
96
97libpng-config:
98 ( cat scripts/libpng-config-head.in; \
99 echo prefix=\"$(prefix)\"; \
100 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
101 echo cppflags=\"\"; \
102 echo L_opts=\"-L$(LIBPATH)\"; \
103 echo R_opts=\"-R$(LIBPATH)\"; \
104 echo libs=\"-lpng15 -lz -lm\"; \
105 cat scripts/libpng-config-body.in ) > libpng-config
106 chmod +x libpng-config
107
108$(LIBSO): $(LIBSOMAJ)
109 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
110
111$(LIBSOMAJ): $(OBJSDLL)
112 @case "`type ld`" in *ucb*) \
113 echo; \
114 echo '## WARNING:'; \
115 echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \
116 echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \
117 echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \
118 echo '## The environment variable LD_LIBRARY_PATH should not be set'; \
119 echo '## at all. If it is, things are likely to break because of'; \
120 echo '## the libucb dependency that is created.'; \
121 echo; \
122 ;; \
123 esac
124 $(LD) -G -h $(LIBSOMAJ) \
125 -o $(LIBSOMAJ) $(OBJSDLL)
126
127pngtest: pngtest.o $(LIBSO)
128 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
129
130test: pngtest
131 ./pngtest
132
133install-headers: png.h pngconf.h pnglibconf.h
134 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
135 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
136 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
137 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
138 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
139 -@$(RM_F) $(DI)/libpng
140 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
141
142install-static: install-headers libpng.a
143 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
144 cp libpng.a $(DL)/$(LIBNAME).a
145 chmod 644 $(DL)/$(LIBNAME).a
146 -@$(RM_F) $(DL)/libpng.a
147 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
148
149install-shared: install-headers $(LIBSOMAJ) libpng.pc
150 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
151 -@$(RM_F) $(DL)/$(LIBSO)
152 -@$(RM_F) $(DL)/$(LIBSOREL)
153 -@$(RM_F) $(DL)/$(OLDSO)
154 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
155 chmod 755 $(DL)/$(LIBSOREL)
156 (cd $(DL); \
157 $(LN_SF) $(LIBSOREL) $(LIBSO); \
158 $(LN_SF) $(LIBSO) $(OLDSO))
159 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
160 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
161 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
162 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
163 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
164 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
165
166install-man: libpng.3 libpngpf.3 png.5
167 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
168 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
169 -@$(RM_F) $(DM)/man3/libpng.3
170 -@$(RM_F) $(DM)/man3/libpngpf.3
171 cp libpng.3 $(DM)/man3
172 cp libpngpf.3 $(DM)/man3
173 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
174 -@$(RM_F) $(DM)/man5/png.5
175 cp png.5 $(DM)/man5
176
177install-config: libpng-config
178 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
179 -@$(RM_F) $(DB)/libpng-config
180 -@$(RM_F) $(DB)/$(LIBNAME)-config
181 cp libpng-config $(DB)/$(LIBNAME)-config
182 chmod 755 $(DB)/$(LIBNAME)-config
183 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
184
185install: install-static install-shared install-man install-config
186
187# If you installed in $(DESTDIR), test-installed won't work until you
188# move the library to its final location. Use test-dd to test it
189# before then.
190
191test-dd:
192 echo
193 echo Testing installed dynamic shared library in $(DL).
194 $(CC) -I$(DI) -I$(ZLIBINC) \
195 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
196 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \
197 -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL)
198 ./pngtestd pngtest.png
199
200test-installed:
201 echo
202 echo Testing installed dynamic shared library.
203 $(CC) -I$(ZLIBINC) \
204 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
205 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \
206 -L$(ZLIBLIB) -R$(ZLIBLIB)
207 ./pngtesti pngtest.png
208
209clean:
210 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
211 libpng-config $(LIBSO) $(LIBSOMAJ)* \
212 libpng.pc pnglibconf.h
213
214DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
215writelock:
216 chmod a-w *.[ch35] $(DOCS) scripts/*
217
218# DO NOT DELETE THIS LINE -- make depend depends on it.
219
220png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235
236pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris-x86 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris-x86
new file mode 100644
index 0000000..4a43e53
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.solaris-x86
@@ -0,0 +1,236 @@
1# makefile for libpng on Solaris 2.x with gcc
2# Copyright (C) 2004, 2006-2008, 2010-2011 Glenn Randers-Pehrson
3# Contributed by William L. Sebok, based on makefile.linux
4# Copyright (C) 1998 Greg Roelofs
5# Copyright (C) 1996, 1997 Andreas Dilger
6
7# This code is released under the libpng license.
8# For conditions of distribution and use, see the disclaimer
9# and license in png.h
10
11# Library name:
12LIBNAME = libpng15
13PNGMAJ = 15
14
15# Shared library names:
16LIBSO=$(LIBNAME).so
17LIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)
18LIBSOREL=$(LIBSOMAJ).$(RELEASE)
19OLDSO=libpng.so
20
21# Utilities:
22AR_RC=ar rc
23CC=gcc
24MKDIR_P=mkdir -p
25LN_SF=ln -f -s
26RANLIB=echo
27RM_F=/bin/rm -f
28
29# Where make install puts libpng.a, libpng15.so*, and png.h
30prefix=/usr/local
31exec_prefix=$(prefix)
32
33# Where the zlib library and include files are located
34# Changing these to ../zlib poses a security risk. If you want
35# to have zlib in an adjacent directory, specify the full path instead of "..".
36#ZLIBLIB=../zlib
37#ZLIBINC=../zlib
38
39ZLIBLIB=/usr/local/lib
40ZLIBINC=/usr/local/include
41
42WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
43 -Wmissing-declarations -Wtraditional -Wcast-align \
44 -Wstrict-prototypes -Wmissing-prototypes #-Wconversion
45CFLAGS=-I$(ZLIBINC) -W -Wall -O \
46 # $(WARNMORE) -g -DPNG_DEBUG=5
47LDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng15 -lz -lm
48
49INCPATH=$(prefix)/include
50LIBPATH=$(exec_prefix)/lib
51MANPATH=$(prefix)/man
52BINPATH=$(exec_prefix)/bin
53
54# override DESTDIR= on the make install command line to easily support
55# installing into a temporary location. Example:
56#
57# make install DESTDIR=/tmp/build/libpng
58#
59# If you're going to install into a temporary location
60# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
61# you execute make install.
62DESTDIR=
63
64DB=$(DESTDIR)$(BINPATH)
65DI=$(DESTDIR)$(INCPATH)
66DL=$(DESTDIR)$(LIBPATH)
67DM=$(DESTDIR)$(MANPATH)
68
69OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
70 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
71 pngwtran.o pngmem.o pngerror.o pngpread.o
72
73OBJSDLL = $(OBJS:.o=.pic.o)
74
75.SUFFIXES: .c .o .pic.o
76
77.c.pic.o:
78 $(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
79
80all: libpng.a $(LIBSO) pngtest libpng.pc libpng-config
81
82# see scripts/pnglibconf.mak for more options
83pnglibconf.h: scripts/pnglibconf.h.prebuilt
84 cp scripts/pnglibconf.h.prebuilt $@
85
86libpng.a: $(OBJS)
87 $(AR_RC) $@ $(OBJS)
88 $(RANLIB) $@
89
90libpng.pc:
91 cat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \
92 -e s!@exec_prefix@!$(exec_prefix)! \
93 -e s!@libdir@!$(LIBPATH)! \
94 -e s!@includedir@!$(INCPATH)! \
95 -e s!-lpng15!-lpng15\ -lz\ -lm! > libpng.pc
96
97libpng-config:
98 ( cat scripts/libpng-config-head.in; \
99 echo prefix=\"$(prefix)\"; \
100 echo I_opts=\"-I$(INCPATH)/$(LIBNAME)\"; \
101 echo cppflags=\""; \
102 echo L_opts=\"-L$(LIBPATH)\"; \
103 echo R_opts=\"-R$(LIBPATH)\"; \
104 echo libs=\"-lpng15 -lz -lm\"; \
105 cat scripts/libpng-config-body.in ) > libpng-config
106 chmod +x libpng-config
107
108$(LIBSO): $(LIBSOMAJ)
109 $(LN_SF) $(LIBSOMAJ) $(LIBSO)
110
111$(LIBSOMAJ): $(OBJSDLL)
112 @case "`type ld`" in *ucb*) \
113 echo; \
114 echo '## WARNING:'; \
115 echo '## The commands "CC" and "LD" must NOT refer to /usr/ucb/cc'; \
116 echo '## and /usr/ucb/ld. If they do, you need to adjust your PATH'; \
117 echo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \
118 echo '## The environment variable LD_LIBRARY_PATH should not be set'; \
119 echo '## at all. If it is, things are likely to break because of'; \
120 echo '## the libucb dependency that is created.'; \
121 echo; \
122 ;; \
123 esac
124 $(LD) -G -h $(LIBSOMAJ) \
125 -o $(LIBSOMAJ) $(OBJSDLL)
126
127pngtest: pngtest.o $(LIBSO)
128 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
129
130test: pngtest
131 ./pngtest
132
133install-headers: png.h pngconf.h pnglibconf.h
134 -@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi
135 -@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
136 cp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)
137 chmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h
138 -@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h
139 -@$(RM_F) $(DI)/libpng
140 (cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)
141
142install-static: install-headers libpng.a
143 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
144 cp libpng.a $(DL)/$(LIBNAME).a
145 chmod 644 $(DL)/$(LIBNAME).a
146 -@$(RM_F) $(DL)/libpng.a
147 (cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)
148
149install-shared: install-headers $(LIBSOMAJ) libpng.pc
150 -@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi
151 -@$(RM_F) $(DL)/$(LIBSO)
152 -@$(RM_F) $(DL)/$(LIBSOREL)
153 -@$(RM_F) $(DL)/$(OLDSO)
154 cp $(LIBSOMAJ) $(DL)/$(LIBSOREL)
155 chmod 755 $(DL)/$(LIBSOREL)
156 (cd $(DL); \
157 $(LN_SF) $(LIBSOREL) $(LIBSO); \
158 $(LN_SF) $(LIBSO) $(OLDSO))
159 -@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi
160 -@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc
161 -@$(RM_F) $(DL)/pkgconfig/libpng.pc
162 cp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc
163 chmod 644 $(DL)/pkgconfig/$(LIBNAME).pc
164 (cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)
165
166install-man: libpng.3 libpngpf.3 png.5
167 -@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi
168 -@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi
169 -@$(RM_F) $(DM)/man3/libpng.3
170 -@$(RM_F) $(DM)/man3/libpngpf.3
171 cp libpng.3 $(DM)/man3
172 cp libpngpf.3 $(DM)/man3
173 -@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi
174 -@$(RM_F) $(DM)/man5/png.5
175 cp png.5 $(DM)/man5
176
177install-config: libpng-config
178 -@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi
179 -@$(RM_F) $(DB)/libpng-config
180 -@$(RM_F) $(DB)/$(LIBNAME)-config
181 cp libpng-config $(DB)/$(LIBNAME)-config
182 chmod 755 $(DB)/$(LIBNAME)-config
183 (cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)
184
185install: install-static install-shared install-man install-config
186
187# If you installed in $(DESTDIR), test-installed won't work until you
188# move the library to its final location. Use test-dd to test it
189# before then.
190
191test-dd:
192 echo
193 echo Testing installed dynamic shared library in $(DL).
194 $(CC) -I$(DI) -I$(ZLIBINC) \
195 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
196 -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \
197 -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL)
198 ./pngtestd pngtest.png
199
200test-installed:
201 echo
202 echo Testing installed dynamic shared library.
203 $(CC) -I$(ZLIBINC) \
204 `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \
205 -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \
206 -L$(ZLIBLIB) -R$(ZLIBLIB)
207 ./pngtesti pngtest.png
208
209clean:
210 $(RM_F) *.o libpng.a pngtest pngtesti pngout.png \
211 libpng-config $(LIBSO) $(LIBSOMAJ)* \
212 libpng.pc pnglibconf.h
213
214DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
215writelock:
216 chmod a-w *.[ch35] $(DOCS) scripts/*
217
218# DO NOT DELETE THIS LINE -- make depend depends on it.
219
220png.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
221pngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
222pngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
223pngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
224pngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
225pngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
226pngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
227pngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
228pngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
229pngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
230pngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
231pngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
232pngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
233pngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
234pngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
235
236pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.std b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.std
new file mode 100644
index 0000000..d394f96
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.std
@@ -0,0 +1,123 @@
1# makefile for libpng
2# Copyright (C) 2002, 2006 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# where make install puts libpng.a and png.h
10prefix=/usr/local
11INCPATH=$(prefix)/include
12LIBPATH=$(prefix)/lib
13
14# override DESTDIR= on the make install command line to easily support
15# installing into a temporary location. Example:
16#
17# make install DESTDIR=/tmp/build/libpng
18#
19# If you're going to install into a temporary location
20# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
21# you execute make install.
22DESTDIR=
23
24# Where the zlib library and include files are located
25#ZLIBLIB=/usr/local/lib
26#ZLIBINC=/usr/local/include
27ZLIBLIB=../zlib
28ZLIBINC=../zlib
29
30CC=cc
31AR_RC=ar rc
32MKDIR_P=mkdir
33LN_SF=ln -sf
34RANLIB=ranlib
35RM_F=rm -f
36AWK = awk
37SED = sed
38CPP = $(CC) -E
39ECHO = echo
40
41DFNFLAGS = # DFNFLAGS contains -D options to use in the libpng build
42CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=5
43LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
44
45OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
46 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
47 pngwtran.o pngmem.o pngerror.o pngpread.o
48
49all: libpng.a pngtest
50
51# The standard pnglibconf.h exists as scripts/pnglibconf.h.prebuilt,
52# copy this if the following doesn't work.
53pnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h
54 $(RM_F) $@ dfn?.out
55 $(AWK) -f scripts/options.awk out=dfn1.out version=search pngconf.h\
56 scripts/pnglibconf.dfa $(DFA_XTRA) 1>&2
57 $(AWK) -f scripts/options.awk out=dfn2.out dfn1.out 1>&2
58 cp dfn2.out $@
59 $(RM_F) dfn?.out
60
61pnglibconf.h: pnglibconf.dfn
62 $(RM_F) $@ dfn.c dfn?.out
63 $(ECHO) '#include "pnglibconf.dfn"' >dfn.c
64 $(CPP) $(DFNFLAGS) dfn.c >dfn1.out
65 $(SED) -n -e 's|^.*PNG_DEFN_MAGIC *-\(.*\)- *PNG_DEFN_END.*$$|\1|p'\
66 dfn1.out >dfn2.out
67 $(SED) -e 's| *PNG_JOIN *||g' -e 's| *$$||' dfn2.out >dfn3.out
68 cp dfn3.out $@
69 $(RM_F) dfn.c dfn?.out
70
71libpng.a: $(OBJS)
72 $(AR_RC) $@ $(OBJS)
73 $(RANLIB) $@
74
75pngtest: pngtest.o libpng.a
76 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
77
78test: pngtest
79 ./pngtest
80
81install: libpng.a pnglibconf.h
82 -@$(MKDIR_P) $(DESTDIR)$(INCPATH)
83 -@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng
84 -@$(MKDIR_P) $(DESTDIR)$(LIBPATH)
85 -@$(RM_F) $(DESTDIR)$(INCPATH)/png.h
86 -@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h
87 -@$(RM_F) $(DESTDIR)$(INCPATH)/pnglibconf.h
88 cp png.h $(DESTDIR)$(INCPATH)/libpng
89 cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
90 cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
91 chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
92 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
93 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
94 (cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)
95 cp libpng.a $(DESTDIR)$(LIBPATH)
96 chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a
97
98clean:
99 $(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.* dfn.c dfn?.out
100
101DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
102writelock:
103 chmod a-w *.[ch35] $(DOCS) scripts/*
104
105# DO NOT DELETE THIS LINE -- make depend depends on it.
106
107png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
108pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
109pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
110pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
111pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
112pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
113pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
114pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
115pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
116pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
117pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
118pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
119pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
120pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
121pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
122
123pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sunos b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sunos
new file mode 100644
index 0000000..52cd4d4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.sunos
@@ -0,0 +1,107 @@
1# makefile for libpng
2# Copyright (C) 2002, 2006 Glenn Randers-Pehrson
3# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9# where make install puts libpng.a and png.h
10prefix=/usr/local
11INCPATH=$(prefix)/include
12LIBPATH=$(prefix)/lib
13
14# override DESTDIR= on the make install command line to easily support
15# installing into a temporary location. Example:
16#
17# make install DESTDIR=/tmp/build/libpng
18#
19# If you're going to install into a temporary location
20# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
21# you execute make install.
22DESTDIR=
23
24# Where the zlib library and include files are located
25#ZLIBLIB=/usr/local/lib
26#ZLIBINC=/usr/local/include
27ZLIBLIB=../zlib
28ZLIBINC=../zlib
29
30
31WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow -Wconversion \
32 -Wmissing-declarations -Wtraditional -Wcast-align \
33 -Wstrict-prototypes -Wmissing-prototypes
34
35CC=gcc
36AR_RC=ar rc
37MKDIR_P=mkdir -p
38LN_SF=ln -f -s
39RANLIB=ranlib
40RM_F=/bin/rm -f
41
42CFLAGS=-I$(ZLIBINC) -O # $(WARNMORE) -DPNG_DEBUG=5
43LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
44
45OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
46 pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
47 pngwtran.o pngmem.o pngerror.o pngpread.o
48
49all: libpng.a pngtest
50
51# see scripts/pnglibconf.mak for more options
52pnglibconf.h: scripts/pnglibconf.h.prebuilt
53 cp scripts/pnglibconf.h.prebuilt $@
54
55libpng.a: $(OBJS)
56 $(AR_RC) $@ $(OBJS)
57 $(RANLIB) $@
58
59pngtest: pngtest.o libpng.a
60 $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
61
62test: pngtest
63 ./pngtest
64
65install: libpng.a
66 -@$(MKDIR_P) $(DESTDIR)$(INCPATH)
67 -@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng
68 -@$(MKDIR_P) $(DESTDIR)$(LIBPATH)
69 -@$(RM_F) $(DESTDIR)$(INCPATH)/png.h
70 -@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h
71 -@$(RM_F) $(DESTDIR)$(INCPATH)/pnglibconf.h
72 cp png.h $(DESTDIR)$(INCPATH)/libpng
73 cp pngconf.h $(DESTDIR)$(INCPATH)/libpng
74 cp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng
75 chmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h
76 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h
77 chmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h
78 (cd $(DESTDIR)$(INCPATH); $(LN_SF) libpng/* .)
79 cp libpng.a $(DESTDIR)$(LIBPATH)
80 chmod 644 $(DESTDIR)$(LIBPATH)/libpng.a
81
82clean:
83 $(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.h
84
85DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
86writelock:
87 chmod a-w *.[ch35] $(DOCS) scripts/*
88
89# DO NOT DELETE THIS LINE -- make depend depends on it.
90
91png.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
92pngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
93pngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
94pngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
95pngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
96pngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
97pngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
98pngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
99pngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
100pngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
101pngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
102pngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
103pngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
104pngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
105pngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
106
107pngtest.o: png.h pngconf.h pnglibconf.h
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.tc3 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.tc3
new file mode 100644
index 0000000..311acfb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.tc3
@@ -0,0 +1,93 @@
1# Makefile for libpng
2# TurboC/C++ (Note: All modules are compiled in C mode)
3
4# To use, do "make -fmakefile.tc3"
5
6# ----- Turbo C 3.00 (can be modified to work with earlier versions) -----
7
8MODEL=l
9CFLAGS=-O2 -Z -m$(MODEL) -I..\zlib
10#CFLAGS=-D_NO_PROTO -O2 -Z -m$(MODEL) -I..\zlib # Turbo C older than 3.00
11CC=tcc
12LD=tcc
13LIB=tlib
14LDFLAGS=-m$(MODEL) -L..\zlib
15O=.obj
16E=.exe
17
18# variables
19OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
20OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
21OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
22OBJSL1 = +png$(O) +pngset$(O) +pngget$(O) +pngrutil$(O) +pngtrans$(O)
23OBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O) +pngerror$(O)
24OBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)
25
26all: libpng$(MODEL).lib pngtest$(E)
27
28# see scripts/pnglibconf.mak for more options
29pnglibconf.h: scripts/pnglibconf.h.prebuilt
30 cp scripts/pnglibconf.h.prebuilt $@
31
32pngtest: pngtest$(E)
33
34test: pngtest$(E)
35 pngtest$(E)
36
37png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
38 $(CC) -c $(CFLAGS) $*.c
39
40pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
41 $(CC) -c $(CFLAGS) $*.c
42
43pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
44 $(CC) -c $(CFLAGS) $*.c
45
46pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
47 $(CC) -c $(CFLAGS) $*.c
48
49pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
50 $(CC) -c $(CFLAGS) $*.c
51
52pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
53 $(CC) -c $(CFLAGS) $*.c
54
55pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
56 $(CC) -c $(CFLAGS) $*.c
57
58pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
59 $(CC) -c $(CFLAGS) $*.c
60
61pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
62 $(CC) -c $(CFLAGS) $*.c
63
64pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
65 $(CC) -c $(CFLAGS) $*.c
66
67pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
68 $(CC) -c $(CFLAGS) $*.c
69
70pngtest$(O): png.h pngconf.h pnglibconf.h
71 $(CC) -c $(CFLAGS) $*.c
72
73pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
74 $(CC) -c $(CFLAGS) $*.c
75
76pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
77 $(CC) -c $(CFLAGS) $*.c
78
79pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
80 $(CC) -c $(CFLAGS) $*.c
81
82pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
83 $(CC) -c $(CFLAGS) $*.c
84
85libpng$(MODEL).lib: $(OBJS1) $(OBJS2) $(OBJS3)
86 $(LIB) libpng$(MODEL) +$(OBJSL1)
87 $(LIB) libpng$(MODEL) +$(OBJSL2)
88 $(LIB) libpng$(MODEL) +$(OBJSL3)
89
90pngtest$(E): pngtest$(O) libpng$(MODEL).lib
91 $(LD) $(LDFLAGS) pngtest.obj libpng$(MODEL).lib zlib_$(MODEL).lib
92
93# End of makefile for libpng
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.vcwin32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.vcwin32
new file mode 100644
index 0000000..bdcc508
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makefile.vcwin32
@@ -0,0 +1,108 @@
1# makefile for libpng
2# Copyright (C) 1998 Tim Wegner
3# Copyright (C) 2006,2009,2011 Glenn Randers-Pehrson
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8#
9# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\zlib
10# To use, do "nmake /f scripts\makefile.vcwin32"
11
12# -------- Microsoft Visual C++ 2.0 and later, no assembler code --------
13
14# Compiler, linker, librarian, and other tools
15CC = cl
16LD = link
17AR = lib
18CFLAGS = -nologo -D_CRT_SECURE_NO_DEPRECATE -MD -O2 -W3 -I..\zlib
19LDFLAGS = -nologo
20ARFLAGS = -nologo
21RM = del
22
23# File extensions
24O=.obj
25
26#uncomment next to put error messages in a file
27#ERRFILE= >> pngerrs.log
28
29# Variables
30OBJS1 = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O)
31OBJS2 = pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O)
32OBJS3 = pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)
33OBJS = $(OBJS1) $(OBJS2) $(OBJS3)
34
35# Targets
36all: libpng.lib
37
38# see scripts/pnglibconf.mak for more options
39pnglibconf.h: scripts\pnglibconf.h.prebuilt
40 copy scripts\pnglibconf.h.prebuilt $@
41
42png$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
43 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
44
45pngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
46 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
47
48pngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
49 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
50
51pngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
52 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
53
54pngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
55 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
56
57pngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
58 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
59
60pngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
61 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
62
63pngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
64 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
65
66pngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
67 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
68
69pngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
70 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
71
72pngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
73 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
74
75pngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
76 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
77
78pngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
79 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
80
81pngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
82 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
83
84pngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
85 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
86
87libpng.lib: $(OBJS)
88 -$(RM) $@
89 $(AR) $(ARFLAGS) -out:$@ $(OBJS) $(ERRFILE)
90
91pngtest$(O): png.h pngconf.h pnglibconf.h
92 $(CC) -c $(CFLAGS) $*.c $(ERRFILE)
93
94pngtest.exe: pngtest$(O) libpng.lib
95 $(LD) $(LDFLAGS) -out:$@ pngtest$(O) libpng.lib ..\zlib\zlib.lib $(ERRFILE)
96
97test: pngtest.exe
98 pngtest
99
100clean:
101 -$(RM) *$(O)
102 -$(RM) libpng.lib
103 -$(RM) pnglibconf.h
104 -$(RM) pngtest.exe
105 -$(RM) pngout.png
106
107# End of makefile for libpng
108
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makevms.com b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makevms.com
new file mode 100644
index 0000000..6563684
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/makevms.com
@@ -0,0 +1,142 @@
1$! make libpng under VMS
2$!
3$!
4$! Check for MMK/MMS
5$!
6$! This procedure accepts one parameter (contrib), which causes it to build
7$! the programs from the contrib directory instead of libpng.
8$!
9$ p1 = f$edit(p1,"UPCASE")
10$ if p1 .eqs. "CONTRIB"
11$ then
12$ set def [.contrib.gregbook]
13$ @makevms
14$ set def [-.pngminus]
15$ @makevms
16$ set def [--]
17$ exit
18$ endif
19$ Make = ""
20$ If F$Search ("Sys$System:MMS.EXE") .nes. "" Then Make = "MMS"
21$ If F$Type (MMK) .eqs. "STRING" Then Make = "MMK"
22$!
23$! Look for the compiler used
24$!
25$ zlibsrc = "[-.zlib]"
26$ ccopt="/include=''zlibsrc'"
27$ if f$getsyi("HW_MODEL").ge.1024
28$ then
29$ ccopt = "/prefix=all"+ccopt
30$ comp = "__decc__=1"
31$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
32$ else
33$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
34$ then
35$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
36$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
37$ then
38$ comp = "__gcc__=1"
39$ CC :== GCC
40$ else
41$ comp = "__vaxc__=1"
42$ endif
43$ else
44$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
45$ ccopt = "/decc/prefix=all"+ccopt
46$ comp = "__decc__=1"
47$ endif
48$ endif
49$!
50$! Build the thing plain or with mms/mmk
51$!
52$ write sys$output "Compiling Libpng sources ..."
53$ if make.eqs.""
54$ then
55$ dele pngtest.obj;*
56$ CALL MAKE png.OBJ "cc ''CCOPT' png" -
57 png.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
58$ CALL MAKE pngset.OBJ "cc ''CCOPT' pngset" -
59 pngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
60$ CALL MAKE pngget.OBJ "cc ''CCOPT' pngget" -
61 pngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
62$ CALL MAKE pngread.OBJ "cc ''CCOPT' pngread" -
63 pngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
64$ CALL MAKE pngpread.OBJ "cc ''CCOPT' pngpread" -
65 pngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
66$ CALL MAKE pngrtran.OBJ "cc ''CCOPT' pngrtran" -
67 pngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
68$ CALL MAKE pngrutil.OBJ "cc ''CCOPT' pngrutil" -
69 pngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
70$ CALL MAKE pngerror.OBJ "cc ''CCOPT' pngerror" -
71 pngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
72$ CALL MAKE pngmem.OBJ "cc ''CCOPT' pngmem" -
73 pngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
74$ CALL MAKE pngrio.OBJ "cc ''CCOPT' pngrio" -
75 pngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
76$ CALL MAKE pngwio.OBJ "cc ''CCOPT' pngwio" -
77 pngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
78$ CALL MAKE pngtrans.OBJ "cc ''CCOPT' pngtrans" -
79 pngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
80$ CALL MAKE pngwrite.OBJ "cc ''CCOPT' pngwrite" -
81 pngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
82$ CALL MAKE pngwtran.OBJ "cc ''CCOPT' pngwtran" -
83 pngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
84$ CALL MAKE pngwutil.OBJ "cc ''CCOPT' pngwutil" -
85 pngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h
86$ write sys$output "Building Libpng ..."
87$ CALL MAKE libpng.OLB "lib/crea libpng.olb *.obj" *.OBJ
88$ write sys$output "Building pngtest..."
89$ CALL MAKE pngtest.OBJ "cc ''CCOPT' pngtest" -
90 pngtest.c png.h pngconf.h pnglibconf.h
91$ call make pngtest.exe -
92 "LINK pngtest,libpng.olb/lib,''zlibsrc'libz.olb/lib" -
93 pngtest.obj libpng.olb
94$ write sys$output "Testing Libpng..."
95$ run pngtest
96$ else
97$ if f$search("DESCRIP.MMS") .eqs. "" then copy/nolog [.SCRIPTS]DESCRIP.MMS []
98$ 'make'/macro=('comp',zlibsrc='zlibsrc')
99$ endif
100$ write sys$output "Libpng build completed"
101$ exit
102$!
103$!
104$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
105$ V = 'F$Verify(0)
106$! P1 = What we are trying to make
107$! P2 = Command to make it
108$! P3 - P8 What it depends on
109$
110$ If F$Search(P1) .Eqs. "" Then Goto Makeit
111$ Time = F$CvTime(F$File(P1,"RDT"))
112$arg=3
113$Loop:
114$ Argument = P'arg
115$ If Argument .Eqs. "" Then Goto Exit
116$ El=0
117$Loop2:
118$ File = F$Element(El," ",Argument)
119$ If File .Eqs. " " Then Goto Endl
120$ AFile = ""
121$Loop3:
122$ OFile = AFile
123$ AFile = F$Search(File)
124$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
125$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
126$ Goto Loop3
127$NextEL:
128$ El = El + 1
129$ Goto Loop2
130$EndL:
131$ arg=arg+1
132$ If arg .Le. 8 Then Goto Loop
133$ Goto Exit
134$
135$Makeit:
136$ VV=F$VERIFY(0)
137$ write sys$output P2
138$ 'P2
139$ VV='F$Verify(VV)
140$Exit:
141$ If V Then Set Verify
142$ENDSUBROUTINE
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/options.awk b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/options.awk
new file mode 100644
index 0000000..29ea31d
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/options.awk
@@ -0,0 +1,777 @@
1#!/bin/awk -f
2# scripts/options.awk - library build configuration control
3#
4# last changed in libpng version 1.5.7 - December 15, 2011
5#
6# Copyright (c) 1998-2011 Glenn Randers-Pehrson
7#
8# This code is released under the libpng license.
9# For conditions of distribution and use, see the disclaimer
10# and license in png.h
11
12# The output of this script is written to the file given by
13# the variable 'out'. The script is run twice, once with
14# an intermediate output file, 'options.tmp' then again on
15# that file to produce the final output:
16#
17# awk -f scripts/options.awk out=options.tmp scripts/options.dfa 1>&2
18# awk -f scripts/options.awk out=options.dfn options.tmp 1>&2
19#
20# Some options may be specified on the command line:
21#
22# deb=1 Causes debugging to be output
23# logunsupported=1 Causes all options to be recorded in the output
24# everything=off Causes all options to be disabled by default
25# everything=on Causes all options to be enabled by default
26#
27# If awk fails on your platform, try nawk instead.
28#
29# These options may also be specified in the original input file (and
30# are copied to the preprocessed file).
31
32BEGIN{
33 out="/dev/null" # intermediate, preprocessed, file
34 pre=-1 # preprocess (first line)
35 version="libpng version unknown" # version information
36 version_file="" # where to find the version
37 err=0 # in-line exit sets this
38 start="PNG_DEFN_MAGIC-" # Arbitrary start
39 end="-PNG_DEFN_END" # Arbitrary end
40 ct="PNG_JOIN" # Join two tokens
41 cx= "/" ct "*" # Open C comment for output file
42 comment=start cx # Comment start
43 cend="*/" end # Comment end
44 def=start "#define PNG_" ct # Arbitrary define
45 sup=ct "_SUPPORTED" end # end supported option
46 und=comment "#undef PNG_" ct # Unsupported option
47 une=ct "_SUPPORTED" cend # end unsupported option
48 error=start "ERROR:" # error message
49
50 # Variables
51 deb=0 # debug - set on command line
52 everything="" # do not override defaults
53 logunsupported=0 # write unsupported options too
54
55 # Precreate arrays
56 option[""] = "" # list of all options: default enabled/disabled
57 done[""] = 1 # marks option as having been output
58 requires[""] = "" # requires by option
59 iffs[""] = "" # if by option
60 enabledby[""] = "" # options that enable it by option
61 setting[""] = "" # requires by setting
62 defaults[""] = "" # used for a defaulted value
63 doneset[""] = 1 # marks setting as having been output
64 r[""] = "" # Temporary array
65
66 # For decorating the output file
67 protect = ""
68}
69
70# The output file must be specified before any input:
71out == "/dev/null" {
72 print "out=output.file must be given on the command line"
73 err = 1
74 exit 1
75}
76
77# The very first line indicates whether we are reading pre-processed
78# input or not, this must come *first* because 'PREPROCESSED' needs
79# to be the very first line in the temporary file.
80pre == -1{
81 if ($0 == "PREPROCESSED") {
82 pre = 0
83 next
84 } else {
85 pre = 1
86 print "PREPROCESSED" >out
87 # And fall through to continue processing
88 }
89}
90
91# While pre-processing if version is set to "search" look for a version string
92# in the following file.
93pre && version == "search" && version_file == ""{
94 version_file = FILENAME
95}
96
97pre && version == "search" && version_file != FILENAME{
98 print "version string not found in", version_file
99 err = 1
100 exit 1
101}
102
103pre && version == "search" && $0 ~ /^ \* libpng version/{
104 version = substr($0, 4)
105 print "version =", version >out
106 next
107}
108
109pre && FILENAME == version_file{
110 next
111}
112
113# variable=value
114# Sets the given variable to the given value (the syntax is fairly
115# free form, except for deb (you are expected to understand how to
116# set the debug variable...)
117#
118# This happens before the check on 'pre' below skips most of the
119# rest of the actions, so the variable settings happen during
120# preprocessing but are recorded in the END action too. This
121# allows them to be set on the command line too.
122$0 ~ /^[ ]*version[ ]*=/{
123 sub(/^[ ]*version[ ]*=[ ]*/, "")
124 version = $0
125 next
126}
127$0 ~ /^[ ]*everything[ =]*off[ ]*$/{
128 everything = "off"
129 next
130}
131$0 ~ /^[ ]*everything[ =]*on[ ]*$/{
132 everything = "on"
133 next
134}
135$0 ~ /^[ ]*logunsupported[ =]*0[ ]*$/{
136 logunsupported = 0
137 next
138}
139$0 ~ /^[ ]*logunsupported[ =]*1[ ]*$/{
140 logunsupported = 1
141 next
142}
143$1 == "deb" && $2 == "=" && NF == 3{
144 deb = $3
145 next
146}
147
148# Preprocessing - this just copies the input file with lines
149# that need preprocessing (just chunk at present) expanded
150# The bare "pre" instead of "pre != 0" crashes under Sunos awk
151pre && $1 != "chunk"{
152 print >out
153 next
154}
155
156# The first characters of the line determine how it is processed,
157# leading spaces are ignored. In general tokens that are not
158# keywords are the names of options. An option 'name' is
159# controlled by the definition of the corresponding macros:
160#
161# PNG_name_SUPPORTED The option is turned on
162# PNG_NO_name
163# PNG_NO_name_SUPPORTED If the first macro is not defined
164# either of these will turn the option off
165#
166# If none of these macros are defined the option is turned on, unless
167# the keyword 'off' is given in a line relating to the option. The
168# keyword 'on' can also be given, but it will be ignored (since it is
169# the default.)
170#
171# In the syntax below a 'name' is indicated by "NAME", other macro
172# values are indicated by "MACRO", as with "NAME" the leading "PNG_"
173# is omitted, but in this case the "NO_" prefix and the "_SUPPORTED"
174# suffix are never used.
175#
176# Each line is introduced by a keyword - the first non-space characters
177# on the line. A line starting with a '#' is a comment - it is totally
178# ignored. Keywords are as follows, a NAME, is simply a macro name
179# without the leading PNG_, PNG_NO_ or the trailing _SUPPORTED.
180
181$1 ~ /^#/ || $0 ~ /^[ ]*$/{
182 next
183}
184
185# com <comment>
186# The whole line is placed in the output file as a comment with
187# the preceding 'com' removed
188$1 == "com"{
189 if (NF > 1) {
190 # sub(/^[ ]*com[ ]*/, "")
191 $1 = ""
192 print comment, $0, cend >out
193 } else
194 print start end >out
195 next
196}
197
198# version
199# Inserts a version comment
200$1 == "version" && NF == 1{
201 if (version == "") {
202 print "ERROR: no version string set"
203 err = 1 # prevent END{} running
204 exit 1
205 }
206
207 print comment, version, cend >out
208 next
209}
210
211# file output input protect
212# Informational: the official name of the input file (without
213# make generated local directories), the official name of the
214# output file and, if required, a name to use in a protection
215# macro for the contents.
216$1 == "file" && NF >= 2{
217 print comment, $2, cend >out
218 print comment, "Machine generated file: DO NOT EDIT", cend >out
219 if (NF >= 3)
220 print comment, "Derived from:", $3, cend >out
221 protect = $4
222 if (protect != "") {
223 print start "#ifndef", protect end >out
224 print start "#define", protect end >out
225 }
226 next
227}
228
229# option NAME ( (requires|enables|if) NAME* | on | off | disabled )*
230# Declares an option 'NAME' and describes its default setting (disabled)
231# and its relationship to other options. The option is disabled
232# unless *all* the options listed after 'requires' are set and at
233# least one of the options listed after 'if' is set. If the
234# option is set then it turns on all the options listed after 'enables'.
235#
236# Note that "enables" takes priority over the required/if/disabled/off
237# setting of the target option.
238#
239# The definition file may list an option as 'disabled': off by default,
240# otherwise the option is enabled: on by default. A later (and it must
241# be later) entry may turn an option on or off explicitly.
242
243$1 == "option" && NF >= 2{
244 onoff = option[$2] # records current (and the default is "", enabled)
245 key = ""
246 for (i=3; i<=NF; ++i) {
247 if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") {
248 key = ""
249 if (onoff != $(i)) {
250 # on or off can zap disabled or enabled:
251 if (onoff == "" || (onoff == "disabled" || onoff == "enabled") && ($(i) == "on" || $(i) == "off")) {
252 # It's easy to mis-spell the option when turning it
253 # on or off, so warn about it here:
254 if (onoff == "" && ($(i) == "on" || $(i) == "off")) {
255 print $2 ": ERROR: turning unrecognized option", $(i)
256 # For the moment error out - it is safer
257 err = 1 # prevent END{} running
258 exit 1
259 }
260 onoff = $(i)
261 } else {
262 # Print a message, otherwise the error
263 # below is incomprehensible
264 print $2 ": currently", onoff ": attempt to turn", $(i)
265 break
266 }
267 }
268 } else if ($(i) == "requires" || $(i) == "if" || $(i) == "enables") {
269 key = $(i)
270 } else if (key == "requires") {
271 requires[$2] = requires[$2] " " $(i)
272 } else if (key == "if") {
273 iffs[$2] = iffs[$2] " " $(i)
274 } else if (key == "enables") {
275 enabledby[$(i)] = enabledby[$(i)] " " $2
276 } else
277 break # bad line format
278 }
279
280 if (i > NF) {
281 # Set the option, defaulting to 'enabled'
282 if (onoff == "") onoff = "enabled"
283 option[$2] = onoff
284 next
285 }
286 # Else fall through to the error handler
287}
288
289# chunk NAME [requires OPT] [on|off|disabled]
290# Expands to the 'option' settings appropriate to the reading and
291# writing of an ancilliary PNG chunk 'NAME':
292#
293# option READ_NAME requires READ_ANCILLARY_CHUNKS [READ_OPT]
294# option READ_NAME enables NAME
295# [option READ_NAME off]
296# option WRITE_NAME requires WRITE_ANCILLARY_CHUNKS [WRITE_OPT]
297# option WRITE_NAME enables NAME
298# [option WRITE_NAME off]
299
300pre != 0 && $1 == "chunk" && NF >= 2{
301 # 'chunk' is handled on the first pass by writing appropriate
302 # 'option' lines into the intermediate file.
303 onoff = ""
304 reqread = ""
305 reqwrite = ""
306 i = 3 # indicates format error
307 if (NF > 2) {
308 # read the keywords/additional OPTS
309 req = 0
310 for (i=3; i<=NF; ++i) {
311 if ($(i) == "on" || $(i) == "off" || $(i) == "disabled") {
312 if (onoff != $(i)) {
313 if (onoff == "")
314 onoff = $(i)
315 else
316 break # on/off conflict
317 }
318 } else if ($(i) == "requires")
319 req = 1
320 else if (req != 1)
321 break # bad line: handled below
322 else {
323 reqread = reqread " READ_" $(i)
324 reqwrite = reqwrite " WRITE_" $(i)
325 }
326 }
327 }
328
329 if (i > NF) {
330 # Output new 'option' lines to the intermediate file (out)
331 print "option READ_" $2, "requires READ_ANCILLARY_CHUNKS" reqread, "enables", $2, onoff >out
332 print "option WRITE_" $2, "requires WRITE_ANCILLARY_CHUNKS" reqwrite, "enables", $2, onoff >out
333 next
334 }
335 # Else hit the error handler below - bad line format!
336}
337
338# setting MACRO ( requires MACRO* )* [ default VALUE ]
339# Behaves in a similar way to 'option' without looking for NO_ or
340# _SUPPORTED; the macro is enabled if it is defined so long as all
341# the 'requires' macros are also defined. The definitions may be
342# empty, an error will be issued if the 'requires' macros are
343# *not* defined. If given the 'default' value is used if the
344# macro is not defined. The default value will be re-tokenised.
345# (BTW: this is somewhat restrictive, it mainly exists for the
346# support of non-standard configurations and numeric parameters,
347# see the uses in scripts/options.dat
348
349$1 == "setting" && (NF == 2 || NF >= 3 && ($3 == "requires" || $3 == "default")){
350 reqs = ""
351 deflt = ""
352 isdef = 0
353 key = ""
354 for (i=3; i<=NF; ++i)
355 if ($(i) == "requires" || $(i) == "default") {
356 key = $(i)
357 if (key == "default") isdef = 1
358 } else if (key == "requires")
359 reqs = reqs " " $(i)
360 else if (key == "default")
361 deflt = deflt " " $(i)
362 else
363 break # Format error, handled below
364
365 setting[$2] = reqs
366 # NOTE: this overwrites a previous value silently
367 if (isdef && deflt == "")
368 deflt = " " # as a flag to force output
369 defaults[$2] = deflt
370 next
371}
372
373# The order of the dependency lines (option, chunk, setting) is irrelevant
374# - the 'enables', 'requires' and 'if' settings will be used to determine
375# the correct order in the output and the final values in pnglibconf.h are
376# not order dependent. 'requires' and 'if' entries take precedence over
377# 'enables' from other options; if an option requires another option it
378# won't be set regardless of any options that enable it unless the other
379# option is also enabled.
380#
381# Similarly 'enables' trumps a NO_ definition in CFLAGS or pngusr.h
382#
383# For simplicity cycles in the definitions are regarded as errors,
384# even if they are not ambiguous.
385# A given NAME can be specified in as many 'option' lines as required, the
386# definitions are additive.
387
388# For backwards compatibility equivalent macros may be listed thus:
389#
390# = [NO_]NAME MACRO
391# Makes -DMACRO equivalent to -DPNG_NO_NAME or -DPNG_NAME_SUPPORTED
392# as appropriate.
393#
394# The definition is injected into the C compiler input when encountered
395# in the second pass (so all these definitions appear *after* the @
396# lines!)
397#
398# 'NAME' is as above, but 'MACRO' is the full text of the equivalent
399# old, deprecated, macro.
400
401$1 == "=" && NF == 3{
402 print "#ifdef PNG_" $3 >out
403 if ($2 ~ /^NO_/)
404 print "# define PNG_" $2 >out
405 else
406 print "# define PNG_" $2 "_SUPPORTED" >out
407 print "#endif" >out
408 next
409}
410
411# Lines may be injected into the C compiler input by preceding them
412# with an "@" character. The line is copied with just the leading
413# @ removed.
414
415$1 ~ /^@/{
416 # sub(/^[ ]*@/, "")
417 $1 = substr($1, 2)
418 print >out
419 next
420}
421
422# Check for unreognized lines, because of the preprocessing chunk
423# format errors will be detected on the first pass independent of
424# any other format errors.
425{
426 print "options.awk: bad line (" NR "):", $0
427 err = 1 # prevent END{} running
428 exit 1
429}
430
431# For checking purposes names that start with "ok_" or "fail_" are
432# not output to pnglibconf.h and must be either enabled or disabled
433# respectively for the build to succeed. This allows interdependencies
434# between options of the form "at least one of" or "at most one of"
435# to be checked. For example:
436#
437# option FLOATING_POINT enables ok_math
438# option FIXED_POINT enables ok_math
439# This ensures that at least one of FLOATING_POINT and FIXED_POINT
440# must be set for the build to succeed.
441#
442# option fail_math requires FLOATING_POINT FIXED_POINT
443# This means the build will fail if *both* FLOATING_POINT and
444# FIXED_POINT are set (this is an example; in fact both are allowed.)
445#
446# If all these options were given the build would require exactly one
447# of the names to be enabled.
448
449END{
450 # END{} gets run on an exit (a traditional awk feature)
451 if (err) exit 1
452
453 if (pre) {
454 # Record the final value of the variables
455 print "deb =", deb >out
456 if (everything != "") {
457 print "everything =", everything >out
458 }
459 print "logunsupported =", logunsupported >out
460 exit 0
461 }
462
463 # Do the 'setting' values first, the algorithm the standard
464 # tree walk (O(1)) done in an O(2) while/for loop; interations
465 # settings x depth, outputing the deepest required macros
466 # first.
467 print "" >out
468 print "/* SETTINGS */" >out
469 print comment, "settings", cend >out
470 finished = 0
471 while (!finished) {
472 finished = 1
473 movement = 0 # done nothing
474 for (i in setting) if (!doneset[i]) {
475 nreqs = split(setting[i], r)
476 if (nreqs > 0) {
477 for (j=1; j<=nreqs; ++j) if (!doneset[r[j]]) {
478 break
479 }
480 if (j<=nreqs) {
481 finished = 0
482 continue # try a different setting
483 }
484 }
485
486 # All the requirements have been processed, output
487 # this setting.
488 if (deb) print "setting", i
489 print "" >out
490 print "/* setting: ", i >out
491 print " * requires:" setting[i] >out
492 print " * default: ", defaults[i], "*/" >out
493 if (defaults[i] == "") { # no default, only check if defined
494 print "#ifdef PNG_" i >out
495 }
496 for (j=1; j<=nreqs; ++j) {
497 print "# ifndef PNG_" r[j] >out
498 print error, i, "requires", r[j] end >out
499 print "# endif" >out
500 }
501 if (defaults[i] != "") { # default handling
502 print "#ifdef PNG_" i >out
503 }
504 print def i, "PNG_" i end >out
505 if (defaults[i] != "") {
506 print "#else /*default*/" >out
507 # And add the default definition for the benefit
508 # of later settings an options test:
509 print "# define PNG_" i defaults[i] >out
510 print def i defaults[i] end >out
511 }
512 print "#endif" >out
513
514 doneset[i] = 1
515 ++movement
516 }
517
518 if (!finished && !movement) {
519 print "setting: loop or missing setting in 'requires', cannot process:"
520 for (i in setting) if (!doneset[i]) {
521 print " setting", i, "requires" setting[i]
522 }
523 exit 1
524 }
525 }
526 print comment, "end of settings", cend >out
527
528 # Now do the options - somewhat more complex. The dependency
529 # tree is thus:
530 #
531 # name > name
532 # name requires name
533 # name if name
534 # name enabledby name
535 #
536 # First build a list 'tree' by option of all the things on which
537 # it depends.
538 print "" >out
539 print "/* OPTIONS */" >out
540 print comment, "options", cend >out
541 for (opt in enabledby) tree[opt] = 1 # may not be explicit options
542 for (opt in option) if (opt != "") {
543 o = option[opt]
544 # option should always be one of the following values
545 if (o != "on" && o != "off" && o != "disabled" && o != "enabled") {
546 print "internal option error (" o ")"
547 exit 1
548 }
549 tree[opt] = "" # so unlisted options marked
550 }
551 for (opt in tree) if (opt != "") {
552 if (tree[opt] == 1) {
553 tree[opt] = ""
554 if (option[opt] != "") {
555 print "internal error (1)"
556 exit 1
557 }
558 # Macros only listed in 'enables' remain off unless
559 # one of the enabling macros is on.
560 option[opt] = "disabled"
561 }
562
563 split("", list) # clear 'list'
564 # Now add every requires, iffs or enabledby entry to 'list'
565 # so that we can add a unique list of requirements to tree[i]
566 split(requires[opt] iffs[opt] enabledby[opt], r)
567 for (i in r) list[r[i]] = 1
568 for (i in list) tree[opt] = tree[opt] " " i
569 }
570
571 # print the tree for extreme debugging
572 if (deb > 2) for (i in tree) if (i != "") print i, "depends-on" tree[i]
573
574 # Ok, now check all options marked explicitly 'on' or 'off':
575 #
576 # If an option[opt] is 'on' then turn on all requires[opt]
577 # If an option[opt] is 'off' then turn off all enabledby[opt]
578 #
579 # Error out if we have to turn 'on' an 'off' option or vice versa.
580 npending = 0
581 for (opt in option) if (opt != "") {
582 if (option[opt] == "on" || option[opt] == "off") {
583 pending[++npending] = opt
584 }
585 }
586
587 err = 0 # set on error
588 while (npending > 0) {
589 opt = pending[npending--]
590 if (option[opt] == "on") {
591 nreqs = split(requires[opt], r)
592 for (j=1; j<=nreqs; ++j) {
593 if (option[r[j]] == "off") {
594 print "option", opt, "turned on, but requirement", r[j], "is turned off"
595 err = 1
596 } else if (option[r[j]] != "on") {
597 option[r[j]] = "on"
598 pending[++npending] = r[j]
599 }
600 }
601 } else {
602 if (option[opt] != "off") {
603 print "internal error (2)"
604 exit 1
605 }
606 nreqs = split(enabledby[opt], r)
607 for (j=1; j<=nreqs; ++j) {
608 if (option[r[j]] == "on") {
609 print "option", opt, "turned off, but enabled by", r[j], "which is turned on"
610 err = 1
611 } else if (option[r[j]] != "off") {
612 option[r[j]] = "off"
613 pending[++npending] = r[j]
614 }
615 }
616 }
617 }
618 if (err) exit 1
619
620 # option[i] is now the complete list of all the tokens we may
621 # need to output, go through it as above, depth first.
622 finished = 0
623 while (!finished) {
624 finished = 1
625 movement = 0 # done nothing
626 for (i in option) if (!done[i]) {
627 nreqs = split(tree[i], r)
628 if (nreqs > 0) {
629 for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {
630 break
631 }
632 if (j<=nreqs) {
633 finished = 0
634 continue # next option
635 }
636 }
637
638 # All the requirements have been processed, output
639 # this option. An option is _SUPPORTED if:
640 #
641 # all 'requires' are _SUPPORTED AND
642 # at least one of the 'if' options are _SUPPORTED AND
643 # EITHER:
644 # The name is _SUPPORTED (on the command line)
645 # OR:
646 # an 'enabledby' is _SUPPORTED
647 # OR:
648 # NO_name is not defined AND
649 # the option is not disabled; an option is disabled if:
650 # option == off
651 # option == disabled && everything != on
652 # option == "" && everything == off
653 if (deb) print "option", i
654 print "" >out
655 print "/* option:", i, option[i] >out
656 print " * requires: " requires[i] >out
657 print " * if: " iffs[i] >out
658 print " * enabled-by:" enabledby[i], "*/" >out
659 print "#undef PNG_on" >out
660 print "#define PNG_on 1" >out
661
662 # requires
663 nreqs = split(requires[i], r)
664 for (j=1; j<=nreqs; ++j) {
665 print "#ifndef PNG_" r[j] "_SUPPORTED" >out
666 print "# undef PNG_on /*!" r[j] "*/" >out
667 # this error appears in the final output if something
668 # was switched 'on' but the processing above to force
669 # the requires did not work
670 if (option[i] == "on") {
671 print error, i, "requires", r[j] end >out
672 }
673 print "#endif" >out
674 }
675
676 # if
677 nreqs = split(iffs[i], r)
678 print "#undef PNG_no_if" >out
679 if (nreqs > 0) {
680 print "/* if" iffs[i], "*/" >out
681 print "#define PNG_no_if 1" >out
682 for (j=1; j<=nreqs; ++j) {
683 print "#ifdef PNG_" r[j] "_SUPPORTED" >out
684 print "# undef PNG_no_if /*" r[j] "*/" >out
685 print "#endif" >out
686 }
687 print "#ifdef PNG_no_if /*missing if*/" >out
688 print "# undef PNG_on" >out
689 # There is no checking above for this, because we
690 # don't know which 'if' to choose, so whine about
691 # it here:
692 if (option[i] == "on") {
693 print error, i, "needs one of:", iffs[i] end >out
694 }
695 print "#endif" >out
696 }
697
698 print "#ifdef PNG_on /*requires, if*/" >out
699 # enables
700 print "# undef PNG_not_enabled" >out
701 print "# define PNG_not_enabled 1" >out
702 print " /* enabled by" enabledby[i], "*/" >out
703 nreqs = split(enabledby[i], r)
704 for (j=1; j<=nreqs; ++j) {
705 print "#ifdef PNG_" r[j] "_SUPPORTED" >out
706 print "# undef PNG_not_enabled /*" r[j] "*/" >out
707 # Oops, probably not intended (should be factored
708 # out by the checks above).
709 if (option[i] == "off") {
710 print error, i, "enabled by:", r[j] end >out
711 }
712 print "#endif" >out
713 }
714
715 print "# ifndef PNG_" i "_SUPPORTED /*!command line*/" >out
716 print "# ifdef PNG_not_enabled /*!enabled*/" >out
717 if (option[i] == "off" || option[i] == "disabled" && everything != "on" || option[i] == "enabled" && everything == "off") {
718 print "# undef PNG_on /*default off*/" >out
719 } else {
720 print "# ifdef PNG_NO_" i >out
721 print "# undef PNG_on /*turned off*/" >out
722 print "# endif" >out
723 print "# ifdef PNG_NO_" i "_SUPPORTED" >out
724 print "# undef PNG_on /*turned off*/" >out
725 print "# endif" >out
726 }
727 print "# endif /*!enabled*/" >out
728 print "# ifdef PNG_on" >out
729 # The _SUPPORTED macro must be defined so that dependent
730 # options output later work.
731 print "# define PNG_" i "_SUPPORTED" >out
732 print "# endif" >out
733 print "# endif /*!command line*/" >out
734 # If PNG_on is still set the option should be defined in
735 # pnglibconf.h
736 print "# ifdef PNG_on" >out
737 if (i ~ /^fail_/) {
738 print error, i, "is on: enabled by:" iffs[i] enabledby[i] ", requires" requires[i] end >out
739 } else if (i !~ /^ok_/) {
740 print def i sup >out
741 }
742 print "# endif /* definition */" >out
743 print "#endif /*requires, if*/" >out
744 if (logunsupported || i ~ /^ok_/) {
745 print "#ifndef PNG_on" >out
746 if (logunsupported) {
747 print und i une >out
748 }
749 if (i ~ /^ok_/) {
750 print error, i, "not enabled: requires:" requires[i] ", enabled by:" iffs[i] enabledby[i] end >out
751 }
752 print "#endif" >out
753 }
754
755 done[i] = 1
756 ++movement
757 }
758
759 if (!finished && !movement) {
760 print "option: loop or missing option in dependency tree, cannot process:"
761 for (i in option) if (!done[i]) {
762 print " option", i, "depends on" tree[i], "needs:"
763 nreqs = split(tree[i], r)
764 if (nreqs > 0) for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {
765 print " " r[j]
766 }
767 }
768 exit 1
769 }
770 }
771 print comment, "end of options", cend >out
772
773 # Regular end - everything looks ok
774 if (protect != "") {
775 print start "#endif", cx, protect, "*/" end >out
776 }
777}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.dfa b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.dfa
new file mode 100644
index 0000000..b0ccd39
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.dfa
@@ -0,0 +1,578 @@
1# scripts/pnglibconf.dfa - library build configuration control
2#
3@/*- pnglibconf.dfn intermediate file
4@ * generated from scripts/pnglibconf.dfa
5@ */
6#
7com pnglibconf.h - library build configuration
8com
9version
10com
11com Copyright (c) 1998-2011 Glenn Randers-Pehrson
12com
13com This code is released under the libpng license.
14com For conditions of distribution and use, see the disclaimer
15com and license in png.h
16com
17
18file pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H
19
20# This file is preprocessed by scripts/options.awk and the
21# C compiler to generate 'pnglibconf.h' - a list of all the
22# configuration options. The file lists the various options
23# that can *only* be specified during the libpng build;
24# pnglibconf.h freezes the definitons selected for the specific
25# build.
26#
27# The syntax is detailed in scripts/options.awk, this is a summary
28# only:
29#
30# setting <name> [requires ...] [default]
31# #define PNG_<name> <value> /* value comes from current setting */
32# option <name> [requires ...] [if ...] [enables ...] [disabled]
33# #define PNG_<name>_SUPPORTED if the requirements are met and
34# enable the other options listed
35# chunk <name> [requires ...] [disabled]
36# Enable chunk processing for the given ancillary chunk
37#
38# Note that the 'on' and 'off' keywords, while valid on both option
39# and chunk, should not be used in this file because they force the
40# relevant options on or off.
41
42#----------------------------------------------------------------------
43
44# The following setting, option and chunk values can all be changed
45# while building libpng:
46#
47# setting: change 'setting' lines to fine tune library performance,
48# changes to the settings don't affect the libpng API functionally
49#
50# option: change 'option' lines to remove or add capabilities from
51# or to the library; options change the library API
52#
53# chunk: change 'chunk' lines to remove capabilities to process
54# optional ('ancillary') chunks. This does not prevent PNG
55# decoding but does change the libpng API because some chunks
56# will be ignored.
57#
58# There are three ways of disabling features, in no particular order:
59#
60# 1) Create 'pngusr.h', enter the required private build information
61# detailed below and #define PNG_NO_<option> for each option you
62# don't want in that file in that file. You can also turn on options
63# using PNG_<option>_SUPPORTED. When you have finished rerun
64# configure and rebuild pnglibconf.h file with -DPNG_USER_CONFIG:
65#
66# make clean
67# CPPFLAGS='-DPNG_USER_CONFIG' ./configure
68# make pnglibconf.h
69#
70# pngusr.h is only used during the creation of pnglibconf.h, but it
71# is safer to ensure that -DPNG_USER_CONFIG is specified throughout
72# the build by changing the CPPFLAGS passed to the initial ./configure
73#
74# 2) Add definitions of the settings you want to change to
75# CPPFLAGS; for example:
76#
77# -DPNG_DEFAULT_READ_MACROS=0
78#
79# (This would change the default to *not* use read macros.) Be
80# very careful to change only settings that don't alter the API
81# because this approach bypasses the private build checking. You
82# can also change settings from pngpriv.h (read pngpriv.h) safely
83# without API changes. Do that in the same way.
84#
85# 3) Write a new '.dfa' file (say 'pngusr.dfa') and in this file
86# provide override values for setting entries and turn option or
87# chunk values explicitly 'on' or 'off':
88#
89# setting FOO default VALUE
90# option BAR [on|off]
91#
92# Then add this file to the options.awk command line (the *first*
93# one) after this file. The make macro DFA_XTRA is provided to make
94# this easier (set it like CPPFLAGS prior to running ./configure).
95# Look at the builds below contrib/pngminim for some extreme examples
96# of how this can be used.
97#
98# Don't edit this file unless you are contributing a patch to
99# libpng and need new or modified options/settings.
100#----------------------------------------------------------------------
101
102# The following causes commented out #undef lines to be written to
103# pnglibconf.h; this can be stopped by logunsupported=0 in a later
104# file or on the command line (after pnglibconf.dfa)
105
106logunsupported = 1
107
108# PNG_USER_CONFIG has to be defined on the compiler command line
109# to cause pngusr.h to be read while constructing pnglibconf.h
110#
111# If you create a private DLL you need to define the following
112# macros in the file 'pngusr.h' and set -DPNG_USER_CONFIG for
113# compilation (i.e. in CFLAGS.)
114# #define PNG_USER_PRIVATEBUILD \
115# <Describes by whom and why this version of the DLL was built>
116# e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons."
117# #define PNG_USER_DLLFNAME_POSTFIX <two-letter postfix that serve to
118# distinguish your DLL from those of the official release. These
119# correspond to the trailing letters that come after the version
120# number and must match your private DLL name>
121# e.g. // private DLL "libpng13gx.dll"
122# #define PNG_USER_DLLFNAME_POSTFIX "gx"
123#
124# The following macros are also at your disposal if you want to complete the
125# DLL VERSIONINFO structure.
126# - PNG_USER_VERSIONINFO_COMMENTS
127# - PNG_USER_VERSIONINFO_COMPANYNAME
128# - PNG_USER_VERSIONINFO_LEGALTRADEMARKS
129
130@#ifdef PNG_USER_CONFIG
131@# include "pngusr.h"
132@#endif
133
134# This is a special fixup for the Watcom C compiler on Windows, which has
135# multiple procedure call standards. Unless PNG_API_RULE is set explicitly
136# (i.e. if it is not defined at this point) it will be forced to '2' here when
137# using Watcom. This indicates to the other header files that Watcom behaviour
138# is required where appropriate.
139
140@#ifdef __WATCOMC__
141@# ifndef PNG_API_RULE
142@# define PNG_API_RULE 2 /* Use Watcom calling conventions */
143@# endif
144@#endif
145
146# Note that PNG_USR_CONFIG only has an effect when building
147# pnglibconf.h
148
149setting USER_CONFIG
150setting USER_PRIVATEBUILD
151setting USER_DLLFNAME_POSTFIX
152setting USER_VERSIONINFO_COMMENTS
153setting USER_VERSIONINFO_COMPANYNAME
154setting USER_VERSIONINFO_LEGALTRADEMARKS
155
156# Record the 'API rule' used to select calling conventions on
157# those systems that support such things (see all the comments in
158# pngconf.h)
159# Changing this setting has a fundamental affect on the PNG ABI,
160# do not release shared libraries with this changed.
161
162setting API_RULE default 0
163
164# Default to using the read macros
165
166setting DEFAULT_READ_MACROS default 1
167
168# The alternative is to call functions to read PNG values, if
169# the functions are turned *off* the read macros must always
170# be enabled, so turning this off will actually force the
171# USE_READ_MACROS option on (see pngconf.h)
172
173option READ_INT_FUNCTIONS requires READ
174
175# The same for write, but these can only be switched off if
176# no writing is required at all - hence the use of an 'enables'
177# not a 'requires' below:
178
179option WRITE_INT_FUNCTIONS disabled
180option WRITE enables WRITE_INT_FUNCTIONS
181
182# Generic options - affect both read and write.
183
184option WARNINGS
185option BENIGN_ERRORS
186option MNG_FEATURES
187
188# Arithmetic options, the first is the big switch that chooses between internal
189# floating and fixed point arithmetic implementations - it does not affect any
190# APIs. The second two (the _POINT settings) switch off individual APIs.
191
192option FLOATING_ARITHMETIC
193option FLOATING_POINT enables ok_math
194option FIXED_POINT enables ok_math
195
196# Added at libpng version 1.4.0
197
198option ERROR_TEXT
199
200# The following is always on (defined empty)
201
202setting CALLOC_SUPPORTED default
203
204# This protects us against compilers that run on a windowing system
205# and thus don't have or would rather us not use the stdio types:
206# stdin, stdout, and stderr. The only one currently used is stderr
207# in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will
208# prevent these from being compiled and used. #defining PNG_NO_STDIO
209# will also prevent these, plus will prevent the entire set of stdio
210# macros and functions (FILE *, printf, etc.) from being compiled and used,
211# unless (PNG_DEBUG > 0) has been #defined.
212
213option STDIO
214option CONSOLE_IO requires STDIO
215
216# Note: prior to 1.5.0 this option could not be disabled if STDIO
217# was enabled. Prior to 1.5.3 this option required STDIO
218
219option TIME_RFC1123
220
221# PNG_SETJMP_NOT_SUPPORTED is an old equivalent for NO_SETJMP
222
223option SETJMP
224= NO_SETJMP SETJMP_NOT_SUPPORTED
225
226# For the moment this is disabled (no code support):
227
228option ERROR_NUMBERS disabled
229
230# If this is disabled it is not possible for apps to get the
231# values from the 'info' structure, this effectively removes
232# quite a lot of the READ API.
233
234option EASY_ACCESS
235
236# Added at libpng-1.2.0
237
238option USER_MEM
239
240# Added at libpng-1.4.0
241
242option IO_STATE
243
244# This is only for PowerPC big-endian and 680x0 systems
245# some testing, not enabled by default.
246# NO LONGER USED
247
248#option READ_BIG_ENDIAN disabled
249
250# Allow users to control limits on what the READ code will
251# read:
252
253# Added at libpng-1.2.43; adds limit fields to png_struct,
254# allows some usages of these fields
255
256option USER_LIMITS
257
258# Added at libpng-1.2.6; adds setting APIs, allows additional
259# usage of this field (UTSL)
260
261option SET_USER_LIMITS requires USER_LIMITS
262
263# Feature added at libpng-1.4.0, this flag added at 1.4.1
264option SET_USER_LIMITS enables SET_CHUNK_CACHE_LIMIT
265# Feature added at libpng-1.4.1, this flag added at 1.4.1
266
267option SET_USER_LIMITS enables SET_CHUNK_MALLOC_LIMIT
268
269# Added at libpng-1.0.16 and 1.2.6. To accept all valid PNGs no matter
270# how large, set these two limits to 0x7fffffff
271
272setting USER_WIDTH_MAX default 1000000
273setting USER_HEIGHT_MAX default 1000000
274
275# Added at libpng-1.2.43. To accept all valid PNGs no matter
276# how large, set these two limits to 0.
277
278setting USER_CHUNK_CACHE_MAX default 0
279
280# Added at libpng-1.2.43
281
282setting USER_CHUNK_MALLOC_MAX default 0
283
284# All of the following options relate to code capabilities for
285# processing image data before creating a PNG or after reading one.
286# You can remove these capabilities safely and still be PNG
287# conformant, however the library that results is still non-standard.
288# See the comments above about how to change options and settings.
289
290# READ options
291
292option READ enables READ_INTERLACING
293
294# Disabling READ_16BIT does not disable reading 16-bit PNG files, but it
295# forces them to be chopped down to 8-bit, and disables any 16-bit
296# processing after that has happened. You need to be sure to enable
297# READ_SCALE_16_TO_8 or READ_STRIP_16_TO_8 when you disable READ_16BIT for
298# this to work properly. You should disable the other option if you need to
299# ensure a particular conversion (otherwise the app can chose.)
300
301option READ_16BIT requires READ enables 16BIT
302
303option READ_QUANTIZE requires READ
304
305option READ_TRANSFORMS requires READ
306= NO_READ_TRANSFORMS READ_TRANSFORMS_NOT_SUPPORTED
307
308option READ_EXPAND requires READ_TRANSFORMS
309option READ_EXPAND_16 requires READ_TRANSFORMS READ_16BIT enables READ_EXPAND
310option READ_SHIFT requires READ_TRANSFORMS
311option READ_PACK requires READ_TRANSFORMS
312option READ_BGR requires READ_TRANSFORMS
313option READ_SWAP requires READ_TRANSFORMS READ_16BIT
314option READ_PACKSWAP requires READ_TRANSFORMS
315option READ_INVERT requires READ_TRANSFORMS
316option READ_BACKGROUND requires READ_TRANSFORMS enables READ_STRIP_ALPHA
317option READ_STRIP_16_TO_8 requires READ_TRANSFORMS
318option READ_SCALE_16_TO_8 requires READ_TRANSFORMS
319option READ_FILLER requires READ_TRANSFORMS
320option READ_GAMMA requires READ_TRANSFORMS enables READ_gAMA
321option READ_GRAY_TO_RGB requires READ_TRANSFORMS
322
323option READ_ALPHA_MODE requires READ_TRANSFORMS enables READ_GAMMA
324option READ_SWAP_ALPHA requires READ_TRANSFORMS
325option READ_INVERT_ALPHA requires READ_TRANSFORMS
326option READ_STRIP_ALPHA requires READ_TRANSFORMS
327option READ_USER_TRANSFORM requires READ_TRANSFORMS
328option READ_RGB_TO_GRAY requires READ_TRANSFORMS
329
330option PROGRESSIVE_READ requires READ
331option SEQUENTIAL_READ requires READ
332
333# You can define PNG_NO_PROGRESSIVE_READ if you don't do progressive reading.
334# This is not talking about interlacing capability! You'll still have
335# interlacing unless you turn off the following which is required
336# for PNG-compliant decoders. (In other words, do not do this - in
337# fact it can't be disabled from the command line!)
338#option READ_INTERLACING requires READ
339
340option READ_COMPOSITE_NODIV requires READ
341= NO_READ_COMPOSITE_NODIV NO_READ_COMPOSITED_NODIV
342
343# Inch conversions
344
345option INCH_CONVERSIONS
346= INCH_CONVERSIONS INCH_CONVERSIONS
347
348# API to build a grayscale palette
349
350option BUILD_GRAYSCALE_PALETTE
351
352# IN DEVELOPMENT
353# These are currently experimental features; define them if you want
354
355# NOTHING HERE
356
357# WRITE options
358
359option WRITE
360
361# Disabling WRITE_16BIT prevents 16-bit PNG files from being
362# generated.
363option WRITE_16BIT requires WRITE enables 16BIT
364
365option WRITE_TRANSFORMS requires WRITE
366= NO_WRITE_TRANSFORMS WRITE_TRANSFORMS_NOT_SUPPORTED
367
368option WRITE_SHIFT requires WRITE_TRANSFORMS
369option WRITE_PACK requires WRITE_TRANSFORMS
370option WRITE_BGR requires WRITE_TRANSFORMS
371option WRITE_SWAP requires WRITE_TRANSFORMS WRITE_16BIT
372option WRITE_PACKSWAP requires WRITE_TRANSFORMS
373option WRITE_INVERT requires WRITE_TRANSFORMS
374option WRITE_FILLER requires WRITE_TRANSFORMS
375option WRITE_SWAP_ALPHA requires WRITE_TRANSFORMS
376option WRITE_INVERT_ALPHA requires WRITE_TRANSFORMS
377option WRITE_USER_TRANSFORM requires WRITE_TRANSFORMS
378
379# This is not required for PNG-compliant encoders, but can cause
380# trouble if left undefined
381
382option WRITE_INTERLACING requires WRITE
383
384# The following depends, internally, on WEIGHT_SHIFT and COST_SHIFT
385# where are set below.
386
387option WRITE_WEIGHTED_FILTER requires WRITE
388
389option WRITE_FLUSH requires WRITE
390
391# Note: these can be turned off explicitly if not required by the
392# apps implementing the user transforms
393option USER_TRANSFORM_PTR if READ_USER_TRANSFORM WRITE_USER_TRANSFORM
394option USER_TRANSFORM_INFO if READ_USER_TRANSFORM WRITE_USER_TRANSFORM
395
396# This enables API to set compression parameters for compressing
397# non-IDAT chunks (zTXt, iTXt, iCCP, and unknown chunks). This feature
398# was added at libpng-1.5.3.
399option WRITE_CUSTOMIZE_ZTXT_COMPRESSION requires WRITE
400
401# Any chunks you are not interested in, you can undef here. The
402# ones that allocate memory may be expecially important (hIST,
403# tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info
404# a bit smaller.
405
406# The size of the png_text structure changed in libpng-1.0.6 when
407# iTXt support was added. iTXt support was turned off by default through
408# libpng-1.2.x, to support old apps that malloc the png_text structure
409# instead of calling png_set_text() and letting libpng malloc it. It
410# was turned on by default in libpng-1.4.0.
411
412option READ_ANCILLARY_CHUNKS requires READ
413# PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated.
414= NO_READ_ANCILLARY_CHUNKS READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
415
416option WRITE_ANCILLARY_CHUNKS requires WRITE
417# PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated.
418= NO_WRITE_ANCILLARY_CHUNKS WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
419
420# These options disable *all* the text chunks if turned off
421
422option READ_TEXT requires READ_ANCILLARY_CHUNKS enables TEXT
423option WRITE_TEXT requires WRITE_ANCILLARY_CHUNKS enables TEXT
424
425# Moved to pnglibconf.h at libpng-1.5.0
426# Feature support: in 1.4 this was in pngconf.h, but the following
427# features have no affect on the libpng API. Add library
428# only features to the end of this list. Add features that
429# affect the API above. (Note: the list of chunks follows
430# the library-only settings.)
431#
432# BUILD TIME ONLY OPTIONS
433# These options do not affect the API but rather alter how the
434# API is implemented, they get recorded in pnglibconf.h, but
435# can't be changed by the application.
436
437# Check the correctness of cHRM chunks
438
439option CHECK_cHRM requires cHRM
440
441#
442# Artificially align memory - the code typically aligns to 8 byte
443# boundaries if this is switched on, it's a small waste of space
444# but can help (in theory) on some architectures. Only affects
445# internal structures. Added at libpng 1.4.0
446
447option ALIGN_MEMORY
448
449# Buggy compilers (e.g., gcc 2.7.2.2) need PNG_NO_POINTER_INDEXING
450# See png[wr]util.c, normally this should always be *on*
451
452option POINTER_INDEXING
453
454# Other defines for things like memory and the like can go here.
455
456# BUILD TIME SETTINGS
457# Like build time options these do not affect the API, but they
458# may be useful to applications because they record details of
459# how the API will behave particularly with regard to overall
460# accuracy.
461
462# This controls how fine the quantizing gets. As this allocates
463# a largish chunk of memory (32K), those who are not as concerned
464# with quantizing quality can decrease some or all of these.
465
466setting QUANTIZE_RED_BITS default 5
467setting QUANTIZE_GREEN_BITS default 5
468setting QUANTIZE_BLUE_BITS default 5
469
470# This controls how fine the gamma correction becomes when you
471# are only interested in 8 bits anyway. Increasing this value
472# results in more memory being used, and more pow() functions
473# being called to fill in the gamma tables. Don't set this value
474# less then 8, and even that may not work (I haven't tested it).
475
476setting MAX_GAMMA_8 default 11
477
478# This controls how much a difference in gamma we can tolerate before
479# we actually start doing gamma conversion, it's a fixed point value,
480# so the default below is 0.05, meaning libpng ignores corrections in
481# the range 0.95 to 1.05
482
483setting GAMMA_THRESHOLD_FIXED default 5000
484
485# Scaling factor for filter heuristic weighting calculations
486
487setting WEIGHT_SHIFT default 8
488setting COST_SHIFT default 3
489
490# Precision to use when converting a floating point value to a PNG
491# extension format string in an sCAL chunk (only relevant if the
492# floating point API is enabled)
493
494setting sCAL_PRECISION default 5
495
496# This is the size of the compression buffer, and thus the size of
497# an IDAT chunk. Make this whatever size you feel is best for your
498# machine. One of these will be allocated per png_struct. When this
499# is full, it writes the data to the disk, and does some other
500# calculations. Making this an extremely small size may slow
501# the library down, but you may want to experiment to determine
502# where it becomes significant, if you are concerned with memory
503# usage. Note that zlib allocates at least 32Kb also. For readers,
504# this describes the size of the buffer available to read the data in.
505# Unless this gets smaller than the size of a row (compressed),
506# it should not make much difference how big this is.
507
508setting ZBUF_SIZE default 8192
509
510# Ancillary chunks
511chunk bKGD
512chunk cHRM
513chunk gAMA
514chunk hIST
515chunk iCCP
516chunk iTXt
517chunk oFFs
518chunk pCAL
519chunk sCAL
520chunk pHYs
521chunk sBIT
522chunk sPLT
523chunk sRGB
524chunk tEXt requires TEXT
525chunk tIME
526chunk tRNS
527chunk zTXt
528
529# This only affects support of the optional PLTE chunk in RGB and RGBA
530# images. Notice that READ_ANCILLARY_CHUNKS therefore disables part
531# of the regular chunk reading too.
532
533option READ_OPT_PLTE requires READ_ANCILLARY_CHUNKS
534
535option READ_UNKNOWN_CHUNKS requires READ
536option READ_UNKNOWN_CHUNKS enables UNKNOWN_CHUNKS READ_USER_CHUNKS
537option READ_USER_CHUNKS requires READ enables USER_CHUNKS
538
539option CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS
540# The "tm" structure is not supported on WindowsCE
541
542@#ifdef _WIN32_WCE
543@# define PNG_NO_CONVERT_tIME
544@#endif
545
546option WRITE_FILTER requires WRITE
547
548option WRITE_UNKNOWN_CHUNKS requires WRITE
549
550option HANDLE_AS_UNKNOWN
551
552option SAVE_INT_32 requires WRITE
553
554# png_save_int_32 is required by the ancillary chunks oFFs and pCAL
555
556# added at libpng-1.5.4
557
558option WRITE_OPTIMIZE_CMF requires WRITE
559
560option READ_COMPRESSED_TEXT disabled
561option READ_iCCP enables READ_COMPRESSED_TEXT
562option READ_iTXt enables READ_COMPRESSED_TEXT
563option READ_zTXt enables READ_COMPRESSED_TEXT
564option READ_COMPRESSED_TEXT enables READ_TEXT
565
566option WRITE_oFFs enables SAVE_INT_32
567option WRITE_pCAL enables SAVE_INT_32
568
569option WRITE_COMPRESSED_TEXT disabled
570option WRITE_iCCP enables WRITE_COMPRESSED_TEXT
571option WRITE_iTXt enables WRITE_COMPRESSED_TEXT
572option WRITE_zTXt enables WRITE_COMPRESSED_TEXT
573option WRITE_COMPRESSED_TEXT enables WRITE_TEXT
574
575# Turn this off to disable png_read_png() and png_write_png() and
576# leave the row_pointers member out of the info structure.
577
578option INFO_IMAGE
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.h.prebuilt b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.h.prebuilt
new file mode 100644
index 0000000..36447ce
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.h.prebuilt
@@ -0,0 +1,187 @@
1
2/* libpng STANDARD API DEFINITION */
3
4/* pnglibconf.h - library build configuration */
5
6/* Libpng 1.5.9 - February 18, 2012 */
7
8/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
9
10/* This code is released under the libpng license. */
11/* For conditions of distribution and use, see the disclaimer */
12/* and license in png.h */
13
14/* pnglibconf.h */
15/* Derived from: scripts/pnglibconf.dfa */
16/* If you edit this file by hand you must obey the rules expressed in */
17/* pnglibconf.dfa with respect to the dependencies between the following */
18/* symbols. It is much better to generate a new file using */
19/* scripts/libpngconf.mak */
20
21#ifndef PNGLCONF_H
22#define PNGLCONF_H
23/* settings */
24#define PNG_API_RULE 0
25#define PNG_CALLOC_SUPPORTED
26#define PNG_COST_SHIFT 3
27#define PNG_DEFAULT_READ_MACROS 1
28#define PNG_GAMMA_THRESHOLD_FIXED 5000
29#define PNG_MAX_GAMMA_8 11
30#define PNG_QUANTIZE_BLUE_BITS 5
31#define PNG_QUANTIZE_GREEN_BITS 5
32#define PNG_QUANTIZE_RED_BITS 5
33#define PNG_sCAL_PRECISION 5
34#define PNG_USER_CHUNK_CACHE_MAX 0
35#define PNG_USER_CHUNK_MALLOC_MAX 0
36#define PNG_USER_HEIGHT_MAX 1000000
37#define PNG_USER_WIDTH_MAX 1000000
38#define PNG_WEIGHT_SHIFT 8
39#define PNG_ZBUF_SIZE 8192
40/* end of settings */
41/* options */
42#define PNG_16BIT_SUPPORTED
43#define PNG_ALIGN_MEMORY_SUPPORTED
44#define PNG_BENIGN_ERRORS_SUPPORTED
45#define PNG_bKGD_SUPPORTED
46#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
47#define PNG_CHECK_cHRM_SUPPORTED
48#define PNG_cHRM_SUPPORTED
49#define PNG_CONSOLE_IO_SUPPORTED
50#define PNG_CONVERT_tIME_SUPPORTED
51#define PNG_EASY_ACCESS_SUPPORTED
52/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
53#define PNG_ERROR_TEXT_SUPPORTED
54#define PNG_FIXED_POINT_SUPPORTED
55#define PNG_FLOATING_ARITHMETIC_SUPPORTED
56#define PNG_FLOATING_POINT_SUPPORTED
57#define PNG_gAMA_SUPPORTED
58#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
59#define PNG_hIST_SUPPORTED
60#define PNG_iCCP_SUPPORTED
61#define PNG_INCH_CONVERSIONS_SUPPORTED
62#define PNG_INFO_IMAGE_SUPPORTED
63#define PNG_IO_STATE_SUPPORTED
64#define PNG_iTXt_SUPPORTED
65#define PNG_MNG_FEATURES_SUPPORTED
66#define PNG_oFFs_SUPPORTED
67#define PNG_pCAL_SUPPORTED
68#define PNG_pHYs_SUPPORTED
69#define PNG_POINTER_INDEXING_SUPPORTED
70#define PNG_PROGRESSIVE_READ_SUPPORTED
71#define PNG_READ_16BIT_SUPPORTED
72#define PNG_READ_ALPHA_MODE_SUPPORTED
73#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
74#define PNG_READ_BACKGROUND_SUPPORTED
75#define PNG_READ_BGR_SUPPORTED
76#define PNG_READ_bKGD_SUPPORTED
77#define PNG_READ_cHRM_SUPPORTED
78#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
79#define PNG_READ_COMPRESSED_TEXT_SUPPORTED
80#define PNG_READ_EXPAND_16_SUPPORTED
81#define PNG_READ_EXPAND_SUPPORTED
82#define PNG_READ_FILLER_SUPPORTED
83#define PNG_READ_gAMA_SUPPORTED
84#define PNG_READ_GAMMA_SUPPORTED
85#define PNG_READ_GRAY_TO_RGB_SUPPORTED
86#define PNG_READ_hIST_SUPPORTED
87#define PNG_READ_iCCP_SUPPORTED
88#define PNG_READ_INTERLACING_SUPPORTED
89#define PNG_READ_INT_FUNCTIONS_SUPPORTED
90#define PNG_READ_INVERT_ALPHA_SUPPORTED
91#define PNG_READ_INVERT_SUPPORTED
92#define PNG_READ_iTXt_SUPPORTED
93#define PNG_READ_oFFs_SUPPORTED
94#define PNG_READ_OPT_PLTE_SUPPORTED
95#define PNG_READ_PACK_SUPPORTED
96#define PNG_READ_PACKSWAP_SUPPORTED
97#define PNG_READ_pCAL_SUPPORTED
98#define PNG_READ_pHYs_SUPPORTED
99#define PNG_READ_QUANTIZE_SUPPORTED
100#define PNG_READ_RGB_TO_GRAY_SUPPORTED
101#define PNG_READ_sBIT_SUPPORTED
102#define PNG_READ_SCALE_16_TO_8_SUPPORTED
103#define PNG_READ_sCAL_SUPPORTED
104#define PNG_READ_SHIFT_SUPPORTED
105#define PNG_READ_sPLT_SUPPORTED
106#define PNG_READ_sRGB_SUPPORTED
107#define PNG_READ_STRIP_16_TO_8_SUPPORTED
108#define PNG_READ_STRIP_ALPHA_SUPPORTED
109#define PNG_READ_SUPPORTED
110#define PNG_READ_SWAP_ALPHA_SUPPORTED
111#define PNG_READ_SWAP_SUPPORTED
112#define PNG_READ_tEXt_SUPPORTED
113#define PNG_READ_TEXT_SUPPORTED
114#define PNG_READ_tIME_SUPPORTED
115#define PNG_READ_TRANSFORMS_SUPPORTED
116#define PNG_READ_tRNS_SUPPORTED
117#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
118#define PNG_READ_USER_CHUNKS_SUPPORTED
119#define PNG_READ_USER_TRANSFORM_SUPPORTED
120#define PNG_READ_zTXt_SUPPORTED
121#define PNG_SAVE_INT_32_SUPPORTED
122#define PNG_sBIT_SUPPORTED
123#define PNG_sCAL_SUPPORTED
124#define PNG_SEQUENTIAL_READ_SUPPORTED
125#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
126#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
127#define PNG_SETJMP_SUPPORTED
128#define PNG_SET_USER_LIMITS_SUPPORTED
129#define PNG_sPLT_SUPPORTED
130#define PNG_sRGB_SUPPORTED
131#define PNG_STDIO_SUPPORTED
132#define PNG_tEXt_SUPPORTED
133#define PNG_TEXT_SUPPORTED
134#define PNG_TIME_RFC1123_SUPPORTED
135#define PNG_tIME_SUPPORTED
136#define PNG_tRNS_SUPPORTED
137#define PNG_UNKNOWN_CHUNKS_SUPPORTED
138#define PNG_USER_CHUNKS_SUPPORTED
139#define PNG_USER_LIMITS_SUPPORTED
140#define PNG_USER_MEM_SUPPORTED
141#define PNG_USER_TRANSFORM_INFO_SUPPORTED
142#define PNG_USER_TRANSFORM_PTR_SUPPORTED
143#define PNG_WARNINGS_SUPPORTED
144#define PNG_WRITE_16BIT_SUPPORTED
145#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
146#define PNG_WRITE_BGR_SUPPORTED
147#define PNG_WRITE_bKGD_SUPPORTED
148#define PNG_WRITE_cHRM_SUPPORTED
149#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
150#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
151#define PNG_WRITE_FILLER_SUPPORTED
152#define PNG_WRITE_FILTER_SUPPORTED
153#define PNG_WRITE_FLUSH_SUPPORTED
154#define PNG_WRITE_gAMA_SUPPORTED
155#define PNG_WRITE_hIST_SUPPORTED
156#define PNG_WRITE_iCCP_SUPPORTED
157#define PNG_WRITE_INTERLACING_SUPPORTED
158#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED
159#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
160#define PNG_WRITE_INVERT_SUPPORTED
161#define PNG_WRITE_iTXt_SUPPORTED
162#define PNG_WRITE_oFFs_SUPPORTED
163#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
164#define PNG_WRITE_PACK_SUPPORTED
165#define PNG_WRITE_PACKSWAP_SUPPORTED
166#define PNG_WRITE_pCAL_SUPPORTED
167#define PNG_WRITE_pHYs_SUPPORTED
168#define PNG_WRITE_sBIT_SUPPORTED
169#define PNG_WRITE_sCAL_SUPPORTED
170#define PNG_WRITE_SHIFT_SUPPORTED
171#define PNG_WRITE_sPLT_SUPPORTED
172#define PNG_WRITE_sRGB_SUPPORTED
173#define PNG_WRITE_SUPPORTED
174#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
175#define PNG_WRITE_SWAP_SUPPORTED
176#define PNG_WRITE_tEXt_SUPPORTED
177#define PNG_WRITE_TEXT_SUPPORTED
178#define PNG_WRITE_tIME_SUPPORTED
179#define PNG_WRITE_TRANSFORMS_SUPPORTED
180#define PNG_WRITE_tRNS_SUPPORTED
181#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
182#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
183#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
184#define PNG_WRITE_zTXt_SUPPORTED
185#define PNG_zTXt_SUPPORTED
186/* end of options */
187#endif /* PNGLCONF_H */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.mak b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.mak
new file mode 100644
index 0000000..1dbb232
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pnglibconf.mak
@@ -0,0 +1,58 @@
1#!/usr/bin/make -f
2# pnglibconf.mak - standard make lines for pnglibconf.h
3#
4# These lines are copied from Makefile.am, they illustrate
5# how to automate the build of pnglibconf.h from scripts/pnglibconf.dfa
6# given 'awk' and 'sed'
7
8# Override as appropriate, these definitions can be overridden on
9# the make command line (AWK='nawk' for example).
10AWK = gawk
11AWK = mawk
12AWK = nawk
13AWK = one-true-awk
14AWK = awk # Crashes on SunOS 5.10 - use 'nawk'
15CPP = $(CC) -E # Does not work on SUN OS 5.10 - use /lib/cpp
16SED = sed
17
18COPY = cp
19DELETE = rm -f
20ECHO = echo
21DFA_XTRA = # Appended to scripts/options.awk
22
23# CPPFLAGS should contain the options to control the result,
24# but DEFS and CFLAGS are also supported here, override
25# as appropriate
26DFNFLAGS = $(DEFS) $(CPPFLAGS) $(CFLAGS)
27
28# srcdir is a defacto standard for the location of the source
29srcdir = .
30
31# The standard pnglibconf.h exists as scripts/pnglibconf.h.prebuilt,
32# copy this if the following doesn't work.
33pnglibconf.h: pnglibconf.dfn
34 $(DELETE) $@ dfn.c dfn1.out dfn2.out dfn3.out
35 $(ECHO) '#include "pnglibconf.dfn"' >dfn.c
36 $(CPP) $(DFNFLAGS) dfn.c >dfn1.out
37 $(ECHO) "If 'cpp -e' crashes try /lib/cpp (e.g. CPP='/lib/cpp')" >&2
38 $(SED) -n -e 's|^.*PNG_DEFN_MAGIC *-\(.*\)- *PNG_DEFN_END.*$$|\1|p'\
39 dfn1.out >dfn2.out
40 $(SED) -e 's| *PNG_JOIN *||g' -e 's| *$$||' dfn2.out >dfn3.out
41 $(COPY) dfn3.out $@
42 $(DELETE) dfn.c dfn1.out dfn2.out dfn3.out
43
44pnglibconf.dfn: $(srcdir)/scripts/pnglibconf.dfa $(srcdir)/scripts/options.awk $(srcdir)/pngconf.h
45 $(DELETE) $@ dfn1.out dfn2.out
46 $(ECHO) "Calling $(AWK) from scripts/pnglibconf.mak" >&2
47 $(ECHO) "If 'awk' crashes try a better awk (e.g. AWK='nawk')" >&2
48 $(AWK) -f $(srcdir)/scripts/options.awk out=dfn1.out version=search\
49 $(srcdir)/pngconf.h $(srcdir)/scripts/pnglibconf.dfa\
50 $(DFA_XTRA) 1>&2
51 $(AWK) -f $(srcdir)/scripts/options.awk out=dfn2.out dfn1.out 1>&2
52 $(COPY) dfn2.out $@
53 $(DELETE) dfn1.out dfn2.out
54
55clean-pnglibconf:
56 $(DELETE) pnglibconf.h pnglibconf.dfn dfn.c dfn1.out dfn2.out dfn3.out
57
58clean: clean-pnglibconf
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pngwin.rc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pngwin.rc
new file mode 100644
index 0000000..ccca0d3
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/pngwin.rc
@@ -0,0 +1,112 @@
1#define PNG_VERSION_INFO_ONLY
2
3#include <windows.h>
4#include "../png.h"
5
6#define _QUOTE(x) # x
7#define QUOTE(x) _QUOTE(x)
8
9#define PNG_LIBPNG_DLLFNAME "LIBPNG"
10
11/* Support deprecated PRIVATEBUILD macro */
12#if defined(PRIVATEBUILD) && !defined(PNG_USER_PRIVATEBUILD)
13# define PNG_USER_PRIVATEBUILD PRIVATEBUILD
14#endif
15
16#if defined(PNG_USER_DLLFNAME_POSTFIX) && !defined(PNG_USER_PRIVATEBUILD)
17# error "PNG_USER_PRIVATEBUILD must be defined as a string describing the\
18 custom changes made to the library."
19#endif
20
21/* Prioritize PNG_USER_x over PNG_LIBPNG_x */
22#ifdef PNG_USER_DLLFNAME_POSTFIX
23# undef PNG_LIBPNG_DLLFNAME_POSTFIX
24# define PNG_LIBPNG_DLLFNAME_POSTFIX PNG_USER_DLLFNAME_POSTFIX
25#endif
26
27#ifdef PNG_USER_VERSIONINFO_COMMENTS
28# undef PNG_LIBPNG_VERSIONINFO_COMMENTS
29# define PNG_LIBPNG_VERSIONINFO_COMMENTS PNG_USER_VERSIONINFO_COMMENTS
30#endif
31
32#if defined(PNG_DEBUG) && (PNG_DEBUG > 0)
33# define VS_DEBUG VS_FF_DEBUG
34# ifndef PNG_LIBPNG_DLLFNAME_POSTFIX
35# define PNG_LIBPNG_DLLFNAME_POSTFIX "D"
36# endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */
37# ifndef PNG_LIBPNG_VERSIONINFO_COMMENTS
38# define PNG_LIBPNG_VERSIONINFO_COMMENTS "PNG_DEBUG=" QUOTE(PNG_DEBUG)
39# endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */
40#else
41# define VS_DEBUG 0
42# ifndef PNG_LIBPNG_DLLFNAME_POSTFIX
43# define PNG_LIBPNG_DLLFNAME_POSTFIX
44# endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */
45#endif /* defined(DEBUG)... */
46
47#ifdef PNG_USER_PRIVATEBUILD
48# define VS_PRIVATEBUILD VS_FF_PRIVATEBUILD
49#else
50# define VS_PRIVATEBUILD 0
51#endif /* PNG_USER_PRIVATEBUILD */
52
53#ifdef PNG_LIBPNG_SPECIALBUILD
54# define VS_SPECIALBUILD VS_FF_SPECIALBUILD
55#else
56# define VS_SPECIALBUILD 0
57#endif /* PNG_LIBPNG_BUILD_SPECIAL */
58
59#if ((PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_RELEASE_STATUS_MASK) !=\
60 PNG_LIBPNG_BUILD_STABLE)
61# define VS_PRERELEASE VS_FF_PRERELEASE
62# define VS_PATCHED 0
63#else
64# define VS_PRERELEASE 0
65# if (PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_BUILD_PATCHED)
66# define VS_PATCHED VS_FF_PATCHED
67# else
68# define VS_PATCHED 0
69# endif
70#endif
71
72VS_VERSION_INFO VERSIONINFO
73FILEVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD
74PRODUCTVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD
75FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
76FILEFLAGS VS_DEBUG | VS_PRIVATEBUILD | VS_SPECIALBUILD | VS_PRERELEASE | VS_PATCHED
77FILEOS VOS__WINDOWS32
78FILETYPE VFT_DLL
79FILESUBTYPE VFT2_UNKNOWN
80BEGIN
81 BLOCK "StringFileInfo"
82 BEGIN BLOCK "040904E4" /* Language type = U.S English(0x0409) and Character Set = Windows, Multilingual(0x04E4) */
83 BEGIN
84#ifdef PNG_LIBPNG_VERSIONINFO_COMMENTS
85 VALUE "Comments", PNG_LIBPNG_VERSIONINFO_COMMENTS "\000"
86#endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */
87#ifdef PNG_USER_VERSIONINFO_COMPANYNAME
88 VALUE "CompanyName", PNG_USER_VERSIONINFO_COMPANYNAME "\000"
89#endif /* PNG_USER_VERSIONINFO_COMPANYNAME */
90 VALUE "FileDescription", "PNG image compression library\000"
91 VALUE "FileVersion", PNG_LIBPNG_VER_STRING "\000"
92 VALUE "InternalName", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX " (Windows 32 bit)\000"
93 VALUE "LegalCopyright", "\251 1998-2009 Glenn Randers-Pehrson et al.\000"
94#ifdef PNG_USER_VERSIONINFO_LEGALTRADEMARKS
95 VALUE "LegalTrademarks", PNG_USER_VERSIONINFO_LEGALTRADEMARKS "\000"
96#endif /* PNG_USER_VERSIONINFO_LEGALTRADEMARKS */
97 VALUE "OriginalFilename", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX ".DLL\000"
98#ifdef PNG_USER_PRIVATEBUILD
99 VALUE "PrivateBuild", PNG_USER_PRIVATEBUILD "\000"
100#endif /* PNG_USER_PRIVATEBUILD */
101 VALUE "ProductName", "LibPNG\000"
102 VALUE "ProductVersion", "1\000"
103#ifdef PNG_LIBPNG_SPECIALBUILD
104 VALUE "SpecialBuild", PNG_LIBPNG_SPECIALBUILD "\000"
105#endif /* PNG_LIBPNG_SPECIALBUILD */
106 END
107 END
108 BLOCK "VarFileInfo"
109 BEGIN
110 VALUE "Translation", 0x0409, 0x04E4
111 END
112END
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/smakefile.ppc b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/smakefile.ppc
new file mode 100644
index 0000000..a85c7cf
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/smakefile.ppc
@@ -0,0 +1,34 @@
1# Amiga powerUP (TM) Makefile
2# makefile for libpng and SAS C V6.58/7.00 PPC compiler
3# Copyright (C) 1998 by Andreas R. Kleinert
4#
5# This code is released under the libpng license.
6# For conditions of distribution and use, see the disclaimer
7# and license in png.h
8
9CC = scppc
10CFLAGS = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL IDIR /zlib \
11 OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8
12LIBNAME = libpng.a
13AR = ppc-amigaos-ar
14AR_FLAGS = cr
15RANLIB = ppc-amigaos-ranlib
16LDFLAGS = -r -o
17LDLIBS = ../zlib/libzip.a LIB:scppc.a
18LN = ppc-amigaos-ld
19RM = delete quiet
20MKDIR = makedir
21
22OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o pngread.o \
23 pngerror.o pngpread.o pngwrite.o pngrtran.o pngwtran.o pngrio.o \
24 pngwio.o pngmem.o
25
26all: $(LIBNAME) pngtest
27
28$(LIBNAME): $(OBJS)
29 $(AR) $(AR_FLAGS) $@ $(OBJS)
30 $(RANLIB) $@
31
32pngtest: pngtest.o $(LIBNAME)
33 $(LN) $(LDFLAGS) pngtest LIB:c_ppc.o pngtest.o $(LIBNAME) $(LDLIBS) \
34LIB:end.o
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/sym.dfn b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/sym.dfn
new file mode 100644
index 0000000..83b70d8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/sym.dfn
@@ -0,0 +1,15 @@
1
2/* sym.dfn - define format of libpng.sym
3 *
4 * Last changed in libpng version 1.5.0 [January 6, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 *
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
9 * and license in png.h
10 */
11
12#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
13 PNG_DEFN_MAGIC-SYMBOL_PREFIX PNG_JOIN name-PNG_DEFN_END
14
15#include "../png.h"
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.def b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.def
new file mode 100644
index 0000000..c102a3f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.def
@@ -0,0 +1,241 @@
1;--------------------------------------------------------------
2; LIBPNG symbol list as a Win32 DEF file
3; Contains all the symbols that can be exported from libpng
4;--------------------------------------------------------------
5LIBRARY
6
7EXPORTS
8;Version 1.5.9
9 png_access_version_number @1
10 png_set_sig_bytes @2
11 png_sig_cmp @3
12 png_create_read_struct @4
13 png_create_write_struct @5
14 png_get_compression_buffer_size @6
15 png_set_compression_buffer_size @7
16 png_set_longjmp_fn @8
17 png_longjmp @9
18 png_reset_zstream @10
19 png_create_read_struct_2 @11
20 png_create_write_struct_2 @12
21 png_write_sig @13
22 png_write_chunk @14
23 png_write_chunk_start @15
24 png_write_chunk_data @16
25 png_write_chunk_end @17
26 png_create_info_struct @18
27 png_info_init_3 @19
28 png_write_info_before_PLTE @20
29 png_write_info @21
30 png_read_info @22
31 png_convert_to_rfc1123 @23
32 png_convert_from_struct_tm @24
33 png_convert_from_time_t @25
34 png_set_expand @26
35 png_set_expand_gray_1_2_4_to_8 @27
36 png_set_palette_to_rgb @28
37 png_set_tRNS_to_alpha @29
38 png_set_bgr @30
39 png_set_gray_to_rgb @31
40 png_set_rgb_to_gray @32
41 png_set_rgb_to_gray_fixed @33
42 png_get_rgb_to_gray_status @34
43 png_build_grayscale_palette @35
44 png_set_strip_alpha @36
45 png_set_swap_alpha @37
46 png_set_invert_alpha @38
47 png_set_filler @39
48 png_set_add_alpha @40
49 png_set_swap @41
50 png_set_packing @42
51 png_set_packswap @43
52 png_set_shift @44
53 png_set_interlace_handling @45
54 png_set_invert_mono @46
55 png_set_background @47
56 png_set_strip_16 @48
57 png_set_quantize @49
58 png_set_gamma @50
59 png_set_flush @51
60 png_write_flush @52
61 png_start_read_image @53
62 png_read_update_info @54
63 png_read_rows @55
64 png_read_row @56
65 png_read_image @57
66 png_write_row @58
67 png_write_rows @59
68 png_write_image @60
69 png_write_end @61
70 png_read_end @62
71 png_destroy_info_struct @63
72 png_destroy_read_struct @64
73 png_destroy_write_struct @65
74 png_set_crc_action @66
75 png_set_filter @67
76 png_set_filter_heuristics @68
77 png_set_compression_level @69
78 png_set_compression_mem_level @70
79 png_set_compression_strategy @71
80 png_set_compression_window_bits @72
81 png_set_compression_method @73
82 png_init_io @74
83 png_set_error_fn @75
84 png_get_error_ptr @76
85 png_set_write_fn @77
86 png_set_read_fn @78
87 png_get_io_ptr @79
88 png_set_read_status_fn @80
89 png_set_write_status_fn @81
90 png_set_mem_fn @82
91 png_get_mem_ptr @83
92 png_set_read_user_transform_fn @84
93 png_set_write_user_transform_fn @85
94 png_set_user_transform_info @86
95 png_get_user_transform_ptr @87
96 png_set_read_user_chunk_fn @88
97 png_get_user_chunk_ptr @89
98 png_set_progressive_read_fn @90
99 png_get_progressive_ptr @91
100 png_process_data @92
101 png_progressive_combine_row @93
102 png_malloc @94
103 png_calloc @95
104 png_malloc_warn @96
105 png_free @97
106 png_free_data @98
107 png_data_freer @99
108 png_malloc_default @100
109 png_free_default @101
110 png_error @102
111 png_chunk_error @103
112 png_err @104
113 png_warning @105
114 png_chunk_warning @106
115 png_benign_error @107
116 png_chunk_benign_error @108
117 png_set_benign_errors @109
118 png_get_valid @110
119 png_get_rowbytes @111
120 png_get_rows @112
121 png_set_rows @113
122 png_get_channels @114
123 png_get_image_width @115
124 png_get_image_height @116
125 png_get_bit_depth @117
126 png_get_color_type @118
127 png_get_filter_type @119
128 png_get_interlace_type @120
129 png_get_compression_type @121
130 png_get_pixels_per_meter @122
131 png_get_x_pixels_per_meter @123
132 png_get_y_pixels_per_meter @124
133 png_get_pixel_aspect_ratio @125
134 png_get_x_offset_pixels @126
135 png_get_y_offset_pixels @127
136 png_get_x_offset_microns @128
137 png_get_y_offset_microns @129
138 png_get_signature @130
139 png_get_bKGD @131
140 png_set_bKGD @132
141 png_get_cHRM @133
142 png_get_cHRM_fixed @134
143 png_set_cHRM @135
144 png_set_cHRM_fixed @136
145 png_get_gAMA @137
146 png_get_gAMA_fixed @138
147 png_set_gAMA @139
148 png_set_gAMA_fixed @140
149 png_get_hIST @141
150 png_set_hIST @142
151 png_get_IHDR @143
152 png_set_IHDR @144
153 png_get_oFFs @145
154 png_set_oFFs @146
155 png_get_pCAL @147
156 png_set_pCAL @148
157 png_get_pHYs @149
158 png_set_pHYs @150
159 png_get_PLTE @151
160 png_set_PLTE @152
161 png_get_sBIT @153
162 png_set_sBIT @154
163 png_get_sRGB @155
164 png_set_sRGB @156
165 png_set_sRGB_gAMA_and_cHRM @157
166 png_get_iCCP @158
167 png_set_iCCP @159
168 png_get_sPLT @160
169 png_set_sPLT @161
170 png_get_text @162
171 png_set_text @163
172 png_get_tIME @164
173 png_set_tIME @165
174 png_get_tRNS @166
175 png_set_tRNS @167
176 png_get_sCAL @168
177 png_get_sCAL_s @169
178 png_set_sCAL @170
179 png_set_sCAL_s @171
180 png_set_keep_unknown_chunks @172
181 png_handle_as_unknown @173
182 png_set_unknown_chunks @174
183 png_set_unknown_chunk_location @175
184 png_get_unknown_chunks @176
185 png_set_invalid @177
186 png_read_png @178
187 png_write_png @179
188 png_get_copyright @180
189 png_get_header_ver @181
190 png_get_header_version @182
191 png_get_libpng_ver @183
192 png_permit_mng_features @184
193 png_set_strip_error_numbers @185
194 png_set_user_limits @186
195 png_get_user_width_max @187
196 png_get_user_height_max @188
197 png_set_chunk_cache_max @189
198 png_get_chunk_cache_max @190
199 png_set_chunk_malloc_max @191
200 png_get_chunk_malloc_max @192
201 png_get_pixels_per_inch @193
202 png_get_x_pixels_per_inch @194
203 png_get_y_pixels_per_inch @195
204 png_get_x_offset_inches @196
205 png_get_y_offset_inches @197
206 png_get_pHYs_dpi @198
207 png_get_io_state @199
208 png_get_io_chunk_name @200
209 png_get_uint_32 @201
210 png_get_uint_16 @202
211 png_get_int_32 @203
212 png_get_uint_31 @204
213 png_save_uint_32 @205
214 png_save_int_32 @206
215 png_save_uint_16 @207
216 png_set_gamma_fixed @208
217 png_set_filter_heuristics_fixed @209
218 png_get_pixel_aspect_ratio_fixed @210
219 png_get_x_offset_inches_fixed @211
220 png_get_y_offset_inches_fixed @212
221 png_set_sCAL_fixed @213
222 png_get_sCAL_fixed @214
223 png_set_background_fixed @215
224 png_get_io_chunk_type @216
225 png_get_current_row_number @217
226 png_get_current_pass_number @218
227 png_process_data_pause @219
228 png_process_data_skip @220
229 png_set_expand_16 @221
230 png_set_text_compression_level @222
231 png_set_text_compression_mem_level @223
232 png_set_text_compression_strategy @224
233 png_set_text_compression_window_bits @225
234 png_set_text_compression_method @226
235 png_set_alpha_mode @227
236 png_set_alpha_mode_fixed @228
237 png_set_scale_16 @229
238 png_get_cHRM_XYZ @230
239 png_get_cHRM_XYZ_fixed @231
240 png_set_cHRM_XYZ @232
241 png_set_cHRM_XYZ_fixed @233
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.dfn b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.dfn
new file mode 100644
index 0000000..1596dde
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/symbols.dfn
@@ -0,0 +1,57 @@
1
2/* symbols.dfn - find all exported symbols
3 *
4 * Last changed in libpng version 1.5.0 [January 6, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 *
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
9 * and license in png.h
10 */
11
12/* NOTE: making 'symbols.chk' checks both that the exported
13 * symbols in the library don't change and (implicitly) that
14 * scripts/pnglibconf.h.prebuilt is as expected. If scripts/pnglibconf.h.prebuilt
15 * is remade using scripts/pnglibconf.dfa then this checks the
16 * .dfa file too.
17 */
18
19#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
20 PNG_DEFN_MAGIC-name @ordinal-PNG_DEFN_END
21#define PNG_REMOVED(ordinal, type, name, args, attributes)\
22 PNG_DEFN_MAGIC-; name @ordinal-PNG_DEFN_END
23#define PNG_EXPORT_LAST_ORDINAL(ordinal)\
24 PNG_DEFN_MAGIC-; @ordinal-PNG_DEFN_END
25
26/* Read the defaults, but use scripts/pnglibconf.h.prebuilt; the 'standard'
27 * header file.
28 */
29#include "pnglibconf.h.prebuilt"
30#include "../png.h"
31
32/* Some things are turned off by default. Turn these things
33 * on here (by hand) to get the APIs they expose and validate
34 * that no harm is done. This list is the set of options
35 * defaulted to 'off' in scripts/pnglibconf.dfa
36 *
37 * Maintenance: if scripts/pnglibconf.dfa options are changed
38 * from, or to, 'off' this needs updating!
39 */
40#define PNG_BENIGN_ERRORS_SUPPORTED
41#define PNG_ERROR_NUMBERS_SUPPORTED
42#define PNG_READ_BIG_ENDIAN_SUPPORTED /* should do nothing! */
43#define PNG_INCH_CONVERSIONS_SUPPORTED
44#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
45
46#undef PNG_H
47#include "../png.h"
48
49/* Finally there are a couple of places where option support
50 * actually changes the APIs revealed using a #if/#else/#endif
51 * test in png.h, test these here.
52 */
53#undef PNG_FLOATING_POINT_SUPPORTED /* Exposes 'fixed' APIs */
54#undef PNG_ERROR_TEXT_SUPPORTED /* Exposes unsupported APIs */
55
56#undef PNG_H
57#include "../png.h"
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/vers.dfn b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/vers.dfn
new file mode 100644
index 0000000..548cfb4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/scripts/vers.dfn
@@ -0,0 +1,26 @@
1
2/* vers.dfn - define format of libpng.vers
3 *
4 * Last changed in libpng version 1.5.0 [January 6, 2011]
5 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
6 *
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
9 * and license in png.h
10 */
11
12#define HEADER PNG_DEFN_MAGIC-PNGLIB_LIBNAME {global:-PNG_DEFN_END
13
14/* NOTE: PNG_JOIN is interpreted by the calling script as a signal to
15 * join the two things on either side, so we can do symbol
16 * substitution within the name, regular C ## joins the pp-tokens,
17 * not their final values.
18 */
19#define PNG_EXPORTA(ordinal, type, name, args, attributes)\
20 PNG_DEFN_MAGIC- SYMBOL_PREFIX PNG_JOIN name;-PNG_DEFN_END
21
22#define TRAILER PNG_DEFN_MAGIC-local: *; };-PNG_DEFN_END
23
24HEADER
25#include "../png.h"
26TRAILER