rfreeimage 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/Rakefile +34 -0
- data/ext/rfreeimage/extconf.rb +35 -0
- data/ext/rfreeimage/rfi_main.c +389 -0
- data/lib/rfreeimage/image.rb +26 -0
- data/lib/rfreeimage/version.rb +3 -0
- data/lib/rfreeimage.rb +3 -0
- data/rfreeimage.gemspec +32 -0
- data/vendor/FreeImage/Makefile +34 -0
- data/vendor/FreeImage/Makefile.cygwin +74 -0
- data/vendor/FreeImage/Makefile.fip +84 -0
- data/vendor/FreeImage/Makefile.gnu +83 -0
- data/vendor/FreeImage/Makefile.iphone +96 -0
- data/vendor/FreeImage/Makefile.mingw +136 -0
- data/vendor/FreeImage/Makefile.osx +115 -0
- data/vendor/FreeImage/Makefile.solaris +66 -0
- data/vendor/FreeImage/Makefile.srcs +6 -0
- data/vendor/FreeImage/README.iphone +19 -0
- data/vendor/FreeImage/README.linux +50 -0
- data/vendor/FreeImage/README.minGW +236 -0
- data/vendor/FreeImage/README.osx +44 -0
- data/vendor/FreeImage/README.solaris +67 -0
- data/vendor/FreeImage/Source/CacheFile.h +92 -0
- data/vendor/FreeImage/Source/DeprecationManager/Deprecated.cpp +36 -0
- data/vendor/FreeImage/Source/DeprecationManager/DeprecationMgr.cpp +103 -0
- data/vendor/FreeImage/Source/DeprecationManager/DeprecationMgr.h +83 -0
- data/vendor/FreeImage/Source/FreeImage/BitmapAccess.cpp +1573 -0
- data/vendor/FreeImage/Source/FreeImage/CacheFile.cpp +271 -0
- data/vendor/FreeImage/Source/FreeImage/ColorLookup.cpp +785 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion.cpp +551 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion16_555.cpp +209 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion16_565.cpp +204 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion24.cpp +252 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion32.cpp +345 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion4.cpp +246 -0
- data/vendor/FreeImage/Source/FreeImage/Conversion8.cpp +305 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionFloat.cpp +194 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionRGB16.cpp +144 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionRGBA16.cpp +147 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionRGBAF.cpp +250 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionRGBF.cpp +243 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionType.cpp +699 -0
- data/vendor/FreeImage/Source/FreeImage/ConversionUINT16.cpp +134 -0
- data/vendor/FreeImage/Source/FreeImage/FreeImage.cpp +226 -0
- data/vendor/FreeImage/Source/FreeImage/FreeImageC.c +22 -0
- data/vendor/FreeImage/Source/FreeImage/FreeImageIO.cpp +175 -0
- data/vendor/FreeImage/Source/FreeImage/GetType.cpp +92 -0
- data/vendor/FreeImage/Source/FreeImage/Halftoning.cpp +474 -0
- data/vendor/FreeImage/Source/FreeImage/J2KHelper.cpp +591 -0
- data/vendor/FreeImage/Source/FreeImage/J2KHelper.h +36 -0
- data/vendor/FreeImage/Source/FreeImage/LFPQuantizer.cpp +208 -0
- data/vendor/FreeImage/Source/FreeImage/MNGHelper.cpp +1320 -0
- data/vendor/FreeImage/Source/FreeImage/MemoryIO.cpp +237 -0
- data/vendor/FreeImage/Source/FreeImage/MultiPage.cpp +974 -0
- data/vendor/FreeImage/Source/FreeImage/NNQuantizer.cpp +507 -0
- data/vendor/FreeImage/Source/FreeImage/PSDParser.cpp +1057 -0
- data/vendor/FreeImage/Source/FreeImage/PSDParser.h +271 -0
- data/vendor/FreeImage/Source/FreeImage/PixelAccess.cpp +197 -0
- data/vendor/FreeImage/Source/FreeImage/Plugin.cpp +822 -0
- data/vendor/FreeImage/Source/FreeImage/PluginBMP.cpp +1494 -0
- data/vendor/FreeImage/Source/FreeImage/PluginCUT.cpp +240 -0
- data/vendor/FreeImage/Source/FreeImage/PluginDDS.cpp +655 -0
- data/vendor/FreeImage/Source/FreeImage/PluginEXR.cpp +773 -0
- data/vendor/FreeImage/Source/FreeImage/PluginG3.cpp +433 -0
- data/vendor/FreeImage/Source/FreeImage/PluginGIF.cpp +1407 -0
- data/vendor/FreeImage/Source/FreeImage/PluginHDR.cpp +722 -0
- data/vendor/FreeImage/Source/FreeImage/PluginICO.cpp +824 -0
- data/vendor/FreeImage/Source/FreeImage/PluginIFF.cpp +459 -0
- data/vendor/FreeImage/Source/FreeImage/PluginJ2K.cpp +328 -0
- data/vendor/FreeImage/Source/FreeImage/PluginJNG.cpp +162 -0
- data/vendor/FreeImage/Source/FreeImage/PluginJP2.cpp +328 -0
- data/vendor/FreeImage/Source/FreeImage/PluginJPEG.cpp +1706 -0
- data/vendor/FreeImage/Source/FreeImage/PluginJXR.cpp +1475 -0
- data/vendor/FreeImage/Source/FreeImage/PluginKOALA.cpp +243 -0
- data/vendor/FreeImage/Source/FreeImage/PluginMNG.cpp +153 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPCD.cpp +251 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPCX.cpp +659 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPFM.cpp +409 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPICT.cpp +1343 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPNG.cpp +1115 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPNM.cpp +838 -0
- data/vendor/FreeImage/Source/FreeImage/PluginPSD.cpp +131 -0
- data/vendor/FreeImage/Source/FreeImage/PluginRAS.cpp +512 -0
- data/vendor/FreeImage/Source/FreeImage/PluginRAW.cpp +793 -0
- data/vendor/FreeImage/Source/FreeImage/PluginSGI.cpp +425 -0
- data/vendor/FreeImage/Source/FreeImage/PluginTARGA.cpp +1591 -0
- data/vendor/FreeImage/Source/FreeImage/PluginTIFF.cpp +2631 -0
- data/vendor/FreeImage/Source/FreeImage/PluginWBMP.cpp +372 -0
- data/vendor/FreeImage/Source/FreeImage/PluginWebP.cpp +698 -0
- data/vendor/FreeImage/Source/FreeImage/PluginXBM.cpp +399 -0
- data/vendor/FreeImage/Source/FreeImage/PluginXPM.cpp +487 -0
- data/vendor/FreeImage/Source/FreeImage/TIFFLogLuv.cpp +65 -0
- data/vendor/FreeImage/Source/FreeImage/ToneMapping.cpp +75 -0
- data/vendor/FreeImage/Source/FreeImage/WuQuantizer.cpp +559 -0
- data/vendor/FreeImage/Source/FreeImage/ZLibInterface.cpp +223 -0
- data/vendor/FreeImage/Source/FreeImage/tmoColorConvert.cpp +479 -0
- data/vendor/FreeImage/Source/FreeImage/tmoDrago03.cpp +295 -0
- data/vendor/FreeImage/Source/FreeImage/tmoFattal02.cpp +689 -0
- data/vendor/FreeImage/Source/FreeImage/tmoReinhard05.cpp +260 -0
- data/vendor/FreeImage/Source/FreeImage.h +1153 -0
- data/vendor/FreeImage/Source/FreeImageIO.h +63 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/BSplineRotate.cpp +730 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Background.cpp +895 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Channels.cpp +488 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/ClassicRotate.cpp +917 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Colors.cpp +967 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/CopyPaste.cpp +861 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Display.cpp +230 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Filters.h +287 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Flip.cpp +166 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/JPEGTransform.cpp +623 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/MultigridPoissonSolver.cpp +505 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Rescale.cpp +192 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Resize.cpp +2116 -0
- data/vendor/FreeImage/Source/FreeImageToolkit/Resize.h +196 -0
- data/vendor/FreeImage/Source/LibJPEG/ansi2knr.c +739 -0
- data/vendor/FreeImage/Source/LibJPEG/cderror.h +134 -0
- data/vendor/FreeImage/Source/LibJPEG/cdjpeg.c +181 -0
- data/vendor/FreeImage/Source/LibJPEG/cdjpeg.h +187 -0
- data/vendor/FreeImage/Source/LibJPEG/cjpeg.c +664 -0
- data/vendor/FreeImage/Source/LibJPEG/ckconfig.c +402 -0
- data/vendor/FreeImage/Source/LibJPEG/djpeg.c +617 -0
- data/vendor/FreeImage/Source/LibJPEG/example.c +433 -0
- data/vendor/FreeImage/Source/LibJPEG/jaricom.c +153 -0
- data/vendor/FreeImage/Source/LibJPEG/jcapimin.c +288 -0
- data/vendor/FreeImage/Source/LibJPEG/jcapistd.c +162 -0
- data/vendor/FreeImage/Source/LibJPEG/jcarith.c +944 -0
- data/vendor/FreeImage/Source/LibJPEG/jccoefct.c +454 -0
- data/vendor/FreeImage/Source/LibJPEG/jccolor.c +604 -0
- data/vendor/FreeImage/Source/LibJPEG/jcdctmgr.c +477 -0
- data/vendor/FreeImage/Source/LibJPEG/jchuff.c +1573 -0
- data/vendor/FreeImage/Source/LibJPEG/jcinit.c +84 -0
- data/vendor/FreeImage/Source/LibJPEG/jcmainct.c +297 -0
- data/vendor/FreeImage/Source/LibJPEG/jcmarker.c +719 -0
- data/vendor/FreeImage/Source/LibJPEG/jcmaster.c +856 -0
- data/vendor/FreeImage/Source/LibJPEG/jcomapi.c +106 -0
- data/vendor/FreeImage/Source/LibJPEG/jconfig.h +161 -0
- data/vendor/FreeImage/Source/LibJPEG/jcparam.c +675 -0
- data/vendor/FreeImage/Source/LibJPEG/jcprepct.c +358 -0
- data/vendor/FreeImage/Source/LibJPEG/jcsample.c +545 -0
- data/vendor/FreeImage/Source/LibJPEG/jctrans.c +385 -0
- data/vendor/FreeImage/Source/LibJPEG/jdapimin.c +399 -0
- data/vendor/FreeImage/Source/LibJPEG/jdapistd.c +276 -0
- data/vendor/FreeImage/Source/LibJPEG/jdarith.c +796 -0
- data/vendor/FreeImage/Source/LibJPEG/jdatadst.c +270 -0
- data/vendor/FreeImage/Source/LibJPEG/jdatasrc.c +275 -0
- data/vendor/FreeImage/Source/LibJPEG/jdcoefct.c +741 -0
- data/vendor/FreeImage/Source/LibJPEG/jdcolor.c +748 -0
- data/vendor/FreeImage/Source/LibJPEG/jdct.h +393 -0
- data/vendor/FreeImage/Source/LibJPEG/jddctmgr.c +384 -0
- data/vendor/FreeImage/Source/LibJPEG/jdhuff.c +1554 -0
- data/vendor/FreeImage/Source/LibJPEG/jdinput.c +662 -0
- data/vendor/FreeImage/Source/LibJPEG/jdmainct.c +513 -0
- data/vendor/FreeImage/Source/LibJPEG/jdmarker.c +1511 -0
- data/vendor/FreeImage/Source/LibJPEG/jdmaster.c +543 -0
- data/vendor/FreeImage/Source/LibJPEG/jdmerge.c +401 -0
- data/vendor/FreeImage/Source/LibJPEG/jdpostct.c +290 -0
- data/vendor/FreeImage/Source/LibJPEG/jdsample.c +361 -0
- data/vendor/FreeImage/Source/LibJPEG/jdtrans.c +140 -0
- data/vendor/FreeImage/Source/LibJPEG/jerror.c +253 -0
- data/vendor/FreeImage/Source/LibJPEG/jerror.h +304 -0
- data/vendor/FreeImage/Source/LibJPEG/jfdctflt.c +174 -0
- data/vendor/FreeImage/Source/LibJPEG/jfdctfst.c +230 -0
- data/vendor/FreeImage/Source/LibJPEG/jfdctint.c +4406 -0
- data/vendor/FreeImage/Source/LibJPEG/jidctflt.c +235 -0
- data/vendor/FreeImage/Source/LibJPEG/jidctfst.c +368 -0
- data/vendor/FreeImage/Source/LibJPEG/jidctint.c +5179 -0
- data/vendor/FreeImage/Source/LibJPEG/jinclude.h +91 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemansi.c +167 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemdos.c +638 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemmac.c +289 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemmgr.c +1119 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemname.c +276 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemnobs.c +109 -0
- data/vendor/FreeImage/Source/LibJPEG/jmemsys.h +198 -0
- data/vendor/FreeImage/Source/LibJPEG/jmorecfg.h +442 -0
- data/vendor/FreeImage/Source/LibJPEG/jpegint.h +426 -0
- data/vendor/FreeImage/Source/LibJPEG/jpeglib.h +1180 -0
- data/vendor/FreeImage/Source/LibJPEG/jpegtran.c +577 -0
- data/vendor/FreeImage/Source/LibJPEG/jquant1.c +857 -0
- data/vendor/FreeImage/Source/LibJPEG/jquant2.c +1311 -0
- data/vendor/FreeImage/Source/LibJPEG/jutils.c +227 -0
- data/vendor/FreeImage/Source/LibJPEG/jversion.h +14 -0
- data/vendor/FreeImage/Source/LibJPEG/rdbmp.c +480 -0
- data/vendor/FreeImage/Source/LibJPEG/rdcolmap.c +253 -0
- data/vendor/FreeImage/Source/LibJPEG/rdgif.c +38 -0
- data/vendor/FreeImage/Source/LibJPEG/rdjpgcom.c +515 -0
- data/vendor/FreeImage/Source/LibJPEG/rdppm.c +459 -0
- data/vendor/FreeImage/Source/LibJPEG/rdrle.c +387 -0
- data/vendor/FreeImage/Source/LibJPEG/rdswitch.c +365 -0
- data/vendor/FreeImage/Source/LibJPEG/rdtarga.c +500 -0
- data/vendor/FreeImage/Source/LibJPEG/transupp.c +1763 -0
- data/vendor/FreeImage/Source/LibJPEG/transupp.h +219 -0
- data/vendor/FreeImage/Source/LibJPEG/wrbmp.c +442 -0
- data/vendor/FreeImage/Source/LibJPEG/wrgif.c +399 -0
- data/vendor/FreeImage/Source/LibJPEG/wrjpgcom.c +583 -0
- data/vendor/FreeImage/Source/LibJPEG/wrppm.c +269 -0
- data/vendor/FreeImage/Source/LibJPEG/wrrle.c +305 -0
- data/vendor/FreeImage/Source/LibJPEG/wrtarga.c +253 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/guiddef.h +230 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/wmsal.h +757 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstring.h +342 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_adt.h +71 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_strict.h +1096 -0
- data/vendor/FreeImage/Source/LibJXR/common/include/wmspecstrings_undef.h +406 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/JXRTranscode.c +987 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/decode.c +200 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/decode.h +143 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/postprocess.c +288 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/segdec.c +1205 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/strInvTransform.c +1888 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/strPredQuantDec.c +539 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/strdec.c +3628 -0
- data/vendor/FreeImage/Source/LibJXR/image/decode/strdec_x86.c +1640 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/encode.c +144 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/encode.h +113 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/segenc.c +1186 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/strFwdTransform.c +1111 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/strPredQuantEnc.c +511 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/strenc.c +2370 -0
- data/vendor/FreeImage/Source/LibJXR/image/encode/strenc_x86.c +409 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/adapthuff.c +511 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/ansi.h +61 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/common.h +131 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/image.c +183 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/perfTimer.h +115 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/perfTimerANSI.c +274 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/strPredQuant.c +306 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/strTransform.c +85 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/strTransform.h +50 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/strcodec.c +1251 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/strcodec.h +681 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/windowsmediaphoto.h +515 -0
- data/vendor/FreeImage/Source/LibJXR/image/sys/xplatform_image.h +84 -0
- data/vendor/FreeImage/Source/LibJXR/image/x86/x86.h +58 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlue.c +930 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlue.h +636 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGlueJxr.c +2246 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRGluePFC.c +2338 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRMeta.c +905 -0
- data/vendor/FreeImage/Source/LibJXR/jxrgluelib/JXRMeta.h +258 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/bio.c +188 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/bio.h +128 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/cidx_manager.c +239 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/cidx_manager.h +68 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/cio.c +644 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/cio.h +393 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/dwt.c +919 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/dwt.h +116 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/event.c +141 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/event.h +97 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/function_list.c +114 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/function_list.h +126 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/image.c +235 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/image.h +63 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/indexbox_manager.h +148 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/invert.c +289 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/invert.h +59 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/j2k.c +10238 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/j2k.h +838 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/jp2.c +2776 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/jp2.h +490 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/mct.c +319 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/mct.h +149 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/mqc.c +604 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/mqc.h +201 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/openjpeg.c +955 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/openjpeg.h +1475 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_clock.c +59 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_clock.h +54 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_codec.h +160 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_config.h +9 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_config_private.h +16 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_includes.h +175 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_intmath.h +172 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_inttypes.h +43 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_malloc.h +180 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/opj_stdint.h +47 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/phix_manager.c +191 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/pi.c +1870 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/pi.h +182 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/ppix_manager.c +194 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/raw.c +89 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/raw.h +100 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t1.c +1751 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t1.h +157 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t1_generate_luts.c +276 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t1_luts.h +143 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t2.c +1334 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/t2.h +127 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/tcd.c +2123 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/tcd.h +348 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/tgt.c +331 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/tgt.h +140 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/thix_manager.c +134 -0
- data/vendor/FreeImage/Source/LibOpenJPEG/tpix_manager.c +185 -0
- data/vendor/FreeImage/Source/LibPNG/example.c +1061 -0
- data/vendor/FreeImage/Source/LibPNG/png.c +4493 -0
- data/vendor/FreeImage/Source/LibPNG/png.h +3282 -0
- data/vendor/FreeImage/Source/LibPNG/pngconf.h +644 -0
- data/vendor/FreeImage/Source/LibPNG/pngdebug.h +154 -0
- data/vendor/FreeImage/Source/LibPNG/pngerror.c +963 -0
- data/vendor/FreeImage/Source/LibPNG/pngget.c +1213 -0
- data/vendor/FreeImage/Source/LibPNG/pnginfo.h +260 -0
- data/vendor/FreeImage/Source/LibPNG/pnglibconf.h +218 -0
- data/vendor/FreeImage/Source/LibPNG/pngmem.c +281 -0
- data/vendor/FreeImage/Source/LibPNG/pngpread.c +1168 -0
- data/vendor/FreeImage/Source/LibPNG/pngpriv.h +1944 -0
- data/vendor/FreeImage/Source/LibPNG/pngread.c +4121 -0
- data/vendor/FreeImage/Source/LibPNG/pngrio.c +120 -0
- data/vendor/FreeImage/Source/LibPNG/pngrtran.c +4994 -0
- data/vendor/FreeImage/Source/LibPNG/pngrutil.c +4474 -0
- data/vendor/FreeImage/Source/LibPNG/pngset.c +1611 -0
- data/vendor/FreeImage/Source/LibPNG/pngstruct.h +489 -0
- data/vendor/FreeImage/Source/LibPNG/pngtest.c +2011 -0
- data/vendor/FreeImage/Source/LibPNG/pngtrans.c +849 -0
- data/vendor/FreeImage/Source/LibPNG/pngwio.c +168 -0
- data/vendor/FreeImage/Source/LibPNG/pngwrite.c +2455 -0
- data/vendor/FreeImage/Source/LibPNG/pngwtran.c +574 -0
- data/vendor/FreeImage/Source/LibPNG/pngwutil.c +3029 -0
- data/vendor/FreeImage/Source/LibRawLite/dcraw/dcraw.c +15462 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/aahd_demosaic.cpp +706 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/dcb_demosaicing.c +710 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/dcraw_common.cpp +13593 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/dcraw_fileio.cpp +240 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/defines.h +167 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/demosaic_packs.cpp +99 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/dht_demosaic.cpp +873 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/libraw_internal_funcs.h +282 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/libraw_x3f.cpp +1919 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/var_defines.h +216 -0
- data/vendor/FreeImage/Source/LibRawLite/internal/wf_filtering.cpp +1950 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw.h +338 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_alloc.h +99 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_const.h +233 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_datastream.h +238 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_internal.h +225 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_types.h +442 -0
- data/vendor/FreeImage/Source/LibRawLite/libraw/libraw_version.h +62 -0
- data/vendor/FreeImage/Source/LibRawLite/src/libraw_c_api.cpp +230 -0
- data/vendor/FreeImage/Source/LibRawLite/src/libraw_cxx.cpp +4533 -0
- data/vendor/FreeImage/Source/LibRawLite/src/libraw_datastream.cpp +703 -0
- data/vendor/FreeImage/Source/LibTIFF4/mkg3states.c +451 -0
- data/vendor/FreeImage/Source/LibTIFF4/mkspans.c +82 -0
- data/vendor/FreeImage/Source/LibTIFF4/t4.h +292 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_aux.c +358 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_close.c +140 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_codec.c +166 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_color.c +287 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_compress.c +304 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_config.h +97 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_config.vc.h +74 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_config.wince.h +71 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dir.c +1700 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dir.h +308 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dirinfo.c +959 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dirread.c +5640 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dirwrite.c +2910 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_dumpmode.c +143 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_error.c +80 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_extension.c +118 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_fax3.c +1595 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_fax3.h +538 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_fax3sm.c +1260 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_flush.c +118 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_getimage.c +2890 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_jbig.c +213 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_jpeg.c +2354 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_jpeg_12.c +65 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_luv.c +1683 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_lzma.c +495 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_lzw.c +1169 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_next.c +181 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_ojpeg.c +2501 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_open.c +725 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_packbits.c +300 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_pixarlog.c +1442 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_predict.c +764 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_predict.h +77 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_print.c +716 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_read.c +1086 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_strip.c +383 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_swab.c +310 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_thunder.c +207 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_tile.c +299 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_unix.c +325 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_version.c +40 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_vms.c +603 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_warning.c +81 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_win32.c +443 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_wince.c +293 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_write.c +771 -0
- data/vendor/FreeImage/Source/LibTIFF4/tif_zip.c +472 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiff.h +681 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffconf.h +170 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffconf.vc.h +160 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffconf.wince.h +121 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffio.h +557 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffiop.h +367 -0
- data/vendor/FreeImage/Source/LibTIFF4/tiffvers.h +9 -0
- data/vendor/FreeImage/Source/LibTIFF4/uvcode.h +180 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/alphai.h +55 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.alpha.c +167 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.buffer.c +249 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.frame.c +827 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.idec.c +857 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.io.c +640 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.quant.c +110 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.tree.c +525 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.vp8.c +663 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.vp8l.c +1584 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/dec.webp.c +834 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/decode_vp8.h +185 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/vp8i.h +353 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/vp8li.h +136 -0
- data/vendor/FreeImage/Source/LibWebP/src/dec/webpi.h +120 -0
- data/vendor/FreeImage/Source/LibWebP/src/demux/demux.demux.c +957 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing.c +377 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing_mips_dsp_r2.c +139 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.alpha_processing_sse2.c +296 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb.c +68 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb_mips_dsp_r2.c +108 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.argb_sse2.c +62 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost.c +412 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_mips32.c +154 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_mips_dsp_r2.c +107 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cost_sse2.c +121 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.cpu.c +138 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec.c +760 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_clip_tables.c +366 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_mips32.c +585 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_mips_dsp_r2.c +992 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_neon.c +1489 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.dec_sse2.c +1284 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc.c +788 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_avx2.c +24 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_mips32.c +670 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_mips_dsp_r2.c +1510 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_neon.c +932 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.enc_sse2.c +940 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters.c +240 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters_mips_dsp_r2.c +404 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.filters_sse2.c +349 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.h +434 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless.c +1838 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_mips32.c +416 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_mips_dsp_r2.c +921 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_neon.c +357 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.lossless_sse2.c +535 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler.c +115 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler_mips32.c +192 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.rescaler_mips_dsp_r2.c +210 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling.c +252 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_mips_dsp_r2.c +280 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_neon.c +267 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.upsampling_sse2.c +214 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv.c +166 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_mips32.c +100 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_mips_dsp_r2.c +131 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/dsp.yuv_sse2.c +322 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/lossless.h +313 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/mips_macro.h +200 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/neon.h +82 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/yuv.h +321 -0
- data/vendor/FreeImage/Source/LibWebP/src/dsp/yuv_tables_sse2.h +536 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/backward_references.h +202 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/cost.h +69 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.alpha.c +440 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.analysis.c +501 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.backward_references.c +1076 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.config.c +163 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.cost.c +355 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.filter.c +296 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.frame.c +850 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.histogram.c +897 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.iterator.c +456 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.near_lossless.c +160 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture.c +290 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_csp.c +1100 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_psnr.c +150 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_rescale.c +285 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.picture_tools.c +206 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.quant.c +1191 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.syntax.c +383 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.token.c +285 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.tree.c +504 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.vp8l.c +1437 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/enc.webpenc.c +379 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/histogram.h +114 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/vp8enci.h +551 -0
- data/vendor/FreeImage/Source/LibWebP/src/enc/vp8li.h +78 -0
- data/vendor/FreeImage/Source/LibWebP/src/mux/mux.anim_encode.c +1241 -0
- data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxedit.c +696 -0
- data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxinternal.c +551 -0
- data/vendor/FreeImage/Source/LibWebP/src/mux/mux.muxread.c +544 -0
- data/vendor/FreeImage/Source/LibWebP/src/mux/muxi.h +232 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/bit_reader.h +168 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/bit_reader_inl.h +172 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/bit_writer.h +120 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/color_cache.h +74 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/endian_inl.h +100 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/filters.h +32 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/huffman.h +67 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/huffman_encode.h +60 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/quant_levels.h +36 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/quant_levels_dec.h +35 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/random.h +63 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/rescaler.h +78 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/thread.h +93 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.bit_reader.c +208 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.bit_writer.c +308 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.color_cache.c +49 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.filters.c +76 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.h +121 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.huffman.c +205 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.huffman_encode.c +417 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.quant_levels.c +140 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.quant_levels_dec.c +279 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.random.c +43 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.rescaler.c +82 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.thread.c +309 -0
- data/vendor/FreeImage/Source/LibWebP/src/utils/utils.utils.c +211 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/decode.h +493 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/demux.h +224 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/encode.h +515 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/format_constants.h +88 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/mux.h +507 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/mux_types.h +97 -0
- data/vendor/FreeImage/Source/LibWebP/src/webp/types.h +52 -0
- data/vendor/FreeImage/Source/MapIntrospector.h +212 -0
- data/vendor/FreeImage/Source/Metadata/Exif.cpp +1253 -0
- data/vendor/FreeImage/Source/Metadata/FIRational.cpp +176 -0
- data/vendor/FreeImage/Source/Metadata/FIRational.h +108 -0
- data/vendor/FreeImage/Source/Metadata/FreeImageTag.cpp +353 -0
- data/vendor/FreeImage/Source/Metadata/FreeImageTag.h +500 -0
- data/vendor/FreeImage/Source/Metadata/IPTC.cpp +342 -0
- data/vendor/FreeImage/Source/Metadata/TagConversion.cpp +1094 -0
- data/vendor/FreeImage/Source/Metadata/TagLib.cpp +1618 -0
- data/vendor/FreeImage/Source/Metadata/XTIFF.cpp +766 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/eLut.cpp +114 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/eLut.h +71 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/half.cpp +310 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/half.h +757 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/halfExport.h +27 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/halfFunction.h +179 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/halfLimits.h +102 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/toFloat.cpp +164 -0
- data/vendor/FreeImage/Source/OpenEXR/Half/toFloat.h +16391 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/Iex.h +60 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexBaseExc.cpp +156 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexBaseExc.h +264 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexErrnoExc.h +208 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexExport.h +51 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexForward.h +229 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexMacros.h +170 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexMathExc.h +57 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexNamespace.h +112 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexThrowErrnoExc.cpp +873 -0
- data/vendor/FreeImage/Source/OpenEXR/Iex/IexThrowErrnoExc.h +97 -0
- data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFloatExc.cpp +113 -0
- data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFloatExc.h +146 -0
- data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFpu.cpp +530 -0
- data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathFpu.h +91 -0
- data/vendor/FreeImage/Source/OpenEXR/IexMath/IexMathIeeeExc.h +62 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmBaseConfig.h +61 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAcesFile.cpp +633 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAcesFile.h +324 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfArray.h +285 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAttribute.cpp +158 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAttribute.h +407 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfAutoArray.h +95 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfB44Compressor.cpp +1072 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfB44Compressor.h +118 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfBoxAttribute.cpp +111 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfBoxAttribute.h +87 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCRgbaFile.cpp +1438 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCRgbaFile.h +555 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelList.cpp +322 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelList.h +436 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelListAttribute.cpp +150 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChannelListAttribute.h +74 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCheckedArithmetic.h +163 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticities.cpp +151 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticities.h +131 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.cpp +87 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfChromaticitiesAttribute.h +73 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompositeDeepScanLine.cpp +591 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompositeDeepScanLine.h +142 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompression.h +84 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressionAttribute.cpp +78 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressionAttribute.h +64 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressor.cpp +226 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfCompressor.h +265 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfConvert.cpp +143 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfConvert.h +107 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepCompositing.cpp +110 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepCompositing.h +132 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepFrameBuffer.cpp +230 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepFrameBuffer.h +339 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageState.h +96 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageStateAttribute.cpp +78 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepImageStateAttribute.h +68 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.cpp +2025 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputFile.h +276 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputPart.cpp +149 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineInputPart.h +181 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputFile.cpp +1552 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputFile.h +244 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputPart.cpp +107 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepScanLineOutputPart.h +168 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputFile.cpp +1979 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputFile.h +437 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputPart.cpp +273 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledInputPart.h +362 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputFile.cpp +2055 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputFile.h +475 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputPart.cpp +250 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDeepTiledOutputPart.h +394 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDoubleAttribute.cpp +57 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDoubleAttribute.h +59 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressor.cpp +3424 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressor.h +210 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfDwaCompressorSimd.h +2145 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmap.cpp +335 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmap.h +336 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmapAttribute.cpp +76 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfEnvmapAttribute.h +68 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfExport.h +46 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFastHuf.cpp +768 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFastHuf.h +148 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatAttribute.cpp +57 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatAttribute.h +58 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatVectorAttribute.cpp +84 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFloatVectorAttribute.h +76 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfForward.h +127 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFrameBuffer.cpp +228 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFrameBuffer.h +386 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFramesPerSecond.cpp +76 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfFramesPerSecond.h +94 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericInputFile.cpp +76 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericInputFile.h +58 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericOutputFile.cpp +112 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfGenericOutputFile.h +62 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHeader.cpp +1283 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHeader.h +699 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHuf.cpp +1114 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfHuf.h +82 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIO.cpp +110 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIO.h +255 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputFile.cpp +895 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputFile.h +240 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPart.cpp +114 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPart.h +84 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPartData.cpp +51 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputPartData.h +69 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInputStreamMutex.h +68 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfInt64.h +56 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIntAttribute.cpp +57 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfIntAttribute.h +58 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCode.cpp +217 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCode.h +167 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.cpp +99 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfKeyCodeAttribute.h +73 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrder.h +69 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrderAttribute.cpp +78 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLineOrderAttribute.h +72 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLut.cpp +178 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfLut.h +188 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMatrixAttribute.cpp +263 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMatrixAttribute.h +83 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMisc.cpp +1872 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMisc.h +466 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.cpp +783 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartInputFile.h +128 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartOutputFile.cpp +519 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiPartOutputFile.h +118 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiView.cpp +435 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfMultiView.h +187 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfName.h +150 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfNamespace.h +115 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOpaqueAttribute.cpp +126 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOpaqueAttribute.h +110 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOptimizedPixelReading.h +646 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputFile.cpp +1378 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputFile.h +263 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPart.cpp +105 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPart.h +77 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPartData.cpp +52 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputPartData.h +62 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfOutputStreamMutex.h +70 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartHelper.h +262 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartType.cpp +63 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPartType.h +62 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPixelType.h +67 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPizCompressor.cpp +667 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPizCompressor.h +117 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImage.cpp +104 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImage.h +135 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.cpp +103 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPreviewImageAttribute.h +70 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPxr24Compressor.cpp +553 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfPxr24Compressor.h +109 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRational.cpp +127 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRational.h +98 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRationalAttribute.cpp +74 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRationalAttribute.h +69 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgba.h +109 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaFile.cpp +1405 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaFile.h +346 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaYca.cpp +497 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaYca.h +259 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRle.cpp +157 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRle.h +63 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRleCompressor.cpp +220 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfRleCompressor.h +80 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfScanLineInputFile.cpp +1702 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfScanLineInputFile.h +210 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSimd.h +59 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStandardAttributes.cpp +125 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStandardAttributes.h +382 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStdIO.cpp +242 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStdIO.h +160 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringAttribute.cpp +80 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringAttribute.h +71 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringVectorAttribute.cpp +100 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfStringVectorAttribute.h +74 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSystemSpecific.cpp +129 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfSystemSpecific.h +172 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTestFile.cpp +216 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTestFile.h +97 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfThreading.cpp +62 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfThreading.h +95 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescription.h +107 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.cpp +86 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileDescriptionAttribute.h +72 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileOffsets.cpp +552 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTileOffsets.h +125 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputFile.cpp +1533 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputFile.h +401 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputPart.cpp +208 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledInputPart.h +100 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledMisc.cpp +389 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledMisc.h +106 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputFile.cpp +1841 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputFile.h +495 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputPart.cpp +228 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledOutputPart.h +105 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledRgbaFile.cpp +1163 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTiledRgbaFile.h +482 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCode.cpp +431 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCode.h +242 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.cpp +79 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfTimeCodeAttribute.h +74 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVecAttribute.cpp +217 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVecAttribute.h +100 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVersion.cpp +60 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfVersion.h +136 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfWav.cpp +391 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfWav.h +78 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfXdr.h +927 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZip.cpp +196 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZip.h +78 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZipCompressor.cpp +127 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/ImfZipCompressor.h +89 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/b44ExpLogTable.cpp +136 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/b44ExpLogTable.h +16396 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/dwaLookups.cpp +573 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmImf/dwaLookups.h +98334 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThread.cpp +80 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThread.h +143 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadExport.h +46 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadForward.h +52 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutex.cpp +59 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutex.h +160 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutexPosix.cpp +85 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadMutexWin32.cpp +79 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadNamespace.h +114 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPool.cpp +483 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPool.h +160 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadPosix.cpp +98 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphore.cpp +60 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphore.h +112 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphorePosix.cpp +106 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphorePosixCompat.cpp +155 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadSemaphoreWin32.cpp +153 -0
- data/vendor/FreeImage/Source/OpenEXR/IlmThread/IlmThreadWin32.cpp +100 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBox.cpp +37 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBox.h +849 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathBoxAlgo.h +1016 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColor.h +736 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColorAlgo.cpp +178 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathColorAlgo.h +257 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathEuler.h +926 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathExc.h +73 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathExport.h +46 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathForward.h +72 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrame.h +192 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrustum.h +741 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFrustumTest.h +417 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFun.cpp +181 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathFun.h +269 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathGL.h +166 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathGLU.h +54 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathHalfLimits.h +68 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathInt64.h +62 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathInterval.h +226 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLimits.h +268 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLine.h +185 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathLineAlgo.h +288 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMath.h +208 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrix.h +3441 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrixAlgo.cpp +1252 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathMatrixAlgo.h +1425 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathNamespace.h +115 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathPlane.h +257 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathPlatform.h +112 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathQuat.h +964 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRandom.cpp +194 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRandom.h +401 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathRoots.h +219 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathShear.cpp +54 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathShear.h +656 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathSphere.h +177 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVec.cpp +583 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVec.h +2227 -0
- data/vendor/FreeImage/Source/OpenEXR/Imath/ImathVecAlgo.h +147 -0
- data/vendor/FreeImage/Source/OpenEXR/OpenEXRConfig.h +72 -0
- data/vendor/FreeImage/Source/Plugin.h +144 -0
- data/vendor/FreeImage/Source/Quantizers.h +354 -0
- data/vendor/FreeImage/Source/ToneMapping.h +44 -0
- data/vendor/FreeImage/Source/Utilities.h +516 -0
- data/vendor/FreeImage/Source/ZLib/adler32.c +179 -0
- data/vendor/FreeImage/Source/ZLib/compress.c +80 -0
- data/vendor/FreeImage/Source/ZLib/crc32.c +425 -0
- data/vendor/FreeImage/Source/ZLib/crc32.h +441 -0
- data/vendor/FreeImage/Source/ZLib/deflate.c +1967 -0
- data/vendor/FreeImage/Source/ZLib/deflate.h +346 -0
- data/vendor/FreeImage/Source/ZLib/gzclose.c +25 -0
- data/vendor/FreeImage/Source/ZLib/gzguts.h +209 -0
- data/vendor/FreeImage/Source/ZLib/gzlib.c +634 -0
- data/vendor/FreeImage/Source/ZLib/gzread.c +594 -0
- data/vendor/FreeImage/Source/ZLib/gzwrite.c +577 -0
- data/vendor/FreeImage/Source/ZLib/infback.c +640 -0
- data/vendor/FreeImage/Source/ZLib/inffast.c +340 -0
- data/vendor/FreeImage/Source/ZLib/inffast.h +11 -0
- data/vendor/FreeImage/Source/ZLib/inffixed.h +94 -0
- data/vendor/FreeImage/Source/ZLib/inflate.c +1512 -0
- data/vendor/FreeImage/Source/ZLib/inflate.h +122 -0
- data/vendor/FreeImage/Source/ZLib/inftrees.c +306 -0
- data/vendor/FreeImage/Source/ZLib/inftrees.h +62 -0
- data/vendor/FreeImage/Source/ZLib/trees.c +1226 -0
- data/vendor/FreeImage/Source/ZLib/trees.h +128 -0
- data/vendor/FreeImage/Source/ZLib/uncompr.c +59 -0
- data/vendor/FreeImage/Source/ZLib/zconf.h +511 -0
- data/vendor/FreeImage/Source/ZLib/zlib.h +1768 -0
- data/vendor/FreeImage/Source/ZLib/zutil.c +324 -0
- data/vendor/FreeImage/Source/ZLib/zutil.h +253 -0
- metadata +931 -0
@@ -0,0 +1,4474 @@
|
|
1
|
+
|
2
|
+
/* pngrutil.c - utilities to read a PNG file
|
3
|
+
*
|
4
|
+
* Last changed in libpng 1.6.15 [November 20, 2014]
|
5
|
+
* Copyright (c) 1998-2014 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
|
+
png_uint_32 PNGAPI
|
22
|
+
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
|
23
|
+
{
|
24
|
+
png_uint_32 uval = png_get_uint_32(buf);
|
25
|
+
|
26
|
+
if (uval > PNG_UINT_31_MAX)
|
27
|
+
png_error(png_ptr, "PNG unsigned integer out of range");
|
28
|
+
|
29
|
+
return (uval);
|
30
|
+
}
|
31
|
+
|
32
|
+
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
|
33
|
+
/* The following is a variation on the above for use with the fixed
|
34
|
+
* point values used for gAMA and cHRM. Instead of png_error it
|
35
|
+
* issues a warning and returns (-1) - an invalid value because both
|
36
|
+
* gAMA and cHRM use *unsigned* integers for fixed point values.
|
37
|
+
*/
|
38
|
+
#define PNG_FIXED_ERROR (-1)
|
39
|
+
|
40
|
+
static png_fixed_point /* PRIVATE */
|
41
|
+
png_get_fixed_point(png_structrp png_ptr, png_const_bytep buf)
|
42
|
+
{
|
43
|
+
png_uint_32 uval = png_get_uint_32(buf);
|
44
|
+
|
45
|
+
if (uval <= PNG_UINT_31_MAX)
|
46
|
+
return (png_fixed_point)uval; /* known to be in range */
|
47
|
+
|
48
|
+
/* The caller can turn off the warning by passing NULL. */
|
49
|
+
if (png_ptr != NULL)
|
50
|
+
png_warning(png_ptr, "PNG fixed point integer out of range");
|
51
|
+
|
52
|
+
return PNG_FIXED_ERROR;
|
53
|
+
}
|
54
|
+
#endif
|
55
|
+
|
56
|
+
#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
|
57
|
+
/* NOTE: the read macros will obscure these definitions, so that if
|
58
|
+
* PNG_USE_READ_MACROS is set the library will not use them internally,
|
59
|
+
* but the APIs will still be available externally.
|
60
|
+
*
|
61
|
+
* The parentheses around "PNGAPI function_name" in the following three
|
62
|
+
* functions are necessary because they allow the macros to co-exist with
|
63
|
+
* these (unused but exported) functions.
|
64
|
+
*/
|
65
|
+
|
66
|
+
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
|
67
|
+
png_uint_32 (PNGAPI
|
68
|
+
png_get_uint_32)(png_const_bytep buf)
|
69
|
+
{
|
70
|
+
png_uint_32 uval =
|
71
|
+
((png_uint_32)(*(buf )) << 24) +
|
72
|
+
((png_uint_32)(*(buf + 1)) << 16) +
|
73
|
+
((png_uint_32)(*(buf + 2)) << 8) +
|
74
|
+
((png_uint_32)(*(buf + 3)) ) ;
|
75
|
+
|
76
|
+
return uval;
|
77
|
+
}
|
78
|
+
|
79
|
+
/* Grab a signed 32-bit integer from a buffer in big-endian format. The
|
80
|
+
* data is stored in the PNG file in two's complement format and there
|
81
|
+
* is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
|
82
|
+
* the following code does a two's complement to native conversion.
|
83
|
+
*/
|
84
|
+
png_int_32 (PNGAPI
|
85
|
+
png_get_int_32)(png_const_bytep buf)
|
86
|
+
{
|
87
|
+
png_uint_32 uval = png_get_uint_32(buf);
|
88
|
+
if ((uval & 0x80000000) == 0) /* non-negative */
|
89
|
+
return uval;
|
90
|
+
|
91
|
+
uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */
|
92
|
+
return -(png_int_32)uval;
|
93
|
+
}
|
94
|
+
|
95
|
+
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
|
96
|
+
png_uint_16 (PNGAPI
|
97
|
+
png_get_uint_16)(png_const_bytep buf)
|
98
|
+
{
|
99
|
+
/* ANSI-C requires an int value to accomodate at least 16 bits so this
|
100
|
+
* works and allows the compiler not to worry about possible narrowing
|
101
|
+
* on 32 bit systems. (Pre-ANSI systems did not make integers smaller
|
102
|
+
* than 16 bits either.)
|
103
|
+
*/
|
104
|
+
unsigned int val =
|
105
|
+
((unsigned int)(*buf) << 8) +
|
106
|
+
((unsigned int)(*(buf + 1)));
|
107
|
+
|
108
|
+
return (png_uint_16)val;
|
109
|
+
}
|
110
|
+
|
111
|
+
#endif /* READ_INT_FUNCTIONS */
|
112
|
+
|
113
|
+
/* Read and check the PNG file signature */
|
114
|
+
void /* PRIVATE */
|
115
|
+
png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
|
116
|
+
{
|
117
|
+
png_size_t num_checked, num_to_check;
|
118
|
+
|
119
|
+
/* Exit if the user application does not expect a signature. */
|
120
|
+
if (png_ptr->sig_bytes >= 8)
|
121
|
+
return;
|
122
|
+
|
123
|
+
num_checked = png_ptr->sig_bytes;
|
124
|
+
num_to_check = 8 - num_checked;
|
125
|
+
|
126
|
+
#ifdef PNG_IO_STATE_SUPPORTED
|
127
|
+
png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
|
128
|
+
#endif
|
129
|
+
|
130
|
+
/* The signature must be serialized in a single I/O call. */
|
131
|
+
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
|
132
|
+
png_ptr->sig_bytes = 8;
|
133
|
+
|
134
|
+
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
|
135
|
+
{
|
136
|
+
if (num_checked < 4 &&
|
137
|
+
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
|
138
|
+
png_error(png_ptr, "Not a PNG file");
|
139
|
+
else
|
140
|
+
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
|
141
|
+
}
|
142
|
+
if (num_checked < 3)
|
143
|
+
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
|
144
|
+
}
|
145
|
+
|
146
|
+
/* Read the chunk header (length + type name).
|
147
|
+
* Put the type name into png_ptr->chunk_name, and return the length.
|
148
|
+
*/
|
149
|
+
png_uint_32 /* PRIVATE */
|
150
|
+
png_read_chunk_header(png_structrp png_ptr)
|
151
|
+
{
|
152
|
+
png_byte buf[8];
|
153
|
+
png_uint_32 length;
|
154
|
+
|
155
|
+
#ifdef PNG_IO_STATE_SUPPORTED
|
156
|
+
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
|
157
|
+
#endif
|
158
|
+
|
159
|
+
/* Read the length and the chunk name.
|
160
|
+
* This must be performed in a single I/O call.
|
161
|
+
*/
|
162
|
+
png_read_data(png_ptr, buf, 8);
|
163
|
+
length = png_get_uint_31(png_ptr, buf);
|
164
|
+
|
165
|
+
/* Put the chunk name into png_ptr->chunk_name. */
|
166
|
+
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4);
|
167
|
+
|
168
|
+
png_debug2(0, "Reading %lx chunk, length = %lu",
|
169
|
+
(unsigned long)png_ptr->chunk_name, (unsigned long)length);
|
170
|
+
|
171
|
+
/* Reset the crc and run it over the chunk name. */
|
172
|
+
png_reset_crc(png_ptr);
|
173
|
+
png_calculate_crc(png_ptr, buf + 4, 4);
|
174
|
+
|
175
|
+
/* Check to see if chunk name is valid. */
|
176
|
+
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
177
|
+
|
178
|
+
#ifdef PNG_IO_STATE_SUPPORTED
|
179
|
+
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
|
180
|
+
#endif
|
181
|
+
|
182
|
+
return length;
|
183
|
+
}
|
184
|
+
|
185
|
+
/* Read data, and (optionally) run it through the CRC. */
|
186
|
+
void /* PRIVATE */
|
187
|
+
png_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length)
|
188
|
+
{
|
189
|
+
if (png_ptr == NULL)
|
190
|
+
return;
|
191
|
+
|
192
|
+
png_read_data(png_ptr, buf, length);
|
193
|
+
png_calculate_crc(png_ptr, buf, length);
|
194
|
+
}
|
195
|
+
|
196
|
+
/* Optionally skip data and then check the CRC. Depending on whether we
|
197
|
+
* are reading an ancillary or critical chunk, and how the program has set
|
198
|
+
* things up, we may calculate the CRC on the data and print a message.
|
199
|
+
* Returns '1' if there was a CRC error, '0' otherwise.
|
200
|
+
*/
|
201
|
+
int /* PRIVATE */
|
202
|
+
png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
|
203
|
+
{
|
204
|
+
/* The size of the local buffer for inflate is a good guess as to a
|
205
|
+
* reasonable size to use for buffering reads from the application.
|
206
|
+
*/
|
207
|
+
while (skip > 0)
|
208
|
+
{
|
209
|
+
png_uint_32 len;
|
210
|
+
png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
|
211
|
+
|
212
|
+
len = (sizeof tmpbuf);
|
213
|
+
if (len > skip)
|
214
|
+
len = skip;
|
215
|
+
skip -= len;
|
216
|
+
|
217
|
+
png_crc_read(png_ptr, tmpbuf, len);
|
218
|
+
}
|
219
|
+
|
220
|
+
if (png_crc_error(png_ptr) != 0)
|
221
|
+
{
|
222
|
+
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ?
|
223
|
+
(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0 :
|
224
|
+
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0)
|
225
|
+
{
|
226
|
+
png_chunk_warning(png_ptr, "CRC error");
|
227
|
+
}
|
228
|
+
|
229
|
+
else
|
230
|
+
png_chunk_error(png_ptr, "CRC error");
|
231
|
+
|
232
|
+
return (1);
|
233
|
+
}
|
234
|
+
|
235
|
+
return (0);
|
236
|
+
}
|
237
|
+
|
238
|
+
/* Compare the CRC stored in the PNG file with that calculated by libpng from
|
239
|
+
* the data it has read thus far.
|
240
|
+
*/
|
241
|
+
int /* PRIVATE */
|
242
|
+
png_crc_error(png_structrp png_ptr)
|
243
|
+
{
|
244
|
+
png_byte crc_bytes[4];
|
245
|
+
png_uint_32 crc;
|
246
|
+
int need_crc = 1;
|
247
|
+
|
248
|
+
if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)
|
249
|
+
{
|
250
|
+
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
|
251
|
+
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
|
252
|
+
need_crc = 0;
|
253
|
+
}
|
254
|
+
|
255
|
+
else /* critical */
|
256
|
+
{
|
257
|
+
if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)
|
258
|
+
need_crc = 0;
|
259
|
+
}
|
260
|
+
|
261
|
+
#ifdef PNG_IO_STATE_SUPPORTED
|
262
|
+
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
|
263
|
+
#endif
|
264
|
+
|
265
|
+
/* The chunk CRC must be serialized in a single I/O call. */
|
266
|
+
png_read_data(png_ptr, crc_bytes, 4);
|
267
|
+
|
268
|
+
if (need_crc != 0)
|
269
|
+
{
|
270
|
+
crc = png_get_uint_32(crc_bytes);
|
271
|
+
return ((int)(crc != png_ptr->crc));
|
272
|
+
}
|
273
|
+
|
274
|
+
else
|
275
|
+
return (0);
|
276
|
+
}
|
277
|
+
|
278
|
+
#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\
|
279
|
+
defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\
|
280
|
+
defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\
|
281
|
+
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED)
|
282
|
+
/* Manage the read buffer; this simply reallocates the buffer if it is not small
|
283
|
+
* enough (or if it is not allocated). The routine returns a pointer to the
|
284
|
+
* buffer; if an error occurs and 'warn' is set the routine returns NULL, else
|
285
|
+
* it will call png_error (via png_malloc) on failure. (warn == 2 means
|
286
|
+
* 'silent').
|
287
|
+
*/
|
288
|
+
static png_bytep
|
289
|
+
png_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)
|
290
|
+
{
|
291
|
+
png_bytep buffer = png_ptr->read_buffer;
|
292
|
+
|
293
|
+
if (buffer != NULL && new_size > png_ptr->read_buffer_size)
|
294
|
+
{
|
295
|
+
png_ptr->read_buffer = NULL;
|
296
|
+
png_ptr->read_buffer = NULL;
|
297
|
+
png_ptr->read_buffer_size = 0;
|
298
|
+
png_free(png_ptr, buffer);
|
299
|
+
buffer = NULL;
|
300
|
+
}
|
301
|
+
|
302
|
+
if (buffer == NULL)
|
303
|
+
{
|
304
|
+
buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size));
|
305
|
+
|
306
|
+
if (buffer != NULL)
|
307
|
+
{
|
308
|
+
png_ptr->read_buffer = buffer;
|
309
|
+
png_ptr->read_buffer_size = new_size;
|
310
|
+
}
|
311
|
+
|
312
|
+
else if (warn < 2) /* else silent */
|
313
|
+
{
|
314
|
+
if (warn != 0)
|
315
|
+
png_chunk_warning(png_ptr, "insufficient memory to read chunk");
|
316
|
+
|
317
|
+
else
|
318
|
+
png_chunk_error(png_ptr, "insufficient memory to read chunk");
|
319
|
+
}
|
320
|
+
}
|
321
|
+
|
322
|
+
return buffer;
|
323
|
+
}
|
324
|
+
#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */
|
325
|
+
|
326
|
+
/* png_inflate_claim: claim the zstream for some nefarious purpose that involves
|
327
|
+
* decompression. Returns Z_OK on success, else a zlib error code. It checks
|
328
|
+
* the owner but, in final release builds, just issues a warning if some other
|
329
|
+
* chunk apparently owns the stream. Prior to release it does a png_error.
|
330
|
+
*/
|
331
|
+
static int
|
332
|
+
png_inflate_claim(png_structrp png_ptr, png_uint_32 owner)
|
333
|
+
{
|
334
|
+
if (png_ptr->zowner != 0)
|
335
|
+
{
|
336
|
+
char msg[64];
|
337
|
+
|
338
|
+
PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner);
|
339
|
+
/* So the message that results is "<chunk> using zstream"; this is an
|
340
|
+
* internal error, but is very useful for debugging. i18n requirements
|
341
|
+
* are minimal.
|
342
|
+
*/
|
343
|
+
(void)png_safecat(msg, (sizeof msg), 4, " using zstream");
|
344
|
+
#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC
|
345
|
+
png_chunk_warning(png_ptr, msg);
|
346
|
+
png_ptr->zowner = 0;
|
347
|
+
#else
|
348
|
+
png_chunk_error(png_ptr, msg);
|
349
|
+
#endif
|
350
|
+
}
|
351
|
+
|
352
|
+
/* Implementation note: unlike 'png_deflate_claim' this internal function
|
353
|
+
* does not take the size of the data as an argument. Some efficiency could
|
354
|
+
* be gained by using this when it is known *if* the zlib stream itself does
|
355
|
+
* not record the number; however, this is an illusion: the original writer
|
356
|
+
* of the PNG may have selected a lower window size, and we really must
|
357
|
+
* follow that because, for systems with with limited capabilities, we
|
358
|
+
* would otherwise reject the application's attempts to use a smaller window
|
359
|
+
* size (zlib doesn't have an interface to say "this or lower"!).
|
360
|
+
*
|
361
|
+
* inflateReset2 was added to zlib 1.2.4; before this the window could not be
|
362
|
+
* reset, therefore it is necessary to always allocate the maximum window
|
363
|
+
* size with earlier zlibs just in case later compressed chunks need it.
|
364
|
+
*/
|
365
|
+
{
|
366
|
+
int ret; /* zlib return code */
|
367
|
+
#if PNG_ZLIB_VERNUM >= 0x1240
|
368
|
+
|
369
|
+
# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)
|
370
|
+
int window_bits;
|
371
|
+
|
372
|
+
if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==
|
373
|
+
PNG_OPTION_ON)
|
374
|
+
window_bits = 15;
|
375
|
+
|
376
|
+
else
|
377
|
+
window_bits = 0;
|
378
|
+
# else
|
379
|
+
# define window_bits 0
|
380
|
+
# endif
|
381
|
+
#endif
|
382
|
+
|
383
|
+
/* Set this for safety, just in case the previous owner left pointers to
|
384
|
+
* memory allocations.
|
385
|
+
*/
|
386
|
+
png_ptr->zstream.next_in = NULL;
|
387
|
+
png_ptr->zstream.avail_in = 0;
|
388
|
+
png_ptr->zstream.next_out = NULL;
|
389
|
+
png_ptr->zstream.avail_out = 0;
|
390
|
+
|
391
|
+
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
|
392
|
+
{
|
393
|
+
#if PNG_ZLIB_VERNUM < 0x1240
|
394
|
+
ret = inflateReset(&png_ptr->zstream);
|
395
|
+
#else
|
396
|
+
ret = inflateReset2(&png_ptr->zstream, window_bits);
|
397
|
+
#endif
|
398
|
+
}
|
399
|
+
|
400
|
+
else
|
401
|
+
{
|
402
|
+
#if PNG_ZLIB_VERNUM < 0x1240
|
403
|
+
ret = inflateInit(&png_ptr->zstream);
|
404
|
+
#else
|
405
|
+
ret = inflateInit2(&png_ptr->zstream, window_bits);
|
406
|
+
#endif
|
407
|
+
|
408
|
+
if (ret == Z_OK)
|
409
|
+
png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;
|
410
|
+
}
|
411
|
+
|
412
|
+
if (ret == Z_OK)
|
413
|
+
png_ptr->zowner = owner;
|
414
|
+
|
415
|
+
else
|
416
|
+
png_zstream_error(png_ptr, ret);
|
417
|
+
|
418
|
+
return ret;
|
419
|
+
}
|
420
|
+
|
421
|
+
#ifdef window_bits
|
422
|
+
# undef window_bits
|
423
|
+
#endif
|
424
|
+
}
|
425
|
+
|
426
|
+
#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
|
427
|
+
/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to
|
428
|
+
* allow the caller to do multiple calls if required. If the 'finish' flag is
|
429
|
+
* set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must
|
430
|
+
* be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and
|
431
|
+
* Z_OK or Z_STREAM_END will be returned on success.
|
432
|
+
*
|
433
|
+
* The input and output sizes are updated to the actual amounts of data consumed
|
434
|
+
* or written, not the amount available (as in a z_stream). The data pointers
|
435
|
+
* are not changed, so the next input is (data+input_size) and the next
|
436
|
+
* available output is (output+output_size).
|
437
|
+
*/
|
438
|
+
static int
|
439
|
+
png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,
|
440
|
+
/* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr,
|
441
|
+
/* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr)
|
442
|
+
{
|
443
|
+
if (png_ptr->zowner == owner) /* Else not claimed */
|
444
|
+
{
|
445
|
+
int ret;
|
446
|
+
png_alloc_size_t avail_out = *output_size_ptr;
|
447
|
+
png_uint_32 avail_in = *input_size_ptr;
|
448
|
+
|
449
|
+
/* zlib can't necessarily handle more than 65535 bytes at once (i.e. it
|
450
|
+
* can't even necessarily handle 65536 bytes) because the type uInt is
|
451
|
+
* "16 bits or more". Consequently it is necessary to chunk the input to
|
452
|
+
* zlib. This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the
|
453
|
+
* maximum value that can be stored in a uInt.) It is possible to set
|
454
|
+
* ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have
|
455
|
+
* a performance advantage, because it reduces the amount of data accessed
|
456
|
+
* at each step and that may give the OS more time to page it in.
|
457
|
+
*/
|
458
|
+
png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input);
|
459
|
+
/* avail_in and avail_out are set below from 'size' */
|
460
|
+
png_ptr->zstream.avail_in = 0;
|
461
|
+
png_ptr->zstream.avail_out = 0;
|
462
|
+
|
463
|
+
/* Read directly into the output if it is available (this is set to
|
464
|
+
* a local buffer below if output is NULL).
|
465
|
+
*/
|
466
|
+
if (output != NULL)
|
467
|
+
png_ptr->zstream.next_out = output;
|
468
|
+
|
469
|
+
do
|
470
|
+
{
|
471
|
+
uInt avail;
|
472
|
+
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
|
473
|
+
|
474
|
+
/* zlib INPUT BUFFER */
|
475
|
+
/* The setting of 'avail_in' used to be outside the loop; by setting it
|
476
|
+
* inside it is possible to chunk the input to zlib and simply rely on
|
477
|
+
* zlib to advance the 'next_in' pointer. This allows arbitrary
|
478
|
+
* amounts of data to be passed through zlib at the unavoidable cost of
|
479
|
+
* requiring a window save (memcpy of up to 32768 output bytes)
|
480
|
+
* every ZLIB_IO_MAX input bytes.
|
481
|
+
*/
|
482
|
+
avail_in += png_ptr->zstream.avail_in; /* not consumed last time */
|
483
|
+
|
484
|
+
avail = ZLIB_IO_MAX;
|
485
|
+
|
486
|
+
if (avail_in < avail)
|
487
|
+
avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */
|
488
|
+
|
489
|
+
avail_in -= avail;
|
490
|
+
png_ptr->zstream.avail_in = avail;
|
491
|
+
|
492
|
+
/* zlib OUTPUT BUFFER */
|
493
|
+
avail_out += png_ptr->zstream.avail_out; /* not written last time */
|
494
|
+
|
495
|
+
avail = ZLIB_IO_MAX; /* maximum zlib can process */
|
496
|
+
|
497
|
+
if (output == NULL)
|
498
|
+
{
|
499
|
+
/* Reset the output buffer each time round if output is NULL and
|
500
|
+
* make available the full buffer, up to 'remaining_space'
|
501
|
+
*/
|
502
|
+
png_ptr->zstream.next_out = local_buffer;
|
503
|
+
if ((sizeof local_buffer) < avail)
|
504
|
+
avail = (sizeof local_buffer);
|
505
|
+
}
|
506
|
+
|
507
|
+
if (avail_out < avail)
|
508
|
+
avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */
|
509
|
+
|
510
|
+
png_ptr->zstream.avail_out = avail;
|
511
|
+
avail_out -= avail;
|
512
|
+
|
513
|
+
/* zlib inflate call */
|
514
|
+
/* In fact 'avail_out' may be 0 at this point, that happens at the end
|
515
|
+
* of the read when the final LZ end code was not passed at the end of
|
516
|
+
* the previous chunk of input data. Tell zlib if we have reached the
|
517
|
+
* end of the output buffer.
|
518
|
+
*/
|
519
|
+
ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH :
|
520
|
+
(finish ? Z_FINISH : Z_SYNC_FLUSH));
|
521
|
+
} while (ret == Z_OK);
|
522
|
+
|
523
|
+
/* For safety kill the local buffer pointer now */
|
524
|
+
if (output == NULL)
|
525
|
+
png_ptr->zstream.next_out = NULL;
|
526
|
+
|
527
|
+
/* Claw back the 'size' and 'remaining_space' byte counts. */
|
528
|
+
avail_in += png_ptr->zstream.avail_in;
|
529
|
+
avail_out += png_ptr->zstream.avail_out;
|
530
|
+
|
531
|
+
/* Update the input and output sizes; the updated values are the amount
|
532
|
+
* consumed or written, effectively the inverse of what zlib uses.
|
533
|
+
*/
|
534
|
+
if (avail_out > 0)
|
535
|
+
*output_size_ptr -= avail_out;
|
536
|
+
|
537
|
+
if (avail_in > 0)
|
538
|
+
*input_size_ptr -= avail_in;
|
539
|
+
|
540
|
+
/* Ensure png_ptr->zstream.msg is set (even in the success case!) */
|
541
|
+
png_zstream_error(png_ptr, ret);
|
542
|
+
return ret;
|
543
|
+
}
|
544
|
+
|
545
|
+
else
|
546
|
+
{
|
547
|
+
/* This is a bad internal error. The recovery assigns to the zstream msg
|
548
|
+
* pointer, which is not owned by the caller, but this is safe; it's only
|
549
|
+
* used on errors!
|
550
|
+
*/
|
551
|
+
png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed");
|
552
|
+
return Z_STREAM_ERROR;
|
553
|
+
}
|
554
|
+
}
|
555
|
+
|
556
|
+
/*
|
557
|
+
* Decompress trailing data in a chunk. The assumption is that read_buffer
|
558
|
+
* points at an allocated area holding the contents of a chunk with a
|
559
|
+
* trailing compressed part. What we get back is an allocated area
|
560
|
+
* holding the original prefix part and an uncompressed version of the
|
561
|
+
* trailing part (the malloc area passed in is freed).
|
562
|
+
*/
|
563
|
+
static int
|
564
|
+
png_decompress_chunk(png_structrp png_ptr,
|
565
|
+
png_uint_32 chunklength, png_uint_32 prefix_size,
|
566
|
+
png_alloc_size_t *newlength /* must be initialized to the maximum! */,
|
567
|
+
int terminate /*add a '\0' to the end of the uncompressed data*/)
|
568
|
+
{
|
569
|
+
/* TODO: implement different limits for different types of chunk.
|
570
|
+
*
|
571
|
+
* The caller supplies *newlength set to the maximum length of the
|
572
|
+
* uncompressed data, but this routine allocates space for the prefix and
|
573
|
+
* maybe a '\0' terminator too. We have to assume that 'prefix_size' is
|
574
|
+
* limited only by the maximum chunk size.
|
575
|
+
*/
|
576
|
+
png_alloc_size_t limit = PNG_SIZE_MAX;
|
577
|
+
|
578
|
+
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
|
579
|
+
if (png_ptr->user_chunk_malloc_max > 0 &&
|
580
|
+
png_ptr->user_chunk_malloc_max < limit)
|
581
|
+
limit = png_ptr->user_chunk_malloc_max;
|
582
|
+
# elif PNG_USER_CHUNK_MALLOC_MAX > 0
|
583
|
+
if (PNG_USER_CHUNK_MALLOC_MAX < limit)
|
584
|
+
limit = PNG_USER_CHUNK_MALLOC_MAX;
|
585
|
+
# endif
|
586
|
+
|
587
|
+
if (limit >= prefix_size + (terminate != 0))
|
588
|
+
{
|
589
|
+
int ret;
|
590
|
+
|
591
|
+
limit -= prefix_size + (terminate != 0);
|
592
|
+
|
593
|
+
if (limit < *newlength)
|
594
|
+
*newlength = limit;
|
595
|
+
|
596
|
+
/* Now try to claim the stream. */
|
597
|
+
ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);
|
598
|
+
|
599
|
+
if (ret == Z_OK)
|
600
|
+
{
|
601
|
+
png_uint_32 lzsize = chunklength - prefix_size;
|
602
|
+
|
603
|
+
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
|
604
|
+
/* input: */ png_ptr->read_buffer + prefix_size, &lzsize,
|
605
|
+
/* output: */ NULL, newlength);
|
606
|
+
|
607
|
+
if (ret == Z_STREAM_END)
|
608
|
+
{
|
609
|
+
/* Use 'inflateReset' here, not 'inflateReset2' because this
|
610
|
+
* preserves the previously decided window size (otherwise it would
|
611
|
+
* be necessary to store the previous window size.) In practice
|
612
|
+
* this doesn't matter anyway, because png_inflate will call inflate
|
613
|
+
* with Z_FINISH in almost all cases, so the window will not be
|
614
|
+
* maintained.
|
615
|
+
*/
|
616
|
+
if (inflateReset(&png_ptr->zstream) == Z_OK)
|
617
|
+
{
|
618
|
+
/* Because of the limit checks above we know that the new,
|
619
|
+
* expanded, size will fit in a size_t (let alone an
|
620
|
+
* png_alloc_size_t). Use png_malloc_base here to avoid an
|
621
|
+
* extra OOM message.
|
622
|
+
*/
|
623
|
+
png_alloc_size_t new_size = *newlength;
|
624
|
+
png_alloc_size_t buffer_size = prefix_size + new_size +
|
625
|
+
(terminate != 0);
|
626
|
+
png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,
|
627
|
+
buffer_size));
|
628
|
+
|
629
|
+
if (text != NULL)
|
630
|
+
{
|
631
|
+
ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,
|
632
|
+
png_ptr->read_buffer + prefix_size, &lzsize,
|
633
|
+
text + prefix_size, newlength);
|
634
|
+
|
635
|
+
if (ret == Z_STREAM_END)
|
636
|
+
{
|
637
|
+
if (new_size == *newlength)
|
638
|
+
{
|
639
|
+
if (terminate != 0)
|
640
|
+
text[prefix_size + *newlength] = 0;
|
641
|
+
|
642
|
+
if (prefix_size > 0)
|
643
|
+
memcpy(text, png_ptr->read_buffer, prefix_size);
|
644
|
+
|
645
|
+
{
|
646
|
+
png_bytep old_ptr = png_ptr->read_buffer;
|
647
|
+
|
648
|
+
png_ptr->read_buffer = text;
|
649
|
+
png_ptr->read_buffer_size = buffer_size;
|
650
|
+
text = old_ptr; /* freed below */
|
651
|
+
}
|
652
|
+
}
|
653
|
+
|
654
|
+
else
|
655
|
+
{
|
656
|
+
/* The size changed on the second read, there can be no
|
657
|
+
* guarantee that anything is correct at this point.
|
658
|
+
* The 'msg' pointer has been set to "unexpected end of
|
659
|
+
* LZ stream", which is fine, but return an error code
|
660
|
+
* that the caller won't accept.
|
661
|
+
*/
|
662
|
+
ret = PNG_UNEXPECTED_ZLIB_RETURN;
|
663
|
+
}
|
664
|
+
}
|
665
|
+
|
666
|
+
else if (ret == Z_OK)
|
667
|
+
ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */
|
668
|
+
|
669
|
+
/* Free the text pointer (this is the old read_buffer on
|
670
|
+
* success)
|
671
|
+
*/
|
672
|
+
png_free(png_ptr, text);
|
673
|
+
text = NULL;
|
674
|
+
|
675
|
+
/* This really is very benign, but it's still an error because
|
676
|
+
* the extra space may otherwise be used as a Trojan Horse.
|
677
|
+
*/
|
678
|
+
if (ret == Z_STREAM_END &&
|
679
|
+
chunklength - prefix_size != lzsize)
|
680
|
+
png_chunk_benign_error(png_ptr, "extra compressed data");
|
681
|
+
}
|
682
|
+
|
683
|
+
else
|
684
|
+
{
|
685
|
+
/* Out of memory allocating the buffer */
|
686
|
+
ret = Z_MEM_ERROR;
|
687
|
+
png_zstream_error(png_ptr, Z_MEM_ERROR);
|
688
|
+
}
|
689
|
+
}
|
690
|
+
|
691
|
+
else
|
692
|
+
{
|
693
|
+
/* inflateReset failed, store the error message */
|
694
|
+
png_zstream_error(png_ptr, ret);
|
695
|
+
|
696
|
+
if (ret == Z_STREAM_END)
|
697
|
+
ret = PNG_UNEXPECTED_ZLIB_RETURN;
|
698
|
+
}
|
699
|
+
}
|
700
|
+
|
701
|
+
else if (ret == Z_OK)
|
702
|
+
ret = PNG_UNEXPECTED_ZLIB_RETURN;
|
703
|
+
|
704
|
+
/* Release the claimed stream */
|
705
|
+
png_ptr->zowner = 0;
|
706
|
+
}
|
707
|
+
|
708
|
+
else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */
|
709
|
+
ret = PNG_UNEXPECTED_ZLIB_RETURN;
|
710
|
+
|
711
|
+
return ret;
|
712
|
+
}
|
713
|
+
|
714
|
+
else
|
715
|
+
{
|
716
|
+
/* Application/configuration limits exceeded */
|
717
|
+
png_zstream_error(png_ptr, Z_MEM_ERROR);
|
718
|
+
return Z_MEM_ERROR;
|
719
|
+
}
|
720
|
+
}
|
721
|
+
#endif /* READ_COMPRESSED_TEXT */
|
722
|
+
|
723
|
+
#ifdef PNG_READ_iCCP_SUPPORTED
|
724
|
+
/* Perform a partial read and decompress, producing 'avail_out' bytes and
|
725
|
+
* reading from the current chunk as required.
|
726
|
+
*/
|
727
|
+
static int
|
728
|
+
png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,
|
729
|
+
png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,
|
730
|
+
int finish)
|
731
|
+
{
|
732
|
+
if (png_ptr->zowner == png_ptr->chunk_name)
|
733
|
+
{
|
734
|
+
int ret;
|
735
|
+
|
736
|
+
/* next_in and avail_in must have been initialized by the caller. */
|
737
|
+
png_ptr->zstream.next_out = next_out;
|
738
|
+
png_ptr->zstream.avail_out = 0; /* set in the loop */
|
739
|
+
|
740
|
+
do
|
741
|
+
{
|
742
|
+
if (png_ptr->zstream.avail_in == 0)
|
743
|
+
{
|
744
|
+
if (read_size > *chunk_bytes)
|
745
|
+
read_size = (uInt)*chunk_bytes;
|
746
|
+
*chunk_bytes -= read_size;
|
747
|
+
|
748
|
+
if (read_size > 0)
|
749
|
+
png_crc_read(png_ptr, read_buffer, read_size);
|
750
|
+
|
751
|
+
png_ptr->zstream.next_in = read_buffer;
|
752
|
+
png_ptr->zstream.avail_in = read_size;
|
753
|
+
}
|
754
|
+
|
755
|
+
if (png_ptr->zstream.avail_out == 0)
|
756
|
+
{
|
757
|
+
uInt avail = ZLIB_IO_MAX;
|
758
|
+
if (avail > *out_size)
|
759
|
+
avail = (uInt)*out_size;
|
760
|
+
*out_size -= avail;
|
761
|
+
|
762
|
+
png_ptr->zstream.avail_out = avail;
|
763
|
+
}
|
764
|
+
|
765
|
+
/* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all
|
766
|
+
* the available output is produced; this allows reading of truncated
|
767
|
+
* streams.
|
768
|
+
*/
|
769
|
+
ret = inflate(&png_ptr->zstream,
|
770
|
+
*chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));
|
771
|
+
}
|
772
|
+
while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));
|
773
|
+
|
774
|
+
*out_size += png_ptr->zstream.avail_out;
|
775
|
+
png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */
|
776
|
+
|
777
|
+
/* Ensure the error message pointer is always set: */
|
778
|
+
png_zstream_error(png_ptr, ret);
|
779
|
+
return ret;
|
780
|
+
}
|
781
|
+
|
782
|
+
else
|
783
|
+
{
|
784
|
+
png_ptr->zstream.msg = PNGZ_MSG_CAST("zstream unclaimed");
|
785
|
+
return Z_STREAM_ERROR;
|
786
|
+
}
|
787
|
+
}
|
788
|
+
#endif
|
789
|
+
|
790
|
+
/* Read and check the IDHR chunk */
|
791
|
+
|
792
|
+
void /* PRIVATE */
|
793
|
+
png_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
794
|
+
{
|
795
|
+
png_byte buf[13];
|
796
|
+
png_uint_32 width, height;
|
797
|
+
int bit_depth, color_type, compression_type, filter_type;
|
798
|
+
int interlace_type;
|
799
|
+
|
800
|
+
png_debug(1, "in png_handle_IHDR");
|
801
|
+
|
802
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) != 0)
|
803
|
+
png_chunk_error(png_ptr, "out of place");
|
804
|
+
|
805
|
+
/* Check the length */
|
806
|
+
if (length != 13)
|
807
|
+
png_chunk_error(png_ptr, "invalid");
|
808
|
+
|
809
|
+
png_ptr->mode |= PNG_HAVE_IHDR;
|
810
|
+
|
811
|
+
png_crc_read(png_ptr, buf, 13);
|
812
|
+
png_crc_finish(png_ptr, 0);
|
813
|
+
|
814
|
+
width = png_get_uint_31(png_ptr, buf);
|
815
|
+
height = png_get_uint_31(png_ptr, buf + 4);
|
816
|
+
bit_depth = buf[8];
|
817
|
+
color_type = buf[9];
|
818
|
+
compression_type = buf[10];
|
819
|
+
filter_type = buf[11];
|
820
|
+
interlace_type = buf[12];
|
821
|
+
|
822
|
+
/* Set internal variables */
|
823
|
+
png_ptr->width = width;
|
824
|
+
png_ptr->height = height;
|
825
|
+
png_ptr->bit_depth = (png_byte)bit_depth;
|
826
|
+
png_ptr->interlaced = (png_byte)interlace_type;
|
827
|
+
png_ptr->color_type = (png_byte)color_type;
|
828
|
+
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
829
|
+
png_ptr->filter_type = (png_byte)filter_type;
|
830
|
+
#endif
|
831
|
+
png_ptr->compression_type = (png_byte)compression_type;
|
832
|
+
|
833
|
+
/* Find number of channels */
|
834
|
+
switch (png_ptr->color_type)
|
835
|
+
{
|
836
|
+
default: /* invalid, png_set_IHDR calls png_error */
|
837
|
+
case PNG_COLOR_TYPE_GRAY:
|
838
|
+
case PNG_COLOR_TYPE_PALETTE:
|
839
|
+
png_ptr->channels = 1;
|
840
|
+
break;
|
841
|
+
|
842
|
+
case PNG_COLOR_TYPE_RGB:
|
843
|
+
png_ptr->channels = 3;
|
844
|
+
break;
|
845
|
+
|
846
|
+
case PNG_COLOR_TYPE_GRAY_ALPHA:
|
847
|
+
png_ptr->channels = 2;
|
848
|
+
break;
|
849
|
+
|
850
|
+
case PNG_COLOR_TYPE_RGB_ALPHA:
|
851
|
+
png_ptr->channels = 4;
|
852
|
+
break;
|
853
|
+
}
|
854
|
+
|
855
|
+
/* Set up other useful info */
|
856
|
+
png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);
|
857
|
+
png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
|
858
|
+
png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
|
859
|
+
png_debug1(3, "channels = %d", png_ptr->channels);
|
860
|
+
png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes);
|
861
|
+
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
|
862
|
+
color_type, interlace_type, compression_type, filter_type);
|
863
|
+
}
|
864
|
+
|
865
|
+
/* Read and check the palette */
|
866
|
+
void /* PRIVATE */
|
867
|
+
png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
868
|
+
{
|
869
|
+
png_color palette[PNG_MAX_PALETTE_LENGTH];
|
870
|
+
int num, i;
|
871
|
+
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
872
|
+
png_colorp pal_ptr;
|
873
|
+
#endif
|
874
|
+
|
875
|
+
png_debug(1, "in png_handle_PLTE");
|
876
|
+
|
877
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
878
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
879
|
+
|
880
|
+
/* Moved to before the 'after IDAT' check below because otherwise duplicate
|
881
|
+
* PLTE chunks are potentially ignored (the spec says there shall not be more
|
882
|
+
* than one PLTE, the error is not treated as benign, so this check trumps
|
883
|
+
* the requirement that PLTE appears before IDAT.)
|
884
|
+
*/
|
885
|
+
else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0)
|
886
|
+
png_chunk_error(png_ptr, "duplicate");
|
887
|
+
|
888
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
889
|
+
{
|
890
|
+
/* This is benign because the non-benign error happened before, when an
|
891
|
+
* IDAT was encountered in a color-mapped image with no PLTE.
|
892
|
+
*/
|
893
|
+
png_crc_finish(png_ptr, length);
|
894
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
895
|
+
return;
|
896
|
+
}
|
897
|
+
|
898
|
+
png_ptr->mode |= PNG_HAVE_PLTE;
|
899
|
+
|
900
|
+
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)
|
901
|
+
{
|
902
|
+
png_crc_finish(png_ptr, length);
|
903
|
+
png_chunk_benign_error(png_ptr, "ignored in grayscale PNG");
|
904
|
+
return;
|
905
|
+
}
|
906
|
+
|
907
|
+
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
|
908
|
+
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
909
|
+
{
|
910
|
+
png_crc_finish(png_ptr, length);
|
911
|
+
return;
|
912
|
+
}
|
913
|
+
#endif
|
914
|
+
|
915
|
+
if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
|
916
|
+
{
|
917
|
+
png_crc_finish(png_ptr, length);
|
918
|
+
|
919
|
+
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
920
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
921
|
+
|
922
|
+
else
|
923
|
+
png_chunk_error(png_ptr, "invalid");
|
924
|
+
|
925
|
+
return;
|
926
|
+
}
|
927
|
+
|
928
|
+
/* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */
|
929
|
+
num = (int)length / 3;
|
930
|
+
|
931
|
+
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
932
|
+
for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
|
933
|
+
{
|
934
|
+
png_byte buf[3];
|
935
|
+
|
936
|
+
png_crc_read(png_ptr, buf, 3);
|
937
|
+
pal_ptr->red = buf[0];
|
938
|
+
pal_ptr->green = buf[1];
|
939
|
+
pal_ptr->blue = buf[2];
|
940
|
+
}
|
941
|
+
#else
|
942
|
+
for (i = 0; i < num; i++)
|
943
|
+
{
|
944
|
+
png_byte buf[3];
|
945
|
+
|
946
|
+
png_crc_read(png_ptr, buf, 3);
|
947
|
+
/* Don't depend upon png_color being any order */
|
948
|
+
palette[i].red = buf[0];
|
949
|
+
palette[i].green = buf[1];
|
950
|
+
palette[i].blue = buf[2];
|
951
|
+
}
|
952
|
+
#endif
|
953
|
+
|
954
|
+
/* If we actually need the PLTE chunk (ie for a paletted image), we do
|
955
|
+
* whatever the normal CRC configuration tells us. However, if we
|
956
|
+
* have an RGB image, the PLTE can be considered ancillary, so
|
957
|
+
* we will act as though it is.
|
958
|
+
*/
|
959
|
+
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
|
960
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
961
|
+
#endif
|
962
|
+
{
|
963
|
+
png_crc_finish(png_ptr, 0);
|
964
|
+
}
|
965
|
+
|
966
|
+
#ifndef PNG_READ_OPT_PLTE_SUPPORTED
|
967
|
+
else if (png_crc_error(png_ptr) != 0) /* Only if we have a CRC error */
|
968
|
+
{
|
969
|
+
/* If we don't want to use the data from an ancillary chunk,
|
970
|
+
* we have two options: an error abort, or a warning and we
|
971
|
+
* ignore the data in this chunk (which should be OK, since
|
972
|
+
* it's considered ancillary for a RGB or RGBA image).
|
973
|
+
*
|
974
|
+
* IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the
|
975
|
+
* chunk type to determine whether to check the ancillary or the critical
|
976
|
+
* flags.
|
977
|
+
*/
|
978
|
+
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0)
|
979
|
+
{
|
980
|
+
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0)
|
981
|
+
return;
|
982
|
+
|
983
|
+
else
|
984
|
+
png_chunk_error(png_ptr, "CRC error");
|
985
|
+
}
|
986
|
+
|
987
|
+
/* Otherwise, we (optionally) emit a warning and use the chunk. */
|
988
|
+
else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0)
|
989
|
+
png_chunk_warning(png_ptr, "CRC error");
|
990
|
+
}
|
991
|
+
#endif
|
992
|
+
|
993
|
+
/* TODO: png_set_PLTE has the side effect of setting png_ptr->palette to its
|
994
|
+
* own copy of the palette. This has the side effect that when png_start_row
|
995
|
+
* is called (this happens after any call to png_read_update_info) the
|
996
|
+
* info_ptr palette gets changed. This is extremely unexpected and
|
997
|
+
* confusing.
|
998
|
+
*
|
999
|
+
* Fix this by not sharing the palette in this way.
|
1000
|
+
*/
|
1001
|
+
png_set_PLTE(png_ptr, info_ptr, palette, num);
|
1002
|
+
|
1003
|
+
/* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before
|
1004
|
+
* IDAT. Prior to 1.6.0 this was not checked; instead the code merely
|
1005
|
+
* checked the apparent validity of a tRNS chunk inserted before PLTE on a
|
1006
|
+
* palette PNG. 1.6.0 attempts to rigorously follow the standard and
|
1007
|
+
* therefore does a benign error if the erroneous condition is detected *and*
|
1008
|
+
* cancels the tRNS if the benign error returns. The alternative is to
|
1009
|
+
* amend the standard since it would be rather hypocritical of the standards
|
1010
|
+
* maintainers to ignore it.
|
1011
|
+
*/
|
1012
|
+
#ifdef PNG_READ_tRNS_SUPPORTED
|
1013
|
+
if (png_ptr->num_trans > 0 ||
|
1014
|
+
(info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))
|
1015
|
+
{
|
1016
|
+
/* Cancel this because otherwise it would be used if the transforms
|
1017
|
+
* require it. Don't cancel the 'valid' flag because this would prevent
|
1018
|
+
* detection of duplicate chunks.
|
1019
|
+
*/
|
1020
|
+
png_ptr->num_trans = 0;
|
1021
|
+
|
1022
|
+
if (info_ptr != NULL)
|
1023
|
+
info_ptr->num_trans = 0;
|
1024
|
+
|
1025
|
+
png_chunk_benign_error(png_ptr, "tRNS must be after");
|
1026
|
+
}
|
1027
|
+
#endif
|
1028
|
+
|
1029
|
+
#ifdef PNG_READ_hIST_SUPPORTED
|
1030
|
+
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)
|
1031
|
+
png_chunk_benign_error(png_ptr, "hIST must be after");
|
1032
|
+
#endif
|
1033
|
+
|
1034
|
+
#ifdef PNG_READ_bKGD_SUPPORTED
|
1035
|
+
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)
|
1036
|
+
png_chunk_benign_error(png_ptr, "bKGD must be after");
|
1037
|
+
#endif
|
1038
|
+
}
|
1039
|
+
|
1040
|
+
void /* PRIVATE */
|
1041
|
+
png_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1042
|
+
{
|
1043
|
+
png_debug(1, "in png_handle_IEND");
|
1044
|
+
|
1045
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 ||
|
1046
|
+
(png_ptr->mode & PNG_HAVE_IDAT) == 0)
|
1047
|
+
png_chunk_error(png_ptr, "out of place");
|
1048
|
+
|
1049
|
+
png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
|
1050
|
+
|
1051
|
+
png_crc_finish(png_ptr, length);
|
1052
|
+
|
1053
|
+
if (length != 0)
|
1054
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1055
|
+
|
1056
|
+
PNG_UNUSED(info_ptr)
|
1057
|
+
}
|
1058
|
+
|
1059
|
+
#ifdef PNG_READ_gAMA_SUPPORTED
|
1060
|
+
void /* PRIVATE */
|
1061
|
+
png_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1062
|
+
{
|
1063
|
+
png_fixed_point igamma;
|
1064
|
+
png_byte buf[4];
|
1065
|
+
|
1066
|
+
png_debug(1, "in png_handle_gAMA");
|
1067
|
+
|
1068
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1069
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1070
|
+
|
1071
|
+
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
|
1072
|
+
{
|
1073
|
+
png_crc_finish(png_ptr, length);
|
1074
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1075
|
+
return;
|
1076
|
+
}
|
1077
|
+
|
1078
|
+
if (length != 4)
|
1079
|
+
{
|
1080
|
+
png_crc_finish(png_ptr, length);
|
1081
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1082
|
+
return;
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
png_crc_read(png_ptr, buf, 4);
|
1086
|
+
|
1087
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1088
|
+
return;
|
1089
|
+
|
1090
|
+
igamma = png_get_fixed_point(NULL, buf);
|
1091
|
+
|
1092
|
+
png_colorspace_set_gamma(png_ptr, &png_ptr->colorspace, igamma);
|
1093
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1094
|
+
}
|
1095
|
+
#endif
|
1096
|
+
|
1097
|
+
#ifdef PNG_READ_sBIT_SUPPORTED
|
1098
|
+
void /* PRIVATE */
|
1099
|
+
png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1100
|
+
{
|
1101
|
+
unsigned int truelen, i;
|
1102
|
+
png_byte sample_depth;
|
1103
|
+
png_byte buf[4];
|
1104
|
+
|
1105
|
+
png_debug(1, "in png_handle_sBIT");
|
1106
|
+
|
1107
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1108
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1109
|
+
|
1110
|
+
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
|
1111
|
+
{
|
1112
|
+
png_crc_finish(png_ptr, length);
|
1113
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1114
|
+
return;
|
1115
|
+
}
|
1116
|
+
|
1117
|
+
if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0)
|
1118
|
+
{
|
1119
|
+
png_crc_finish(png_ptr, length);
|
1120
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
1121
|
+
return;
|
1122
|
+
}
|
1123
|
+
|
1124
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
1125
|
+
{
|
1126
|
+
truelen = 3;
|
1127
|
+
sample_depth = 8;
|
1128
|
+
}
|
1129
|
+
|
1130
|
+
else
|
1131
|
+
{
|
1132
|
+
truelen = png_ptr->channels;
|
1133
|
+
sample_depth = png_ptr->bit_depth;
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
if (length != truelen || length > 4)
|
1137
|
+
{
|
1138
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1139
|
+
png_crc_finish(png_ptr, length);
|
1140
|
+
return;
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;
|
1144
|
+
png_crc_read(png_ptr, buf, truelen);
|
1145
|
+
|
1146
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1147
|
+
return;
|
1148
|
+
|
1149
|
+
for (i=0; i<truelen; ++i)
|
1150
|
+
if (buf[i] == 0 || buf[i] > sample_depth)
|
1151
|
+
{
|
1152
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1153
|
+
return;
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
1157
|
+
{
|
1158
|
+
png_ptr->sig_bit.red = buf[0];
|
1159
|
+
png_ptr->sig_bit.green = buf[1];
|
1160
|
+
png_ptr->sig_bit.blue = buf[2];
|
1161
|
+
png_ptr->sig_bit.alpha = buf[3];
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
else
|
1165
|
+
{
|
1166
|
+
png_ptr->sig_bit.gray = buf[0];
|
1167
|
+
png_ptr->sig_bit.red = buf[0];
|
1168
|
+
png_ptr->sig_bit.green = buf[0];
|
1169
|
+
png_ptr->sig_bit.blue = buf[0];
|
1170
|
+
png_ptr->sig_bit.alpha = buf[1];
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
|
1174
|
+
}
|
1175
|
+
#endif
|
1176
|
+
|
1177
|
+
#ifdef PNG_READ_cHRM_SUPPORTED
|
1178
|
+
void /* PRIVATE */
|
1179
|
+
png_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1180
|
+
{
|
1181
|
+
png_byte buf[32];
|
1182
|
+
png_xy xy;
|
1183
|
+
|
1184
|
+
png_debug(1, "in png_handle_cHRM");
|
1185
|
+
|
1186
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1187
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1188
|
+
|
1189
|
+
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
|
1190
|
+
{
|
1191
|
+
png_crc_finish(png_ptr, length);
|
1192
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1193
|
+
return;
|
1194
|
+
}
|
1195
|
+
|
1196
|
+
if (length != 32)
|
1197
|
+
{
|
1198
|
+
png_crc_finish(png_ptr, length);
|
1199
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1200
|
+
return;
|
1201
|
+
}
|
1202
|
+
|
1203
|
+
png_crc_read(png_ptr, buf, 32);
|
1204
|
+
|
1205
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1206
|
+
return;
|
1207
|
+
|
1208
|
+
xy.whitex = png_get_fixed_point(NULL, buf);
|
1209
|
+
xy.whitey = png_get_fixed_point(NULL, buf + 4);
|
1210
|
+
xy.redx = png_get_fixed_point(NULL, buf + 8);
|
1211
|
+
xy.redy = png_get_fixed_point(NULL, buf + 12);
|
1212
|
+
xy.greenx = png_get_fixed_point(NULL, buf + 16);
|
1213
|
+
xy.greeny = png_get_fixed_point(NULL, buf + 20);
|
1214
|
+
xy.bluex = png_get_fixed_point(NULL, buf + 24);
|
1215
|
+
xy.bluey = png_get_fixed_point(NULL, buf + 28);
|
1216
|
+
|
1217
|
+
if (xy.whitex == PNG_FIXED_ERROR ||
|
1218
|
+
xy.whitey == PNG_FIXED_ERROR ||
|
1219
|
+
xy.redx == PNG_FIXED_ERROR ||
|
1220
|
+
xy.redy == PNG_FIXED_ERROR ||
|
1221
|
+
xy.greenx == PNG_FIXED_ERROR ||
|
1222
|
+
xy.greeny == PNG_FIXED_ERROR ||
|
1223
|
+
xy.bluex == PNG_FIXED_ERROR ||
|
1224
|
+
xy.bluey == PNG_FIXED_ERROR)
|
1225
|
+
{
|
1226
|
+
png_chunk_benign_error(png_ptr, "invalid values");
|
1227
|
+
return;
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
/* If a colorspace error has already been output skip this chunk */
|
1231
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
|
1232
|
+
return;
|
1233
|
+
|
1234
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0)
|
1235
|
+
{
|
1236
|
+
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
|
1237
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1238
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
1239
|
+
return;
|
1240
|
+
}
|
1241
|
+
|
1242
|
+
png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;
|
1243
|
+
(void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,
|
1244
|
+
1/*prefer cHRM values*/);
|
1245
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1246
|
+
}
|
1247
|
+
#endif
|
1248
|
+
|
1249
|
+
#ifdef PNG_READ_sRGB_SUPPORTED
|
1250
|
+
void /* PRIVATE */
|
1251
|
+
png_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1252
|
+
{
|
1253
|
+
png_byte intent;
|
1254
|
+
|
1255
|
+
png_debug(1, "in png_handle_sRGB");
|
1256
|
+
|
1257
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1258
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1259
|
+
|
1260
|
+
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
|
1261
|
+
{
|
1262
|
+
png_crc_finish(png_ptr, length);
|
1263
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1264
|
+
return;
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
if (length != 1)
|
1268
|
+
{
|
1269
|
+
png_crc_finish(png_ptr, length);
|
1270
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1271
|
+
return;
|
1272
|
+
}
|
1273
|
+
|
1274
|
+
png_crc_read(png_ptr, &intent, 1);
|
1275
|
+
|
1276
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1277
|
+
return;
|
1278
|
+
|
1279
|
+
/* If a colorspace error has already been output skip this chunk */
|
1280
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
|
1281
|
+
return;
|
1282
|
+
|
1283
|
+
/* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect
|
1284
|
+
* this.
|
1285
|
+
*/
|
1286
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0)
|
1287
|
+
{
|
1288
|
+
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
|
1289
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1290
|
+
png_chunk_benign_error(png_ptr, "too many profiles");
|
1291
|
+
return;
|
1292
|
+
}
|
1293
|
+
|
1294
|
+
(void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent);
|
1295
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1296
|
+
}
|
1297
|
+
#endif /* READ_sRGB */
|
1298
|
+
|
1299
|
+
#ifdef PNG_READ_iCCP_SUPPORTED
|
1300
|
+
void /* PRIVATE */
|
1301
|
+
png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1302
|
+
/* Note: this does not properly handle profiles that are > 64K under DOS */
|
1303
|
+
{
|
1304
|
+
png_const_charp errmsg = NULL; /* error message output, or no error */
|
1305
|
+
int finished = 0; /* crc checked */
|
1306
|
+
|
1307
|
+
png_debug(1, "in png_handle_iCCP");
|
1308
|
+
|
1309
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1310
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1311
|
+
|
1312
|
+
else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)
|
1313
|
+
{
|
1314
|
+
png_crc_finish(png_ptr, length);
|
1315
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1316
|
+
return;
|
1317
|
+
}
|
1318
|
+
|
1319
|
+
/* Consistent with all the above colorspace handling an obviously *invalid*
|
1320
|
+
* chunk is just ignored, so does not invalidate the color space. An
|
1321
|
+
* alternative is to set the 'invalid' flags at the start of this routine
|
1322
|
+
* and only clear them in they were not set before and all the tests pass.
|
1323
|
+
* The minimum 'deflate' stream is assumed to be just the 2 byte header and
|
1324
|
+
* 4 byte checksum. The keyword must be at least one character and there is
|
1325
|
+
* a terminator (0) byte and the compression method.
|
1326
|
+
*/
|
1327
|
+
if (length < 9)
|
1328
|
+
{
|
1329
|
+
png_crc_finish(png_ptr, length);
|
1330
|
+
png_chunk_benign_error(png_ptr, "too short");
|
1331
|
+
return;
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
/* If a colorspace error has already been output skip this chunk */
|
1335
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)
|
1336
|
+
{
|
1337
|
+
png_crc_finish(png_ptr, length);
|
1338
|
+
return;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
/* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect
|
1342
|
+
* this.
|
1343
|
+
*/
|
1344
|
+
if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) == 0)
|
1345
|
+
{
|
1346
|
+
uInt read_length, keyword_length;
|
1347
|
+
char keyword[81];
|
1348
|
+
|
1349
|
+
/* Find the keyword; the keyword plus separator and compression method
|
1350
|
+
* bytes can be at most 81 characters long.
|
1351
|
+
*/
|
1352
|
+
read_length = 81; /* maximum */
|
1353
|
+
if (read_length > length)
|
1354
|
+
read_length = (uInt)length;
|
1355
|
+
|
1356
|
+
png_crc_read(png_ptr, (png_bytep)keyword, read_length);
|
1357
|
+
length -= read_length;
|
1358
|
+
|
1359
|
+
keyword_length = 0;
|
1360
|
+
while (keyword_length < 80 && keyword_length < read_length &&
|
1361
|
+
keyword[keyword_length] != 0)
|
1362
|
+
++keyword_length;
|
1363
|
+
|
1364
|
+
/* TODO: make the keyword checking common */
|
1365
|
+
if (keyword_length >= 1 && keyword_length <= 79)
|
1366
|
+
{
|
1367
|
+
/* We only understand '0' compression - deflate - so if we get a
|
1368
|
+
* different value we can't safely decode the chunk.
|
1369
|
+
*/
|
1370
|
+
if (keyword_length+1 < read_length &&
|
1371
|
+
keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE)
|
1372
|
+
{
|
1373
|
+
read_length -= keyword_length+2;
|
1374
|
+
|
1375
|
+
if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)
|
1376
|
+
{
|
1377
|
+
Byte profile_header[132];
|
1378
|
+
Byte local_buffer[PNG_INFLATE_BUF_SIZE];
|
1379
|
+
png_alloc_size_t size = (sizeof profile_header);
|
1380
|
+
|
1381
|
+
png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);
|
1382
|
+
png_ptr->zstream.avail_in = read_length;
|
1383
|
+
(void)png_inflate_read(png_ptr, local_buffer,
|
1384
|
+
(sizeof local_buffer), &length, profile_header, &size,
|
1385
|
+
0/*finish: don't, because the output is too small*/);
|
1386
|
+
|
1387
|
+
if (size == 0)
|
1388
|
+
{
|
1389
|
+
/* We have the ICC profile header; do the basic header checks.
|
1390
|
+
*/
|
1391
|
+
const png_uint_32 profile_length =
|
1392
|
+
png_get_uint_32(profile_header);
|
1393
|
+
|
1394
|
+
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
|
1395
|
+
keyword, profile_length) != 0)
|
1396
|
+
{
|
1397
|
+
/* The length is apparently ok, so we can check the 132
|
1398
|
+
* byte header.
|
1399
|
+
*/
|
1400
|
+
if (png_icc_check_header(png_ptr, &png_ptr->colorspace,
|
1401
|
+
keyword, profile_length, profile_header,
|
1402
|
+
png_ptr->color_type) != 0)
|
1403
|
+
{
|
1404
|
+
/* Now read the tag table; a variable size buffer is
|
1405
|
+
* needed at this point, allocate one for the whole
|
1406
|
+
* profile. The header check has already validated
|
1407
|
+
* that none of these stuff will overflow.
|
1408
|
+
*/
|
1409
|
+
const png_uint_32 tag_count = png_get_uint_32(
|
1410
|
+
profile_header+128);
|
1411
|
+
png_bytep profile = png_read_buffer(png_ptr,
|
1412
|
+
profile_length, 2/*silent*/);
|
1413
|
+
|
1414
|
+
if (profile != NULL)
|
1415
|
+
{
|
1416
|
+
memcpy(profile, profile_header,
|
1417
|
+
(sizeof profile_header));
|
1418
|
+
|
1419
|
+
size = 12 * tag_count;
|
1420
|
+
|
1421
|
+
(void)png_inflate_read(png_ptr, local_buffer,
|
1422
|
+
(sizeof local_buffer), &length,
|
1423
|
+
profile + (sizeof profile_header), &size, 0);
|
1424
|
+
|
1425
|
+
/* Still expect a buffer error because we expect
|
1426
|
+
* there to be some tag data!
|
1427
|
+
*/
|
1428
|
+
if (size == 0)
|
1429
|
+
{
|
1430
|
+
if (png_icc_check_tag_table(png_ptr,
|
1431
|
+
&png_ptr->colorspace, keyword, profile_length,
|
1432
|
+
profile) != 0)
|
1433
|
+
{
|
1434
|
+
/* The profile has been validated for basic
|
1435
|
+
* security issues, so read the whole thing in.
|
1436
|
+
*/
|
1437
|
+
size = profile_length - (sizeof profile_header)
|
1438
|
+
- 12 * tag_count;
|
1439
|
+
|
1440
|
+
(void)png_inflate_read(png_ptr, local_buffer,
|
1441
|
+
(sizeof local_buffer), &length,
|
1442
|
+
profile + (sizeof profile_header) +
|
1443
|
+
12 * tag_count, &size, 1/*finish*/);
|
1444
|
+
|
1445
|
+
if (length > 0 && !(png_ptr->flags &
|
1446
|
+
PNG_FLAG_BENIGN_ERRORS_WARN))
|
1447
|
+
errmsg = "extra compressed data";
|
1448
|
+
|
1449
|
+
/* But otherwise allow extra data: */
|
1450
|
+
else if (size == 0)
|
1451
|
+
{
|
1452
|
+
if (length > 0)
|
1453
|
+
{
|
1454
|
+
/* This can be handled completely, so
|
1455
|
+
* keep going.
|
1456
|
+
*/
|
1457
|
+
png_chunk_warning(png_ptr,
|
1458
|
+
"extra compressed data");
|
1459
|
+
}
|
1460
|
+
|
1461
|
+
png_crc_finish(png_ptr, length);
|
1462
|
+
finished = 1;
|
1463
|
+
|
1464
|
+
# ifdef PNG_sRGB_SUPPORTED
|
1465
|
+
/* Check for a match against sRGB */
|
1466
|
+
png_icc_set_sRGB(png_ptr,
|
1467
|
+
&png_ptr->colorspace, profile,
|
1468
|
+
png_ptr->zstream.adler);
|
1469
|
+
# endif
|
1470
|
+
|
1471
|
+
/* Steal the profile for info_ptr. */
|
1472
|
+
if (info_ptr != NULL)
|
1473
|
+
{
|
1474
|
+
png_free_data(png_ptr, info_ptr,
|
1475
|
+
PNG_FREE_ICCP, 0);
|
1476
|
+
|
1477
|
+
info_ptr->iccp_name = png_voidcast(char*,
|
1478
|
+
png_malloc_base(png_ptr,
|
1479
|
+
keyword_length+1));
|
1480
|
+
if (info_ptr->iccp_name != NULL)
|
1481
|
+
{
|
1482
|
+
memcpy(info_ptr->iccp_name, keyword,
|
1483
|
+
keyword_length+1);
|
1484
|
+
info_ptr->iccp_proflen =
|
1485
|
+
profile_length;
|
1486
|
+
info_ptr->iccp_profile = profile;
|
1487
|
+
png_ptr->read_buffer = NULL; /*steal*/
|
1488
|
+
info_ptr->free_me |= PNG_FREE_ICCP;
|
1489
|
+
info_ptr->valid |= PNG_INFO_iCCP;
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
else
|
1493
|
+
{
|
1494
|
+
png_ptr->colorspace.flags |=
|
1495
|
+
PNG_COLORSPACE_INVALID;
|
1496
|
+
errmsg = "out of memory";
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
/* else the profile remains in the read
|
1501
|
+
* buffer which gets reused for subsequent
|
1502
|
+
* chunks.
|
1503
|
+
*/
|
1504
|
+
|
1505
|
+
if (info_ptr != NULL)
|
1506
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1507
|
+
|
1508
|
+
if (errmsg == NULL)
|
1509
|
+
{
|
1510
|
+
png_ptr->zowner = 0;
|
1511
|
+
return;
|
1512
|
+
}
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
else if (size > 0)
|
1516
|
+
errmsg = "truncated";
|
1517
|
+
|
1518
|
+
else
|
1519
|
+
errmsg = png_ptr->zstream.msg;
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
/* else png_icc_check_tag_table output an error */
|
1523
|
+
}
|
1524
|
+
|
1525
|
+
else /* profile truncated */
|
1526
|
+
errmsg = png_ptr->zstream.msg;
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
else
|
1530
|
+
errmsg = "out of memory";
|
1531
|
+
}
|
1532
|
+
|
1533
|
+
/* else png_icc_check_header output an error */
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
/* else png_icc_check_length output an error */
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
else /* profile truncated */
|
1540
|
+
errmsg = png_ptr->zstream.msg;
|
1541
|
+
|
1542
|
+
/* Release the stream */
|
1543
|
+
png_ptr->zowner = 0;
|
1544
|
+
}
|
1545
|
+
|
1546
|
+
else /* png_inflate_claim failed */
|
1547
|
+
errmsg = png_ptr->zstream.msg;
|
1548
|
+
}
|
1549
|
+
|
1550
|
+
else
|
1551
|
+
errmsg = "bad compression method"; /* or missing */
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
else
|
1555
|
+
errmsg = "bad keyword";
|
1556
|
+
}
|
1557
|
+
|
1558
|
+
else
|
1559
|
+
errmsg = "too many profiles";
|
1560
|
+
|
1561
|
+
/* Failure: the reason is in 'errmsg' */
|
1562
|
+
if (finished == 0)
|
1563
|
+
png_crc_finish(png_ptr, length);
|
1564
|
+
|
1565
|
+
png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;
|
1566
|
+
png_colorspace_sync(png_ptr, info_ptr);
|
1567
|
+
if (errmsg != NULL) /* else already output */
|
1568
|
+
png_chunk_benign_error(png_ptr, errmsg);
|
1569
|
+
}
|
1570
|
+
#endif /* READ_iCCP */
|
1571
|
+
|
1572
|
+
#ifdef PNG_READ_sPLT_SUPPORTED
|
1573
|
+
void /* PRIVATE */
|
1574
|
+
png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1575
|
+
/* Note: this does not properly handle chunks that are > 64K under DOS */
|
1576
|
+
{
|
1577
|
+
png_bytep entry_start, buffer;
|
1578
|
+
png_sPLT_t new_palette;
|
1579
|
+
png_sPLT_entryp pp;
|
1580
|
+
png_uint_32 data_length;
|
1581
|
+
int entry_size, i;
|
1582
|
+
png_uint_32 skip = 0;
|
1583
|
+
png_uint_32 dl;
|
1584
|
+
png_size_t max_dl;
|
1585
|
+
|
1586
|
+
png_debug(1, "in png_handle_sPLT");
|
1587
|
+
|
1588
|
+
#ifdef PNG_USER_LIMITS_SUPPORTED
|
1589
|
+
if (png_ptr->user_chunk_cache_max != 0)
|
1590
|
+
{
|
1591
|
+
if (png_ptr->user_chunk_cache_max == 1)
|
1592
|
+
{
|
1593
|
+
png_crc_finish(png_ptr, length);
|
1594
|
+
return;
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
if (--png_ptr->user_chunk_cache_max == 1)
|
1598
|
+
{
|
1599
|
+
png_warning(png_ptr, "No space in chunk cache for sPLT");
|
1600
|
+
png_crc_finish(png_ptr, length);
|
1601
|
+
return;
|
1602
|
+
}
|
1603
|
+
}
|
1604
|
+
#endif
|
1605
|
+
|
1606
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1607
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1608
|
+
|
1609
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
1610
|
+
{
|
1611
|
+
png_crc_finish(png_ptr, length);
|
1612
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1613
|
+
return;
|
1614
|
+
}
|
1615
|
+
|
1616
|
+
#ifdef PNG_MAX_MALLOC_64K
|
1617
|
+
if (length > 65535U)
|
1618
|
+
{
|
1619
|
+
png_crc_finish(png_ptr, length);
|
1620
|
+
png_chunk_benign_error(png_ptr, "too large to fit in memory");
|
1621
|
+
return;
|
1622
|
+
}
|
1623
|
+
#endif
|
1624
|
+
|
1625
|
+
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
|
1626
|
+
if (buffer == NULL)
|
1627
|
+
{
|
1628
|
+
png_crc_finish(png_ptr, length);
|
1629
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
1630
|
+
return;
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
|
1634
|
+
/* WARNING: this may break if size_t is less than 32 bits; it is assumed
|
1635
|
+
* that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
|
1636
|
+
* potential breakage point if the types in pngconf.h aren't exactly right.
|
1637
|
+
*/
|
1638
|
+
png_crc_read(png_ptr, buffer, length);
|
1639
|
+
|
1640
|
+
if (png_crc_finish(png_ptr, skip) != 0)
|
1641
|
+
return;
|
1642
|
+
|
1643
|
+
buffer[length] = 0;
|
1644
|
+
|
1645
|
+
for (entry_start = buffer; *entry_start; entry_start++)
|
1646
|
+
/* Empty loop to find end of name */ ;
|
1647
|
+
|
1648
|
+
++entry_start;
|
1649
|
+
|
1650
|
+
/* A sample depth should follow the separator, and we should be on it */
|
1651
|
+
if (entry_start > buffer + length - 2)
|
1652
|
+
{
|
1653
|
+
png_warning(png_ptr, "malformed sPLT chunk");
|
1654
|
+
return;
|
1655
|
+
}
|
1656
|
+
|
1657
|
+
new_palette.depth = *entry_start++;
|
1658
|
+
entry_size = (new_palette.depth == 8 ? 6 : 10);
|
1659
|
+
/* This must fit in a png_uint_32 because it is derived from the original
|
1660
|
+
* chunk data length.
|
1661
|
+
*/
|
1662
|
+
data_length = length - (png_uint_32)(entry_start - buffer);
|
1663
|
+
|
1664
|
+
/* Integrity-check the data length */
|
1665
|
+
if ((data_length % entry_size) != 0)
|
1666
|
+
{
|
1667
|
+
png_warning(png_ptr, "sPLT chunk has bad length");
|
1668
|
+
return;
|
1669
|
+
}
|
1670
|
+
|
1671
|
+
dl = (png_int_32)(data_length / entry_size);
|
1672
|
+
max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));
|
1673
|
+
|
1674
|
+
if (dl > max_dl)
|
1675
|
+
{
|
1676
|
+
png_warning(png_ptr, "sPLT chunk too long");
|
1677
|
+
return;
|
1678
|
+
}
|
1679
|
+
|
1680
|
+
new_palette.nentries = (png_int_32)(data_length / entry_size);
|
1681
|
+
|
1682
|
+
new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
|
1683
|
+
png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));
|
1684
|
+
|
1685
|
+
if (new_palette.entries == NULL)
|
1686
|
+
{
|
1687
|
+
png_warning(png_ptr, "sPLT chunk requires too much memory");
|
1688
|
+
return;
|
1689
|
+
}
|
1690
|
+
|
1691
|
+
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
1692
|
+
for (i = 0; i < new_palette.nentries; i++)
|
1693
|
+
{
|
1694
|
+
pp = new_palette.entries + i;
|
1695
|
+
|
1696
|
+
if (new_palette.depth == 8)
|
1697
|
+
{
|
1698
|
+
pp->red = *entry_start++;
|
1699
|
+
pp->green = *entry_start++;
|
1700
|
+
pp->blue = *entry_start++;
|
1701
|
+
pp->alpha = *entry_start++;
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
else
|
1705
|
+
{
|
1706
|
+
pp->red = png_get_uint_16(entry_start); entry_start += 2;
|
1707
|
+
pp->green = png_get_uint_16(entry_start); entry_start += 2;
|
1708
|
+
pp->blue = png_get_uint_16(entry_start); entry_start += 2;
|
1709
|
+
pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
|
1710
|
+
}
|
1711
|
+
|
1712
|
+
pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
|
1713
|
+
}
|
1714
|
+
#else
|
1715
|
+
pp = new_palette.entries;
|
1716
|
+
|
1717
|
+
for (i = 0; i < new_palette.nentries; i++)
|
1718
|
+
{
|
1719
|
+
|
1720
|
+
if (new_palette.depth == 8)
|
1721
|
+
{
|
1722
|
+
pp[i].red = *entry_start++;
|
1723
|
+
pp[i].green = *entry_start++;
|
1724
|
+
pp[i].blue = *entry_start++;
|
1725
|
+
pp[i].alpha = *entry_start++;
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
else
|
1729
|
+
{
|
1730
|
+
pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
|
1731
|
+
pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
|
1732
|
+
pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
|
1733
|
+
pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
|
1734
|
+
}
|
1735
|
+
|
1736
|
+
pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;
|
1737
|
+
}
|
1738
|
+
#endif
|
1739
|
+
|
1740
|
+
/* Discard all chunk data except the name and stash that */
|
1741
|
+
new_palette.name = (png_charp)buffer;
|
1742
|
+
|
1743
|
+
png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
|
1744
|
+
|
1745
|
+
png_free(png_ptr, new_palette.entries);
|
1746
|
+
}
|
1747
|
+
#endif /* READ_sPLT */
|
1748
|
+
|
1749
|
+
#ifdef PNG_READ_tRNS_SUPPORTED
|
1750
|
+
void /* PRIVATE */
|
1751
|
+
png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1752
|
+
{
|
1753
|
+
png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
|
1754
|
+
|
1755
|
+
png_debug(1, "in png_handle_tRNS");
|
1756
|
+
|
1757
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1758
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1759
|
+
|
1760
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
1761
|
+
{
|
1762
|
+
png_crc_finish(png_ptr, length);
|
1763
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1764
|
+
return;
|
1765
|
+
}
|
1766
|
+
|
1767
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)
|
1768
|
+
{
|
1769
|
+
png_crc_finish(png_ptr, length);
|
1770
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
1771
|
+
return;
|
1772
|
+
}
|
1773
|
+
|
1774
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
|
1775
|
+
{
|
1776
|
+
png_byte buf[2];
|
1777
|
+
|
1778
|
+
if (length != 2)
|
1779
|
+
{
|
1780
|
+
png_crc_finish(png_ptr, length);
|
1781
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1782
|
+
return;
|
1783
|
+
}
|
1784
|
+
|
1785
|
+
png_crc_read(png_ptr, buf, 2);
|
1786
|
+
png_ptr->num_trans = 1;
|
1787
|
+
png_ptr->trans_color.gray = png_get_uint_16(buf);
|
1788
|
+
}
|
1789
|
+
|
1790
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
1791
|
+
{
|
1792
|
+
png_byte buf[6];
|
1793
|
+
|
1794
|
+
if (length != 6)
|
1795
|
+
{
|
1796
|
+
png_crc_finish(png_ptr, length);
|
1797
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1798
|
+
return;
|
1799
|
+
}
|
1800
|
+
|
1801
|
+
png_crc_read(png_ptr, buf, length);
|
1802
|
+
png_ptr->num_trans = 1;
|
1803
|
+
png_ptr->trans_color.red = png_get_uint_16(buf);
|
1804
|
+
png_ptr->trans_color.green = png_get_uint_16(buf + 2);
|
1805
|
+
png_ptr->trans_color.blue = png_get_uint_16(buf + 4);
|
1806
|
+
}
|
1807
|
+
|
1808
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
1809
|
+
{
|
1810
|
+
if ((png_ptr->mode & PNG_HAVE_PLTE) == 0)
|
1811
|
+
{
|
1812
|
+
/* TODO: is this actually an error in the ISO spec? */
|
1813
|
+
png_crc_finish(png_ptr, length);
|
1814
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1815
|
+
return;
|
1816
|
+
}
|
1817
|
+
|
1818
|
+
if (length > png_ptr->num_palette || length > PNG_MAX_PALETTE_LENGTH ||
|
1819
|
+
length == 0)
|
1820
|
+
{
|
1821
|
+
png_crc_finish(png_ptr, length);
|
1822
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1823
|
+
return;
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
png_crc_read(png_ptr, readbuf, length);
|
1827
|
+
png_ptr->num_trans = (png_uint_16)length;
|
1828
|
+
}
|
1829
|
+
|
1830
|
+
else
|
1831
|
+
{
|
1832
|
+
png_crc_finish(png_ptr, length);
|
1833
|
+
png_chunk_benign_error(png_ptr, "invalid with alpha channel");
|
1834
|
+
return;
|
1835
|
+
}
|
1836
|
+
|
1837
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1838
|
+
{
|
1839
|
+
png_ptr->num_trans = 0;
|
1840
|
+
return;
|
1841
|
+
}
|
1842
|
+
|
1843
|
+
/* TODO: this is a horrible side effect in the palette case because the
|
1844
|
+
* png_struct ends up with a pointer to the tRNS buffer owned by the
|
1845
|
+
* png_info. Fix this.
|
1846
|
+
*/
|
1847
|
+
png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
|
1848
|
+
&(png_ptr->trans_color));
|
1849
|
+
}
|
1850
|
+
#endif
|
1851
|
+
|
1852
|
+
#ifdef PNG_READ_bKGD_SUPPORTED
|
1853
|
+
void /* PRIVATE */
|
1854
|
+
png_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1855
|
+
{
|
1856
|
+
unsigned int truelen;
|
1857
|
+
png_byte buf[6];
|
1858
|
+
png_color_16 background;
|
1859
|
+
|
1860
|
+
png_debug(1, "in png_handle_bKGD");
|
1861
|
+
|
1862
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1863
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1864
|
+
|
1865
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
|
1866
|
+
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
1867
|
+
(png_ptr->mode & PNG_HAVE_PLTE) == 0))
|
1868
|
+
{
|
1869
|
+
png_crc_finish(png_ptr, length);
|
1870
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1871
|
+
return;
|
1872
|
+
}
|
1873
|
+
|
1874
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)
|
1875
|
+
{
|
1876
|
+
png_crc_finish(png_ptr, length);
|
1877
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
1878
|
+
return;
|
1879
|
+
}
|
1880
|
+
|
1881
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
1882
|
+
truelen = 1;
|
1883
|
+
|
1884
|
+
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
1885
|
+
truelen = 6;
|
1886
|
+
|
1887
|
+
else
|
1888
|
+
truelen = 2;
|
1889
|
+
|
1890
|
+
if (length != truelen)
|
1891
|
+
{
|
1892
|
+
png_crc_finish(png_ptr, length);
|
1893
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1894
|
+
return;
|
1895
|
+
}
|
1896
|
+
|
1897
|
+
png_crc_read(png_ptr, buf, truelen);
|
1898
|
+
|
1899
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1900
|
+
return;
|
1901
|
+
|
1902
|
+
/* We convert the index value into RGB components so that we can allow
|
1903
|
+
* arbitrary RGB values for background when we have transparency, and
|
1904
|
+
* so it is easy to determine the RGB values of the background color
|
1905
|
+
* from the info_ptr struct.
|
1906
|
+
*/
|
1907
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
1908
|
+
{
|
1909
|
+
background.index = buf[0];
|
1910
|
+
|
1911
|
+
if (info_ptr != NULL && info_ptr->num_palette != 0)
|
1912
|
+
{
|
1913
|
+
if (buf[0] >= info_ptr->num_palette)
|
1914
|
+
{
|
1915
|
+
png_chunk_benign_error(png_ptr, "invalid index");
|
1916
|
+
return;
|
1917
|
+
}
|
1918
|
+
|
1919
|
+
background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
|
1920
|
+
background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
|
1921
|
+
background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
|
1922
|
+
}
|
1923
|
+
|
1924
|
+
else
|
1925
|
+
background.red = background.green = background.blue = 0;
|
1926
|
+
|
1927
|
+
background.gray = 0;
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */
|
1931
|
+
{
|
1932
|
+
background.index = 0;
|
1933
|
+
background.red =
|
1934
|
+
background.green =
|
1935
|
+
background.blue =
|
1936
|
+
background.gray = png_get_uint_16(buf);
|
1937
|
+
}
|
1938
|
+
|
1939
|
+
else
|
1940
|
+
{
|
1941
|
+
background.index = 0;
|
1942
|
+
background.red = png_get_uint_16(buf);
|
1943
|
+
background.green = png_get_uint_16(buf + 2);
|
1944
|
+
background.blue = png_get_uint_16(buf + 4);
|
1945
|
+
background.gray = 0;
|
1946
|
+
}
|
1947
|
+
|
1948
|
+
png_set_bKGD(png_ptr, info_ptr, &background);
|
1949
|
+
}
|
1950
|
+
#endif
|
1951
|
+
|
1952
|
+
#ifdef PNG_READ_hIST_SUPPORTED
|
1953
|
+
void /* PRIVATE */
|
1954
|
+
png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
1955
|
+
{
|
1956
|
+
unsigned int num, i;
|
1957
|
+
png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
|
1958
|
+
|
1959
|
+
png_debug(1, "in png_handle_hIST");
|
1960
|
+
|
1961
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
1962
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
1963
|
+
|
1964
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||
|
1965
|
+
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
|
1966
|
+
{
|
1967
|
+
png_crc_finish(png_ptr, length);
|
1968
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
1969
|
+
return;
|
1970
|
+
}
|
1971
|
+
|
1972
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)
|
1973
|
+
{
|
1974
|
+
png_crc_finish(png_ptr, length);
|
1975
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
1976
|
+
return;
|
1977
|
+
}
|
1978
|
+
|
1979
|
+
num = length / 2 ;
|
1980
|
+
|
1981
|
+
if (num != png_ptr->num_palette || num > PNG_MAX_PALETTE_LENGTH)
|
1982
|
+
{
|
1983
|
+
png_crc_finish(png_ptr, length);
|
1984
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
1985
|
+
return;
|
1986
|
+
}
|
1987
|
+
|
1988
|
+
for (i = 0; i < num; i++)
|
1989
|
+
{
|
1990
|
+
png_byte buf[2];
|
1991
|
+
|
1992
|
+
png_crc_read(png_ptr, buf, 2);
|
1993
|
+
readbuf[i] = png_get_uint_16(buf);
|
1994
|
+
}
|
1995
|
+
|
1996
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
1997
|
+
return;
|
1998
|
+
|
1999
|
+
png_set_hIST(png_ptr, info_ptr, readbuf);
|
2000
|
+
}
|
2001
|
+
#endif
|
2002
|
+
|
2003
|
+
#ifdef PNG_READ_pHYs_SUPPORTED
|
2004
|
+
void /* PRIVATE */
|
2005
|
+
png_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2006
|
+
{
|
2007
|
+
png_byte buf[9];
|
2008
|
+
png_uint_32 res_x, res_y;
|
2009
|
+
int unit_type;
|
2010
|
+
|
2011
|
+
png_debug(1, "in png_handle_pHYs");
|
2012
|
+
|
2013
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2014
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2015
|
+
|
2016
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2017
|
+
{
|
2018
|
+
png_crc_finish(png_ptr, length);
|
2019
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
2020
|
+
return;
|
2021
|
+
}
|
2022
|
+
|
2023
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0)
|
2024
|
+
{
|
2025
|
+
png_crc_finish(png_ptr, length);
|
2026
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
2027
|
+
return;
|
2028
|
+
}
|
2029
|
+
|
2030
|
+
if (length != 9)
|
2031
|
+
{
|
2032
|
+
png_crc_finish(png_ptr, length);
|
2033
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
2034
|
+
return;
|
2035
|
+
}
|
2036
|
+
|
2037
|
+
png_crc_read(png_ptr, buf, 9);
|
2038
|
+
|
2039
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2040
|
+
return;
|
2041
|
+
|
2042
|
+
res_x = png_get_uint_32(buf);
|
2043
|
+
res_y = png_get_uint_32(buf + 4);
|
2044
|
+
unit_type = buf[8];
|
2045
|
+
png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
|
2046
|
+
}
|
2047
|
+
#endif
|
2048
|
+
|
2049
|
+
#ifdef PNG_READ_oFFs_SUPPORTED
|
2050
|
+
void /* PRIVATE */
|
2051
|
+
png_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2052
|
+
{
|
2053
|
+
png_byte buf[9];
|
2054
|
+
png_int_32 offset_x, offset_y;
|
2055
|
+
int unit_type;
|
2056
|
+
|
2057
|
+
png_debug(1, "in png_handle_oFFs");
|
2058
|
+
|
2059
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2060
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2061
|
+
|
2062
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2063
|
+
{
|
2064
|
+
png_crc_finish(png_ptr, length);
|
2065
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
2066
|
+
return;
|
2067
|
+
}
|
2068
|
+
|
2069
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0)
|
2070
|
+
{
|
2071
|
+
png_crc_finish(png_ptr, length);
|
2072
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
2073
|
+
return;
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
if (length != 9)
|
2077
|
+
{
|
2078
|
+
png_crc_finish(png_ptr, length);
|
2079
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
2080
|
+
return;
|
2081
|
+
}
|
2082
|
+
|
2083
|
+
png_crc_read(png_ptr, buf, 9);
|
2084
|
+
|
2085
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2086
|
+
return;
|
2087
|
+
|
2088
|
+
offset_x = png_get_int_32(buf);
|
2089
|
+
offset_y = png_get_int_32(buf + 4);
|
2090
|
+
unit_type = buf[8];
|
2091
|
+
png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
|
2092
|
+
}
|
2093
|
+
#endif
|
2094
|
+
|
2095
|
+
#ifdef PNG_READ_pCAL_SUPPORTED
|
2096
|
+
/* Read the pCAL chunk (described in the PNG Extensions document) */
|
2097
|
+
void /* PRIVATE */
|
2098
|
+
png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2099
|
+
{
|
2100
|
+
png_int_32 X0, X1;
|
2101
|
+
png_byte type, nparams;
|
2102
|
+
png_bytep buffer, buf, units, endptr;
|
2103
|
+
png_charpp params;
|
2104
|
+
int i;
|
2105
|
+
|
2106
|
+
png_debug(1, "in png_handle_pCAL");
|
2107
|
+
|
2108
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2109
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2110
|
+
|
2111
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2112
|
+
{
|
2113
|
+
png_crc_finish(png_ptr, length);
|
2114
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
2115
|
+
return;
|
2116
|
+
}
|
2117
|
+
|
2118
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0)
|
2119
|
+
{
|
2120
|
+
png_crc_finish(png_ptr, length);
|
2121
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
2122
|
+
return;
|
2123
|
+
}
|
2124
|
+
|
2125
|
+
png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",
|
2126
|
+
length + 1);
|
2127
|
+
|
2128
|
+
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
|
2129
|
+
|
2130
|
+
if (buffer == NULL)
|
2131
|
+
{
|
2132
|
+
png_crc_finish(png_ptr, length);
|
2133
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2134
|
+
return;
|
2135
|
+
}
|
2136
|
+
|
2137
|
+
png_crc_read(png_ptr, buffer, length);
|
2138
|
+
|
2139
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2140
|
+
return;
|
2141
|
+
|
2142
|
+
buffer[length] = 0; /* Null terminate the last string */
|
2143
|
+
|
2144
|
+
png_debug(3, "Finding end of pCAL purpose string");
|
2145
|
+
for (buf = buffer; *buf; buf++)
|
2146
|
+
/* Empty loop */ ;
|
2147
|
+
|
2148
|
+
endptr = buffer + length;
|
2149
|
+
|
2150
|
+
/* We need to have at least 12 bytes after the purpose string
|
2151
|
+
* in order to get the parameter information.
|
2152
|
+
*/
|
2153
|
+
if (endptr <= buf + 12)
|
2154
|
+
{
|
2155
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
2156
|
+
return;
|
2157
|
+
}
|
2158
|
+
|
2159
|
+
png_debug(3, "Reading pCAL X0, X1, type, nparams, and units");
|
2160
|
+
X0 = png_get_int_32((png_bytep)buf+1);
|
2161
|
+
X1 = png_get_int_32((png_bytep)buf+5);
|
2162
|
+
type = buf[9];
|
2163
|
+
nparams = buf[10];
|
2164
|
+
units = buf + 11;
|
2165
|
+
|
2166
|
+
png_debug(3, "Checking pCAL equation type and number of parameters");
|
2167
|
+
/* Check that we have the right number of parameters for known
|
2168
|
+
* equation types.
|
2169
|
+
*/
|
2170
|
+
if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
|
2171
|
+
(type == PNG_EQUATION_BASE_E && nparams != 3) ||
|
2172
|
+
(type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
|
2173
|
+
(type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
|
2174
|
+
{
|
2175
|
+
png_chunk_benign_error(png_ptr, "invalid parameter count");
|
2176
|
+
return;
|
2177
|
+
}
|
2178
|
+
|
2179
|
+
else if (type >= PNG_EQUATION_LAST)
|
2180
|
+
{
|
2181
|
+
png_chunk_benign_error(png_ptr, "unrecognized equation type");
|
2182
|
+
}
|
2183
|
+
|
2184
|
+
for (buf = units; *buf; buf++)
|
2185
|
+
/* Empty loop to move past the units string. */ ;
|
2186
|
+
|
2187
|
+
png_debug(3, "Allocating pCAL parameters array");
|
2188
|
+
|
2189
|
+
params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,
|
2190
|
+
nparams * (sizeof (png_charp))));
|
2191
|
+
|
2192
|
+
if (params == NULL)
|
2193
|
+
{
|
2194
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2195
|
+
return;
|
2196
|
+
}
|
2197
|
+
|
2198
|
+
/* Get pointers to the start of each parameter string. */
|
2199
|
+
for (i = 0; i < nparams; i++)
|
2200
|
+
{
|
2201
|
+
buf++; /* Skip the null string terminator from previous parameter. */
|
2202
|
+
|
2203
|
+
png_debug1(3, "Reading pCAL parameter %d", i);
|
2204
|
+
|
2205
|
+
for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++)
|
2206
|
+
/* Empty loop to move past each parameter string */ ;
|
2207
|
+
|
2208
|
+
/* Make sure we haven't run out of data yet */
|
2209
|
+
if (buf > endptr)
|
2210
|
+
{
|
2211
|
+
png_free(png_ptr, params);
|
2212
|
+
png_chunk_benign_error(png_ptr, "invalid data");
|
2213
|
+
return;
|
2214
|
+
}
|
2215
|
+
}
|
2216
|
+
|
2217
|
+
png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,
|
2218
|
+
(png_charp)units, params);
|
2219
|
+
|
2220
|
+
png_free(png_ptr, params);
|
2221
|
+
}
|
2222
|
+
#endif
|
2223
|
+
|
2224
|
+
#ifdef PNG_READ_sCAL_SUPPORTED
|
2225
|
+
/* Read the sCAL chunk */
|
2226
|
+
void /* PRIVATE */
|
2227
|
+
png_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2228
|
+
{
|
2229
|
+
png_bytep buffer;
|
2230
|
+
png_size_t i;
|
2231
|
+
int state;
|
2232
|
+
|
2233
|
+
png_debug(1, "in png_handle_sCAL");
|
2234
|
+
|
2235
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2236
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2237
|
+
|
2238
|
+
else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2239
|
+
{
|
2240
|
+
png_crc_finish(png_ptr, length);
|
2241
|
+
png_chunk_benign_error(png_ptr, "out of place");
|
2242
|
+
return;
|
2243
|
+
}
|
2244
|
+
|
2245
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0)
|
2246
|
+
{
|
2247
|
+
png_crc_finish(png_ptr, length);
|
2248
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
2249
|
+
return;
|
2250
|
+
}
|
2251
|
+
|
2252
|
+
/* Need unit type, width, \0, height: minimum 4 bytes */
|
2253
|
+
else if (length < 4)
|
2254
|
+
{
|
2255
|
+
png_crc_finish(png_ptr, length);
|
2256
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
2257
|
+
return;
|
2258
|
+
}
|
2259
|
+
|
2260
|
+
png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
|
2261
|
+
length + 1);
|
2262
|
+
|
2263
|
+
buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);
|
2264
|
+
|
2265
|
+
if (buffer == NULL)
|
2266
|
+
{
|
2267
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2268
|
+
png_crc_finish(png_ptr, length);
|
2269
|
+
return;
|
2270
|
+
}
|
2271
|
+
|
2272
|
+
png_crc_read(png_ptr, buffer, length);
|
2273
|
+
buffer[length] = 0; /* Null terminate the last string */
|
2274
|
+
|
2275
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2276
|
+
return;
|
2277
|
+
|
2278
|
+
/* Validate the unit. */
|
2279
|
+
if (buffer[0] != 1 && buffer[0] != 2)
|
2280
|
+
{
|
2281
|
+
png_chunk_benign_error(png_ptr, "invalid unit");
|
2282
|
+
return;
|
2283
|
+
}
|
2284
|
+
|
2285
|
+
/* Validate the ASCII numbers, need two ASCII numbers separated by
|
2286
|
+
* a '\0' and they need to fit exactly in the chunk data.
|
2287
|
+
*/
|
2288
|
+
i = 1;
|
2289
|
+
state = 0;
|
2290
|
+
|
2291
|
+
if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||
|
2292
|
+
i >= length || buffer[i++] != 0)
|
2293
|
+
png_chunk_benign_error(png_ptr, "bad width format");
|
2294
|
+
|
2295
|
+
else if (PNG_FP_IS_POSITIVE(state) == 0)
|
2296
|
+
png_chunk_benign_error(png_ptr, "non-positive width");
|
2297
|
+
|
2298
|
+
else
|
2299
|
+
{
|
2300
|
+
png_size_t heighti = i;
|
2301
|
+
|
2302
|
+
state = 0;
|
2303
|
+
if (png_check_fp_number((png_const_charp)buffer, length,
|
2304
|
+
&state, &i) == 0 || i != length)
|
2305
|
+
png_chunk_benign_error(png_ptr, "bad height format");
|
2306
|
+
|
2307
|
+
else if (PNG_FP_IS_POSITIVE(state) == 0)
|
2308
|
+
png_chunk_benign_error(png_ptr, "non-positive height");
|
2309
|
+
|
2310
|
+
else
|
2311
|
+
/* This is the (only) success case. */
|
2312
|
+
png_set_sCAL_s(png_ptr, info_ptr, buffer[0],
|
2313
|
+
(png_charp)buffer+1, (png_charp)buffer+heighti);
|
2314
|
+
}
|
2315
|
+
}
|
2316
|
+
#endif
|
2317
|
+
|
2318
|
+
#ifdef PNG_READ_tIME_SUPPORTED
|
2319
|
+
void /* PRIVATE */
|
2320
|
+
png_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2321
|
+
{
|
2322
|
+
png_byte buf[7];
|
2323
|
+
png_time mod_time;
|
2324
|
+
|
2325
|
+
png_debug(1, "in png_handle_tIME");
|
2326
|
+
|
2327
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2328
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2329
|
+
|
2330
|
+
else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0)
|
2331
|
+
{
|
2332
|
+
png_crc_finish(png_ptr, length);
|
2333
|
+
png_chunk_benign_error(png_ptr, "duplicate");
|
2334
|
+
return;
|
2335
|
+
}
|
2336
|
+
|
2337
|
+
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2338
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
2339
|
+
|
2340
|
+
if (length != 7)
|
2341
|
+
{
|
2342
|
+
png_crc_finish(png_ptr, length);
|
2343
|
+
png_chunk_benign_error(png_ptr, "invalid");
|
2344
|
+
return;
|
2345
|
+
}
|
2346
|
+
|
2347
|
+
png_crc_read(png_ptr, buf, 7);
|
2348
|
+
|
2349
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2350
|
+
return;
|
2351
|
+
|
2352
|
+
mod_time.second = buf[6];
|
2353
|
+
mod_time.minute = buf[5];
|
2354
|
+
mod_time.hour = buf[4];
|
2355
|
+
mod_time.day = buf[3];
|
2356
|
+
mod_time.month = buf[2];
|
2357
|
+
mod_time.year = png_get_uint_16(buf);
|
2358
|
+
|
2359
|
+
png_set_tIME(png_ptr, info_ptr, &mod_time);
|
2360
|
+
}
|
2361
|
+
#endif
|
2362
|
+
|
2363
|
+
#ifdef PNG_READ_tEXt_SUPPORTED
|
2364
|
+
/* Note: this does not properly handle chunks that are > 64K under DOS */
|
2365
|
+
void /* PRIVATE */
|
2366
|
+
png_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2367
|
+
{
|
2368
|
+
png_text text_info;
|
2369
|
+
png_bytep buffer;
|
2370
|
+
png_charp key;
|
2371
|
+
png_charp text;
|
2372
|
+
png_uint_32 skip = 0;
|
2373
|
+
|
2374
|
+
png_debug(1, "in png_handle_tEXt");
|
2375
|
+
|
2376
|
+
#ifdef PNG_USER_LIMITS_SUPPORTED
|
2377
|
+
if (png_ptr->user_chunk_cache_max != 0)
|
2378
|
+
{
|
2379
|
+
if (png_ptr->user_chunk_cache_max == 1)
|
2380
|
+
{
|
2381
|
+
png_crc_finish(png_ptr, length);
|
2382
|
+
return;
|
2383
|
+
}
|
2384
|
+
|
2385
|
+
if (--png_ptr->user_chunk_cache_max == 1)
|
2386
|
+
{
|
2387
|
+
png_crc_finish(png_ptr, length);
|
2388
|
+
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
2389
|
+
return;
|
2390
|
+
}
|
2391
|
+
}
|
2392
|
+
#endif
|
2393
|
+
|
2394
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2395
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2396
|
+
|
2397
|
+
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2398
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
2399
|
+
|
2400
|
+
#ifdef PNG_MAX_MALLOC_64K
|
2401
|
+
if (length > 65535U)
|
2402
|
+
{
|
2403
|
+
png_crc_finish(png_ptr, length);
|
2404
|
+
png_chunk_benign_error(png_ptr, "too large to fit in memory");
|
2405
|
+
return;
|
2406
|
+
}
|
2407
|
+
#endif
|
2408
|
+
|
2409
|
+
buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);
|
2410
|
+
|
2411
|
+
if (buffer == NULL)
|
2412
|
+
{
|
2413
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2414
|
+
return;
|
2415
|
+
}
|
2416
|
+
|
2417
|
+
png_crc_read(png_ptr, buffer, length);
|
2418
|
+
|
2419
|
+
if (png_crc_finish(png_ptr, skip) != 0)
|
2420
|
+
return;
|
2421
|
+
|
2422
|
+
key = (png_charp)buffer;
|
2423
|
+
key[length] = 0;
|
2424
|
+
|
2425
|
+
for (text = key; *text; text++)
|
2426
|
+
/* Empty loop to find end of key */ ;
|
2427
|
+
|
2428
|
+
if (text != key + length)
|
2429
|
+
text++;
|
2430
|
+
|
2431
|
+
text_info.compression = PNG_TEXT_COMPRESSION_NONE;
|
2432
|
+
text_info.key = key;
|
2433
|
+
text_info.lang = NULL;
|
2434
|
+
text_info.lang_key = NULL;
|
2435
|
+
text_info.itxt_length = 0;
|
2436
|
+
text_info.text = text;
|
2437
|
+
text_info.text_length = strlen(text);
|
2438
|
+
|
2439
|
+
if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0)
|
2440
|
+
png_warning(png_ptr, "Insufficient memory to process text chunk");
|
2441
|
+
}
|
2442
|
+
#endif
|
2443
|
+
|
2444
|
+
#ifdef PNG_READ_zTXt_SUPPORTED
|
2445
|
+
/* Note: this does not correctly handle chunks that are > 64K under DOS */
|
2446
|
+
void /* PRIVATE */
|
2447
|
+
png_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2448
|
+
{
|
2449
|
+
png_const_charp errmsg = NULL;
|
2450
|
+
png_bytep buffer;
|
2451
|
+
png_uint_32 keyword_length;
|
2452
|
+
|
2453
|
+
png_debug(1, "in png_handle_zTXt");
|
2454
|
+
|
2455
|
+
#ifdef PNG_USER_LIMITS_SUPPORTED
|
2456
|
+
if (png_ptr->user_chunk_cache_max != 0)
|
2457
|
+
{
|
2458
|
+
if (png_ptr->user_chunk_cache_max == 1)
|
2459
|
+
{
|
2460
|
+
png_crc_finish(png_ptr, length);
|
2461
|
+
return;
|
2462
|
+
}
|
2463
|
+
|
2464
|
+
if (--png_ptr->user_chunk_cache_max == 1)
|
2465
|
+
{
|
2466
|
+
png_crc_finish(png_ptr, length);
|
2467
|
+
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
2468
|
+
return;
|
2469
|
+
}
|
2470
|
+
}
|
2471
|
+
#endif
|
2472
|
+
|
2473
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2474
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2475
|
+
|
2476
|
+
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2477
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
2478
|
+
|
2479
|
+
buffer = png_read_buffer(png_ptr, length, 2/*silent*/);
|
2480
|
+
|
2481
|
+
if (buffer == NULL)
|
2482
|
+
{
|
2483
|
+
png_crc_finish(png_ptr, length);
|
2484
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2485
|
+
return;
|
2486
|
+
}
|
2487
|
+
|
2488
|
+
png_crc_read(png_ptr, buffer, length);
|
2489
|
+
|
2490
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2491
|
+
return;
|
2492
|
+
|
2493
|
+
/* TODO: also check that the keyword contents match the spec! */
|
2494
|
+
for (keyword_length = 0;
|
2495
|
+
keyword_length < length && buffer[keyword_length] != 0;
|
2496
|
+
++keyword_length)
|
2497
|
+
/* Empty loop to find end of name */ ;
|
2498
|
+
|
2499
|
+
if (keyword_length > 79 || keyword_length < 1)
|
2500
|
+
errmsg = "bad keyword";
|
2501
|
+
|
2502
|
+
/* zTXt must have some LZ data after the keyword, although it may expand to
|
2503
|
+
* zero bytes; we need a '\0' at the end of the keyword, the compression type
|
2504
|
+
* then the LZ data:
|
2505
|
+
*/
|
2506
|
+
else if (keyword_length + 3 > length)
|
2507
|
+
errmsg = "truncated";
|
2508
|
+
|
2509
|
+
else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE)
|
2510
|
+
errmsg = "unknown compression type";
|
2511
|
+
|
2512
|
+
else
|
2513
|
+
{
|
2514
|
+
png_alloc_size_t uncompressed_length = PNG_SIZE_MAX;
|
2515
|
+
|
2516
|
+
/* TODO: at present png_decompress_chunk imposes a single application
|
2517
|
+
* level memory limit, this should be split to different values for iCCP
|
2518
|
+
* and text chunks.
|
2519
|
+
*/
|
2520
|
+
if (png_decompress_chunk(png_ptr, length, keyword_length+2,
|
2521
|
+
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
2522
|
+
{
|
2523
|
+
png_text text;
|
2524
|
+
|
2525
|
+
/* It worked; png_ptr->read_buffer now looks like a tEXt chunk except
|
2526
|
+
* for the extra compression type byte and the fact that it isn't
|
2527
|
+
* necessarily '\0' terminated.
|
2528
|
+
*/
|
2529
|
+
buffer = png_ptr->read_buffer;
|
2530
|
+
buffer[uncompressed_length+(keyword_length+2)] = 0;
|
2531
|
+
|
2532
|
+
text.compression = PNG_TEXT_COMPRESSION_zTXt;
|
2533
|
+
text.key = (png_charp)buffer;
|
2534
|
+
text.text = (png_charp)(buffer + keyword_length+2);
|
2535
|
+
text.text_length = uncompressed_length;
|
2536
|
+
text.itxt_length = 0;
|
2537
|
+
text.lang = NULL;
|
2538
|
+
text.lang_key = NULL;
|
2539
|
+
|
2540
|
+
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
|
2541
|
+
errmsg = "insufficient memory";
|
2542
|
+
}
|
2543
|
+
|
2544
|
+
else
|
2545
|
+
errmsg = png_ptr->zstream.msg;
|
2546
|
+
}
|
2547
|
+
|
2548
|
+
if (errmsg != NULL)
|
2549
|
+
png_chunk_benign_error(png_ptr, errmsg);
|
2550
|
+
}
|
2551
|
+
#endif
|
2552
|
+
|
2553
|
+
#ifdef PNG_READ_iTXt_SUPPORTED
|
2554
|
+
/* Note: this does not correctly handle chunks that are > 64K under DOS */
|
2555
|
+
void /* PRIVATE */
|
2556
|
+
png_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
|
2557
|
+
{
|
2558
|
+
png_const_charp errmsg = NULL;
|
2559
|
+
png_bytep buffer;
|
2560
|
+
png_uint_32 prefix_length;
|
2561
|
+
|
2562
|
+
png_debug(1, "in png_handle_iTXt");
|
2563
|
+
|
2564
|
+
#ifdef PNG_USER_LIMITS_SUPPORTED
|
2565
|
+
if (png_ptr->user_chunk_cache_max != 0)
|
2566
|
+
{
|
2567
|
+
if (png_ptr->user_chunk_cache_max == 1)
|
2568
|
+
{
|
2569
|
+
png_crc_finish(png_ptr, length);
|
2570
|
+
return;
|
2571
|
+
}
|
2572
|
+
|
2573
|
+
if (--png_ptr->user_chunk_cache_max == 1)
|
2574
|
+
{
|
2575
|
+
png_crc_finish(png_ptr, length);
|
2576
|
+
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
2577
|
+
return;
|
2578
|
+
}
|
2579
|
+
}
|
2580
|
+
#endif
|
2581
|
+
|
2582
|
+
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
2583
|
+
png_chunk_error(png_ptr, "missing IHDR");
|
2584
|
+
|
2585
|
+
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
2586
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
2587
|
+
|
2588
|
+
buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);
|
2589
|
+
|
2590
|
+
if (buffer == NULL)
|
2591
|
+
{
|
2592
|
+
png_crc_finish(png_ptr, length);
|
2593
|
+
png_chunk_benign_error(png_ptr, "out of memory");
|
2594
|
+
return;
|
2595
|
+
}
|
2596
|
+
|
2597
|
+
png_crc_read(png_ptr, buffer, length);
|
2598
|
+
|
2599
|
+
if (png_crc_finish(png_ptr, 0) != 0)
|
2600
|
+
return;
|
2601
|
+
|
2602
|
+
/* First the keyword. */
|
2603
|
+
for (prefix_length=0;
|
2604
|
+
prefix_length < length && buffer[prefix_length] != 0;
|
2605
|
+
++prefix_length)
|
2606
|
+
/* Empty loop */ ;
|
2607
|
+
|
2608
|
+
/* Perform a basic check on the keyword length here. */
|
2609
|
+
if (prefix_length > 79 || prefix_length < 1)
|
2610
|
+
errmsg = "bad keyword";
|
2611
|
+
|
2612
|
+
/* Expect keyword, compression flag, compression type, language, translated
|
2613
|
+
* keyword (both may be empty but are 0 terminated) then the text, which may
|
2614
|
+
* be empty.
|
2615
|
+
*/
|
2616
|
+
else if (prefix_length + 5 > length)
|
2617
|
+
errmsg = "truncated";
|
2618
|
+
|
2619
|
+
else if (buffer[prefix_length+1] == 0 ||
|
2620
|
+
(buffer[prefix_length+1] == 1 &&
|
2621
|
+
buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE))
|
2622
|
+
{
|
2623
|
+
int compressed = buffer[prefix_length+1] != 0;
|
2624
|
+
png_uint_32 language_offset, translated_keyword_offset;
|
2625
|
+
png_alloc_size_t uncompressed_length = 0;
|
2626
|
+
|
2627
|
+
/* Now the language tag */
|
2628
|
+
prefix_length += 3;
|
2629
|
+
language_offset = prefix_length;
|
2630
|
+
|
2631
|
+
for (; prefix_length < length && buffer[prefix_length] != 0;
|
2632
|
+
++prefix_length)
|
2633
|
+
/* Empty loop */ ;
|
2634
|
+
|
2635
|
+
/* WARNING: the length may be invalid here, this is checked below. */
|
2636
|
+
translated_keyword_offset = ++prefix_length;
|
2637
|
+
|
2638
|
+
for (; prefix_length < length && buffer[prefix_length] != 0;
|
2639
|
+
++prefix_length)
|
2640
|
+
/* Empty loop */ ;
|
2641
|
+
|
2642
|
+
/* prefix_length should now be at the trailing '\0' of the translated
|
2643
|
+
* keyword, but it may already be over the end. None of this arithmetic
|
2644
|
+
* can overflow because chunks are at most 2^31 bytes long, but on 16-bit
|
2645
|
+
* systems the available allocation may overflow.
|
2646
|
+
*/
|
2647
|
+
++prefix_length;
|
2648
|
+
|
2649
|
+
if (compressed == 0 && prefix_length <= length)
|
2650
|
+
uncompressed_length = length - prefix_length;
|
2651
|
+
|
2652
|
+
else if (compressed != 0 && prefix_length < length)
|
2653
|
+
{
|
2654
|
+
uncompressed_length = PNG_SIZE_MAX;
|
2655
|
+
|
2656
|
+
/* TODO: at present png_decompress_chunk imposes a single application
|
2657
|
+
* level memory limit, this should be split to different values for
|
2658
|
+
* iCCP and text chunks.
|
2659
|
+
*/
|
2660
|
+
if (png_decompress_chunk(png_ptr, length, prefix_length,
|
2661
|
+
&uncompressed_length, 1/*terminate*/) == Z_STREAM_END)
|
2662
|
+
buffer = png_ptr->read_buffer;
|
2663
|
+
|
2664
|
+
else
|
2665
|
+
errmsg = png_ptr->zstream.msg;
|
2666
|
+
}
|
2667
|
+
|
2668
|
+
else
|
2669
|
+
errmsg = "truncated";
|
2670
|
+
|
2671
|
+
if (errmsg == NULL)
|
2672
|
+
{
|
2673
|
+
png_text text;
|
2674
|
+
|
2675
|
+
buffer[uncompressed_length+prefix_length] = 0;
|
2676
|
+
|
2677
|
+
if (compressed == 0)
|
2678
|
+
text.compression = PNG_ITXT_COMPRESSION_NONE;
|
2679
|
+
|
2680
|
+
else
|
2681
|
+
text.compression = PNG_ITXT_COMPRESSION_zTXt;
|
2682
|
+
|
2683
|
+
text.key = (png_charp)buffer;
|
2684
|
+
text.lang = (png_charp)buffer + language_offset;
|
2685
|
+
text.lang_key = (png_charp)buffer + translated_keyword_offset;
|
2686
|
+
text.text = (png_charp)buffer + prefix_length;
|
2687
|
+
text.text_length = 0;
|
2688
|
+
text.itxt_length = uncompressed_length;
|
2689
|
+
|
2690
|
+
if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)
|
2691
|
+
errmsg = "insufficient memory";
|
2692
|
+
}
|
2693
|
+
}
|
2694
|
+
|
2695
|
+
else
|
2696
|
+
errmsg = "bad compression info";
|
2697
|
+
|
2698
|
+
if (errmsg != NULL)
|
2699
|
+
png_chunk_benign_error(png_ptr, errmsg);
|
2700
|
+
}
|
2701
|
+
#endif
|
2702
|
+
|
2703
|
+
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
2704
|
+
/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */
|
2705
|
+
static int
|
2706
|
+
png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)
|
2707
|
+
{
|
2708
|
+
png_alloc_size_t limit = PNG_SIZE_MAX;
|
2709
|
+
|
2710
|
+
if (png_ptr->unknown_chunk.data != NULL)
|
2711
|
+
{
|
2712
|
+
png_free(png_ptr, png_ptr->unknown_chunk.data);
|
2713
|
+
png_ptr->unknown_chunk.data = NULL;
|
2714
|
+
}
|
2715
|
+
|
2716
|
+
# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
|
2717
|
+
if (png_ptr->user_chunk_malloc_max > 0 &&
|
2718
|
+
png_ptr->user_chunk_malloc_max < limit)
|
2719
|
+
limit = png_ptr->user_chunk_malloc_max;
|
2720
|
+
|
2721
|
+
# elif PNG_USER_CHUNK_MALLOC_MAX > 0
|
2722
|
+
if (PNG_USER_CHUNK_MALLOC_MAX < limit)
|
2723
|
+
limit = PNG_USER_CHUNK_MALLOC_MAX;
|
2724
|
+
# endif
|
2725
|
+
|
2726
|
+
if (length <= limit)
|
2727
|
+
{
|
2728
|
+
PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);
|
2729
|
+
/* The following is safe because of the PNG_SIZE_MAX init above */
|
2730
|
+
png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/;
|
2731
|
+
/* 'mode' is a flag array, only the bottom four bits matter here */
|
2732
|
+
png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;
|
2733
|
+
|
2734
|
+
if (length == 0)
|
2735
|
+
png_ptr->unknown_chunk.data = NULL;
|
2736
|
+
|
2737
|
+
else
|
2738
|
+
{
|
2739
|
+
/* Do a 'warn' here - it is handled below. */
|
2740
|
+
png_ptr->unknown_chunk.data = png_voidcast(png_bytep,
|
2741
|
+
png_malloc_warn(png_ptr, length));
|
2742
|
+
}
|
2743
|
+
}
|
2744
|
+
|
2745
|
+
if (png_ptr->unknown_chunk.data == NULL && length > 0)
|
2746
|
+
{
|
2747
|
+
/* This is benign because we clean up correctly */
|
2748
|
+
png_crc_finish(png_ptr, length);
|
2749
|
+
png_chunk_benign_error(png_ptr, "unknown chunk exceeds memory limits");
|
2750
|
+
return 0;
|
2751
|
+
}
|
2752
|
+
|
2753
|
+
else
|
2754
|
+
{
|
2755
|
+
if (length > 0)
|
2756
|
+
png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);
|
2757
|
+
png_crc_finish(png_ptr, 0);
|
2758
|
+
return 1;
|
2759
|
+
}
|
2760
|
+
}
|
2761
|
+
#endif /* READ_UNKNOWN_CHUNKS */
|
2762
|
+
|
2763
|
+
/* Handle an unknown, or known but disabled, chunk */
|
2764
|
+
void /* PRIVATE */
|
2765
|
+
png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
|
2766
|
+
png_uint_32 length, int keep)
|
2767
|
+
{
|
2768
|
+
int handled = 0; /* the chunk was handled */
|
2769
|
+
|
2770
|
+
png_debug(1, "in png_handle_unknown");
|
2771
|
+
|
2772
|
+
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
2773
|
+
/* NOTE: this code is based on the code in libpng-1.4.12 except for fixing
|
2774
|
+
* the bug which meant that setting a non-default behavior for a specific
|
2775
|
+
* chunk would be ignored (the default was always used unless a user
|
2776
|
+
* callback was installed).
|
2777
|
+
*
|
2778
|
+
* 'keep' is the value from the png_chunk_unknown_handling, the setting for
|
2779
|
+
* this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it
|
2780
|
+
* will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.
|
2781
|
+
* This is just an optimization to avoid multiple calls to the lookup
|
2782
|
+
* function.
|
2783
|
+
*/
|
2784
|
+
# ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
2785
|
+
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
2786
|
+
keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);
|
2787
|
+
# endif
|
2788
|
+
# endif
|
2789
|
+
|
2790
|
+
/* One of the following methods will read the chunk or skip it (at least one
|
2791
|
+
* of these is always defined because this is the only way to switch on
|
2792
|
+
* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
2793
|
+
*/
|
2794
|
+
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
2795
|
+
/* The user callback takes precedence over the chunk keep value, but the
|
2796
|
+
* keep value is still required to validate a save of a critical chunk.
|
2797
|
+
*/
|
2798
|
+
if (png_ptr->read_user_chunk_fn != NULL)
|
2799
|
+
{
|
2800
|
+
if (png_cache_unknown_chunk(png_ptr, length) != 0)
|
2801
|
+
{
|
2802
|
+
/* Callback to user unknown chunk handler */
|
2803
|
+
int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,
|
2804
|
+
&png_ptr->unknown_chunk);
|
2805
|
+
|
2806
|
+
/* ret is:
|
2807
|
+
* negative: An error occured, png_chunk_error will be called.
|
2808
|
+
* zero: The chunk was not handled, the chunk will be discarded
|
2809
|
+
* unless png_set_keep_unknown_chunks has been used to set
|
2810
|
+
* a 'keep' behavior for this particular chunk, in which
|
2811
|
+
* case that will be used. A critical chunk will cause an
|
2812
|
+
* error at this point unless it is to be saved.
|
2813
|
+
* positive: The chunk was handled, libpng will ignore/discard it.
|
2814
|
+
*/
|
2815
|
+
if (ret < 0)
|
2816
|
+
png_chunk_error(png_ptr, "error in user chunk");
|
2817
|
+
|
2818
|
+
else if (ret == 0)
|
2819
|
+
{
|
2820
|
+
/* If the keep value is 'default' or 'never' override it, but
|
2821
|
+
* still error out on critical chunks unless the keep value is
|
2822
|
+
* 'always' While this is weird it is the behavior in 1.4.12.
|
2823
|
+
* A possible improvement would be to obey the value set for the
|
2824
|
+
* chunk, but this would be an API change that would probably
|
2825
|
+
* damage some applications.
|
2826
|
+
*
|
2827
|
+
* The png_app_warning below catches the case that matters, where
|
2828
|
+
* the application has not set specific save or ignore for this
|
2829
|
+
* chunk or global save or ignore.
|
2830
|
+
*/
|
2831
|
+
if (keep < PNG_HANDLE_CHUNK_IF_SAFE)
|
2832
|
+
{
|
2833
|
+
# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
2834
|
+
if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)
|
2835
|
+
{
|
2836
|
+
png_chunk_warning(png_ptr, "Saving unknown chunk:");
|
2837
|
+
png_app_warning(png_ptr,
|
2838
|
+
"forcing save of an unhandled chunk;"
|
2839
|
+
" please call png_set_keep_unknown_chunks");
|
2840
|
+
/* with keep = PNG_HANDLE_CHUNK_IF_SAFE */
|
2841
|
+
}
|
2842
|
+
# endif
|
2843
|
+
keep = PNG_HANDLE_CHUNK_IF_SAFE;
|
2844
|
+
}
|
2845
|
+
}
|
2846
|
+
|
2847
|
+
else /* chunk was handled */
|
2848
|
+
{
|
2849
|
+
handled = 1;
|
2850
|
+
/* Critical chunks can be safely discarded at this point. */
|
2851
|
+
keep = PNG_HANDLE_CHUNK_NEVER;
|
2852
|
+
}
|
2853
|
+
}
|
2854
|
+
|
2855
|
+
else
|
2856
|
+
keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */
|
2857
|
+
}
|
2858
|
+
|
2859
|
+
else
|
2860
|
+
/* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */
|
2861
|
+
# endif /* READ_USER_CHUNKS */
|
2862
|
+
|
2863
|
+
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
2864
|
+
{
|
2865
|
+
/* keep is currently just the per-chunk setting, if there was no
|
2866
|
+
* setting change it to the global default now (not that this may
|
2867
|
+
* still be AS_DEFAULT) then obtain the cache of the chunk if required,
|
2868
|
+
* if not simply skip the chunk.
|
2869
|
+
*/
|
2870
|
+
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
|
2871
|
+
keep = png_ptr->unknown_default;
|
2872
|
+
|
2873
|
+
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
|
2874
|
+
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
|
2875
|
+
PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
|
2876
|
+
{
|
2877
|
+
if (png_cache_unknown_chunk(png_ptr, length) == 0)
|
2878
|
+
keep = PNG_HANDLE_CHUNK_NEVER;
|
2879
|
+
}
|
2880
|
+
|
2881
|
+
else
|
2882
|
+
png_crc_finish(png_ptr, length);
|
2883
|
+
}
|
2884
|
+
# else
|
2885
|
+
# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
|
2886
|
+
# error no method to support READ_UNKNOWN_CHUNKS
|
2887
|
+
# endif
|
2888
|
+
|
2889
|
+
{
|
2890
|
+
/* If here there is no read callback pointer set and no support is
|
2891
|
+
* compiled in to just save the unknown chunks, so simply skip this
|
2892
|
+
* chunk. If 'keep' is something other than AS_DEFAULT or NEVER then
|
2893
|
+
* the app has erroneously asked for unknown chunk saving when there
|
2894
|
+
* is no support.
|
2895
|
+
*/
|
2896
|
+
if (keep > PNG_HANDLE_CHUNK_NEVER)
|
2897
|
+
png_app_error(png_ptr, "no unknown chunk support available");
|
2898
|
+
|
2899
|
+
png_crc_finish(png_ptr, length);
|
2900
|
+
}
|
2901
|
+
# endif
|
2902
|
+
|
2903
|
+
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
2904
|
+
/* Now store the chunk in the chunk list if appropriate, and if the limits
|
2905
|
+
* permit it.
|
2906
|
+
*/
|
2907
|
+
if (keep == PNG_HANDLE_CHUNK_ALWAYS ||
|
2908
|
+
(keep == PNG_HANDLE_CHUNK_IF_SAFE &&
|
2909
|
+
PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))
|
2910
|
+
{
|
2911
|
+
# ifdef PNG_USER_LIMITS_SUPPORTED
|
2912
|
+
switch (png_ptr->user_chunk_cache_max)
|
2913
|
+
{
|
2914
|
+
case 2:
|
2915
|
+
png_ptr->user_chunk_cache_max = 1;
|
2916
|
+
png_chunk_benign_error(png_ptr, "no space in chunk cache");
|
2917
|
+
/* FALL THROUGH */
|
2918
|
+
case 1:
|
2919
|
+
/* NOTE: prior to 1.6.0 this case resulted in an unknown critical
|
2920
|
+
* chunk being skipped, now there will be a hard error below.
|
2921
|
+
*/
|
2922
|
+
break;
|
2923
|
+
|
2924
|
+
default: /* not at limit */
|
2925
|
+
--(png_ptr->user_chunk_cache_max);
|
2926
|
+
/* FALL THROUGH */
|
2927
|
+
case 0: /* no limit */
|
2928
|
+
# endif /* USER_LIMITS */
|
2929
|
+
/* Here when the limit isn't reached or when limits are compiled
|
2930
|
+
* out; store the chunk.
|
2931
|
+
*/
|
2932
|
+
png_set_unknown_chunks(png_ptr, info_ptr,
|
2933
|
+
&png_ptr->unknown_chunk, 1);
|
2934
|
+
handled = 1;
|
2935
|
+
# ifdef PNG_USER_LIMITS_SUPPORTED
|
2936
|
+
break;
|
2937
|
+
}
|
2938
|
+
# endif
|
2939
|
+
}
|
2940
|
+
# else /* no store support: the chunk must be handled by the user callback */
|
2941
|
+
PNG_UNUSED(info_ptr)
|
2942
|
+
# endif
|
2943
|
+
|
2944
|
+
/* Regardless of the error handling below the cached data (if any) can be
|
2945
|
+
* freed now. Notice that the data is not freed if there is a png_error, but
|
2946
|
+
* it will be freed by destroy_read_struct.
|
2947
|
+
*/
|
2948
|
+
if (png_ptr->unknown_chunk.data != NULL)
|
2949
|
+
png_free(png_ptr, png_ptr->unknown_chunk.data);
|
2950
|
+
png_ptr->unknown_chunk.data = NULL;
|
2951
|
+
|
2952
|
+
#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */
|
2953
|
+
/* There is no support to read an unknown chunk, so just skip it. */
|
2954
|
+
png_crc_finish(png_ptr, length);
|
2955
|
+
PNG_UNUSED(info_ptr)
|
2956
|
+
PNG_UNUSED(keep)
|
2957
|
+
#endif /* !READ_UNKNOWN_CHUNKS */
|
2958
|
+
|
2959
|
+
/* Check for unhandled critical chunks */
|
2960
|
+
if (handled == 0 && PNG_CHUNK_CRITICAL(png_ptr->chunk_name))
|
2961
|
+
png_chunk_error(png_ptr, "unhandled critical chunk");
|
2962
|
+
}
|
2963
|
+
|
2964
|
+
/* This function is called to verify that a chunk name is valid.
|
2965
|
+
* This function can't have the "critical chunk check" incorporated
|
2966
|
+
* into it, since in the future we will need to be able to call user
|
2967
|
+
* functions to handle unknown critical chunks after we check that
|
2968
|
+
* the chunk name itself is valid.
|
2969
|
+
*/
|
2970
|
+
|
2971
|
+
/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is:
|
2972
|
+
*
|
2973
|
+
* ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
|
2974
|
+
*/
|
2975
|
+
|
2976
|
+
void /* PRIVATE */
|
2977
|
+
png_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name)
|
2978
|
+
{
|
2979
|
+
int i;
|
2980
|
+
|
2981
|
+
png_debug(1, "in png_check_chunk_name");
|
2982
|
+
|
2983
|
+
for (i=1; i<=4; ++i)
|
2984
|
+
{
|
2985
|
+
int c = chunk_name & 0xff;
|
2986
|
+
|
2987
|
+
if (c < 65 || c > 122 || (c > 90 && c < 97))
|
2988
|
+
png_chunk_error(png_ptr, "invalid chunk type");
|
2989
|
+
|
2990
|
+
chunk_name >>= 8;
|
2991
|
+
}
|
2992
|
+
}
|
2993
|
+
|
2994
|
+
/* Combines the row recently read in with the existing pixels in the row. This
|
2995
|
+
* routine takes care of alpha and transparency if requested. This routine also
|
2996
|
+
* handles the two methods of progressive display of interlaced images,
|
2997
|
+
* depending on the 'display' value; if 'display' is true then the whole row
|
2998
|
+
* (dp) is filled from the start by replicating the available pixels. If
|
2999
|
+
* 'display' is false only those pixels present in the pass are filled in.
|
3000
|
+
*/
|
3001
|
+
void /* PRIVATE */
|
3002
|
+
png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
|
3003
|
+
{
|
3004
|
+
unsigned int pixel_depth = png_ptr->transformed_pixel_depth;
|
3005
|
+
png_const_bytep sp = png_ptr->row_buf + 1;
|
3006
|
+
png_alloc_size_t row_width = png_ptr->width;
|
3007
|
+
unsigned int pass = png_ptr->pass;
|
3008
|
+
png_bytep end_ptr = 0;
|
3009
|
+
png_byte end_byte = 0;
|
3010
|
+
unsigned int end_mask;
|
3011
|
+
|
3012
|
+
png_debug(1, "in png_combine_row");
|
3013
|
+
|
3014
|
+
/* Added in 1.5.6: it should not be possible to enter this routine until at
|
3015
|
+
* least one row has been read from the PNG data and transformed.
|
3016
|
+
*/
|
3017
|
+
if (pixel_depth == 0)
|
3018
|
+
png_error(png_ptr, "internal row logic error");
|
3019
|
+
|
3020
|
+
/* Added in 1.5.4: the pixel depth should match the information returned by
|
3021
|
+
* any call to png_read_update_info at this point. Do not continue if we got
|
3022
|
+
* this wrong.
|
3023
|
+
*/
|
3024
|
+
if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
|
3025
|
+
PNG_ROWBYTES(pixel_depth, row_width))
|
3026
|
+
png_error(png_ptr, "internal row size calculation error");
|
3027
|
+
|
3028
|
+
/* Don't expect this to ever happen: */
|
3029
|
+
if (row_width == 0)
|
3030
|
+
png_error(png_ptr, "internal row width error");
|
3031
|
+
|
3032
|
+
/* Preserve the last byte in cases where only part of it will be overwritten,
|
3033
|
+
* the multiply below may overflow, we don't care because ANSI-C guarantees
|
3034
|
+
* we get the low bits.
|
3035
|
+
*/
|
3036
|
+
end_mask = (pixel_depth * row_width) & 7;
|
3037
|
+
if (end_mask != 0)
|
3038
|
+
{
|
3039
|
+
/* end_ptr == NULL is a flag to say do nothing */
|
3040
|
+
end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1;
|
3041
|
+
end_byte = *end_ptr;
|
3042
|
+
# ifdef PNG_READ_PACKSWAP_SUPPORTED
|
3043
|
+
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
3044
|
+
/* little-endian byte */
|
3045
|
+
end_mask = 0xff << end_mask;
|
3046
|
+
|
3047
|
+
else /* big-endian byte */
|
3048
|
+
# endif
|
3049
|
+
end_mask = 0xff >> end_mask;
|
3050
|
+
/* end_mask is now the bits to *keep* from the destination row */
|
3051
|
+
}
|
3052
|
+
|
3053
|
+
/* For non-interlaced images this reduces to a memcpy(). A memcpy()
|
3054
|
+
* will also happen if interlacing isn't supported or if the application
|
3055
|
+
* does not call png_set_interlace_handling(). In the latter cases the
|
3056
|
+
* caller just gets a sequence of the unexpanded rows from each interlace
|
3057
|
+
* pass.
|
3058
|
+
*/
|
3059
|
+
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
3060
|
+
if (png_ptr->interlaced != 0 &&
|
3061
|
+
(png_ptr->transformations & PNG_INTERLACE) != 0 &&
|
3062
|
+
pass < 6 && (display == 0 ||
|
3063
|
+
/* The following copies everything for 'display' on passes 0, 2 and 4. */
|
3064
|
+
(display == 1 && (pass & 1) != 0)))
|
3065
|
+
{
|
3066
|
+
/* Narrow images may have no bits in a pass; the caller should handle
|
3067
|
+
* this, but this test is cheap:
|
3068
|
+
*/
|
3069
|
+
if (row_width <= PNG_PASS_START_COL(pass))
|
3070
|
+
return;
|
3071
|
+
|
3072
|
+
if (pixel_depth < 8)
|
3073
|
+
{
|
3074
|
+
/* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit
|
3075
|
+
* into 32 bits, then a single loop over the bytes using the four byte
|
3076
|
+
* values in the 32-bit mask can be used. For the 'display' option the
|
3077
|
+
* expanded mask may also not require any masking within a byte. To
|
3078
|
+
* make this work the PACKSWAP option must be taken into account - it
|
3079
|
+
* simply requires the pixels to be reversed in each byte.
|
3080
|
+
*
|
3081
|
+
* The 'regular' case requires a mask for each of the first 6 passes,
|
3082
|
+
* the 'display' case does a copy for the even passes in the range
|
3083
|
+
* 0..6. This has already been handled in the test above.
|
3084
|
+
*
|
3085
|
+
* The masks are arranged as four bytes with the first byte to use in
|
3086
|
+
* the lowest bits (little-endian) regardless of the order (PACKSWAP or
|
3087
|
+
* not) of the pixels in each byte.
|
3088
|
+
*
|
3089
|
+
* NOTE: the whole of this logic depends on the caller of this function
|
3090
|
+
* only calling it on rows appropriate to the pass. This function only
|
3091
|
+
* understands the 'x' logic; the 'y' logic is handled by the caller.
|
3092
|
+
*
|
3093
|
+
* The following defines allow generation of compile time constant bit
|
3094
|
+
* masks for each pixel depth and each possibility of swapped or not
|
3095
|
+
* swapped bytes. Pass 'p' is in the range 0..6; 'x', a pixel index,
|
3096
|
+
* is in the range 0..7; and the result is 1 if the pixel is to be
|
3097
|
+
* copied in the pass, 0 if not. 'S' is for the sparkle method, 'B'
|
3098
|
+
* for the block method.
|
3099
|
+
*
|
3100
|
+
* With some compilers a compile time expression of the general form:
|
3101
|
+
*
|
3102
|
+
* (shift >= 32) ? (a >> (shift-32)) : (b >> shift)
|
3103
|
+
*
|
3104
|
+
* Produces warnings with values of 'shift' in the range 33 to 63
|
3105
|
+
* because the right hand side of the ?: expression is evaluated by
|
3106
|
+
* the compiler even though it isn't used. Microsoft Visual C (various
|
3107
|
+
* versions) and the Intel C compiler are known to do this. To avoid
|
3108
|
+
* this the following macros are used in 1.5.6. This is a temporary
|
3109
|
+
* solution to avoid destabilizing the code during the release process.
|
3110
|
+
*/
|
3111
|
+
# if PNG_USE_COMPILE_TIME_MASKS
|
3112
|
+
# define PNG_LSR(x,s) ((x)>>((s) & 0x1f))
|
3113
|
+
# define PNG_LSL(x,s) ((x)<<((s) & 0x1f))
|
3114
|
+
# else
|
3115
|
+
# define PNG_LSR(x,s) ((x)>>(s))
|
3116
|
+
# define PNG_LSL(x,s) ((x)<<(s))
|
3117
|
+
# endif
|
3118
|
+
# define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\
|
3119
|
+
PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1)
|
3120
|
+
# define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\
|
3121
|
+
PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1)
|
3122
|
+
|
3123
|
+
/* Return a mask for pass 'p' pixel 'x' at depth 'd'. The mask is
|
3124
|
+
* little endian - the first pixel is at bit 0 - however the extra
|
3125
|
+
* parameter 's' can be set to cause the mask position to be swapped
|
3126
|
+
* within each byte, to match the PNG format. This is done by XOR of
|
3127
|
+
* the shift with 7, 6 or 4 for bit depths 1, 2 and 4.
|
3128
|
+
*/
|
3129
|
+
# define PIXEL_MASK(p,x,d,s) \
|
3130
|
+
(PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0))))
|
3131
|
+
|
3132
|
+
/* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.
|
3133
|
+
*/
|
3134
|
+
# define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
|
3135
|
+
# define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)
|
3136
|
+
|
3137
|
+
/* Combine 8 of these to get the full mask. For the 1-bpp and 2-bpp
|
3138
|
+
* cases the result needs replicating, for the 4-bpp case the above
|
3139
|
+
* generates a full 32 bits.
|
3140
|
+
*/
|
3141
|
+
# define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))
|
3142
|
+
|
3143
|
+
# define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\
|
3144
|
+
S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\
|
3145
|
+
S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)
|
3146
|
+
|
3147
|
+
# define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\
|
3148
|
+
B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\
|
3149
|
+
B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)
|
3150
|
+
|
3151
|
+
#if PNG_USE_COMPILE_TIME_MASKS
|
3152
|
+
/* Utility macros to construct all the masks for a depth/swap
|
3153
|
+
* combination. The 's' parameter says whether the format is PNG
|
3154
|
+
* (big endian bytes) or not. Only the three odd-numbered passes are
|
3155
|
+
* required for the display/block algorithm.
|
3156
|
+
*/
|
3157
|
+
# define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\
|
3158
|
+
S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }
|
3159
|
+
|
3160
|
+
# define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) }
|
3161
|
+
|
3162
|
+
# define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))
|
3163
|
+
|
3164
|
+
/* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
|
3165
|
+
* then pass:
|
3166
|
+
*/
|
3167
|
+
static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
|
3168
|
+
{
|
3169
|
+
/* Little-endian byte masks for PACKSWAP */
|
3170
|
+
{ S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
|
3171
|
+
/* Normal (big-endian byte) masks - PNG format */
|
3172
|
+
{ S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) }
|
3173
|
+
};
|
3174
|
+
|
3175
|
+
/* display_mask has only three entries for the odd passes, so index by
|
3176
|
+
* pass>>1.
|
3177
|
+
*/
|
3178
|
+
static PNG_CONST png_uint_32 display_mask[2][3][3] =
|
3179
|
+
{
|
3180
|
+
/* Little-endian byte masks for PACKSWAP */
|
3181
|
+
{ B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
|
3182
|
+
/* Normal (big-endian byte) masks - PNG format */
|
3183
|
+
{ B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) }
|
3184
|
+
};
|
3185
|
+
|
3186
|
+
# define MASK(pass,depth,display,png)\
|
3187
|
+
((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\
|
3188
|
+
row_mask[png][DEPTH_INDEX(depth)][pass])
|
3189
|
+
|
3190
|
+
#else /* !PNG_USE_COMPILE_TIME_MASKS */
|
3191
|
+
/* This is the runtime alternative: it seems unlikely that this will
|
3192
|
+
* ever be either smaller or faster than the compile time approach.
|
3193
|
+
*/
|
3194
|
+
# define MASK(pass,depth,display,png)\
|
3195
|
+
((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))
|
3196
|
+
#endif /* !USE_COMPILE_TIME_MASKS */
|
3197
|
+
|
3198
|
+
/* Use the appropriate mask to copy the required bits. In some cases
|
3199
|
+
* the byte mask will be 0 or 0xff; optimize these cases. row_width is
|
3200
|
+
* the number of pixels, but the code copies bytes, so it is necessary
|
3201
|
+
* to special case the end.
|
3202
|
+
*/
|
3203
|
+
png_uint_32 pixels_per_byte = 8 / pixel_depth;
|
3204
|
+
png_uint_32 mask;
|
3205
|
+
|
3206
|
+
# ifdef PNG_READ_PACKSWAP_SUPPORTED
|
3207
|
+
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
3208
|
+
mask = MASK(pass, pixel_depth, display, 0);
|
3209
|
+
|
3210
|
+
else
|
3211
|
+
# endif
|
3212
|
+
mask = MASK(pass, pixel_depth, display, 1);
|
3213
|
+
|
3214
|
+
for (;;)
|
3215
|
+
{
|
3216
|
+
png_uint_32 m;
|
3217
|
+
|
3218
|
+
/* It doesn't matter in the following if png_uint_32 has more than
|
3219
|
+
* 32 bits because the high bits always match those in m<<24; it is,
|
3220
|
+
* however, essential to use OR here, not +, because of this.
|
3221
|
+
*/
|
3222
|
+
m = mask;
|
3223
|
+
mask = (m >> 8) | (m << 24); /* rotate right to good compilers */
|
3224
|
+
m &= 0xff;
|
3225
|
+
|
3226
|
+
if (m != 0) /* something to copy */
|
3227
|
+
{
|
3228
|
+
if (m != 0xff)
|
3229
|
+
*dp = (png_byte)((*dp & ~m) | (*sp & m));
|
3230
|
+
else
|
3231
|
+
*dp = *sp;
|
3232
|
+
}
|
3233
|
+
|
3234
|
+
/* NOTE: this may overwrite the last byte with garbage if the image
|
3235
|
+
* is not an exact number of bytes wide; libpng has always done
|
3236
|
+
* this.
|
3237
|
+
*/
|
3238
|
+
if (row_width <= pixels_per_byte)
|
3239
|
+
break; /* May need to restore part of the last byte */
|
3240
|
+
|
3241
|
+
row_width -= pixels_per_byte;
|
3242
|
+
++dp;
|
3243
|
+
++sp;
|
3244
|
+
}
|
3245
|
+
}
|
3246
|
+
|
3247
|
+
else /* pixel_depth >= 8 */
|
3248
|
+
{
|
3249
|
+
unsigned int bytes_to_copy, bytes_to_jump;
|
3250
|
+
|
3251
|
+
/* Validate the depth - it must be a multiple of 8 */
|
3252
|
+
if (pixel_depth & 7)
|
3253
|
+
png_error(png_ptr, "invalid user transform pixel depth");
|
3254
|
+
|
3255
|
+
pixel_depth >>= 3; /* now in bytes */
|
3256
|
+
row_width *= pixel_depth;
|
3257
|
+
|
3258
|
+
/* Regardless of pass number the Adam 7 interlace always results in a
|
3259
|
+
* fixed number of pixels to copy then to skip. There may be a
|
3260
|
+
* different number of pixels to skip at the start though.
|
3261
|
+
*/
|
3262
|
+
{
|
3263
|
+
unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth;
|
3264
|
+
|
3265
|
+
row_width -= offset;
|
3266
|
+
dp += offset;
|
3267
|
+
sp += offset;
|
3268
|
+
}
|
3269
|
+
|
3270
|
+
/* Work out the bytes to copy. */
|
3271
|
+
if (display != 0)
|
3272
|
+
{
|
3273
|
+
/* When doing the 'block' algorithm the pixel in the pass gets
|
3274
|
+
* replicated to adjacent pixels. This is why the even (0,2,4,6)
|
3275
|
+
* passes are skipped above - the entire expanded row is copied.
|
3276
|
+
*/
|
3277
|
+
bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;
|
3278
|
+
|
3279
|
+
/* But don't allow this number to exceed the actual row width. */
|
3280
|
+
if (bytes_to_copy > row_width)
|
3281
|
+
bytes_to_copy = (unsigned int)/*SAFE*/row_width;
|
3282
|
+
}
|
3283
|
+
|
3284
|
+
else /* normal row; Adam7 only ever gives us one pixel to copy. */
|
3285
|
+
bytes_to_copy = pixel_depth;
|
3286
|
+
|
3287
|
+
/* In Adam7 there is a constant offset between where the pixels go. */
|
3288
|
+
bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth;
|
3289
|
+
|
3290
|
+
/* And simply copy these bytes. Some optimization is possible here,
|
3291
|
+
* depending on the value of 'bytes_to_copy'. Special case the low
|
3292
|
+
* byte counts, which we know to be frequent.
|
3293
|
+
*
|
3294
|
+
* Notice that these cases all 'return' rather than 'break' - this
|
3295
|
+
* avoids an unnecessary test on whether to restore the last byte
|
3296
|
+
* below.
|
3297
|
+
*/
|
3298
|
+
switch (bytes_to_copy)
|
3299
|
+
{
|
3300
|
+
case 1:
|
3301
|
+
for (;;)
|
3302
|
+
{
|
3303
|
+
*dp = *sp;
|
3304
|
+
|
3305
|
+
if (row_width <= bytes_to_jump)
|
3306
|
+
return;
|
3307
|
+
|
3308
|
+
dp += bytes_to_jump;
|
3309
|
+
sp += bytes_to_jump;
|
3310
|
+
row_width -= bytes_to_jump;
|
3311
|
+
}
|
3312
|
+
|
3313
|
+
case 2:
|
3314
|
+
/* There is a possibility of a partial copy at the end here; this
|
3315
|
+
* slows the code down somewhat.
|
3316
|
+
*/
|
3317
|
+
do
|
3318
|
+
{
|
3319
|
+
dp[0] = sp[0], dp[1] = sp[1];
|
3320
|
+
|
3321
|
+
if (row_width <= bytes_to_jump)
|
3322
|
+
return;
|
3323
|
+
|
3324
|
+
sp += bytes_to_jump;
|
3325
|
+
dp += bytes_to_jump;
|
3326
|
+
row_width -= bytes_to_jump;
|
3327
|
+
}
|
3328
|
+
while (row_width > 1);
|
3329
|
+
|
3330
|
+
/* And there can only be one byte left at this point: */
|
3331
|
+
*dp = *sp;
|
3332
|
+
return;
|
3333
|
+
|
3334
|
+
case 3:
|
3335
|
+
/* This can only be the RGB case, so each copy is exactly one
|
3336
|
+
* pixel and it is not necessary to check for a partial copy.
|
3337
|
+
*/
|
3338
|
+
for (;;)
|
3339
|
+
{
|
3340
|
+
dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];
|
3341
|
+
|
3342
|
+
if (row_width <= bytes_to_jump)
|
3343
|
+
return;
|
3344
|
+
|
3345
|
+
sp += bytes_to_jump;
|
3346
|
+
dp += bytes_to_jump;
|
3347
|
+
row_width -= bytes_to_jump;
|
3348
|
+
}
|
3349
|
+
|
3350
|
+
default:
|
3351
|
+
#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE
|
3352
|
+
/* Check for double byte alignment and, if possible, use a
|
3353
|
+
* 16-bit copy. Don't attempt this for narrow images - ones that
|
3354
|
+
* are less than an interlace panel wide. Don't attempt it for
|
3355
|
+
* wide bytes_to_copy either - use the memcpy there.
|
3356
|
+
*/
|
3357
|
+
if (bytes_to_copy < 16 /*else use memcpy*/ &&
|
3358
|
+
png_isaligned(dp, png_uint_16) &&
|
3359
|
+
png_isaligned(sp, png_uint_16) &&
|
3360
|
+
bytes_to_copy % (sizeof (png_uint_16)) == 0 &&
|
3361
|
+
bytes_to_jump % (sizeof (png_uint_16)) == 0)
|
3362
|
+
{
|
3363
|
+
/* Everything is aligned for png_uint_16 copies, but try for
|
3364
|
+
* png_uint_32 first.
|
3365
|
+
*/
|
3366
|
+
if (png_isaligned(dp, png_uint_32) != 0 &&
|
3367
|
+
png_isaligned(sp, png_uint_32) != 0 &&
|
3368
|
+
bytes_to_copy % (sizeof (png_uint_32)) == 0 &&
|
3369
|
+
bytes_to_jump % (sizeof (png_uint_32)) == 0)
|
3370
|
+
{
|
3371
|
+
png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);
|
3372
|
+
png_const_uint_32p sp32 = png_aligncastconst(
|
3373
|
+
png_const_uint_32p, sp);
|
3374
|
+
size_t skip = (bytes_to_jump-bytes_to_copy) /
|
3375
|
+
(sizeof (png_uint_32));
|
3376
|
+
|
3377
|
+
do
|
3378
|
+
{
|
3379
|
+
size_t c = bytes_to_copy;
|
3380
|
+
do
|
3381
|
+
{
|
3382
|
+
*dp32++ = *sp32++;
|
3383
|
+
c -= (sizeof (png_uint_32));
|
3384
|
+
}
|
3385
|
+
while (c > 0);
|
3386
|
+
|
3387
|
+
if (row_width <= bytes_to_jump)
|
3388
|
+
return;
|
3389
|
+
|
3390
|
+
dp32 += skip;
|
3391
|
+
sp32 += skip;
|
3392
|
+
row_width -= bytes_to_jump;
|
3393
|
+
}
|
3394
|
+
while (bytes_to_copy <= row_width);
|
3395
|
+
|
3396
|
+
/* Get to here when the row_width truncates the final copy.
|
3397
|
+
* There will be 1-3 bytes left to copy, so don't try the
|
3398
|
+
* 16-bit loop below.
|
3399
|
+
*/
|
3400
|
+
dp = (png_bytep)dp32;
|
3401
|
+
sp = (png_const_bytep)sp32;
|
3402
|
+
do
|
3403
|
+
*dp++ = *sp++;
|
3404
|
+
while (--row_width > 0);
|
3405
|
+
return;
|
3406
|
+
}
|
3407
|
+
|
3408
|
+
/* Else do it in 16-bit quantities, but only if the size is
|
3409
|
+
* not too large.
|
3410
|
+
*/
|
3411
|
+
else
|
3412
|
+
{
|
3413
|
+
png_uint_16p dp16 = png_aligncast(png_uint_16p, dp);
|
3414
|
+
png_const_uint_16p sp16 = png_aligncastconst(
|
3415
|
+
png_const_uint_16p, sp);
|
3416
|
+
size_t skip = (bytes_to_jump-bytes_to_copy) /
|
3417
|
+
(sizeof (png_uint_16));
|
3418
|
+
|
3419
|
+
do
|
3420
|
+
{
|
3421
|
+
size_t c = bytes_to_copy;
|
3422
|
+
do
|
3423
|
+
{
|
3424
|
+
*dp16++ = *sp16++;
|
3425
|
+
c -= (sizeof (png_uint_16));
|
3426
|
+
}
|
3427
|
+
while (c > 0);
|
3428
|
+
|
3429
|
+
if (row_width <= bytes_to_jump)
|
3430
|
+
return;
|
3431
|
+
|
3432
|
+
dp16 += skip;
|
3433
|
+
sp16 += skip;
|
3434
|
+
row_width -= bytes_to_jump;
|
3435
|
+
}
|
3436
|
+
while (bytes_to_copy <= row_width);
|
3437
|
+
|
3438
|
+
/* End of row - 1 byte left, bytes_to_copy > row_width: */
|
3439
|
+
dp = (png_bytep)dp16;
|
3440
|
+
sp = (png_const_bytep)sp16;
|
3441
|
+
do
|
3442
|
+
*dp++ = *sp++;
|
3443
|
+
while (--row_width > 0);
|
3444
|
+
return;
|
3445
|
+
}
|
3446
|
+
}
|
3447
|
+
#endif /* ALIGN_TYPE code */
|
3448
|
+
|
3449
|
+
/* The true default - use a memcpy: */
|
3450
|
+
for (;;)
|
3451
|
+
{
|
3452
|
+
memcpy(dp, sp, bytes_to_copy);
|
3453
|
+
|
3454
|
+
if (row_width <= bytes_to_jump)
|
3455
|
+
return;
|
3456
|
+
|
3457
|
+
sp += bytes_to_jump;
|
3458
|
+
dp += bytes_to_jump;
|
3459
|
+
row_width -= bytes_to_jump;
|
3460
|
+
if (bytes_to_copy > row_width)
|
3461
|
+
bytes_to_copy = (unsigned int)/*SAFE*/row_width;
|
3462
|
+
}
|
3463
|
+
}
|
3464
|
+
|
3465
|
+
/* NOT REACHED*/
|
3466
|
+
} /* pixel_depth >= 8 */
|
3467
|
+
|
3468
|
+
/* Here if pixel_depth < 8 to check 'end_ptr' below. */
|
3469
|
+
}
|
3470
|
+
else
|
3471
|
+
#endif /* READ_INTERLACING */
|
3472
|
+
|
3473
|
+
/* If here then the switch above wasn't used so just memcpy the whole row
|
3474
|
+
* from the temporary row buffer (notice that this overwrites the end of the
|
3475
|
+
* destination row if it is a partial byte.)
|
3476
|
+
*/
|
3477
|
+
memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));
|
3478
|
+
|
3479
|
+
/* Restore the overwritten bits from the last byte if necessary. */
|
3480
|
+
if (end_ptr != NULL)
|
3481
|
+
*end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));
|
3482
|
+
}
|
3483
|
+
|
3484
|
+
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
3485
|
+
void /* PRIVATE */
|
3486
|
+
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
3487
|
+
png_uint_32 transformations /* Because these may affect the byte layout */)
|
3488
|
+
{
|
3489
|
+
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
3490
|
+
/* Offset to next interlace block */
|
3491
|
+
static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
3492
|
+
|
3493
|
+
png_debug(1, "in png_do_read_interlace");
|
3494
|
+
if (row != NULL && row_info != NULL)
|
3495
|
+
{
|
3496
|
+
png_uint_32 final_width;
|
3497
|
+
|
3498
|
+
final_width = row_info->width * png_pass_inc[pass];
|
3499
|
+
|
3500
|
+
switch (row_info->pixel_depth)
|
3501
|
+
{
|
3502
|
+
case 1:
|
3503
|
+
{
|
3504
|
+
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
|
3505
|
+
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
|
3506
|
+
int sshift, dshift;
|
3507
|
+
int s_start, s_end, s_inc;
|
3508
|
+
int jstop = png_pass_inc[pass];
|
3509
|
+
png_byte v;
|
3510
|
+
png_uint_32 i;
|
3511
|
+
int j;
|
3512
|
+
|
3513
|
+
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
3514
|
+
if ((transformations & PNG_PACKSWAP) != 0)
|
3515
|
+
{
|
3516
|
+
sshift = (int)((row_info->width + 7) & 0x07);
|
3517
|
+
dshift = (int)((final_width + 7) & 0x07);
|
3518
|
+
s_start = 7;
|
3519
|
+
s_end = 0;
|
3520
|
+
s_inc = -1;
|
3521
|
+
}
|
3522
|
+
|
3523
|
+
else
|
3524
|
+
#endif
|
3525
|
+
{
|
3526
|
+
sshift = 7 - (int)((row_info->width + 7) & 0x07);
|
3527
|
+
dshift = 7 - (int)((final_width + 7) & 0x07);
|
3528
|
+
s_start = 0;
|
3529
|
+
s_end = 7;
|
3530
|
+
s_inc = 1;
|
3531
|
+
}
|
3532
|
+
|
3533
|
+
for (i = 0; i < row_info->width; i++)
|
3534
|
+
{
|
3535
|
+
v = (png_byte)((*sp >> sshift) & 0x01);
|
3536
|
+
for (j = 0; j < jstop; j++)
|
3537
|
+
{
|
3538
|
+
unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));
|
3539
|
+
tmp |= v << dshift;
|
3540
|
+
*dp = (png_byte)(tmp & 0xff);
|
3541
|
+
|
3542
|
+
if (dshift == s_end)
|
3543
|
+
{
|
3544
|
+
dshift = s_start;
|
3545
|
+
dp--;
|
3546
|
+
}
|
3547
|
+
|
3548
|
+
else
|
3549
|
+
dshift += s_inc;
|
3550
|
+
}
|
3551
|
+
|
3552
|
+
if (sshift == s_end)
|
3553
|
+
{
|
3554
|
+
sshift = s_start;
|
3555
|
+
sp--;
|
3556
|
+
}
|
3557
|
+
|
3558
|
+
else
|
3559
|
+
sshift += s_inc;
|
3560
|
+
}
|
3561
|
+
break;
|
3562
|
+
}
|
3563
|
+
|
3564
|
+
case 2:
|
3565
|
+
{
|
3566
|
+
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
|
3567
|
+
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
|
3568
|
+
int sshift, dshift;
|
3569
|
+
int s_start, s_end, s_inc;
|
3570
|
+
int jstop = png_pass_inc[pass];
|
3571
|
+
png_uint_32 i;
|
3572
|
+
|
3573
|
+
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
3574
|
+
if ((transformations & PNG_PACKSWAP) != 0)
|
3575
|
+
{
|
3576
|
+
sshift = (int)(((row_info->width + 3) & 0x03) << 1);
|
3577
|
+
dshift = (int)(((final_width + 3) & 0x03) << 1);
|
3578
|
+
s_start = 6;
|
3579
|
+
s_end = 0;
|
3580
|
+
s_inc = -2;
|
3581
|
+
}
|
3582
|
+
|
3583
|
+
else
|
3584
|
+
#endif
|
3585
|
+
{
|
3586
|
+
sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
|
3587
|
+
dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
|
3588
|
+
s_start = 0;
|
3589
|
+
s_end = 6;
|
3590
|
+
s_inc = 2;
|
3591
|
+
}
|
3592
|
+
|
3593
|
+
for (i = 0; i < row_info->width; i++)
|
3594
|
+
{
|
3595
|
+
png_byte v;
|
3596
|
+
int j;
|
3597
|
+
|
3598
|
+
v = (png_byte)((*sp >> sshift) & 0x03);
|
3599
|
+
for (j = 0; j < jstop; j++)
|
3600
|
+
{
|
3601
|
+
unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));
|
3602
|
+
tmp |= v << dshift;
|
3603
|
+
*dp = (png_byte)(tmp & 0xff);
|
3604
|
+
|
3605
|
+
if (dshift == s_end)
|
3606
|
+
{
|
3607
|
+
dshift = s_start;
|
3608
|
+
dp--;
|
3609
|
+
}
|
3610
|
+
|
3611
|
+
else
|
3612
|
+
dshift += s_inc;
|
3613
|
+
}
|
3614
|
+
|
3615
|
+
if (sshift == s_end)
|
3616
|
+
{
|
3617
|
+
sshift = s_start;
|
3618
|
+
sp--;
|
3619
|
+
}
|
3620
|
+
|
3621
|
+
else
|
3622
|
+
sshift += s_inc;
|
3623
|
+
}
|
3624
|
+
break;
|
3625
|
+
}
|
3626
|
+
|
3627
|
+
case 4:
|
3628
|
+
{
|
3629
|
+
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
|
3630
|
+
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
|
3631
|
+
int sshift, dshift;
|
3632
|
+
int s_start, s_end, s_inc;
|
3633
|
+
png_uint_32 i;
|
3634
|
+
int jstop = png_pass_inc[pass];
|
3635
|
+
|
3636
|
+
#ifdef PNG_READ_PACKSWAP_SUPPORTED
|
3637
|
+
if ((transformations & PNG_PACKSWAP) != 0)
|
3638
|
+
{
|
3639
|
+
sshift = (int)(((row_info->width + 1) & 0x01) << 2);
|
3640
|
+
dshift = (int)(((final_width + 1) & 0x01) << 2);
|
3641
|
+
s_start = 4;
|
3642
|
+
s_end = 0;
|
3643
|
+
s_inc = -4;
|
3644
|
+
}
|
3645
|
+
|
3646
|
+
else
|
3647
|
+
#endif
|
3648
|
+
{
|
3649
|
+
sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
|
3650
|
+
dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
|
3651
|
+
s_start = 0;
|
3652
|
+
s_end = 4;
|
3653
|
+
s_inc = 4;
|
3654
|
+
}
|
3655
|
+
|
3656
|
+
for (i = 0; i < row_info->width; i++)
|
3657
|
+
{
|
3658
|
+
png_byte v = (png_byte)((*sp >> sshift) & 0x0f);
|
3659
|
+
int j;
|
3660
|
+
|
3661
|
+
for (j = 0; j < jstop; j++)
|
3662
|
+
{
|
3663
|
+
unsigned int tmp = *dp & (0xf0f >> (4 - dshift));
|
3664
|
+
tmp |= v << dshift;
|
3665
|
+
*dp = (png_byte)(tmp & 0xff);
|
3666
|
+
|
3667
|
+
if (dshift == s_end)
|
3668
|
+
{
|
3669
|
+
dshift = s_start;
|
3670
|
+
dp--;
|
3671
|
+
}
|
3672
|
+
|
3673
|
+
else
|
3674
|
+
dshift += s_inc;
|
3675
|
+
}
|
3676
|
+
|
3677
|
+
if (sshift == s_end)
|
3678
|
+
{
|
3679
|
+
sshift = s_start;
|
3680
|
+
sp--;
|
3681
|
+
}
|
3682
|
+
|
3683
|
+
else
|
3684
|
+
sshift += s_inc;
|
3685
|
+
}
|
3686
|
+
break;
|
3687
|
+
}
|
3688
|
+
|
3689
|
+
default:
|
3690
|
+
{
|
3691
|
+
png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
|
3692
|
+
|
3693
|
+
png_bytep sp = row + (png_size_t)(row_info->width - 1)
|
3694
|
+
* pixel_bytes;
|
3695
|
+
|
3696
|
+
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
3697
|
+
|
3698
|
+
int jstop = png_pass_inc[pass];
|
3699
|
+
png_uint_32 i;
|
3700
|
+
|
3701
|
+
for (i = 0; i < row_info->width; i++)
|
3702
|
+
{
|
3703
|
+
png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */
|
3704
|
+
int j;
|
3705
|
+
|
3706
|
+
memcpy(v, sp, pixel_bytes);
|
3707
|
+
|
3708
|
+
for (j = 0; j < jstop; j++)
|
3709
|
+
{
|
3710
|
+
memcpy(dp, v, pixel_bytes);
|
3711
|
+
dp -= pixel_bytes;
|
3712
|
+
}
|
3713
|
+
|
3714
|
+
sp -= pixel_bytes;
|
3715
|
+
}
|
3716
|
+
break;
|
3717
|
+
}
|
3718
|
+
}
|
3719
|
+
|
3720
|
+
row_info->width = final_width;
|
3721
|
+
row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
|
3722
|
+
}
|
3723
|
+
#ifndef PNG_READ_PACKSWAP_SUPPORTED
|
3724
|
+
PNG_UNUSED(transformations) /* Silence compiler warning */
|
3725
|
+
#endif
|
3726
|
+
}
|
3727
|
+
#endif /* READ_INTERLACING */
|
3728
|
+
|
3729
|
+
static void
|
3730
|
+
png_read_filter_row_sub(png_row_infop row_info, png_bytep row,
|
3731
|
+
png_const_bytep prev_row)
|
3732
|
+
{
|
3733
|
+
png_size_t i;
|
3734
|
+
png_size_t istop = row_info->rowbytes;
|
3735
|
+
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
|
3736
|
+
png_bytep rp = row + bpp;
|
3737
|
+
|
3738
|
+
PNG_UNUSED(prev_row)
|
3739
|
+
|
3740
|
+
for (i = bpp; i < istop; i++)
|
3741
|
+
{
|
3742
|
+
*rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);
|
3743
|
+
rp++;
|
3744
|
+
}
|
3745
|
+
}
|
3746
|
+
|
3747
|
+
static void
|
3748
|
+
png_read_filter_row_up(png_row_infop row_info, png_bytep row,
|
3749
|
+
png_const_bytep prev_row)
|
3750
|
+
{
|
3751
|
+
png_size_t i;
|
3752
|
+
png_size_t istop = row_info->rowbytes;
|
3753
|
+
png_bytep rp = row;
|
3754
|
+
png_const_bytep pp = prev_row;
|
3755
|
+
|
3756
|
+
for (i = 0; i < istop; i++)
|
3757
|
+
{
|
3758
|
+
*rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
|
3759
|
+
rp++;
|
3760
|
+
}
|
3761
|
+
}
|
3762
|
+
|
3763
|
+
static void
|
3764
|
+
png_read_filter_row_avg(png_row_infop row_info, png_bytep row,
|
3765
|
+
png_const_bytep prev_row)
|
3766
|
+
{
|
3767
|
+
png_size_t i;
|
3768
|
+
png_bytep rp = row;
|
3769
|
+
png_const_bytep pp = prev_row;
|
3770
|
+
unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
|
3771
|
+
png_size_t istop = row_info->rowbytes - bpp;
|
3772
|
+
|
3773
|
+
for (i = 0; i < bpp; i++)
|
3774
|
+
{
|
3775
|
+
*rp = (png_byte)(((int)(*rp) +
|
3776
|
+
((int)(*pp++) / 2 )) & 0xff);
|
3777
|
+
|
3778
|
+
rp++;
|
3779
|
+
}
|
3780
|
+
|
3781
|
+
for (i = 0; i < istop; i++)
|
3782
|
+
{
|
3783
|
+
*rp = (png_byte)(((int)(*rp) +
|
3784
|
+
(int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);
|
3785
|
+
|
3786
|
+
rp++;
|
3787
|
+
}
|
3788
|
+
}
|
3789
|
+
|
3790
|
+
static void
|
3791
|
+
png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,
|
3792
|
+
png_const_bytep prev_row)
|
3793
|
+
{
|
3794
|
+
png_bytep rp_end = row + row_info->rowbytes;
|
3795
|
+
int a, c;
|
3796
|
+
|
3797
|
+
/* First pixel/byte */
|
3798
|
+
c = *prev_row++;
|
3799
|
+
a = *row + c;
|
3800
|
+
*row++ = (png_byte)a;
|
3801
|
+
|
3802
|
+
/* Remainder */
|
3803
|
+
while (row < rp_end)
|
3804
|
+
{
|
3805
|
+
int b, pa, pb, pc, p;
|
3806
|
+
|
3807
|
+
a &= 0xff; /* From previous iteration or start */
|
3808
|
+
b = *prev_row++;
|
3809
|
+
|
3810
|
+
p = b - c;
|
3811
|
+
pc = a - c;
|
3812
|
+
|
3813
|
+
# ifdef PNG_USE_ABS
|
3814
|
+
pa = abs(p);
|
3815
|
+
pb = abs(pc);
|
3816
|
+
pc = abs(p + pc);
|
3817
|
+
# else
|
3818
|
+
pa = p < 0 ? -p : p;
|
3819
|
+
pb = pc < 0 ? -pc : pc;
|
3820
|
+
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
3821
|
+
# endif
|
3822
|
+
|
3823
|
+
/* Find the best predictor, the least of pa, pb, pc favoring the earlier
|
3824
|
+
* ones in the case of a tie.
|
3825
|
+
*/
|
3826
|
+
if (pb < pa) pa = pb, a = b;
|
3827
|
+
if (pc < pa) a = c;
|
3828
|
+
|
3829
|
+
/* Calculate the current pixel in a, and move the previous row pixel to c
|
3830
|
+
* for the next time round the loop
|
3831
|
+
*/
|
3832
|
+
c = b;
|
3833
|
+
a += *row;
|
3834
|
+
*row++ = (png_byte)a;
|
3835
|
+
}
|
3836
|
+
}
|
3837
|
+
|
3838
|
+
static void
|
3839
|
+
png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,
|
3840
|
+
png_const_bytep prev_row)
|
3841
|
+
{
|
3842
|
+
int bpp = (row_info->pixel_depth + 7) >> 3;
|
3843
|
+
png_bytep rp_end = row + bpp;
|
3844
|
+
|
3845
|
+
/* Process the first pixel in the row completely (this is the same as 'up'
|
3846
|
+
* because there is only one candidate predictor for the first row).
|
3847
|
+
*/
|
3848
|
+
while (row < rp_end)
|
3849
|
+
{
|
3850
|
+
int a = *row + *prev_row++;
|
3851
|
+
*row++ = (png_byte)a;
|
3852
|
+
}
|
3853
|
+
|
3854
|
+
/* Remainder */
|
3855
|
+
rp_end += row_info->rowbytes - bpp;
|
3856
|
+
|
3857
|
+
while (row < rp_end)
|
3858
|
+
{
|
3859
|
+
int a, b, c, pa, pb, pc, p;
|
3860
|
+
|
3861
|
+
c = *(prev_row - bpp);
|
3862
|
+
a = *(row - bpp);
|
3863
|
+
b = *prev_row++;
|
3864
|
+
|
3865
|
+
p = b - c;
|
3866
|
+
pc = a - c;
|
3867
|
+
|
3868
|
+
# ifdef PNG_USE_ABS
|
3869
|
+
pa = abs(p);
|
3870
|
+
pb = abs(pc);
|
3871
|
+
pc = abs(p + pc);
|
3872
|
+
# else
|
3873
|
+
pa = p < 0 ? -p : p;
|
3874
|
+
pb = pc < 0 ? -pc : pc;
|
3875
|
+
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
3876
|
+
# endif
|
3877
|
+
|
3878
|
+
if (pb < pa) pa = pb, a = b;
|
3879
|
+
if (pc < pa) a = c;
|
3880
|
+
|
3881
|
+
a += *row;
|
3882
|
+
*row++ = (png_byte)a;
|
3883
|
+
}
|
3884
|
+
}
|
3885
|
+
|
3886
|
+
static void
|
3887
|
+
png_init_filter_functions(png_structrp pp)
|
3888
|
+
/* This function is called once for every PNG image (except for PNG images
|
3889
|
+
* that only use PNG_FILTER_VALUE_NONE for all rows) to set the
|
3890
|
+
* implementations required to reverse the filtering of PNG rows. Reversing
|
3891
|
+
* the filter is the first transformation performed on the row data. It is
|
3892
|
+
* performed in place, therefore an implementation can be selected based on
|
3893
|
+
* the image pixel format. If the implementation depends on image width then
|
3894
|
+
* take care to ensure that it works correctly if the image is interlaced -
|
3895
|
+
* interlacing causes the actual row width to vary.
|
3896
|
+
*/
|
3897
|
+
{
|
3898
|
+
unsigned int bpp = (pp->pixel_depth + 7) >> 3;
|
3899
|
+
|
3900
|
+
pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub;
|
3901
|
+
pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up;
|
3902
|
+
pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg;
|
3903
|
+
if (bpp == 1)
|
3904
|
+
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
3905
|
+
png_read_filter_row_paeth_1byte_pixel;
|
3906
|
+
else
|
3907
|
+
pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
|
3908
|
+
png_read_filter_row_paeth_multibyte_pixel;
|
3909
|
+
|
3910
|
+
#ifdef PNG_FILTER_OPTIMIZATIONS
|
3911
|
+
/* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to
|
3912
|
+
* call to install hardware optimizations for the above functions; simply
|
3913
|
+
* replace whatever elements of the pp->read_filter[] array with a hardware
|
3914
|
+
* specific (or, for that matter, generic) optimization.
|
3915
|
+
*
|
3916
|
+
* To see an example of this examine what configure.ac does when
|
3917
|
+
* --enable-arm-neon is specified on the command line.
|
3918
|
+
*/
|
3919
|
+
PNG_FILTER_OPTIMIZATIONS(pp, bpp);
|
3920
|
+
#endif
|
3921
|
+
}
|
3922
|
+
|
3923
|
+
void /* PRIVATE */
|
3924
|
+
png_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,
|
3925
|
+
png_const_bytep prev_row, int filter)
|
3926
|
+
{
|
3927
|
+
/* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define
|
3928
|
+
* PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic
|
3929
|
+
* implementations. See png_init_filter_functions above.
|
3930
|
+
*/
|
3931
|
+
if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)
|
3932
|
+
{
|
3933
|
+
if (pp->read_filter[0] == NULL)
|
3934
|
+
png_init_filter_functions(pp);
|
3935
|
+
|
3936
|
+
pp->read_filter[filter-1](row_info, row, prev_row);
|
3937
|
+
}
|
3938
|
+
}
|
3939
|
+
|
3940
|
+
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
3941
|
+
void /* PRIVATE */
|
3942
|
+
png_read_IDAT_data(png_structrp png_ptr, png_bytep output,
|
3943
|
+
png_alloc_size_t avail_out)
|
3944
|
+
{
|
3945
|
+
/* Loop reading IDATs and decompressing the result into output[avail_out] */
|
3946
|
+
png_ptr->zstream.next_out = output;
|
3947
|
+
png_ptr->zstream.avail_out = 0; /* safety: set below */
|
3948
|
+
|
3949
|
+
if (output == NULL)
|
3950
|
+
avail_out = 0;
|
3951
|
+
|
3952
|
+
do
|
3953
|
+
{
|
3954
|
+
int ret;
|
3955
|
+
png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];
|
3956
|
+
|
3957
|
+
if (png_ptr->zstream.avail_in == 0)
|
3958
|
+
{
|
3959
|
+
uInt avail_in;
|
3960
|
+
png_bytep buffer;
|
3961
|
+
|
3962
|
+
while (png_ptr->idat_size == 0)
|
3963
|
+
{
|
3964
|
+
png_crc_finish(png_ptr, 0);
|
3965
|
+
|
3966
|
+
png_ptr->idat_size = png_read_chunk_header(png_ptr);
|
3967
|
+
/* This is an error even in the 'check' case because the code just
|
3968
|
+
* consumed a non-IDAT header.
|
3969
|
+
*/
|
3970
|
+
if (png_ptr->chunk_name != png_IDAT)
|
3971
|
+
png_error(png_ptr, "Not enough image data");
|
3972
|
+
}
|
3973
|
+
|
3974
|
+
avail_in = png_ptr->IDAT_read_size;
|
3975
|
+
|
3976
|
+
if (avail_in > png_ptr->idat_size)
|
3977
|
+
avail_in = (uInt)png_ptr->idat_size;
|
3978
|
+
|
3979
|
+
/* A PNG with a gradually increasing IDAT size will defeat this attempt
|
3980
|
+
* to minimize memory usage by causing lots of re-allocs, but
|
3981
|
+
* realistically doing IDAT_read_size re-allocs is not likely to be a
|
3982
|
+
* big problem.
|
3983
|
+
*/
|
3984
|
+
buffer = png_read_buffer(png_ptr, avail_in, 0/*error*/);
|
3985
|
+
|
3986
|
+
png_crc_read(png_ptr, buffer, avail_in);
|
3987
|
+
png_ptr->idat_size -= avail_in;
|
3988
|
+
|
3989
|
+
png_ptr->zstream.next_in = buffer;
|
3990
|
+
png_ptr->zstream.avail_in = avail_in;
|
3991
|
+
}
|
3992
|
+
|
3993
|
+
/* And set up the output side. */
|
3994
|
+
if (output != NULL) /* standard read */
|
3995
|
+
{
|
3996
|
+
uInt out = ZLIB_IO_MAX;
|
3997
|
+
|
3998
|
+
if (out > avail_out)
|
3999
|
+
out = (uInt)avail_out;
|
4000
|
+
|
4001
|
+
avail_out -= out;
|
4002
|
+
png_ptr->zstream.avail_out = out;
|
4003
|
+
}
|
4004
|
+
|
4005
|
+
else /* after last row, checking for end */
|
4006
|
+
{
|
4007
|
+
png_ptr->zstream.next_out = tmpbuf;
|
4008
|
+
png_ptr->zstream.avail_out = (sizeof tmpbuf);
|
4009
|
+
}
|
4010
|
+
|
4011
|
+
/* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the
|
4012
|
+
* process. If the LZ stream is truncated the sequential reader will
|
4013
|
+
* terminally damage the stream, above, by reading the chunk header of the
|
4014
|
+
* following chunk (it then exits with png_error).
|
4015
|
+
*
|
4016
|
+
* TODO: deal more elegantly with truncated IDAT lists.
|
4017
|
+
*/
|
4018
|
+
ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
|
4019
|
+
|
4020
|
+
/* Take the unconsumed output back. */
|
4021
|
+
if (output != NULL)
|
4022
|
+
avail_out += png_ptr->zstream.avail_out;
|
4023
|
+
|
4024
|
+
else /* avail_out counts the extra bytes */
|
4025
|
+
avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;
|
4026
|
+
|
4027
|
+
png_ptr->zstream.avail_out = 0;
|
4028
|
+
|
4029
|
+
if (ret == Z_STREAM_END)
|
4030
|
+
{
|
4031
|
+
/* Do this for safety; we won't read any more into this row. */
|
4032
|
+
png_ptr->zstream.next_out = NULL;
|
4033
|
+
|
4034
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
4035
|
+
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
|
4036
|
+
|
4037
|
+
if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)
|
4038
|
+
png_chunk_benign_error(png_ptr, "Extra compressed data");
|
4039
|
+
break;
|
4040
|
+
}
|
4041
|
+
|
4042
|
+
if (ret != Z_OK)
|
4043
|
+
{
|
4044
|
+
png_zstream_error(png_ptr, ret);
|
4045
|
+
|
4046
|
+
if (output != NULL)
|
4047
|
+
png_chunk_error(png_ptr, png_ptr->zstream.msg);
|
4048
|
+
|
4049
|
+
else /* checking */
|
4050
|
+
{
|
4051
|
+
png_chunk_benign_error(png_ptr, png_ptr->zstream.msg);
|
4052
|
+
return;
|
4053
|
+
}
|
4054
|
+
}
|
4055
|
+
} while (avail_out > 0);
|
4056
|
+
|
4057
|
+
if (avail_out > 0)
|
4058
|
+
{
|
4059
|
+
/* The stream ended before the image; this is the same as too few IDATs so
|
4060
|
+
* should be handled the same way.
|
4061
|
+
*/
|
4062
|
+
if (output != NULL)
|
4063
|
+
png_error(png_ptr, "Not enough image data");
|
4064
|
+
|
4065
|
+
else /* the deflate stream contained extra data */
|
4066
|
+
png_chunk_benign_error(png_ptr, "Too much image data");
|
4067
|
+
}
|
4068
|
+
}
|
4069
|
+
|
4070
|
+
void /* PRIVATE */
|
4071
|
+
png_read_finish_IDAT(png_structrp png_ptr)
|
4072
|
+
{
|
4073
|
+
/* We don't need any more data and the stream should have ended, however the
|
4074
|
+
* LZ end code may actually not have been processed. In this case we must
|
4075
|
+
* read it otherwise stray unread IDAT data or, more likely, an IDAT chunk
|
4076
|
+
* may still remain to be consumed.
|
4077
|
+
*/
|
4078
|
+
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
4079
|
+
{
|
4080
|
+
/* The NULL causes png_read_IDAT_data to swallow any remaining bytes in
|
4081
|
+
* the compressed stream, but the stream may be damaged too, so even after
|
4082
|
+
* this call we may need to terminate the zstream ownership.
|
4083
|
+
*/
|
4084
|
+
png_read_IDAT_data(png_ptr, NULL, 0);
|
4085
|
+
png_ptr->zstream.next_out = NULL; /* safety */
|
4086
|
+
|
4087
|
+
/* Now clear everything out for safety; the following may not have been
|
4088
|
+
* done.
|
4089
|
+
*/
|
4090
|
+
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
4091
|
+
{
|
4092
|
+
png_ptr->mode |= PNG_AFTER_IDAT;
|
4093
|
+
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
|
4094
|
+
}
|
4095
|
+
}
|
4096
|
+
|
4097
|
+
/* If the zstream has not been released do it now *and* terminate the reading
|
4098
|
+
* of the final IDAT chunk.
|
4099
|
+
*/
|
4100
|
+
if (png_ptr->zowner == png_IDAT)
|
4101
|
+
{
|
4102
|
+
/* Always do this; the pointers otherwise point into the read buffer. */
|
4103
|
+
png_ptr->zstream.next_in = NULL;
|
4104
|
+
png_ptr->zstream.avail_in = 0;
|
4105
|
+
|
4106
|
+
/* Now we no longer own the zstream. */
|
4107
|
+
png_ptr->zowner = 0;
|
4108
|
+
|
4109
|
+
/* The slightly weird semantics of the sequential IDAT reading is that we
|
4110
|
+
* are always in or at the end of an IDAT chunk, so we always need to do a
|
4111
|
+
* crc_finish here. If idat_size is non-zero we also need to read the
|
4112
|
+
* spurious bytes at the end of the chunk now.
|
4113
|
+
*/
|
4114
|
+
(void)png_crc_finish(png_ptr, png_ptr->idat_size);
|
4115
|
+
}
|
4116
|
+
}
|
4117
|
+
|
4118
|
+
void /* PRIVATE */
|
4119
|
+
png_read_finish_row(png_structrp png_ptr)
|
4120
|
+
{
|
4121
|
+
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
4122
|
+
|
4123
|
+
/* Start of interlace block */
|
4124
|
+
static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
4125
|
+
|
4126
|
+
/* Offset to next interlace block */
|
4127
|
+
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
4128
|
+
|
4129
|
+
/* Start of interlace block in the y direction */
|
4130
|
+
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
4131
|
+
|
4132
|
+
/* Offset to next interlace block in the y direction */
|
4133
|
+
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
4134
|
+
|
4135
|
+
png_debug(1, "in png_read_finish_row");
|
4136
|
+
png_ptr->row_number++;
|
4137
|
+
if (png_ptr->row_number < png_ptr->num_rows)
|
4138
|
+
return;
|
4139
|
+
|
4140
|
+
if (png_ptr->interlaced != 0)
|
4141
|
+
{
|
4142
|
+
png_ptr->row_number = 0;
|
4143
|
+
|
4144
|
+
/* TO DO: don't do this if prev_row isn't needed (requires
|
4145
|
+
* read-ahead of the next row's filter byte.
|
4146
|
+
*/
|
4147
|
+
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
|
4148
|
+
|
4149
|
+
do
|
4150
|
+
{
|
4151
|
+
png_ptr->pass++;
|
4152
|
+
|
4153
|
+
if (png_ptr->pass >= 7)
|
4154
|
+
break;
|
4155
|
+
|
4156
|
+
png_ptr->iwidth = (png_ptr->width +
|
4157
|
+
png_pass_inc[png_ptr->pass] - 1 -
|
4158
|
+
png_pass_start[png_ptr->pass]) /
|
4159
|
+
png_pass_inc[png_ptr->pass];
|
4160
|
+
|
4161
|
+
if ((png_ptr->transformations & PNG_INTERLACE) == 0)
|
4162
|
+
{
|
4163
|
+
png_ptr->num_rows = (png_ptr->height +
|
4164
|
+
png_pass_yinc[png_ptr->pass] - 1 -
|
4165
|
+
png_pass_ystart[png_ptr->pass]) /
|
4166
|
+
png_pass_yinc[png_ptr->pass];
|
4167
|
+
}
|
4168
|
+
|
4169
|
+
else /* if (png_ptr->transformations & PNG_INTERLACE) */
|
4170
|
+
break; /* libpng deinterlacing sees every row */
|
4171
|
+
|
4172
|
+
} while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
|
4173
|
+
|
4174
|
+
if (png_ptr->pass < 7)
|
4175
|
+
return;
|
4176
|
+
}
|
4177
|
+
|
4178
|
+
/* Here after at the end of the last row of the last pass. */
|
4179
|
+
png_read_finish_IDAT(png_ptr);
|
4180
|
+
}
|
4181
|
+
#endif /* SEQUENTIAL_READ */
|
4182
|
+
|
4183
|
+
void /* PRIVATE */
|
4184
|
+
png_read_start_row(png_structrp png_ptr)
|
4185
|
+
{
|
4186
|
+
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
4187
|
+
|
4188
|
+
/* Start of interlace block */
|
4189
|
+
static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
4190
|
+
|
4191
|
+
/* Offset to next interlace block */
|
4192
|
+
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
4193
|
+
|
4194
|
+
/* Start of interlace block in the y direction */
|
4195
|
+
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
4196
|
+
|
4197
|
+
/* Offset to next interlace block in the y direction */
|
4198
|
+
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
4199
|
+
|
4200
|
+
int max_pixel_depth;
|
4201
|
+
png_size_t row_bytes;
|
4202
|
+
|
4203
|
+
png_debug(1, "in png_read_start_row");
|
4204
|
+
|
4205
|
+
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
4206
|
+
png_init_read_transformations(png_ptr);
|
4207
|
+
#endif
|
4208
|
+
if (png_ptr->interlaced != 0)
|
4209
|
+
{
|
4210
|
+
if ((png_ptr->transformations & PNG_INTERLACE) == 0)
|
4211
|
+
png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
|
4212
|
+
png_pass_ystart[0]) / png_pass_yinc[0];
|
4213
|
+
|
4214
|
+
else
|
4215
|
+
png_ptr->num_rows = png_ptr->height;
|
4216
|
+
|
4217
|
+
png_ptr->iwidth = (png_ptr->width +
|
4218
|
+
png_pass_inc[png_ptr->pass] - 1 -
|
4219
|
+
png_pass_start[png_ptr->pass]) /
|
4220
|
+
png_pass_inc[png_ptr->pass];
|
4221
|
+
}
|
4222
|
+
|
4223
|
+
else
|
4224
|
+
{
|
4225
|
+
png_ptr->num_rows = png_ptr->height;
|
4226
|
+
png_ptr->iwidth = png_ptr->width;
|
4227
|
+
}
|
4228
|
+
|
4229
|
+
max_pixel_depth = png_ptr->pixel_depth;
|
4230
|
+
|
4231
|
+
/* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of
|
4232
|
+
* calculations to calculate the final pixel depth, then
|
4233
|
+
* png_do_read_transforms actually does the transforms. This means that the
|
4234
|
+
* code which effectively calculates this value is actually repeated in three
|
4235
|
+
* separate places. They must all match. Innocent changes to the order of
|
4236
|
+
* transformations can and will break libpng in a way that causes memory
|
4237
|
+
* overwrites.
|
4238
|
+
*
|
4239
|
+
* TODO: fix this.
|
4240
|
+
*/
|
4241
|
+
#ifdef PNG_READ_PACK_SUPPORTED
|
4242
|
+
if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8)
|
4243
|
+
max_pixel_depth = 8;
|
4244
|
+
#endif
|
4245
|
+
|
4246
|
+
#ifdef PNG_READ_EXPAND_SUPPORTED
|
4247
|
+
if ((png_ptr->transformations & PNG_EXPAND) != 0)
|
4248
|
+
{
|
4249
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
4250
|
+
{
|
4251
|
+
if (png_ptr->num_trans != 0)
|
4252
|
+
max_pixel_depth = 32;
|
4253
|
+
|
4254
|
+
else
|
4255
|
+
max_pixel_depth = 24;
|
4256
|
+
}
|
4257
|
+
|
4258
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
|
4259
|
+
{
|
4260
|
+
if (max_pixel_depth < 8)
|
4261
|
+
max_pixel_depth = 8;
|
4262
|
+
|
4263
|
+
if (png_ptr->num_trans != 0)
|
4264
|
+
max_pixel_depth *= 2;
|
4265
|
+
}
|
4266
|
+
|
4267
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
4268
|
+
{
|
4269
|
+
if (png_ptr->num_trans != 0)
|
4270
|
+
{
|
4271
|
+
max_pixel_depth *= 4;
|
4272
|
+
max_pixel_depth /= 3;
|
4273
|
+
}
|
4274
|
+
}
|
4275
|
+
}
|
4276
|
+
#endif
|
4277
|
+
|
4278
|
+
#ifdef PNG_READ_EXPAND_16_SUPPORTED
|
4279
|
+
if ((png_ptr->transformations & PNG_EXPAND_16) != 0)
|
4280
|
+
{
|
4281
|
+
# ifdef PNG_READ_EXPAND_SUPPORTED
|
4282
|
+
/* In fact it is an error if it isn't supported, but checking is
|
4283
|
+
* the safe way.
|
4284
|
+
*/
|
4285
|
+
if ((png_ptr->transformations & PNG_EXPAND) != 0)
|
4286
|
+
{
|
4287
|
+
if (png_ptr->bit_depth < 16)
|
4288
|
+
max_pixel_depth *= 2;
|
4289
|
+
}
|
4290
|
+
else
|
4291
|
+
# endif
|
4292
|
+
png_ptr->transformations &= ~PNG_EXPAND_16;
|
4293
|
+
}
|
4294
|
+
#endif
|
4295
|
+
|
4296
|
+
#ifdef PNG_READ_FILLER_SUPPORTED
|
4297
|
+
if ((png_ptr->transformations & (PNG_FILLER)) != 0)
|
4298
|
+
{
|
4299
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
|
4300
|
+
{
|
4301
|
+
if (max_pixel_depth <= 8)
|
4302
|
+
max_pixel_depth = 16;
|
4303
|
+
|
4304
|
+
else
|
4305
|
+
max_pixel_depth = 32;
|
4306
|
+
}
|
4307
|
+
|
4308
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB ||
|
4309
|
+
png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
4310
|
+
{
|
4311
|
+
if (max_pixel_depth <= 32)
|
4312
|
+
max_pixel_depth = 32;
|
4313
|
+
|
4314
|
+
else
|
4315
|
+
max_pixel_depth = 64;
|
4316
|
+
}
|
4317
|
+
}
|
4318
|
+
#endif
|
4319
|
+
|
4320
|
+
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
|
4321
|
+
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)
|
4322
|
+
{
|
4323
|
+
if (
|
4324
|
+
#ifdef PNG_READ_EXPAND_SUPPORTED
|
4325
|
+
(png_ptr->num_trans != 0 &&
|
4326
|
+
(png_ptr->transformations & PNG_EXPAND) != 0) ||
|
4327
|
+
#endif
|
4328
|
+
#ifdef PNG_READ_FILLER_SUPPORTED
|
4329
|
+
(png_ptr->transformations & (PNG_FILLER)) != 0 ||
|
4330
|
+
#endif
|
4331
|
+
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
4332
|
+
{
|
4333
|
+
if (max_pixel_depth <= 16)
|
4334
|
+
max_pixel_depth = 32;
|
4335
|
+
|
4336
|
+
else
|
4337
|
+
max_pixel_depth = 64;
|
4338
|
+
}
|
4339
|
+
|
4340
|
+
else
|
4341
|
+
{
|
4342
|
+
if (max_pixel_depth <= 8)
|
4343
|
+
{
|
4344
|
+
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
4345
|
+
max_pixel_depth = 32;
|
4346
|
+
|
4347
|
+
else
|
4348
|
+
max_pixel_depth = 24;
|
4349
|
+
}
|
4350
|
+
|
4351
|
+
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
4352
|
+
max_pixel_depth = 64;
|
4353
|
+
|
4354
|
+
else
|
4355
|
+
max_pixel_depth = 48;
|
4356
|
+
}
|
4357
|
+
}
|
4358
|
+
#endif
|
4359
|
+
|
4360
|
+
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
|
4361
|
+
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
4362
|
+
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
4363
|
+
{
|
4364
|
+
int user_pixel_depth = png_ptr->user_transform_depth *
|
4365
|
+
png_ptr->user_transform_channels;
|
4366
|
+
|
4367
|
+
if (user_pixel_depth > max_pixel_depth)
|
4368
|
+
max_pixel_depth = user_pixel_depth;
|
4369
|
+
}
|
4370
|
+
#endif
|
4371
|
+
|
4372
|
+
/* This value is stored in png_struct and double checked in the row read
|
4373
|
+
* code.
|
4374
|
+
*/
|
4375
|
+
png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;
|
4376
|
+
png_ptr->transformed_pixel_depth = 0; /* calculated on demand */
|
4377
|
+
|
4378
|
+
/* Align the width on the next larger 8 pixels. Mainly used
|
4379
|
+
* for interlacing
|
4380
|
+
*/
|
4381
|
+
row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
|
4382
|
+
/* Calculate the maximum bytes needed, adding a byte and a pixel
|
4383
|
+
* for safety's sake
|
4384
|
+
*/
|
4385
|
+
row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
|
4386
|
+
1 + ((max_pixel_depth + 7) >> 3);
|
4387
|
+
|
4388
|
+
#ifdef PNG_MAX_MALLOC_64K
|
4389
|
+
if (row_bytes > (png_uint_32)65536L)
|
4390
|
+
png_error(png_ptr, "This image requires a row greater than 64KB");
|
4391
|
+
#endif
|
4392
|
+
|
4393
|
+
if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
|
4394
|
+
{
|
4395
|
+
png_free(png_ptr, png_ptr->big_row_buf);
|
4396
|
+
png_free(png_ptr, png_ptr->big_prev_row);
|
4397
|
+
|
4398
|
+
if (png_ptr->interlaced != 0)
|
4399
|
+
png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
|
4400
|
+
row_bytes + 48);
|
4401
|
+
|
4402
|
+
else
|
4403
|
+
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
4404
|
+
|
4405
|
+
png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);
|
4406
|
+
|
4407
|
+
#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
|
4408
|
+
/* Use 16-byte aligned memory for row_buf with at least 16 bytes
|
4409
|
+
* of padding before and after row_buf; treat prev_row similarly.
|
4410
|
+
* NOTE: the alignment is to the start of the pixels, one beyond the start
|
4411
|
+
* of the buffer, because of the filter byte. Prior to libpng 1.5.6 this
|
4412
|
+
* was incorrect; the filter byte was aligned, which had the exact
|
4413
|
+
* opposite effect of that intended.
|
4414
|
+
*/
|
4415
|
+
{
|
4416
|
+
png_bytep temp = png_ptr->big_row_buf + 32;
|
4417
|
+
int extra = (int)((temp - (png_bytep)0) & 0x0f);
|
4418
|
+
png_ptr->row_buf = temp - extra - 1/*filter byte*/;
|
4419
|
+
|
4420
|
+
temp = png_ptr->big_prev_row + 32;
|
4421
|
+
extra = (int)((temp - (png_bytep)0) & 0x0f);
|
4422
|
+
png_ptr->prev_row = temp - extra - 1/*filter byte*/;
|
4423
|
+
}
|
4424
|
+
|
4425
|
+
#else
|
4426
|
+
/* Use 31 bytes of padding before and 17 bytes after row_buf. */
|
4427
|
+
png_ptr->row_buf = png_ptr->big_row_buf + 31;
|
4428
|
+
png_ptr->prev_row = png_ptr->big_prev_row + 31;
|
4429
|
+
#endif
|
4430
|
+
png_ptr->old_big_row_buf_size = row_bytes + 48;
|
4431
|
+
}
|
4432
|
+
|
4433
|
+
#ifdef PNG_MAX_MALLOC_64K
|
4434
|
+
if (png_ptr->rowbytes > 65535)
|
4435
|
+
png_error(png_ptr, "This image requires a row greater than 64KB");
|
4436
|
+
|
4437
|
+
#endif
|
4438
|
+
if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))
|
4439
|
+
png_error(png_ptr, "Row has too many bytes to allocate in memory");
|
4440
|
+
|
4441
|
+
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
|
4442
|
+
|
4443
|
+
png_debug1(3, "width = %u,", png_ptr->width);
|
4444
|
+
png_debug1(3, "height = %u,", png_ptr->height);
|
4445
|
+
png_debug1(3, "iwidth = %u,", png_ptr->iwidth);
|
4446
|
+
png_debug1(3, "num_rows = %u,", png_ptr->num_rows);
|
4447
|
+
png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes);
|
4448
|
+
png_debug1(3, "irowbytes = %lu",
|
4449
|
+
(unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
|
4450
|
+
|
4451
|
+
/* The sequential reader needs a buffer for IDAT, but the progressive reader
|
4452
|
+
* does not, so free the read buffer now regardless; the sequential reader
|
4453
|
+
* reallocates it on demand.
|
4454
|
+
*/
|
4455
|
+
if (png_ptr->read_buffer != 0)
|
4456
|
+
{
|
4457
|
+
png_bytep buffer = png_ptr->read_buffer;
|
4458
|
+
|
4459
|
+
png_ptr->read_buffer_size = 0;
|
4460
|
+
png_ptr->read_buffer = NULL;
|
4461
|
+
png_free(png_ptr, buffer);
|
4462
|
+
}
|
4463
|
+
|
4464
|
+
/* Finally claim the zstream for the inflate of the IDAT data, use the bits
|
4465
|
+
* value from the stream (note that this will result in a fatal error if the
|
4466
|
+
* IDAT stream has a bogus deflate header window_bits value, but this should
|
4467
|
+
* not be happening any longer!)
|
4468
|
+
*/
|
4469
|
+
if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK)
|
4470
|
+
png_error(png_ptr, png_ptr->zstream.msg);
|
4471
|
+
|
4472
|
+
png_ptr->flags |= PNG_FLAG_ROW_INIT;
|
4473
|
+
}
|
4474
|
+
#endif /* READ */
|